Mahmad Khoja
Mahmad Khoja

Reputation: 463

Text in marker of MapBox

I want to write some text like '1234' in marker on MapBox's map. Here marker-symbol property allows only one character. Any idea of this please share.

Upvotes: 1

Views: 3346

Answers (2)

ThaCastorp
ThaCastorp

Reputation: 1

You can do it using the "textcontent" method.

Something around these lines:

    const el = document.createElement("div");
    el.className = 'marker';
    const width = 10;
    const height = 50;
    el.style.width = `${width}px`;
    el.style.height = `${height}px`;
    el.textContent = "my-text";
    new mapboxgl.Marker(el)
        .setLngLat(["your coordinates"])

Upvotes: 0

geografa
geografa

Reputation: 701

You can do this in code with Leaflet's L.DivIcon constructor. The example on Mapbox developer pages demonstrate this: https://www.mapbox.com/mapbox.js/example/v1.0.0/divicon/

Upvotes: 1

Related Questions