Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I write my own ISource without forking mapbox-gl-js? #13282

Closed
dzfranklin opened this issue Sep 19, 2024 · 1 comment
Closed

Can I write my own ISource without forking mapbox-gl-js? #13282

dzfranklin opened this issue Sep 19, 2024 · 1 comment

Comments

@dzfranklin
Copy link

mapbox-gl-js version: 3.6.0

Question

My ultimate goal is to render epsg:27700 tiles as a mapbox-gl layer.

OpenLayers provides a function that essentially takes a tile source and a target tile extents and projection and returns a canvas of the target tile reprojected from source tile(s).

I could implement this as a custom layer but I think it fits much better as an ISource. I want to write something like your RasterTileSource except the loadTile function would also do reprojection.

If I wrote a custom layer I think I would need to figure out things like when to load or abort loading tiles based on map interactions whereas if I could write an ISource your existing code would handle all that.

The documentation for ISource hints at this being possible: "The Source interface must be implemented by each source type, including "core" types like vector, raster, or video) and all custom, third-party types". However, I can't figure out how to do this in practice.

  • style.addSource constructs the source via a static map of source type to implementation in ISource
  • ISource (recursively through Evented) contains a bunch of internal logic so I would want to have my class extend it rather than rewrite all the code needed to conform to the interface. But it isn't exported so I can't access it from an external project.

This makes me think I would have to fork mapbox-gl-js and make a few trivial changes to get a custom ISource to work. Is there a better way to do this?

Links to related documentation

@dzfranklin
Copy link
Author

For other who run into this you can do this with maplibre via addProtocol

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

No branches or pull requests

2 participants
@dzfranklin and others