Skip to content

Draw many polylines as tiles, with the Boston roads sample - #18

Merged
wf9a5m75 merged 10 commits into
developfrom
feat/polyline-tiling
Nov 10, 2026
Merged

wf9a5m75 merged 10 commits into
developfrom
feat/polyline-tiling

Conversation

@wf9a5m75

@wf9a5m75 wf9a5m75 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

なぜ

ポリゴンと同じように、ポリラインも数万本を渡せるようにするためです。ボストン市内の道路(54,645 本・234,765 頂点)をネイティブの線で描くと、iOS の Google で全 onAdded まで 114 秒・1.5 GB、Android の Google は Java ヒープが尽きて落ちます。ポリゴンのタイル化(feat/polygon-tiling)と同じ仕組みで、多数のポリラインをラスタータイルとして描きます。

設計の要点(web・Android・iOS で同じ)

  • Polylines(states): Polygons と同じ形のまとめて渡す部品。そのインスタンスが足した id だけを足し引きするので、複数の Polylines / Polyline が同じ地図で共存できます(iOS は既存の Polylines(_:) のまま)。
  • PolylineTilingOptions / PolylineTileSet / PolylineTiler / PolylineController.tiler: 名前と既定値(2,000 本以上または頂点 50,000 以上)はポリゴンと 1 対 1。レイヤー id は mc-polyline-tiles。
  • ポリゴンのタイル化と内部を共通化: タイル集合(ルート・URL の版・16 ms のまとめ・削除)、振り分け、描画(格子索引・ズームごとの簡略化・LRU キャッシュ・無効化・スクラッチのプール・PNG・キャンセル)を内部の ShapeTileSet / ShapeTiler / ShapeTileRenderer に移し、Polygon* はその上の薄い層になりました。公開 API は追加のみです。
  • 描き方: 開いた経路として、ズームの画素格子に丸め → 重複を捨て → Douglas-Peucker 0.5 px(両端は残す)。round cap / round join。線幅は画面上の幅(dp / pt / CSS px)でズームに依らない。候補は線幅の半分だけタイルの外まで引き、はみ出す分もそのまま描くので、タイルの境目で線が切れません。1 px 未満に潰れた線は線幅の点で描きます。
  • タイルにできないもの: geodesic、2 点未満、経度幅 180° 以上。その場の変更でそうなった線はネイティブ描画へ移ります(onAdded は呼ばない)。破線・キャップの指定は API に無いので対象外です。
  • onAdded: ポリゴンと同じ規則(初めて地図に載ったときだけ。タイル⇔ネイティブの移動では呼ばない)。
  • 地図ごとの指定: web はプロバイダの props / config の polylineTilingOptions、Android は compose の PolylineTiling(options)、iOS は MapViewContent.polylineTilingOptions / PolylineTiling 要素。
  • 重なり順: ポリラインのタイルはポリラインの帯の最下段(サークルの上、ネイティブのポリラインとマーカーの下)。下から raster → GroundImage → polygon(+タイル) → circle → polyline(+タイル) → marker(+タイル)。

このリポジトリで変えたこと

  • サンプルアプリにボストンの道路のページ(pages/polyline/boston/)。MCPG v2 の reader が種別(16)と lines(32)のビットを読む。読み込みの試験 BostonRoadsDataTests。
  • データ boston-city-roads.bin(1,019,811 B、gzip 597 KB): Overture transportation/segment 2026-10-21.0 の road を、Analyze Boston の市境で切ったもの。54,645 本・234,765 頂点(元 362,585)。1e-5°、直線上の頂点を 0.5 m で省く(両端は残す)。ID は持たず、種別(u8)と名前だけ。
  • 形式は MCPG v2 にヘッダの fields ビットを 2 つ足したもの(16 = 道路の種別、32 = lines: 開いた折れ線で読み手は閉じない)。3 プラットフォームの読み込み試験は同じ fixture を使います。作り方・出典・ライセンス(ODbL)は react-sdk の examples/basic/tools/boston/README.md。
  • ページ: 種別ごとの色・線幅・zIndex と凡例、読み込み中の表示、onAdded の数(全 54,645 本が来るまで)、タップで InfoBubble(種別・名前・長さ)、タイル化の有無の切り替えと「読み込み → 全 onAdded」の時間、重なり確認用の表示(ポリゴンのタイル・サークル・マーカー)。
  • gitlink: ios-sdk-core・11 プロバイダを各 feat/polyline-tiling へ。feat/overlay-on-added の追従で template・geojson・heatmap・icons 系・kml・clustering の 9 モジュールが develop の先頭へ進んでいます(polygon-tiling 側の変更)。

検証(iOS、追従後の 4ea1d59)

  • サンプルアプリ(Release、iPad)のビルド通過。develop の先頭へ進んだ 9 モジュール(template・geojson・heatmap・icons 系・kml・clustering)も、このブランチの core でビルドできます。
  • 単体テスト: core 457 件すべて通過。mapbox 10・maplibre 25・maptiler 12・openmobilemaps 16 通過。arcgis 24 件中 1 件・tomtom 9 件中 1 件が失敗しますが、どちらも base の時点から同じ失敗です。googlemaps はテストターゲットがビルドできません(GoogleMaps が iOS 17 を要求、既存)。here / longdo / mapkit / mappls はスキームにテストがありません。
  • 公開 API(scripts/api-surface.sh check): core と googlemaps 以外の 10 プロバイダ ok。core は +18 / -0(PolylineTiling・MapViewContent.polylineTilingOptions・PolylineTilingOptions ほか)、プロバイダは変化なし。
  • iPad 実機(Release、ボストンの道路、z16.5、重なり確認 ON):
    • MapLibre: 全 54,645 本の onAdded まで 1,090 ms、footprint 221 MB。Google: 921 ms、394 MB。
    • 重なり順: どちらもポリゴンのタイル → サークル → 道路のタイル → ネイティブの geodesic 線 → マーカーで正しい。
    • タップ(XCUITest): MapLibre・Google ともに InfoBubble(種別・長さ・頂点数)が出て passed。

時間とメモリ(ボストンの道路 54,645 本・234,765 頂点)

web(Chromium、Playwright。「全 onAdded / 次のフレーム」ms)

プロバイダ タイル z13 タイル z16 ネイティブへ切り替え タイルへ戻す
MapLibre 1758 / 1763 1357 / 1365 381 / 658 236 / 312
Google 611 / 626 226 / 308 403 / 799 250 / 332
Mapbox 1151 / 1161 923 / 937 345 / 587 262 / 345
MapTiler 1193 / 1199 596 / 603 363 / 642 238 / 312
TomTom 2077 / 2086 807 / 836 344 / 622 240 / 321
Mappls 5206 / 5226 2248 / 2260 546 / 1108 435 / 565
Longdo 4406 / 4430 1573 / 1587 564 / 990 448 / 595
Leaflet 276 / 281 317 / 410 19385 / 21150 701 / 1141
OpenLayers 264 / 270 209 / 275 1650 / 7931 224 / 291
HERE 349 / 450 376 / 489 992 / 4135 297 / 392
deck.gl 355 / 361 332 / 436 239 / 14743 284 / 1296
Cesium 610 / 627 545 / 559 874 / 7315 629 / 776
ArcGIS 1348 / 1355 292 / 303 1353 / 3656 227 / 298
Azure Maps 1139 / 1153 788 / 802 未測定 未測定
MapKit 724 / 729 391 / 397 未測定 未測定

JS ヒープ(GC 後): MapLibre ⇄ Google をタイルで 4 往復 251.0 → 266.4 → 267.0 MB(2 往復目以降は横ばい)。ネイティブだと Google の時に 475 MB 前後。MapLibre ⇄ Leaflet は 251.1 → 253.2 MB。

Android(タブレット、MapLibre)

タイル化あり ネイティブ
渡してから最初のフレーム 25 ms 49 ms
渡してから全 onAdded 1,202 ms 1,294 ms
画面が落ち着くまで(録画) 2.32 s 2.02 s

Google: タイル化ありで描画 0.87 s(録画)。ネイティブは OOM で落ちる(下記)。
メモリ: MapLibre ⇄ Google を 6 往復、PSS 899,652 K → 最大 1,060,426 K → 916,405 K、native heap 182,752 K → 181,524 K。増え続けません。

iOS(iPad、Release。「読み込み → 全 onAdded」と footprint)

タイル化あり ネイティブ
MapLibre z15 1,010 ms / 218 MB 3,961 ms / 478 MB
MapLibre z13 / z17 / z18 910 / 1,039 / 988 ms 3,826 / 3,967 / 3,838 ms
Google z15 796 ms / 360 MB 114,541 ms / 1,573 MB

ほかのプロバイダ(z16、タイル化あり): Mapbox 1,028 ms / 397 MB、MapTiler 914 / 310、Mappls 1,727 / 241、MapKit 1,021 / 393、ArcGIS 923 / 164、ArcGIS2D 943 / 370、HERE 1,175 / 483、TomTom 1,229 / 303、Longdo 2,499 / 144、OMM 895 / 394。
メモリ: MapLibre ⇄ Google を 8 往復、277 MB → 往復中 259〜396 MB → 260 MB。増え続けません。

挙動の変わる所

  • タップの判定に線幅の半分を足しました(3 プラットフォームの core の PolylineManager.find、タイルでもネイティブでも同じ)。許容距離 = 既存の指の大きさ(tapTolerance)+ 線幅 / 2。太い線は縁から指の大きさ以内であたります。複数あたれば最も近い線。外接矩形で先に候補を絞るので、5 万本でも毎タップ全点をなめません。返す位置(線上の最近点)は今までどおりです。
  • iOS TomTom: 合成スタイルで、SDK のタイル層(ポリゴン・ポリライン・マーカーのタイル)をスタイルの最上段に置きます。TomTom のスタイルは最初の symbol レイヤーより後ろに道路があり、「最初のラベルの前」では道路のタイルが覆われていたためです。そのためポリゴンのタイルも TomTom の道路・ラベルの上に来ます。annotation(ネイティブのサークル・線・マーカー)はこれまでどおりスタイル全体の上です。
  • web Google: overlayMapTypes の中でマーカーのタイルを最上位にしました(ポリゴン < ポリライン < マーカー)。3D 地図ではタイル化せず、すべてネイティブで描きます。
  • web MapLibre 系(maplibre / mapbox / maptiler / mappls / tomtom / longdo): GeoJSON で描くネイティブのポリラインを zIndex 順に並べるようにしました(これまでは渡した順)。タイルとネイティブで重なり方がそろいます。
  • iOS MapLibre / MapTiler / Mappls: raster レンダラが SDK タイル層の重なりのキーを id から取るようにしました(OverlayStacking.rasterKey(styleLayerId:))。追加の順に関係なく、ポリラインのタイルがネイティブのポリラインの下に入ります。

SDK の制約で重なり順を守れないもの

  • web Google(2D): overlayMapTypes は図形・GroundOverlay より必ず下に描かれるので、サークルとネイティブのポリゴンが道路のタイルの上に出ます(ポリゴンのタイル < 道路のタイル < マーカーは守れています)。
  • web Cesium: imagery レイヤーは ground primitive より必ず下。アプリのラスターより上に置くところまで。
  • Android HERE / ArcGIS / TomTom: ポリラインのタイルが SDK のオーバーレイ層(HERE は map item、ArcGIS は GraphicsOverlay)より下になるので、ネイティブのポリゴン・サークルがタイルの上に来ます。ポリゴンのタイルより上、マーカー(とそのタイル)より下は守れています。
  • iOS TomTom: annotation がスタイル全体の上に描かれるので、サークルがポリラインのタイルの上に来ます。ポリゴンのタイルも道路の上(上記)。
  • iOS Longdo / HERE / ArcGIS: z16 の画像を目で見た範囲では、サークルが道路のタイルの上に見えます(画素では測っていない)。iOS OMM: ポリゴンのタイルがほとんど見えません(要調査)。

確認できていないもの

  • Android Google のネイティブ比較: 54,645 本をネイティブで描かせると、main スレッドが OutOfMemoryError で落ちます(GoogleMap.addPolyline → PolylineOptions.writeToParcel、Java ヒープが上限 512 MB に到達)。1 本ずつ Parcel に詰めて GMS に渡すためで、タイル化ありなら落ちません。このため Google のタイル化あり/なしの時間は並べられていません。
  • Android の追従後の実機確認: develop を取り込んだ後の APK は、タブレットが adb に見えず実機で確かめていません(単体テストと apiCheck は通過)。追従前の build では MapLibre / Google で確認済みです。
  • web MapKit: トークンが 401 で地図が出ず、描画と重なり順は確かめていません(タップ判定は 43/43)。
  • web ArcGIS の初回タップ: カメラが一度動くまで当たりません(地図を一度動かすと 43/43)。
  • web Mappls: 右端でタップの位置がずれます(36/43)。
  • iOS の Mac 側照合のずれ: タップ試験の Mac 側の照合(初期カメラを仮定して最寄りの道路を計算)が、Google 16/30・TomTom 18/30・ArcGIS 13/30・ArcGIS2D 10/30・MapKit 11/30 しか合いません。アプリが返した最近点はどれも実在の道路の線から 0.05 pt 以内なので、判定の誤りではなく、Mac 側が仮定するカメラ(ズームの定義・safe area・2D の傾き補正)が SDK と合っていないと見ていますが、確かめてはいません。
  • 既存の失敗(このブランチ由来ではない): Android OMM の OpenMobileMapsDriverConformanceTest 1 件(develop の Log.isLoggable がモックされていない)、iOS ArcGIS・TomTom の単体テスト各 1 件、iOS Google のテストターゲットのビルド(GoogleMaps が iOS 17 を要求)。

base について

ポリラインの差分だけをレビューできるように、base は feat/overlay-on-added(feat/polygon-tiling + onAdded + ボストンのサンプル。そのリポジトリに無い場合は develop)にしています。feat/polygon-tiling は develop にマージ済みなので、feat/overlay-on-added が develop に入ったら、この PR の base を develop に付け替えてください。
追従は rebase せず merge commit で行いました(origin/feat/polygon-tiling → feat/overlay-on-added → feat/polyline-tiling)。

マージの順番

  1. 先に、各リポジトリの feat/overlay-on-added(onAdded とボストンのサンプル)を develop へ。入ったら下の PR の base を develop に付け替えます。
  2. ios-sdk-core: https://github.com/MapConductor/ios-sdk-core/pull/34(base: feat/overlay-on-added)
  3. ios-for-maplibre: https://github.com/MapConductor/ios-for-maplibre/pull/17(base: feat/overlay-on-added)
  4. ios-for-maptiler: https://github.com/MapConductor/ios-for-maptiler/pull/13(base: feat/overlay-on-added)
  5. ios-for-mappls: https://github.com/MapConductor/ios-for-mappls/pull/12(base: feat/overlay-on-added)
  6. ios-for-arcgis: https://github.com/MapConductor/ios-for-arcgis/pull/20(base: feat/overlay-on-added)
  7. ios-for-tomtom: https://github.com/MapConductor/ios-for-tomtom/pull/14(base: feat/overlay-on-added)
  8. ios-for-googlemaps: https://github.com/MapConductor/ios-for-googlemaps/pull/16(base: feat/overlay-on-added)
  9. ios-for-here: https://github.com/MapConductor/ios-for-here/pull/13(base: feat/overlay-on-added)
  10. ios-for-longdo: https://github.com/MapConductor/ios-for-longdo/pull/13(base: develop)
  11. ios-for-mapbox: https://github.com/MapConductor/ios-for-mapbox/pull/17(base: feat/overlay-on-added)
  12. ios-for-mapkit: https://github.com/MapConductor/ios-for-mapkit/pull/18(base: feat/overlay-on-added)
  13. ios-for-openmobilemaps: https://github.com/MapConductor/ios-for-openmobilemaps/pull/10(base: feat/overlay-on-added)
  14. この PR(親)

プロバイダは ios-sdk-core の PolylineTiler / 重なり順を使うので core が先です。どの PR もまだマージしていません。マージはレビューのうえで判断してください。

…the map

The overlay used to go two frames after the list was handed to the map,
and the map then stayed empty while the SDK tiled the parcels (about 4.7 s
on MapLibre and 4.6 s on Google, iPad). Each state now carries onAdded; the
page counts the calls with a flag per building and a counter, ignores calls
for a dataset it has since replaced, and drops the overlay when every shown
state is on the map. "BOSTON added" is printed then.

Bumps ios-sdk-core and the providers to feat/overlay-on-added.
The loading overlay never went for Downtown: the page waited for one
onAdded per state, but the data lists three buildings twice and the map
keeps one polygon per id, so 9,464 calls came for 9,467 states. Switching
the area mid-load also stranded it: a building dropped from the list lost
its flag, and the SDK calls onAdded again only for a polygon it saw
leave -- not one whose list was replaced before it got there.

Each call now records its id, and the count is redone against every list
handed to the map; an id already on the map counts for the new list.
ios-for-maplibre, -mapbox, -maptiler and -mappls report tiled markers and
polygon tiles once their tile layer is in a loaded style, not when it was
handed over while the style was still loading.
The building ids (Overture's, 36 characters each) were most of every file,
and the page is a polygon demo. MCPG v2 drops them: a polygon's id on the
map is its index in the file. Counts and coordinates are zigzag varints of
the same 1e-6 degree differences, a ring's closing vertex is not stored
(the reader closes the ring again), and a header byte says which fields the
file carries: height, land use (as an index), the downtown area, name.
Same format as the React and Android samples.

Downtown is now a v2 resource too (boston-downtown.bin, 0.25 MB, was 2.2 MB
of JSON). The copied city files become boston-city-buildings.bin (2.1 MB,
was 10.5) and boston-city-parcels.bin (4.0 MB, was 14.1). With unique ids
the three downtown buildings listed twice (two parts each) are both drawn.

The InfoBubble and the tap line show the area (outline less holes) where
they showed the Overture id or the parcel id. The attribution stays.
BostonDataTests (Benchmarks bundle, on device) decodes a fixture and the
bundled file.
The city-wide buildings (2.1 MB) and parcels (1.9 MB) now ship in the app
bundle (Resources) next to downtown; nothing has to be copied into
Documents. The React sample's examples/basic/tools/boston/ builds them
(see its README).

MCPG v2 gains a header byte, digits: coordinates are integers of
10^-digits degree. Buildings and downtown stay at 1e-6; parcels are at
1e-5 with near-collinear vertices dropped (0.5 m). The decoding tests
cover both units and check the bundled city files.
Points ios-sdk-core and the providers at their feat/overlay-on-added (feat/polygon-tiling for ios-for-longdo, which has no onAdded branch), each with feat/polygon-tiling and develop merged in.
A Polyline page like the Boston buildings one: Overture transportation segments
(road subtype, cut at the city boundary; 54,645 polylines, 234,765 vertices,
boston-city-roads.bin, 1.0 MB) coloured, widened and stacked by class, with a
legend, the loading overlay counting onAdded up to every road, a tap that
shows class, name and length in an InfoBubble at the closest point on the road,
and a switch that turns polyline tiling off and loads again, timing the file
to the last onAdded. A stacking check adds tiled polygons, a circle, a native
(geodesic) polyline in a second Polylines and markers around Downtown Crossing.

The MCPG v2 reader learns the road class (16) and lines (32) bits; the decoding
test uses the fixture the React and Android tests share.

Point ios-sdk-core and the providers at their polyline tiling commits.
…verlay-on-added

Brings in the nine modules (template, geojson, heatmap, icons, icons-jp,
icons-us, icons-weather, kml, marker-clustering) that polygon-tiling moved
to the head of their develop.
@wf9a5m75

wf9a5m75 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

CI: Test と Public API Surface を workflow_dispatch で実行しました(https://github.com/MapConductor/ios-sdk/actions/runs/42699027311 、https://github.com/MapConductor/ios-sdk/actions/runs/42699032483 )。どちらも落ちますが、develop でも同じ落ち方です(https://github.com/MapConductor/ios-sdk/actions/runs/42699924247 、https://github.com/MapConductor/ios-sdk/actions/runs/42699931788 )。原因は ios-sdk-core/api/TOOLCHAIN が Xcode 27.2 を指定しているのにランナーに無いこと(API Surface もビルド段階で失敗)で、このブランチ由来ではありません。ios-sdk-core と ios-for-mapkit の PR の build は成功しています。

@wf9a5m75
wf9a5m75 changed the base branch from feat/overlay-on-added to develop November 10, 2026 01:55
@wf9a5m75

Copy link
Copy Markdown
Contributor Author

向け先を feat/overlay-on-added から develop に変えました。このため、この PR にはボストンのサンプル(feat/overlay-on-added:onAdded の数え方、MCPG v2 のデータ同梱など)の commit も含まれます。

@wf9a5m75
wf9a5m75 merged commit 1590864 into develop Nov 10, 2026
1 check passed
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