2018-10-03 10:39:35 +02:00
|
|
|
const LON = '2.428462';
|
|
|
|
const LAT = '46.538192';
|
|
|
|
const DEFAULT_POSITION = { lon: LON, lat: LAT, zoom: 5 };
|
2018-10-13 10:32:44 +02:00
|
|
|
import L from 'leaflet';
|
2018-10-03 10:39:35 +02:00
|
|
|
|
|
|
|
export { DEFAULT_POSITION, LAT, LON };
|
2018-10-13 10:32:44 +02:00
|
|
|
const LAYERS = {};
|
|
|
|
|
2018-10-13 10:33:23 +02:00
|
|
|
export function drawLayer(map, data, style, layerName = 'default') {
|
|
|
|
removeLayer(map, layerName);
|
|
|
|
|
|
|
|
if (Array.isArray(data) && data.length > 0) {
|
|
|
|
const layer = createLayer(map, layerName);
|
|
|
|
|
|
|
|
data.forEach(function(item) {
|
|
|
|
layer.addData(item.geometry);
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.setStyle(style).addTo(map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-13 10:32:44 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|