Repository navigation
Stop the styleReady flip-flop; put raster overlays under the basemap's labels - #18
Merged
Merged
Conversation
styleReady flipped between true and false about every 0.3 s on a map that was doing nothing (26-52 flips in 10 s on the clearOverlays test page, with the map re-rendering ~100 times in that window). The loop: a styledata arriving while a GeoJSON source is still loading sets styleReady to false, the idle that follows sets it back and resyncs every overlay, and each resync called setData on every source and moveLayer on the marker layers. moveLayer marks the style changed even when the layer stays where it was, so another styledata came while the just-rewritten sources were loading, and so on. Stopping any single controller's resync did not end it, because they all wrote. bringMarkerLayersToFront now moves nothing when the marker layers are already on top (or the order is still the one it last produced), and the layers write through setSourceFeatures, which skips setData when the features are the same objects as the last write to that same source. Renderers build a new feature for every change, so identity means "unchanged"; a style swap creates new source objects, so a lost source is always written again and design changes still restore the overlays. ResyncWritesNothing.test.mjs pins both, plus "a resync with nothing to do touches nothing" and "after a style swap it rebuilds".
…ders do After clearOverlays() and sending the same overlays again, the raster was drawn over the polygons. clearOverlays() leaves the polygon, polyline and circle layers in the style with empty sources, and this renderer appended a new raster layer at the top of the style, so the raster now came after them. The same happened on any update that replaced the raster's source object (remove + add), which a re-render does. maplibre, mapbox, mappls, maptiler and longdo got "insert below the style's first label layer" in "Put raster overlays under the basemap's labels"; TomTom was left out. This brings the same rule here, which also puts the raster under the basemap's labels as on the others. RasterLayerOrder.test.mjs covers the add-after-clear and the source-replacement cases. The API snapshot gains the private member.
This was referenced Nov 8, 2026
Merged
Stop resync from rewriting sources and layers that did not change
MapConductor/react-for-maplibre#27
Merged
Merged
Stop resync from rewriting sources and layers that did not change
MapConductor/react-for-maptiler#18
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
なぜ
何も操作していない地図でも、styleReady が約 0.3 秒ごとに true / false を往復し続けていました。
setDataと、マーカーレイヤーへのmoveLayerが走っていました。moveLayerは位置が変わらなくても style を変更扱いにするので、毎回styledataが出ます。そのとき直前のsetDataでソースが読み込み中だとisStyleLoaded()が false になり、styleReady が false に落ちます。idleで true に戻って再同期し、また同じ書き込みをする、の繰り返しでした。6 種類の再同期がどれも書き込んでいたので、1 つ止めただけでは止まりませんでした。無駄な再描画に加えて、styleReady が false の間に来た削除が待たされる(#17 の GroundImage の件)原因にもなっていました。
何を変えたか
bringMarkerLayersToFront: マーカーレイヤーがすでに最上段にあるとき、または前回自分で並べたときから順序が変わっていないときは動かしません。setSourceFeatures(新設): 前回と同じ地物オブジェクトが同じ順で、同じソースへ書かれる場合はsetDataを飛ばします。デザイン変更で style を差し替えるとソースのオブジェクトが新しくなるので、その場合は必ず書き直します。ラスターの重なり順(2 つ目の commit)
clear 後に全部を送り直すと、ラスターがポリゴン・ポリライン・サークルより上に描かれていました。ラスターの source が作り直される更新でも同じでした。
検証
単体テスト
ResyncWritesNothing.test.mjsを足しました。直す前に落ち、直した後に通ることを確かめています。RasterLayerOrder.test.mjsも足しました。 既存のテストもすべて通っています。Playwright で、何も操作しない状態の 10 秒間の往復回数と再描画回数を数えました。
送り直した後とデザイン変更の後も往復は 0 回でした。デザイン変更の後にオーバーレイが戻ることも、レイヤー一覧とスクリーンショットで確かめています。
api-surface は ok です(private メンバーの追加だけ)。
関連 PR(
fix/clear-followupsの一式)それぞれ独立していて、マージの順番の制約はありません(web の変更は js-sdk-core の新しい版を必要としません)。