feat: Add dataDiff prop for incremental GeoJSON updates via updateData()#162
feat: Add dataDiff prop for incremental GeoJSON updates via updateData()#162samtalki wants to merge 3 commits into
Conversation
Resolves the TODO at RawSource.svelte line 95. Adds a `dataDiff` prop to GeoJSONSource that calls MapLibre's updateData(diff) instead of setData(). Property-only changes skip the full geojson-vt re-tile. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 3a8bd54 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR 💥 An error occurred when fetching the changed packages and changesets in this PR |
There was a problem hiding this comment.
Pull request overview
Adds an optional dataDiff prop to enable incremental GeoJSON updates via MapLibre’s GeoJSONSource.updateData() for better performance on large datasets.
Changes:
- Extend
RawSourceandGeoJSONSourceprops withdataDiff?: GeoJSONSourceDiff - Add a new reactive effect in
RawSourcethat appliesupdateData(dataDiff)after initial mount - Add a changeset to publish a minor version with the new API
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| svelte-maplibre-gl/src/lib/sources/RawSource.svelte | Adds dataDiff prop and a new $effect that calls GeoJSONSource.updateData() |
| svelte-maplibre-gl/src/lib/sources/GeoJSONSource.svelte | Wires dataDiff through to RawSource |
| .changeset/geojson-update-data.md | Announces new dataDiff prop and minor bump |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
svelte-maplibre-gl
@svelte-maplibre-gl/contour
@svelte-maplibre-gl/deckgl
@svelte-maplibre-gl/pmtiles
@svelte-maplibre-gl/terradraw
commit: |
Address review feedback: - Single $effect tracks both data and dataDiff to prevent race conditions when both change in the same tick (data takes priority, diff is skipped) - Runtime guard: throws clear error if updateData() is not available (MapLibre GL JS < v4) - prevData tracking ensures diff-only updates don't re-trigger setData() Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reverts the merged single-effect approach. Separate effects are simpler and preserve compatibility with in-place $state mutations on data (where reference equality fails but Svelte's proxy still triggers the effect). The setData effect is unchanged from the original library code. The updateData effect is the new addition for dataDiff. When both fire in the same tick, MapLibre's internal pending update queue handles ordering correctly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
b3e3965 to
e1ba507
Compare
|
@samtalki Thanks for the PR! It'd be nice to leverage Svelte's reactivity for |
|
Totally understand -- sorry for any inconvenience, I'm still learning frontend. Please let me know if there's anything I can do to improve this! @ciscorn |
Summary
Adds a
dataDiffprop toGeoJSONSource(andRawSource) that calls MapLibre'sGeoJSONSource.updateData(diff)instead ofsetData(). This resolves the TODO comment at RawSource.svelte line 95:Motivation
For applications rendering large GeoJSON datasets (thousands of features), every
dataprop change currently triggers a fullsetData()— which serializes the entire FeatureCollection to a web worker, re-runs geojson-vt tiling from scratch, and re-uploads all visible tiles to the GPU.MapLibre GL JS v4+ provides
updateData(diff)which accepts incremental diffs. When only feature properties change (not geometry), this skips the full re-tile entirely — only updating affected features in-place and reloading intersecting tiles.Usage
data→ callssetData()(full replace) — use for structural changesdataDiff→ callsupdateData()(incremental) — use for property-only changesdata, subsequent updates viadataDiffChanges
dataDiffto Props type, new$effectthat callssource.updateData(dataDiff)(same pattern as existingsetDataeffect)dataDiffto Props interface, passes through to RawSourceChecklist
pnpm check:all— 0 errors, 0 warnings (11/11 packages)pnpm build:packages— all packages buildpnpm test:unit -- --run— all tests pass