Adding custom icon and marker data together using Mapbox

对着背影说爱祢 提交于 2019-12-12 01:59:30

问题


I am new to mapbox and I have a simple question. I have made a feature layer and a list of custom icons. How do I add the two together?

My feature layer is formatted as below:

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

And example of my custom marker is below

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

Any help would be perfect.

Thanks


回答1:


From your code, I assume you are talking about mapbox.js, which is a derivative of leaflet.js

If so, I think what you are looking for is leaflet layer groups

So, in your case...

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


来源:https://stackoverflow.com/questions/26324752/adding-custom-icon-and-marker-data-together-using-mapbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!