3

I have point vector layer in my application.Now I am trying to modify its coordinates. I am able to do it but its not reflecting on layer. Here is code I am using :

var selectInt = new ol.interaction.Select({
    wrapX: false
});

var modify = new ol.interaction.Modify({
    features: selectInt.getFeatures()
});

modify.on('modifyend', function (e) {

    var features1 = rdprvectorlayer.getFeatures();
    var featureToUpdate;
    var features = e.features.getArray();
   var id=e.features.getArray()[0].get('id');
   for (var i = 0; i < features1.length; i++) {

       if (features1[i].get('id') == id) {

           featureToUpdate = features1[i];
           break;
       }
   }

   var coordinates = e.features.getArray()[0].getGeometry().getCoordinates();


   var lon =coordinates[0];;
   var lat = coordinates[1];

   featureToUpdate.set('geometry', new ol.geom.Point(getPointFromLongLat(lon, lat)));

   var fea = new ol.Feature({
       geometry: new ol.geom.Point(getPointFromLongLat(lon, lat))
   })

   rdprvectorlayer.addFeatures([fea]);

})

function getPointFromLongLat(long, lat) {
    return ol.proj.transform([long, lat], 'EPSG:4326', 'EPSG:3857')
}

but after adding to vector laying nothing is displaying on map. can any one help me to solve it.

  • In your browser dev tool, put a break point on the featureToUpdate.set(...) line. I suspect the lon & lat are already in the correct projection. That's my guess. – Alexandre Dubé Jan 11 '17 at 13:27
  • u mean to say no need to call getPointFromLongLat() – veena hosur Jan 12 '17 at 5:12
  • Maybe, yeah. I can't say for sure without being able to see for myself. Use your browser dev tool and inspect what happens there, to be sure. – Alexandre Dubé Jan 12 '17 at 14:18
  • You could try to refresh the layer/map with layer.getSource().changed or map.updateSize(). – dvmac01 Jan 13 '17 at 10:47

Your Answer

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

Browse other questions tagged or ask your own question.