[OpenLayers-Users] How obtain the vertex in openlayer

Arnd Wippermann arnd.wippermann at web.de
Sat Oct 10 17:21:02 EDT 2009


Hi Salas,
 
use something like this to get your vertices:
 
function findRectangleFeaturAadded(feature) 
{               
    var GeomFromText = feature.geometry;
    
    var Msg = GeomFromText + "\n";
    
    var theVertexes = GeomFromText.components[0].components;
    for(var i=0;i<theVertexes.length;i++)
    {   Msg += theVertexes[i].x + ", " + theVertexes[i].y + "\n";
    }
    alert(Msg);
}
 
findRectangleFeaturAadded(features); 
 
with this as output:
 
POLYGON((796109.5644078 6668910.3633327,796223.32420378
6668942.9087861,796219.44263594 6668874.8320578,796171.37091113
6668860.7986972,796109.5644078 6668910.3633327))
796109.5644078, 6668910.3633327
796223.32420378, 6668942.9087861
796219.44263594, 6668874.8320578
796171.37091113, 6668860.7986972
796109.5644078, 6668910.3633327
 
To build your sql you can pass feature.geometry instead of the polygon
vertices.
 
Your second question I don't understand.
Perhaps add 
 
featureAdded:  function (feature){ findRectangleFeaturAadded(feature) }, 
 
to your control options. This should call findRectangleFeaturAadded after a
feature is added.

Regards
Arnd

  _____  

Von: fsalas [mailto:fsalas at geocuba.cu] 
Gesendet: Samstag, 10. Oktober 2009 22:32
An: Arnd Wippermann
Cc: users at openlayers.org
Betreff: Re: [OpenLayers-Users] How obtain the vertex in openlayer


Thanks , Arnd 
I tested with
 
var findRectangle = new
OpenLayers.Control.DrawFeature(polygonLayer,OpenLayers.Handler.RegularPolygo
n,{
id: 'defaultControl01',
title: "Klikk eller dra ut firkant rundt objekt i kartet for å finne mer
informasjon",
handlerOptions: {sides: 4, irregular: true},
displayClass: 'findRectangle'  ,       
displayClass: 'olControlDrawFeaturePolygon'
}
);
 
 
 function findRectangleFeaturAadded(feature) {               
  var theVertexes = polygonLayer.features[0].geometry;
  alert(theVertexes);
}
 
This function show the 4 vertex in this format POLYGON((-1487158.8221094
-2661231.5764062,1878516.406875 -2504688.5425,3209132.1950781
-6653078.9410156,-1174072.7542969 -6300857.1147266,-1487158.8221094
-2661231.5764062))
 
My question is : How I can obtain each vertex for example vertice[0].lat ,
vertice[0].long, .........
 
And my second question is .
 
In this test only draw one poligon with 4 vertex , how I implement double
click for a finish the draw  polygon 
 
thanks , 
 
Regards Salas

 
 
 

----- Original Message ----- 
From: Arnd  <mailto:arnd.wippermann at web.de> Wippermann 
To: 'fsalas' <mailto:fsalas at geocuba.cu>  
Cc: users at openlayers.org 
Sent: Thursday, October 08, 2009 4:32 PM
Subject: AW: [OpenLayers-Users] How obtain the vertex in openlayer

Hi,
 
this is the way to get the vertexes of a polygon feature:
var theVertexes = thePolygonFeature.geometry.components[0].components;
 
for(var i=0;i<theVertexes.length;i++)
    ... theVertexes[i];
 
 
or use vectorLayer.features[0].geometry, that returns the wkt string for the
polygon feature
 
POLYGON((-1487158.8221094 -2661231.5764062,1878516.406875
-2504688.5425,3209132.1950781 -6653078.9410156,-1174072.7542969
-6300857.1147266,-1487158.8221094 -2661231.5764062))
 
Arnd

  _____  

Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
Auftrag von fsalas
Gesendet: Donnerstag, 8. Oktober 2009 23:07
An: users at openlayers.org
Betreff: [OpenLayers-Users] How obtain the vertex in openlayer


       Hi, 
 
I need obtain the list of the vertex of my polygon becouse after that I need
to pass this value to POLYGON parameters and obtain all the objects inside
the polygon.
 
I use this
.
.
.
.
var drawpolygon = new OpenLayers.Control.DrawFeature(
                polygonLayer, OpenLayers.Handler.Polygon,
                {displayClass: 'olControlDrawFeaturePolygon'}
            );
 
  panel.addControls([new OpenLayers.Control.Navigation(), drawpolygon]);
..
.
.
.
 
************************************************************* This is the
Sql for postgis **************************
SELECT  cod,tipo,empresa,the_geom
FROM sennal 
WHERE sennal.the_geom && GeomFromText('POLYGON((-85.47677 23.56344,-82.31771
23.51950,-82.33468 21.03659,-85.47677 23.56344))',4267) and tipo = 'FV';
*********************************************************
How implement this ?
 
 
Regards , salas
 
 
 
 
 
 
var drawpolygon = new OpenLayers.Control.DrawFeature(
                polygonLayer, OpenLayers.Handler.Polygon,
                {displayClass: 'olControlDrawFeaturePolygon'}
            );

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20091010/bdd7c21f/attachment.html


More information about the Users mailing list