handling mousemove event (drawing polygons / polylines using the mouse?)
Hi!
I am searching for a solution to draw a polygon or a polyline witht the mouse on the map like it is implemented on local.live.com. There one can press the "Mark an area on the map" button on the scratch pad and can draw with the mouse.
I found a solution by clicking on the map and saving thee.view.LatLong points in an array. After right clicking on the map the polygon is drawn usingVEMap.AddPolygon() method. But it is not the same as local.live.com does it. There is a preview of the polygon which is changing by moving the mouse.
Has anybody an idea how that could be solved?
Thanks,
Yavuz
[760 byte] By [
selim51] at [2007-12-27]
Hello Dwayne,
The problem was not trapping the mouse move event. I don't really know where the problem was but I've solved the problem.
You can look at the situation I have described in my post above and this is the solution I wanted. It's like in local.live.com as mentioned.
Trapping the mouse move event is done in this way:
function DrawPolygon() {
map.AttachEvent('onclick', mapClick);
map.AttachEvent('oncontextmenu', mapContextMenu);
map.AttachEvent('onmousemove', mapMouseMove);
map.vemapcontrol.EnableGeoCommunity(true);
}
function mapClick(e) {
/* ... */
}
function mapContextMenu(e) {
/* ... */
map.DetachEvent('onclick', mapClick);
map.DetachEvent('oncontextmenu', mapContextMenu);
map.DetachEvent('onmousemove', mapMouseMove);
}
function mapMouseMove(e) {
/* ... */
}
I have attached the mouse move event to the VEMap object not to the <div> element as you can see. But I have to enable geo community in order to call the mapMouseMove function when moving the mouse over the map.
I don't know why the mouse move event isn't (officially) supported by the VEMap object.
Yavuz
Well I am not sure if it is realated or not... but I do see a bug in your "solution" linked app that you will want to take a look at.
After I draw a polygon in your solution (which I absolutely agree is a much better experience than the situation link), I noticed that the ability to pan the map is gone after drawing the polygon. It was there prior to the draw, but something that happens in your DrawPolygon routine (perhaps overriding the onmousemove event) is killing the users ability to drag and pan the map.
Dwayne.
Thank you Dwayne. Bug is now fixed!
I have forgotten to disable geo community:
function mapContextMenu(e) {
/* ... */
map.DetachEvent('onclick', mapClick);
map.DetachEvent('oncontextmenu', mapContextMenu);
map.DetachEvent('onmousemove', mapMouseMove);
map.vemapcontrol.EnableGeoCommunity(false); // now internal mousemove event handler is working
}
Now it works.
There is one question about handling mousemove event. Is there another, better way handling that event than the way I have done?
Yavuz
Now you know how to do it 
But it is more a hack I think, because as I said before onmousemove event is not supported by the VEMap class. No onmousemove event in the VEMap Events list.
Yavuz