LoginSignup
0
0

More than 1 year has passed since last update.

Mapbox GL JS スタイル変更後にレイヤーを再セットする

Posted at

各種レイヤーを追加後にスタイルを変更すると、レイヤーが消えてしまいます
image.png
image.png
そこで、

function onstyledatafunc(){
    map.off('styledata', onstyledatafunc); // 'styledata'イベント削除
    Foo(); // すべてのレイヤーを削除,再セットする 
}

document.getElementById('iSelStyle').onchange=function(){ // ドロップダウンリストを変更したらレイヤー変更
    var style = 'mapbox://styles/' + this.options[this.selectedIndex].value;
    map.on('styledata', onstyledatafunc); // 'styledata'イベント追加
    map.setStyle(style); // スタイル変更
}

のようにして、スタイル変更のたびにレイヤーを再セットするようにしました。
image.png

他に良い方法がありましたら教えてください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0