mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-08-20 14:34:38 +00:00
Add geojson setStyle and resetStyle methods, layer feature property
This commit is contained in:
@ -20,27 +20,42 @@ L.GeoJSON = L.FeatureGroup.extend({
|
||||
return this;
|
||||
}
|
||||
|
||||
var options = this.options,
|
||||
style = options.style;
|
||||
var options = this.options;
|
||||
|
||||
if (options.filter && !options.filter(geojson)) { return; }
|
||||
|
||||
var layer = L.GeoJSON.geometryToLayer(geojson, options.pointToLayer);
|
||||
layer.feature = geojson;
|
||||
|
||||
if (style) {
|
||||
if (typeof style === 'function') {
|
||||
style = style(geojson);
|
||||
}
|
||||
if (layer.setStyle) {
|
||||
layer.setStyle(style);
|
||||
}
|
||||
}
|
||||
this.resetStyle(layer);
|
||||
|
||||
if (options.onEachFeature) {
|
||||
options.onEachFeature(geojson, layer);
|
||||
}
|
||||
|
||||
return this.addLayer(layer);
|
||||
},
|
||||
|
||||
resetStyle: function (layer) {
|
||||
var style = this.options.style;
|
||||
if (style) {
|
||||
this._setLayerStyle(layer, style);
|
||||
}
|
||||
},
|
||||
|
||||
setStyle: function (style) {
|
||||
this.eachLayer(function (layer) {
|
||||
this._setLayerStyle(layer, style);
|
||||
}, this);
|
||||
},
|
||||
|
||||
_setLayerStyle: function (layer, style) {
|
||||
if (typeof style === 'function') {
|
||||
style = style(layer.feature);
|
||||
}
|
||||
if (layer.setStyle) {
|
||||
layer.setStyle(style);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -118,4 +133,4 @@ L.Util.extend(L.GeoJSON, {
|
||||
|
||||
L.geoJson = function (geojson, options) {
|
||||
return new L.GeoJSON(geojson, options);
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user