Workin


Hi all -

I am a new developer working with Virtual Earth. What I am doing is drawing a polygon on the base map of VE. The polygon can have three or X number of points making up it's border. Is there a way in VE to retrieve latitude, longitude points in a drawn polygon

Thanks for the info -

- Workin




Re: Polygon points information

Jared H


That would be a nice addition to the API, but is not available currently (if I'm reading the question right, that given a polygon you'd like to determine if lat/lon XY is resident inside). I've seen some decent algorithms and explanations on the internet, so basic searches on things like "mapping,polygon,point,intersection" should get you started. Or, if you're trying to go the other way and generate a lat/lon matrix based on a set polygon then that's a different problem all together.






Re: Polygon points information

Duncan Garratt

The way to retrieve polygon points is to retrieve them when they are plotted on the map using a variable, or hidden field.

Code Snippet

//Global Variables

Var PolyPoints = "";

Var Plotting = false;

Var PlotType = "P";

map.AttachEvent("onclick", mouseClicked);

//Whenever the map is clicked and plotting is true get the latitude and longitude

function mouseClicked(e)

{

if (e.leftMouseButton == true && Plotting == true)

{

//Get the pixel coordinates of where the map was clicked

var x = e.mapX;

var y = e.mapY;

var pixel = new VEPixel(x, y);

var latlong = map.PixelToLatLong(pixel);

//Round the coordinates to 5 decimal places

var latitude = Math.round(10000*latlong.Latitude)/10000;

var longitude = Math.round(10000*latlong.Longitude)/10000;

// Add to a JavaScript variable or hidden field

PolyPoints = PolyPoints + " " + latitude + "," + longitude

if(PlotType == "P")

{

// Code or function to redraw the polygon

}

else if (PlotType == "L")

{

// Code or function to redraw the polyline

}

}

}

When finished with the plotting, post back to the server and store the points in a database. I use a Blob field for this.

Duncan Garratt

http://www.gis-logic.co.uk/







Re: Polygon points information

Workin

Hi Jared H -

First of all, thank you for your reply.

My explanation to the problem should have been more precise.

I am working for an ag company that would like to draw a polygon around a planted or to be planted field - a certain amount of acres. The fields can vary in shape and the polygon is drawn to match the shape of each field. Information is not needed about the points inside the polygon. As the user draws a polygon to match his field shape. the user clicks the mouse button to plot a point and continues to draw the polygon and plots points to match the shape of their field.

Is there a way to get the points (in long, and lat) that the user plots, which is actually the field border I noticed in Microsoft's Live Search (in Scratch pad) when you set a pin there is an option to email the points. How would one code a pushpin to do this.

Thanks again for the help.

- Workin





Re: Polygon points information

Derrick

VEShape.GetPoints();

http://msdn2.microsoft.com/en-us/library/bb412458.aspx

However, just to be clarify. How are you allowing the user to draw the polygon The API does not contain any functions that allow you to draw the shape like on live search. Also, you would need the latlongs to draw the polygon itself, so in theory, you shouldn't even need the GetPoints function. The consrtuctor for VEShape requires a array of latlongs. GetPoints just returns that array.

You could however, create a similar experience using mouse events and drawing a polyline, while using VEShape.SetPoints while the user is drawing.





Re: Polygon points information

Workin

- The user is drawing a polygon with the drawing tools developed by Johannes.

The sample code can be found at:

http://www.viavirtualearth.com/Wiki/Drawing-Tool+for+VE+v5.ashx

I hope this helps.

Workin -





Re: Polygon points information

Derrick

In that case, VEShape.GetPoints(); should work just fine.





Re: Polygon points information

Rockin

I also am trying to obtain the longitute, latitude points for the border of a drawn polygon. I have been able to understand your code but haven't too much experience with javascript. How would you code a function to show the drawn polypoints using inner.html, or in an info box How would you call the function and where should the code be placed

We also need to post back to a sql server 2005 to store the plotted points. How would this be coded

Thank you for the expertise.

Rockin