Tuesday 25 August 2015

javascript - Leaflet custom info control update with extra parameters


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 = '

US Population Density

' + (props ?
'' + props.name + '
' + props.density + ' people / mi2'
: '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?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...