I used custom info control to show information.The below code is working:
var info = L.control();
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
};
info.update = function (props) {
this._div.innerHTML = '<h4>US Population Density</h4>' + (props ?
'<b>' + props.name + '</b><br />' + props.density + ' people / mi<sup>2</sup>'
: 'Hover over a state');
};
info.addTo(map);
and using info.update
in highlightFeature
and resetHighlight
methods
function highlightFeature(e) {
...
info.update(layer.feature.properties);
}
function resetHighlight(e) {
...
info.update();
}
But I refactor the code and I separated the logic to different classes.So in info.update method,I should use some extra parameters.In this case,I easily can call with other parameters info.update
in highlightFeature
and resetHighlight
methods.But in
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info');
// this.update();
return this._div;
};
I did not use this.update();
in info.onAdd ,so 'Hover over a state' text does not display.
When I use this.update()
like that
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
};
info.update = function (props,param1) {
.......
}
I got the error param1 is undefined
.How to achieve this?Is there any way to call
info.update
with extra parameters in info.onAdd
?
info.update = function (props,param1) {}
toinfo.update = function (props,param1=null) {}
the error will be supressed.