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 };
|
export { DEFAULT_POSITION, LAT, LON };
|
||||||
const LAYERS = {};
|
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) {
|
function createLayer(map, layerName) {
|
||||||
const layer = (LAYERS[layerName] = new L.GeoJSON(undefined, {
|
const layer = (LAYERS[layerName] = new L.GeoJSON(undefined, {
|
||||||
interactive: false
|
interactive: false
|
||||||
|
|
Loading…
Add table
Reference in a new issue