[OpenLayers-Users] easiest way to get collection of coordinates from drawn vectors

Tim Schaub noreply at geocartic.com
Wed Mar 28 15:30:18 EDT 2007


Hey Mike-

Mike Quentel wrote:
> I had a look at the API and the FAQ, but I've not
> figured out how to obtain the vertices of a polygon or
> polyline; however, I see there is a getX, getY, and
> toString set of functions for a point (Point.js).  

I think you've already figured this out, but a point has getX and getY - 
everything else is a collection with components.  For a line string, 
components is an array of points.  For a polygon, components is an array 
of linear rings (linear rings are line strings where the last point and 
the first point are the same point).

If you want to get coordinate information about a digitized feature from 
within your application, then you will probably want to dig into the 
components array.

If you want to transfer coordinate information to another client, then 
you should use one of the existing formats.  See OpenLayers/Formats for 
your current options.  I'll be adding well-known text (WKT) to that list 
shortly.

Tim

PS-  I'm also going to advocate for the removal of getX and getY (and 
setX, setY) from point geometries - this is an unnecessary inefficiency. 
  It means that points would not have lon and lat properties (only x and 
y) - but I think this is the right way to go anyway.




More information about the Users mailing list