Recommended way to switch tile urls in mapbox-gl-js

后端 未结 1 1489
广开言路
广开言路 2021-02-04 17:20

Situation

We render a raster layer to the map. The layer\'s source has an initial tile-url. Now we want to change the tile-url of the source an

相关标签:
1条回答
  • 2021-02-04 17:47

    It sounds like you're trying to change the URL of a raster source. The proper way to do this in GL JS is to remove the source and then add a new source with the same id and the new url.

    map.addSource('tile-source', {...});
    map.addLayer('tile-layer', {source: 'tile-source', ...});
    
    // react to a button click or what ever to trigger tile url change
    ...
    map.removeSource('tile-source');
    map.addSource('tile-source', {tiles: ['new-tile-url'], ...});
    
    0 讨论(0)
提交回复
热议问题