Loading geojson markers into mapbox setting custom icon image

后端 未结 2 565
再見小時候
再見小時候 2021-01-24 14:57

I\'m new to mapbox/leaflet and I think it\'s a pretty basic problem I\'m fighting the last two days and though I\'ve tried several ways I can\'t wrap my head around it.

2条回答
  •  Happy的楠姐
    2021-01-24 15:53

    I guess it's a typical beginners mistake and maybe it's just me but I found it pretty confusing in which context to use the several options of setIcon. In the end I made it work using .on(layeradd) and marker.setIcon(pathToYourIcon).

    ma_3.on('layeradd', function(layer) {
                this.eachLayer(function(marker) {
            if (marker.toGeoJSON().properties.title === 'Verpflegung') {
                marker.setIcon(icon_live);
            } 
    
            marker.bindPopup(marker.toGeoJSON().properties.id + ', ' +
                marker.toGeoJSON().properties.title);
        });
    });
    

提交回复
热议问题