carto: add drawLayer method
This commit is contained in:
parent
6673467117
commit
561f9a8164
1 changed files with 14 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue