将自定义属性添加到leaflet / mapbox geoJSON标记

时间:2014-12-31 01:07:08

标签: leaflet mapbox

以下是相关的两个功能。

我想为标记添加自定义属性。具体而言,属性对象的userID。它不一定在那里,但我在下面所做的不起作用。

有没有办法传递自定义属性?

initMap:function(){

  L.mapbox.accessToken = 'myToken';
  Shop.el.map = L.mapbox.map('map');
  Shop.el.retailersLayer = L.mapbox.featureLayer().addTo(Shop.el.map);
  Shop.el.retailMarkers = [];

  // add tile layer
  L.tileLayer('myLayerKey', {
      maxZoom: 18
  }).addTo(Shop.el.map);

  // By default, center map over Colorado
  Shop.el.map.setView([39.7392, -104.9847], 12);

 },

addGeoJSONToMap:function(retailers){

// format geoJSON
jQuery.each(retailers, function(index, val) {

  // Push each on of the retail locations into the retailMarkers array
  Shop.el.retailMarkers.push(
        {
            type: 'Feature',
            geometry: {
                type: 'Point',
                coordinates: [parseFloat(val.lng), parseFloat(val.lat)]
            },
            properties: {
                'userId':'99', <------------------------ This does not work. 
                'marker-color': '#193441',
                'marker-symbol': 'star-stroked',
                title: ' val.name,
                description: 'Marker Description'
            },
        }
  );

});

// Add the retail location as markers to the map
Shop.el.retailersLayer.setGeoJSON({
    type: 'FeatureCollection',
    features: Shop.el.retailMarkers
});

},

1 个答案:

答案 0 :(得分:0)

没关系。这个工作。该物业随后可在以下网址找到:

marker.features.userID
相关问题