I have one array of places which i am displaying in in a table and also in Map. I am displaying marker and one of either circle or polygon for each element in table. When i select ant element from table marker icon changes for that particular element. I also have one slider to change the radius of circles for every element. All this is happening successfully but i want to separate marker, circle and polygon layer separately and then group them using layerGroup so that when i change radius i only update circle layer(right now i have to reset layer and update marker, polygon and circle). Same way if i select any element in table then i should need to update only marker layer and not all three. I have tried to group layers like this:
updateLayers(layerData) {
this.marker = [];
for (const ld of layerData) {
this.marker.push(
marker([ld['latitude'], ld['longitude']], {
icon: icon({
iconSize: [20, 32],
iconAnchor: [10, 16],
iconUrl: this.selectedPlaces.indexOf(ld) !== -1 ? this.iconEnablelink : this.iconDisableLink
})
}),
// ld['geofence_type'] && ld['geofence_type'] == 'POLYGON' ? polygon([ld['geofence']['coordinates'][0][0]]) : circle([ld['latitude'], ld['longitude']], { radius: this.radius }),
);
}
console.log('lg', layerGroup([this.marker]));
this.layers = layerGroup([this.marker]);
}
Response is some this:
options: {}
_initHooksCalled: true
_layers: {45: Array(25)}
__proto__: NewClass
I am getting following error: "Error trying to diff '[object Object]'. Only arrays and iterables are allowed"
Is there any way to implement this efficiently.
Edit: Below is working code. Everytime i click on a checkbox i add or remove that element to selectedPlaces
. Then i call this function. Even on slider change i have to call this function again and again. I am using marker, polygon and slider in the layers but i want to separate layers in three parts so that when i select any element i update only marker (if possible then marker for that particular element) and not all circles and polygons. If i update radius using slider then i should be able to update only circles without modifying markers and polygons.
updateLayers(layerData) {
this.layers = [];
for (const ld of layerData) {
this.layers.push(
marker([ld['latitude'], ld['longitude']], {
icon: icon({
iconSize: [20, 32],
iconAnchor: [10, 16],
iconUrl: this.selectedPlaces.indexOf(ld) !== -1 ? this.iconEnablelink : this.iconDisableLink
})
}),
ld['geofence_type'] && ld['geofence_type'] == 'POLYGON' ? polygon([ld['geofence']['coordinates'][0][0]]) : circle([ld['latitude'], ld['longitude']], { radius: this.radius }),
);
}