Skip to content

Conversation

spwoodcock
Copy link

Issue

  • Currently there is no way to load FlatGeobuf data in this library.
  • It's pretty easy to load a FlatGeobuf using the official lib, deserialize to GeoJSON, then pass through to our GeoJSON component.

Solution

  • Made a FlatGeobuf component that essentially wraps GeoJSON.
  • It has a bit of additional logic there for:
    • Taking a bounding box array and only fetching the data within the BBOX (using RANGE requests). extent={bbox}
    • If a polygon GeoJSON is passed instead, then the BBOX is calculated for fetching data, and the final dataset is trimmed to the extent of the polygon. extent={polygonGeojson}
      • Of course, having a dynamic bbox is possible, via events such as clicking on bounding map geometries. I have tested this and it works nicely.
    • A extractGeomCols prop, when set to true will extract the first geometry from within a GeometryCollection. This is a bit of a hack required so that properties can be extracted alongside the geometry when working with PostGIS.
    • Accepts a function for prop metadataFunc={funcHere} to handle flatgeobuf metadata on fetch.
  • Child components can be passed through via a slot, to allow for styling in the same way as the GeoJSON component.
  • Also takes a few additional props used by the GeoJSON component that are passed directly through.

Note

This component uses Svelte 5 syntax, with the PR anticipating the merge of #197

I had some issues with the rendering orders that are hopefully fixed by the functions I used from context and source logic.
Please let me know if I should change anything here!

Screenshot

image

@changeset-bot
Copy link

changeset-bot bot commented Nov 6, 2024

🦋 Changeset detected

Latest commit: bb6226d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte-maplibre Minor

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

@vercel
Copy link

vercel bot commented Nov 6, 2024

@spwoodcock is attempting to deploy a commit to the Daniel Imfeld's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Owner

@dimfeld dimfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Just FYI since this requires runes it's going to be a bit before this merges though.

The existing PR that you referenced only updates the docs site to use Svelte 5. I'm going to do a release at some point that is a breaking change to make this package only work with Svelte 5, but that's going to require an effort to at least update the slots/snippets and events handling to work with Svelte 5

I don't have a lot of time to work on that right now, but hope to create a next branch later this month to start the work, and I can merge this one into that branch when I do.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this one

@dimfeld
Copy link
Owner

dimfeld commented Nov 9, 2024

The next branch now exists, so if you want to rebase this on to that branch I'm happy to merge it in there.

@spwoodcock
Copy link
Author

Nice! Happy to keep contributing to this lib 😄

Svelte 5 is fully backward compatible with Svelte 4 syntax, so the upgrade could still be done without migrating all the syntax. Of course this would be a breaking major version increment.

The upgrade should be done over time, but it could be gradual and community supported if time is limited 👍

I currently use this lib in a Svelte 5 project without issues

@spwoodcock spwoodcock force-pushed the feat/flatgeobuf-component branch from 24337a3 to bb6226d Compare October 11, 2025 11:25
@spwoodcock
Copy link
Author

Finally rebased this & updated the syntax to match latest library changed 👍

One small issue on the example page:

Error: Source "entities" cannot be removed while layer "fill-1760181839982" is using it.
    removeSource style.ts:1009
    removeSource map.ts:2194
    addSource source.ts:27
    addSourceToMap FlatGeobuf.svelte:105
    updateGeoJSONData FlatGeobuf.svelte:88
    FlatGeobuf FlatGeobuf.svelte:92

Sorry, I didn't have time to dig into why this is happening, but it doesn't affect the rendering and seems like a cleanup operation that probably isn't essential to functionality.

All set I think @dimfeld!

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.

2 participants