I've got a map and have created a feature layer like this:

window.map = L.mapbox.map('map', 'example.wefk232sm')
    .setView([homeLatitude, homeLongitude], initialZoom);

var myLayer = L.mapbox.featureLayer().addTo(map);

// Pass features to the map
myLayer.setGeoJSON(geoJson);

The geoJson object looks like this:

var geoJson = {
    type: 'FeatureCollection',
    features: [
        {
        type: 'Feature',
        properties: {
            title: name,
            other: "text",
            'marker-color': '#54a743',
            'stroke': '#428334',
            url: link
        },
        geometry: {
            type: 'Point',
            coordinates: [longitude, latitude]
        }
    ]
}; 

What I'm trying to do is open the popup relating to a particular feature from, say the name on the geoJson.features[0].properties object, but I can't work out how to do this.

I can access it on click with this:

myLayer.on('click', function(e) {
    e.layer.openPopup();
});

Mapbox is v1.6.2

有帮助吗?

解决方案

You should be able to grab properties.title, for example, with the following

myLayer.on('click', function(e) {
    var title = e.layer.feature.properties.title;
    // do something with the title
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top