0

I am adding a feature layer of ol.geom.Point geometry as follows:

var location = result.geometry.location;
var lat = location.lat.apply();
var lng = location.lng.apply();
var locationCoordinates = [lat, lng];
var vectorSource = new ol.source.Vector({});
var iconFeature = new ol.Feature({ geometry: new ol.geom.Point(ol.proj.transform(locationCoordinates, EPSG_3857, EPSG_4326)) });
vectorSource.addFeature(iconFeature);
var vectorLayer = new ol.layer.Vector({ source: vectorSource });
map.addLayer(vectorLayer);
vectorLayer.setVisible(true);
var extent = vectorLayer.getSource().getExtent();
map.getView().fitExtent(extent, map.getSize());

But the layer is misplaced, not exactly on longitude and latitude.

I am using EPSG:4326 projection, transforming Google Maps that's supposed to use EPSG:3857 projection.

1 Answer 1

0

After many tries and searches to find a solution, I found this issue in OpenLayers repo on github: issue 2876.

When passing longitude and latitude to ol.proj.transform([], string, string), you have to pass the parameters as follows: [longitude, latitude] not [latitude, longitude]. This is not even mentioned in the documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.