change leaflet marker icon

后端 未结 4 1885
醉梦人生
醉梦人生 2021-02-20 04:17

I am using Leaflet Slider, of Dennis Wilhelm, to show changes in data on a Leaflet map.

I am trying to change the change the marker icon but not getting it right. So,How

4条回答
  •  别那么骄傲
    2021-02-20 05:05

    This will be the exact changes in the original slidercontrol.js file

       if (this._layer) {
            var index_temp = 0;
            this._layer.eachLayer(function (layer) {
    
                 var greenIcon = L.icon({ //add this new icon
                    iconUrl: i+'.png',
                    shadowUrl: 'leaf-shadow.png',
    
                    iconSize:     [38, 95], // size of the icon
                    shadowSize:   [50, 64], // size of the shadow
                    iconAnchor:   [22, 94], // point of the icon which will correspond to marker's location
                    shadowAnchor: [4, 62],  // the same for the shadow
                    popupAnchor:  [-3, -76] // point from which the popup should open relative to the iconAnchor
                });
    
                options.markers[index_temp] = layer;
                options.markers[index_temp].setIcon(greenIcon); //Here set the icon to indiviual markers
    
                ++index_temp;
            });
            options.maxValue = index_temp - 1;
            this.options = options;
        }
    

提交回复
热议问题