[OpenLayers-Users] Trying to draw a box on a map, and get the coordinates back.

Christopher Schmidt crschmidt at metacarta.com
Thu Feb 11 17:20:09 EST 2010


On Thu, Feb 11, 2010 at 10:20:07PM +0100, Arnd Wippermann wrote:
> Hi,
> 
> function findcoords (event) {
>      var vertices = event.feature.geometry.getVertices();
>      var brackets =
> vertices.toString().replace(/POINT\(/g,"[").replace(/\),/g,"],").replace(/
> /g,",").replace(/\)/,"]");
>      alert('ID:' + brackets);
> } 

event.feature.geometry.components[0].components is a list of POINT objects,
each with a .x .y property for lon/lat. (components[0] is the first ring
of the polygon, .components is the list of vertices in that ring.)

-- Chris

> This is one way to get what you want. If there is a simple way to get the
> coordinates in this form from a geojson string or object, i don't know.
> 
> Arnd
> 
> -----Ursprüngliche Nachricht-----
> Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
> Auftrag von Jtrsmith
> Gesendet: Donnerstag, 11. Februar 2010 18:16
> An: users at openlayers.org
> Betreff: Re: [OpenLayers-Users] Trying to draw a box on a map,and get the
> coordinates back.
> 
> 
> Thanks again Arnd.
> 
> I was able to get the coordinates back, however they are formatted
> differently.
> i get a csv list i.e. 50, 0, 50, 50, 0, 50, 0, 0, 50, 0 instead of brackets
> i.e. [50, 0], [50, 50], [0, 50], [0, 0], [50, 0]
> 
> i am using the value to get the coordinates of a polygon added to my map so
> i can save it to a database and dynamically create a json file for my
> openlayers map, it looks like the only issue is the brackets, it crashes
> without them and i cannot fiigure out how to get them.
> 
> should i save them to the database the way they are and try to add the
> brackets in my php code when creating the json?
> --
> View this message in context:
> http://n2.nabble.com/Trying-to-draw-a-box-on-a-map-and-get-the-coordinates-b
> ack-tp4251287p4556020.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users

-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list