Dragging entities on the map object
A common request from developers is how to implement dragable map objects on the VE map Control. Virtual Earth supports a number of events on the map object (onmousedown, onmouseup, onmousemove in particular) that make it easy to implement dragging of elements on the map. Grayson Myers and Derrick Quan contributed some nice code samples to illustrate how to use these three events together for seamless drag of pushpins and polygons. Here are the samples -

  • Simple Drag - Draws a default and a custom pushpin and allows re-positioning of either of them
  • Collection Drag - Loads a Collection of travel destinations, each member of which is dragable
  • Shape Drag - Shows how to drag shapes and lines. slightly more complex in that the onmousemove event needs to recalculate the new pixel coordinate of each vertex for the shape being dragged

In each example, there's basically 2 pieces of code that are interesting. first, register the 3 events when initializing the map control like this:


All three events will fire MouseHandler

function MouseHandler(e)
** var msg;
** if (e.eventName == "onmousedown" && e.elementID != null)
** {
***** dragShape = map.GetShapeByID(e.elementID);
***** return true; // prevent the default action
** }else if (e.eventName == "onmouseup")
** {
***** dragShape = null;
** }else if (e.eventName == "onmousemove" && dragShape != null)
** {
***** var x = e.mapX;
***** var y = e.mapY;
***** pixel = new VEPixel(x, y);
***** var LL = map.PixelToLatLong(pixel);
***** dragShape.SetPoints(LL);
***** return true; // prevent the default action
** }

Web.Maps.VE ASP.NET Ajax library updated
A new version of this Server control for your ASP.NET apps is out. Read about the latest version here featuring support for .NET 3.5 and visit the Simplovation website to download it and view demos. If you want to keep most of your VE coding server-side this should be a helpful library.

Click here to view the full post.