Thursday 28 January 2016

javascript - Getting Node.appendChild error with leaflet


I am trying to add a popup function to some polygons. I've been consulting a few different tutorials trying to work it out and I'm concerned that I am getting conflicting instructions.



The map I have now is displaying perfectly. The next step for me is to add the popup when the polygon is clicked on. I keep getting the error "Argument 1 of Node.appendChild is not an object." I have no idea what this means. My only guess is that it has something to do with using a var within landscape.js to create the landscape.geojson, since that might not be creating it in the right way to use it for the popup.




















Answer



The layer.bindPopup method is expecting a string, but you are passing it a numeric property. You can avoid the error by either using .toString():


function toAddPopup (feature, layer) {
layer.bindPopup(feature.properties.metro_severePct.toString());
}

or by appending your property to another string using the + operator, which will also convert the numeric value to a string:



function toAddPopup (feature, layer) {
layer.bindPopup('Percent severe:' + feature.properties.metro_severePct);
}

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...