mapbox / mapbox-gl-traffic

Show and hide traffic layers in your Mapbox GL traffic style
BSD 3-Clause "New" or "Revised" License
81 stars 36 forks source link

Traffic layer disappears when changing base map style #13

Closed niekvb closed 2 years ago

niekvb commented 2 years ago

Traffic layer disappears when changing base map style, like this for example:

showSatellite(value: boolean): void {
    this._map.setStyle(
        value === true ?
            "mapbox://styles/mapbox/satellite-streets-v11" :
            "mapbox://styles/mapbox/streets-v11",
    );
}

The traffic layer's style, sources and layers are still loaded, but I can't figure out why they're not visible on the map...

niekvb commented 2 years ago

Calling MapboxTraffic.render() after setting styles seems to resolve the issue.

Or, add an event callback like this:

this._map.on("style.load", () => {
    this._mapboxTraffic.render();
});