openlayers-3

How to specify the projection for GeoJSON in openlayers3?

巧了我就是萌 提交于 2019-11-28 04:52:50
问题 My intention is to load GeoJSON data and display it on the map. Coordinates of the features specified in GeoJSON are normal lon/lat. For some reason openlayers is rendering them using the projection used by the map and without converting them. // Underlying sat layer. var world = new ol.layer.Tile({ source: new ol.source.MapQuest({layer: 'sat'}) }); // GeoJSON data. var geojsonObject = { 'type': 'FeatureCollection', 'features': [ { 'type': 'Feature', 'geometry': { 'coordinates': [ 50.07539747

How to add a http header to openlayers3 requests?

ぃ、小莉子 提交于 2019-11-28 01:04:28
How can I inject a http header into every map layer request? In this case, I need to send an Authentication header for a given layer and source, but I may want to send other headers too. A search of the code and docs came up with no clues. Answered on github. By default, image loading happens like this: img.src = ' http://example.com/tile.png '; - that is, we set the src attribute of an Image to the image url. In this case, you don't have an opportunity to set the headers for the request. You can override this behavior by calling source.setTileLoadFunction(customLoader). This assumes you are

how to add markers with OpenLayers 3

匆匆过客 提交于 2019-11-27 17:40:48
I'm trying to add makers on a OpenLayers 3 map. The only example I have found is this one in the OpenLayers example list . But the example uses ol.Style.Icon instead of something like OpenLayers.Marker in OpenLayers 2 . First Question The only difference would be that you have to set the image Url but is it the only way to add a marker? Also OpenLayers 3 doesn't seem to come with marker images so it would make sense if there's no other way than ol.Style.Icon Second Question It would be really nice if someone could give me an example of a function to add markers or icons after the map is loaded

OpenLayers 3: How to calculate distance between 2 points?

五迷三道 提交于 2019-11-27 16:06:54
问题 Using OpenLayers 3, how can I determine the distance between two points in the Spherical Mercator (SRID: 3857) projection? I know that distanceTo was used in OpenLayers 2 point1.distanceTo(point2) I looked through the OpenLayers 3 docs, but I'm not finding anything similar... 回答1: You can use the Sphere object to calculate the distance between two coordinates like this: var distance = ol.sphere.WGS84.haversineDistance([0,0],[180,0]); //20037508.34 meters Sphere provides also various

Openlayers 3: how to select a feature programmatically using ol.interaction.Select?

最后都变了- 提交于 2019-11-27 14:22:58
问题 I'm using OpenLayers v3.6 (this is important, because most of solutions that I found and would potentialy work are for OpenLayers 2). I have a table and when I select a row in that table, I would like to highlight/select a corresponding feature on the OpenLayers map. All features are simple polygons ( ol.geom.Polygon ) in the same vector layer ( ol.layer.Vector ). I set up select interaction like this: // there is a lot of other code here ... addSelectListener: function() { this

Access to Image from origin 'null' has been blocked by CORS policy

ⅰ亾dé卋堺 提交于 2019-11-27 01:00:13
问题 I have JavaScript application in OpenLayers 3, and my base layer is created from local tiles. I work only in my computer so I do not know why I have CORS error. var newLayer = new ol.layer.Tile({ source: new ol.source.OSM({ url: 'E:/Maperitive/Tiles/vychod/{z}/{x}/{y}.png' }) }); var schladming = [21.6187, 48.7327]; // longitude first, then latitude // since we are using OSM, we have to transform the coordinates... var schladmingWebMercator = ol.proj.fromLonLat(schladming); var map = new ol