I use Leaflet in Vuejs. I load GeoJSON data on map and I want to highlight a layer(Polygon) when I click on it. That works fine. But when I click on the second layer, I want the first layer to be dehighlighted. Dehighliting of the first layer does not work when I click on second layer. Here is a part of my function which I highlight and try to dehighlight:
makeEditable(feature, layer) {
var highlight = {
'color': '#FFFF00',
'weight': 2,
'opacity': 1
};
var previouscolor = {
'color': '#5dbcd2',
'weight': 2,
'opacity': 1
};
var selected
var previous
layer.on('click', function (e) {
e.target.setStyle(highlight);
if (selected !== null) {
previous = selected;
}
selected = e.target;
if (previous) {
layer.setStyle(previouscolor);
}
});
}
Here is also my computed:
computed: {
options() {
return {
onEachFeature: this.makeEditable,
}
}
}
and I also defined a method to load GeoJSON from DB, which in called in mounted:
async loadGeoJSON() {
try {
this.geojson = await api.getCurrentZones();
} catch (error) {
this.error = error.message;
this.notifyVue();
}
},