Contents
- 1 Why are there so many questions about OpenLayers?
- 2 Which is the best projection to use in OpenLayers?
- 3 Why does OpenLayers not update the map when the container is resized?
- 4 How big is the center of view in OpenLayers?
- 5 How to use geographic coordinates in OpenLayers module?
- 6 Do you need a pointer event polyfill for OpenLayers?
- 7 Why do I get wrong coordinates in OpenLayers?
- 8 Is there only one projection in OpenLayers map?
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.
Which is the best projection to use in OpenLayers?
Certain projections are better suited for different regions in the world. 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).
Which is easier to use, leaflet or OpenLayers?
The Leaflet is designed as easy-to-use and light-weight library. So you can start to develop a map just by copy & paste from the QuickStart tutorial. The OpenLayers offers more functionality than Leaflet and requires more time to start. For example, you need to use projections, just to create a simple map.
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].
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 to use geographic coordinates in OpenLayers module?
Using geographic coordinates for the map view. Calling the useGeographic function in the ‘ol/proj’ module makes it so the map view uses geographic coordinates (even if the view projection is not geographic).
Do you need a pointer event polyfill for OpenLayers?
If you are targeting older browsers that do not support Pointer events, you now need to include a pointer events polyfill ( elm-pep or pepjs) in your application. Several event handling fixes and improvements for seamless integration into scrollable web pages and improved support for maps in web components.
Which is the best example of minzoom in OpenLayers?
Using minZoom and maxZoom to control layer visibility. Example of setting a layer source after construction. Restricting layer rendering to a limited extent. Example of drawing arrows for each line string segment. Example of a localized OpenStreetMap map with a custom tile server and a custom attribution.
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.
Is there only one projection in OpenLayers map?
Every map that you’ll create with OpenLayers will have a view, and every view will have a projection. As the earth is three-dimensional and round but the 2D view of a map isn’t, we need a mathematical expression to represent it. Enter projections. There isn’t only one projection, but there are many common ones.
When to put longitude first in OpenLayers 2?
So when you deal with EPSG:4326 coordinates in OpenLayers, put the longitude first, and then the latitude. This behaviour is the same as we had in OpenLayers 2, and it actually makes sense because of the natural axis order in WGS84.