Choropleth: do not add layer before knowing the whole dataset
And only compute limits once.
This commit is contained in:
parent
d9522d9c1f
commit
35758a1e13
1 changed files with 14 additions and 4 deletions
|
@ -128,6 +128,12 @@ L.U.Layer.Choropleth = L.FeatureGroup.extend({
|
||||||
[],
|
[],
|
||||||
this.datalayer.options.choropleth
|
this.datalayer.options.choropleth
|
||||||
)
|
)
|
||||||
|
this.datalayer.on('datachanged', this.redraw, this)
|
||||||
|
},
|
||||||
|
|
||||||
|
redraw: function () {
|
||||||
|
this.computeLimits()
|
||||||
|
if (this._map) this.eachLayer(this._map.addLayer, this._map)
|
||||||
},
|
},
|
||||||
|
|
||||||
_getValue: function (feature) {
|
_getValue: function (feature) {
|
||||||
|
@ -165,13 +171,17 @@ L.U.Layer.Choropleth = L.FeatureGroup.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
addLayer: function (layer) {
|
addLayer: function (layer) {
|
||||||
this.computeLimits()
|
// Do not add yet the layer to the map
|
||||||
L.FeatureGroup.prototype.addLayer.call(this, layer)
|
// wait for datachanged event, so we want compute limits once
|
||||||
|
var id = this.getLayerId(layer);
|
||||||
|
this._layers[id] = layer;
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
removeLayer: function (layer) {
|
removeLayer: function (layer) {
|
||||||
this.computeLimits()
|
var id = layer in this._layers ? layer : this.getLayerId(layer);
|
||||||
L.FeatureGroup.prototype.removeLayer.call(this, layer)
|
delete this._layers[id];
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
onAdd: function (map) {
|
onAdd: function (map) {
|
||||||
|
|
Loading…
Reference in a new issue