Skip to content

Remove style layers and sources by object so they can come back - #17

Open
wf9a5m75 wants to merge 1 commit into
developfrom
fix/maptiler-overlay-restore
Open

wf9a5m75 wants to merge 1 commit into
developfrom
fix/maptiler-overlay-restore

Conversation

@wf9a5m75

@wf9a5m75 wf9a5m75 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

なぜ

MapTiler の地図から外したオーバーレイ(ポリゴン・サークル・ラスター・GroundImage・ポリライン、または clearOverlays() の後のすべて)を、同じ id で足し直しても地図に戻りませんでした。

MTStyle は addLayer / addSource したものを id で覚えていて、同じ id をもう一度足そうとすると LayerAlreadyExists / SourceAlreadyExists を投げます(レンダラはそれを catch してログに出すだけでした)。removeLayerById / removeSourceById はページ(MapLibre GL JS)から消すだけで、この記録を残します。removeLayer(layer) / removeSource(source) は記録も消してからページへ渡します。

何を変えたか

  • レンダラがソース・レイヤーを外すところを、すべてオブジェクトで外すようにしました(MapTilerStyleRemoval.kt の removeLayerAndForget / removeSourceAndForget)。MTStyle に記録が無いとき(add の記録は SDK のコルーチンで遅れて入る)は id でページから消します。
  • ベクタースタイルの変更で足し外しする background レイヤーも同じです。
  • ソースが変わったラスターは同じ id で外して足し直すので、その経路も壊れていました。これも直ります。
  • MapTilerStyleRemovalTest: 本物の MTStyle を、記録を取る command executor で動かします。id で外すと記録が残り、オブジェクトで外すと同じ id をもう一度足せることを確かめます。

検証

2026-11-08 に develop の上に載せ直してから確かめています。

  • MapTilerStyleRemovalTest は直す前に落ち、直した後に通ります。単体ビルドで全テストが通りました。
  • タブレット実機(載せ直す前): 外す → 戻す、clearOverlays → 送り直し で、直す前は戻らず、直した後は戻ることを撮っています。
  • 載せ直した後は、develop + fix/clear-strategy + fix/overlay-stacking-order と合わせた APK で、clearOverlays → 送り直し の後に 6 種類すべてが戻ることを実機で確かめました。

確認できていないもの

  • 特になし(Strategy のマーカーは別の PR の範囲)。

関連

fix/overlay-stacking-order の Android MapTiler の PR は、この PR の上に載せています(#16)(同じ削除処理を両方が書き換えたため)。この PR を先にマージしてください。 この PR は単独でマージでき、core の変更を必要としません。

Overlays removed from a MapTiler map - a polygon, circle, raster layer,
ground image or polyline taken out of the composition, or everything after
clearOverlays() - did not come back when added again with the same id.
MTStyle remembers every source and layer it added, by id, and refuses to
add the same id again (SourceAlreadyExists / LayerAlreadyExists, which the
renderers caught and logged). removeSourceById / removeLayerById only
remove them from the page and leave that record behind; removeSource /
removeLayer clear it too.

Remove by object everywhere the renderers take a source or layer out,
falling back to the id when MTStyle has no record of it (its add records
asynchronously). The same applies to the background layer the vector-style
mutation target adds and removes. A raster layer whose source changes is
removed and re-added under the same ids, so that path was broken too.

MapTilerStyleRemovalTest drives a real MTStyle through a recording command
executor: removing by id leaves the id recorded; removing by object lets
the same id be added again.
This was referenced Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant