1

I'm using leaflet-pip to return overlays polygon in a clicked point. Results seems to be good, but I have an array with [object Object]. How can I display the name or specific properties of matched features ?

For example

var myLayer = L.geoJson(myData,{
}).addTo(map);

var match = leafletPip.pointInLayer([-0.993005, 49.069792], myLayer, false);

alert(match);

Data

var myData = 
{"type": 'FeatureCollection", "features": [
{ "type": "Feature", "properties": { "name": "01", "type": "type01" ...
{ "type": "Feature", "properties": { "name": "02", "type": "type02" ...
]}

1 Answer 1

1

To access to the feature properties, it should be:

if (match.length) {
    for (var i = 0; i < match.length; i++) { 
        name = match[i].feature.properties.name;
        type = match[i].feature.properties.type;
        // ...
    }
}

Then you can pass the properties to a popup:

var popup = L.popup()
    .setLatLng([lat, lon])
    .setContent("<b>Name:</b> " + name + "<br><b>Type:</b> " + type)
    .openOn(map);

where [lat, lon] are the coordinates of the clicked point.

1
  • Exactly what I was looking for.
    – GeoGyro
    Commented Nov 30, 2017 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.