carto: add createLayer and removeLayer methods
This commit is contained in:
parent
c6a28d1444
commit
6673467117
1 changed files with 19 additions and 0 deletions
|
@ -1,5 +1,24 @@
|
||||||
const LON = '2.428462';
|
const LON = '2.428462';
|
||||||
const LAT = '46.538192';
|
const LAT = '46.538192';
|
||||||
const DEFAULT_POSITION = { lon: LON, lat: LAT, zoom: 5 };
|
const DEFAULT_POSITION = { lon: LON, lat: LAT, zoom: 5 };
|
||||||
|
import L from 'leaflet';
|
||||||
|
|
||||||
export { DEFAULT_POSITION, LAT, LON };
|
export { DEFAULT_POSITION, LAT, LON };
|
||||||
|
const LAYERS = {};
|
||||||
|
|
||||||
|
function createLayer(map, layerName) {
|
||||||
|
const layer = (LAYERS[layerName] = new L.GeoJSON(undefined, {
|
||||||
|
interactive: false
|
||||||
|
}));
|
||||||
|
layer.addTo(map);
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeLayer(map, layerName) {
|
||||||
|
const layer = LAYERS[layerName];
|
||||||
|
|
||||||
|
if (layer) {
|
||||||
|
delete LAYERS[layerName];
|
||||||
|
map.removeLayer(layer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue