2014-05-05 41 views
1

個體特徵彈出我有一張地圖,並創造了這樣的功能層:如何顯示上mapbox

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); 

的GeoJSON的物體看起來是這樣的:

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] 
     } 
    ] 
}; 

我」什麼m試圖做的是打開與特定功能有關的彈出窗口,比如對象上的name,但我無法解決如何執行此操作。

我可以用這個訪問上點擊:

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

Mapbox是V1.6.2

回答

0

你應該能夠抓住properties.title,例如,具有以下

myLayer.on('click', function(e) { 
    var title = e.layer.feature.properties.title; 
    // do something with the title 
});