Contents
Why do I get wrong coordinates in OpenLayers?
If you have set a center in your map view, but don’t see a real change in visual output, chances are that you have provided the coordinates of the map center in the wrong (a non-matching) projection. As the default projection in OpenLayers is Web Mercator (see above), the coordinates for the center have to be provided in that projection.
Which is the default projection for OpenLayers maps?
Back to the original question: OpenLayers is capable of dealing with most projections. If you do not explicitly set one, your map is going to use our default which is the Web Mercator projection (EPSG:3857).
How can I add event on OpenLayers feature using feature?
How can I add an event on OpenLayers Feature using Feature on method? It doesn’t work for me.
Why are there so many questions about OpenLayers?
Certain questions arise more often than others when users ask for help. This document tries to list some of the common questions that frequently get asked, e.g. on Stack Overflow. If you think a question (and naturally its answer) should be added here, feel free to ping us or to send a pull request enhancing this document.
When to use a transformation in projection on the fly?
Transformations are one part of the process used by the Project tool and projection on the fly. If you are converting between different geographic coordinate systems (GCS), you need to use a transformation. In the example above, the map is in a projected coordinate system (PCS).
Which is the best way to use OpenLayers?
OpenLayers has some helpful utility methods to assist you: The method fromLonLat () is available from version 3.5 onwards. If you told OpenLayers about a custom projection (see above), you can use the following method to transform a coordinate from WGS84 to your projection:
Why does OpenLayers not update the map when the container is resized?
OpenLayers does not update the map when the container element is resized. This can be caused by progressive updates to CSS styles or manually resizing the map. When that happens, any interaction will become inaccurate: the map would zoom in and out, and end up not being centered on the pointer.
How big is the center of view in OpenLayers?
Chances are that your map looks like this: Here [-77.036667, 38.895] is provided as the center of the view. But as Web Mercator is a metric projection, you are currently telling OpenLayers that the center shall be some meters (~77m and ~39m respectively) away from [0, 0].