[OpenLayers-Users] DRAW a poligon feature with a custom radius

J.Alejandro Martinez Linares islanis at infomed.sld.cu
Mon Apr 15 07:18:00 PDT 2013


  Hi people, i need a little help from you, i got a 
"OpenLayers.Layer.Vector" and i want to use the
createGeodesicPolygon function, but i cant modifie the feature in the 
featureAdded event of the addElement function, i am doing something bad, 
i need some help from you, below is the code that i use, thanks to all.


OpenLayers.Geometry.Polygon.createGeodesicPolygon = function(origin, 
radius, sides, rotation, projection){

     if (projection.getCode() !== "EPSG:4326") {
         origin.transform(projection, new 
OpenLayers.Projection("EPSG:4326"));
     }
     var latlon = new OpenLayers.LonLat(origin.x, origin.y);

     var angle;
     var new_lonlat, geom_point;
     var points = [];

     for (var i = 0; i < sides; i++) {
         angle = (i * 360 / sides) + rotation;
         new_lonlat = OpenLayers.Util.destinationVincenty(latlon, angle, 
radius);
         new_lonlat.transform(new OpenLayers.Projection("EPSG:4326"), 
projection);
         geom_point = new OpenLayers.Geometry.Point(new_lonlat.lon, 
new_lonlat.lat);
         points.push(geom_point);
     }
     var ring = new OpenLayers.Geometry.LinearRing(points);
     return new OpenLayers.Geometry.Polygon([ring]);
};


// 
------------------------------------------------------------------------------------------------------------- 
|
// 
------------------------------------------------------------------------------------------------------------- 
|
function addElement(tb)
{
///////////////////////////////////////////////////////////////////////////// 

var v = new OpenLayers.Layer.Vector("Punto de influencia");
map.addLayer(v);
window["drawControlpi"] = new OpenLayers.Control.DrawFeature(
v,
OpenLayers.Handler.Point,
{
     handlerOptions :
         {
          multi : false,
          persist: true
         },
     featureAdded : function(feature)
         {
         //onItemToggle2();
         var centroid = feature.geometry.getCentroid();
         var projection = map.getProjectionObject();
         var radius = textRadioAcc.getValue();

         var sides = 40;
         var new_geom = 
OpenLayers.Geometry.Polygon.createGeodesicPolygon(centroid, radius, 
sides, 45, projection);
         feature = new OpenLayers.Feature.Vector(new_geom);
         feature.redraw();
         //feature.refresh();
         console.log(feature);
         }
});

--

Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/


More information about the Users mailing list