carto: add drawLayer method

This commit is contained in:
Paul Chavard 2018-10-13 10:33:23 +02:00
parent 6673467117
commit 561f9a8164

View file

@ -6,6 +6,20 @@ import L from 'leaflet';
export { DEFAULT_POSITION, LAT, LON };
const LAYERS = {};
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);
}
}
function createLayer(map, layerName) {
const layer = (LAYERS[layerName] = new L.GeoJSON(undefined, {
interactive: false