Make API work with user projected coordinates #9846
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The goal of this branch is to support a "user projection" – which will most likely be geographic (WGS-84) – that is different from the view projection. The justification is that many people want a Web Mercator view (often without knowing it) and want to use geographic coordinates for doing things like setting the map center, adding data, etc.
To support this, all API methods need be updated to take and return coordinates (extents, geometries, etc.) in the user projection. And we can create "internal" methods that are not part of the API for dealing with the view (rendered) projection. For example,
view.setCenter()is the API method that will take a coordinate in the user projection and callview.setCenterInternal()with the coordinate transformed to the view projection.In implementing this, I think we can tackle one API method at a time, creating an "internal" counterpart and renaming the existing one to something with "external" in it. After fixing everything that breaks, we can rename the "external" one back to the nicer, short name (e.g. initially we will have
view.setCenterExternal()and then it will be renamed toview.setCenter()after everything works).In case the objective isn't clear, here is a simple example that should be supported by this change:
In the example above, the view is constructed with a center in geographic coordinates. And the user can call
view.getCenter()at any time to get geographic coordinates (as shown in themoveendlistener). So the rendered projection is Web Mercator, but the user can work with coordinates that they are familiar with.I imagine this will be work in progress for a while. A list of API things that need work:
ol/Viewnew View()view.getCenter()view.setCenter()view.animate()view.adjustCenter()view.fit()view.calculateExtent()view.centerOn()view.adjustRotation()view.getResolutionForExtent()ol/Mapmap.getPixelFromCoordinate()map.getCoordinateFromPixel()mapBrowserEvent.coordinateol/Overlayoverlay.setPosition()ol/layerlayer.getExtent()layer.setExtent()And lots more.