Mapbox-gl-js: allow customization of the default marker color

Created on 28 Mar 2018  路  2Comments  路  Source: mapbox/mapbox-gl-js

Hi

I added my marker like this.

popup["0000ebd6f70e0400"] = new mapboxgl.Popup({ offset: 38 }).setHTML('<h3>piGPS</h3><p style=\"text-align: Left;\"><u>Lat:</u> -24.675964<br><u>Lon:</u> 25.937508<br><u>Speed:</u> 45.7 km<br><u>Temp:</u> 27</p>');

marker["0000bd6f70e0400"] = new mapboxgl.Marker().setLngLat([25.937508,-24.675964]).setPopup(popup["b827ebd6f70e0400"]).addTo(map);

How can I change the color of the marker via js code?

image

Thanks!!

feature

Most helpful comment

Hijacking this ticket into a discussion, should this be supported out of the box or left to 3rd parties? So something like:

  1. new mapboxgl.Marker({color: 'red'})

or

  1. new mapboxgl.Marker(Fancy3rdPartyMarkerFactory({ icon: 'default', color: 'red' }))

Either should be quite straightforward to implement, I'm happy to nut it out.

@qvs5010 to answer your question, at the moment you would need to create your own marker element with the design/colour you want and pass this in as the element.

All 2 comments

Hijacking this ticket into a discussion, should this be supported out of the box or left to 3rd parties? So something like:

  1. new mapboxgl.Marker({color: 'red'})

or

  1. new mapboxgl.Marker(Fancy3rdPartyMarkerFactory({ icon: 'default', color: 'red' }))

Either should be quite straightforward to implement, I'm happy to nut it out.

@qvs5010 to answer your question, at the moment you would need to create your own marker element with the design/colour you want and pass this in as the element.

Yip a feature like that will make things so much easier!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Scarysize picture Scarysize  路  3Comments

rasagy picture rasagy  路  3Comments

rigoneri picture rigoneri  路  3Comments

mollymerp picture mollymerp  路  3Comments

stevage picture stevage  路  3Comments