Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I wanting to reproject the vertices of my polygon. I have been able to achieve this for the bounds but having a bit of trouble with the vertices.

           function onFeatureModified(event) {
           var bounds = event.feature.geometry.getBounds();
           var answer = "bottom: " + bounds.bottom + "\n";
           answer += "left: " + bounds.left + "\n";
           answer += "right: " + bounds.right + "\n";
           answer += "top: " + bounds.top + "\n";
           alert(answer);

           var mapProjv =  map.getProjectionObject();
           var epsg4326v = new OpenLayers.Projection("EPSG:4326");
       var verticesNative = event.features[0].geometry.getVertices();
       var verticesLatLon = verticesNative.transform( mapProjv , epsg4326v  );
       var vertices = verticesNative;
           alert(verticesNative);
           }

Below code that works:

           var vertices = event.features[0].geometry.getVertices();
           alert(vertices);
share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

The event parameter returned on the onFeatureModified returns a single feature instead of an array of features. So var verticesNative = event.features[0].geometry.getVertices(); won't work.

Also you cannot call .transform() on an array, rather you need to call it on the geometries that are withing the array. For that you will need to loop through.

Try this code:

   function onFeatureModified(event) {

       var bounds = event.feature.geometry.getBounds();
       var answer = "bottom: " + bounds.bottom + "\n";
       answer += "left: " + bounds.left + "\n";
       answer += "right: " + bounds.right + "\n";
       answer += "top: " + bounds.top + "\n";
       //alert(answer);

       var mapProjv = map.getProjectionObject();
       var epsg4326v = new OpenLayers.Projection("EPSG:4326");

       //var verticesNative = event.features[0].geometry.getVertices();
       var verticesNative = event.feature.geometry.getVertices();

       var verticesLatLon = [];

       var alertString = "";

       for (var x in verticesNative) {
           verticesLatLon.push(verticesNative[x].clone().transform(mapProjv, epsg4326v));
           alertString += "Vertice " + x + ": " + verticesLatLon[x].toShortString() + "\n";
       }

       alert(alertString);
   }
share|improve this answer
1  
Once again you are correct @CaptDragon. thank you:) Great Answer. You truly are a blessing to the Stack Community. –  Blake Loizides Mar 30 '12 at 10:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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