From 37e0b3c285d7c2b55af65a59d966748537e0926a Mon Sep 17 00:00:00 2001 From: Masashi Katsumata Date: Sat, 7 Nov 2026 06:07:50 -0800 Subject: [PATCH] Draw large polygon sets as raster tiles (PolygonTiler) The polygon controller gets ios-sdk-core's PolygonTiler: from 2,000 polygons or 50,000 vertices they are drawn into raster tiles on the local tile server and shown as one raster layer (mc-polygon-tiles), upserted into the raster layer controller so the app's raster layers and the marker tiles are left alone. Taps still resolve against the original shapes. The content update asks the tiler to show the tiles again when the tile server has moved. --- Sources/MapConductorForMapKit/MapKitMapView.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/MapConductorForMapKit/MapKitMapView.swift b/Sources/MapConductorForMapKit/MapKitMapView.swift index 2461e97..ac275b5 100644 --- a/Sources/MapConductorForMapKit/MapKitMapView.swift +++ b/Sources/MapConductorForMapKit/MapKitMapView.swift @@ -1,6 +1,6 @@ import Combine import MapKit -import MapConductorCore +@_spi(MapConductorDriver) import MapConductorCore import QuartzCore import SwiftUI import UIKit @@ -271,6 +271,17 @@ private struct MapKitMapViewRepresentable: UIViewRepresentable { let rasterLayerController = MapKitRasterLayerController(mapView: mapView) self.rasterLayerController = rasterLayerController + // Many polygons are drawn into raster tiles and shown as one raster + // layer; taps still resolve against the original shapes. + let polygonTiler = PolygonTiler() + polygonTiler.onTemplate = { [weak rasterLayerController] template, tileSize in + if let template { + await rasterLayerController?.upsert(state: PolygonTiler.rasterLayerState(template: template, tileSize: tileSize)) + } else { + await rasterLayerController?.removeById(PolygonTiler.layerId) + } + } + polygonController.tiler = polygonTiler let groundImageController = MapKitGroundImageController(mapView: mapView) self.groundImageController = groundImageController @@ -376,6 +387,7 @@ private struct MapKitMapViewRepresentable: UIViewRepresentable { overlayScope?.circleCollector.sync(content.circles.map { $0.state }) overlayScope?.polylineCollector.sync(content.polylines.map { $0.state }) overlayScope?.polygonCollector.sync(content.polygons.map { $0.state }) + polygonController?.tiler?.refreshIfServerMoved() for handler in content.polygonSyncHandlers { let hullController = hullPolygonController handler.bindPolygonSync { [weak hullController] states in