AngularJS

Leaflet for AngualrJS: GeoJSON Repaint

How to repaint a certain GeoJSON field(s).

The way we reset style in layer.on({}) is to use, say with mouseout:

mouseout: function resetHighlight(e) {
   geolayer.resetStyle(e.target);
}

geolayer is what we get after initialising geoJSON, but what is this e.target, and where do we grab it outside of onEachFeature function?

Logging all kinds of stuff around out, it turns out to be a single layer object. So, we grab it inside of onEachFeature. Create an object and store the layer information there:

var layers = {};

function onEachFeature (feature, layer) {
    layers[layer.feature.properties.name] = layer;

    var geolayer = L.geoJson(
      countriesGeo,
      {style: getCountryStyle}
    );
};

And when we need to reset the style of certain layer, we only need to find the layer object according to the name we gave it, and then use this to do the job:

geolayer.resetStyle(layers[layerName]);
Standard