使用Mapbox将自定义图标和标记数据添加到一起

时间:2014-10-12 11:44:58

标签: javascript json geolocation geocoding mapbox

我是mapbox的新手,我有一个简单的问题。我制作了一个要素图层和一个自定义图标列表。如何将两者加在一起?

我的要素图层格式如下:

L.mapbox.featureLayer({
     "type": "Feature",
     "geometry": {
     "coordinates": [
     '.$long.','.$lat.'
     ],
     "type": "Point"
     },
     "properties": {
     "title": "'.$business_name.'",
     "description": "'.$address_1.', '.$address_2.', '.$address_3 .', '.$postcode .'"
     }
     }).addTo(map);

我的自定义标记的示例位于

之下
var accomodation = L.icon({
    iconUrl: '/img/pins/day-and-night/accommodation.png',
    iconSize: [46, 62],
    iconAnchor: [8, 60],
    });

任何帮助都是完美的。

由于

1 个答案:

答案 0 :(得分:1)

从你的代码中,我假设你在谈论mapbox.js,这是leaflet.js的衍生物

如果是这样,我认为您要找的是leaflet layer groups

所以,在你的情况下......

var featureLayer = L.mapbox.featureLayer({
   "type": "Feature",
   "geometry": {
   "coordinates": [
      '.$long.','.$lat.'
   ],
   "type": "Point"
   },
   "properties": {
      "title": "'.$business_name.'",
      "description": "'.$address_1.', '.$address_2.', '.$address_3 .', '.$postcode .'"
   }
   });

var accomodation = L.icon({
   iconUrl: '/img/pins/day-and-night/accommodation.png',
   iconSize: [46, 62],
   iconAnchor: [8, 60],
});

var layergroup = L.layerGroup([featureLayer, accomodation]);

layergroup.addTo(map);