简体   繁体   中英

Mapbox single marker change color onclick

Iam just wondering how to change marker color using onclick function. Im trying to achieve it in this way: but something is wrong...Can anyone help me??

var testmarker = L.marker([74.18, -15.56], {
      icon: L.mapbox.marker.icon({
        'marker-color': '#9c89cc'
      })
    })
    .bindPopup(testmarker)
    .addTo(map);
testmarker.on('click', function(e) {
L.marker(setColor('red')); 

Use the setIcon method of L.Marker in your click handler to set a new icon:

Changes the marker icon.

http://leafletjs.com/reference.html#marker-seticon

testmarker.on('click', function() {
    this.setIcon(
        L.mapbox.marker.icon({
            'marker-color': 'red'
        })
    );
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM