Open mike-marcacci opened 6 years ago
π I think it would be great to expose the transformation and projection logic that currently exists in Transform
as a public module. Ideally, we would do this by extracting pure functions for those difficult calculations out of this class and export those as a utility module, keeping this state-wielding class private.
That would be awesome, and extra ππΌππΌ and style points for the suggestion to use pure functions!
This is opened in response to this comment on PR #5662, suggesting I open an issue to discuss this use case.
My Use Case
I have a react app which uses a map to geographically filter lots of results which appear in a sidebar β think Zillow-style navigation.
As is the idiom of react and other compositional frameworks, data flows unidirectionaly from the outermost component down the heirarchy of children. My goal here is to be able to calculate a GeoJSON polygon that represents the visible region of the globe, independant of actually rendering the map component.
Given the center point (Lng/Lat), zoom, pitch, bearing (all of which are stored in the URL), and the screen resolution, I need to get a
LngLat
for a givenPoint
on the screen.It's important that it's seperate from the rendered map for a few reasons:
Of course, the resulting polygon must be identical to the field of view in the map itself. This would be trivial, except for pitch and bearing.
Initial Design
My initial strategy was to use the same
Transform
class used internally by the map. This worked quite well in the browser, but my PR to export it exposed more internals than was desired. Additionally, when I began using it server-side, its requirement for WebGL broke in our current SSR strategy.Here's the kind of thing I would do using the
Transform
class:Is there any reasonable way to accomplish this without the heavy internals of
Transform
?Thanks!