0

I'm working in a Geocoder tool that can put new features in a vector layer directly just pressing a button. When press the button all the features of the layer disappear in the map. The features still exists because I can get the length increased by one using after that:

 alert(vector.getSource().getFeatures().length)

I did the following function as button click handler

function addPoint(lng,lat)
{
  var pp = new ol.geom.Point( [
    ol.proj.transform([lng,lat], 'EPSG:4326', 'EPSG:3857'),
]);
var featurething = new ol.Feature({
   geometry: pp
});
vector.getSource().addFeature(featurething); 
}
0

ol.proj.transform returns Array. so it means,

var pp = new ol.geom.Point([[lng,lat]]);

there's useless square brackets. remove them, then it works.

var pp = new ol.geom.Point(
    ol.proj.transform([lng,lat], 'EPSG:4326', 'EPSG:3857')
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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