Contents
Which is the default projection for OpenLayers maps?
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). Similarly, you are converting your coordinates from lat-long to 3857 via the command ol.proj.fromLonLat.
What is SRS for GeoServer in OpenLayers?
My Geoserver’s polygon layer has a native srs of EPSG:4326, my Openlayer’s Vector source srsname is EPSG:4326, the polygon is saved into my PostGis with a SRID of 4326. When I save the polygon and then try and show it in a Vector Layer in Openlayers the coordinates of the polygon are changed, and do not show on the map.
How to retrieve the geometry coordinates of a WKT?
You should change your query, selecting st_astext (geometry) instead of geometry, than treat the result as a string and give it back to OpenLayers. Then use OpenLayers.Geometry.fromWKT to parse the WKT into an OpenLayers.Geometry
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 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].
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.
Can you download the full distribution of OpenLayers?
The full distribution can be downloaded from the release page. OpenLayers makes it easy to put a dynamic map in any web page. It can display map tiles, vector data and markers loaded from any source. OpenLayers has been developed to further the use of geographic information of all kinds.
How to change the center of view in OpenLayers?
As Michael Gentry explains in his answer, another Problem is that you have to specify the longitude (west-east thus x) first and then the latitude (south-north thus y). And a better way to set the center is to get the current view and set the center there instead of always creating a new one.
Why is float parameter 3 non finite in OpenLayers 3?
I have a new stack exchange account and don’t have a reputation high enough to comment on the “Uncaught TypeError: Failed to execute ‘putImageData’ on ‘CanvasRenderingContext2D’: float parameter 3 is non-finite.” error. This occurs because you have the lat and the long inputs backwards. in case anyone else has this problem.
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:
How to create an openlayer map in JavaScript?
Place the OpenLayers CSS and JavaScript files in the header. Download OpenLayers LayerSwitcher from github. OpenLayers LayerSwitcher grouped layer list control for an OpenLayer map. In my case the project name is kapany.
How to use OpenLayers feature in GeoDjango?
Using OpenLayers Feature singleclick event to read data from geodjango model. Find line map.addControl (layerSwitcher) then append with: