Microsoft Developer Network >
Forums Home
>
Windows Live Developer Forums Forums
>
Multimap API Development Forum
>
Event Handler for Clicks on a Polyline
Event Handler for Clicks on a Polyline
- Hi,
I'm sure this should be really straightforward, but I can't get and event handler working to pick up clicks on a Polyline. I've tried to base it on this example, which uses closed filled polygons - http://www.multimap.com/apidocs/1.2/demos/clickablepolygons.htm, but to no avail. Also tried chopping around some of the code from here http://social.msdn.microsoft.com/Forums/en/multimapapi/thread/d4a5fa90-b5c5-45b4-b4b8-2e5745e58131 but again no luck.
Here's a basic snippet of my latest efforts:
I think the main problem is that I can't find out what values the "target" parameter takes, and how to handle it.polyline = new MMPolyLineOverlay( points, '#FF0000', 0.5, 1, true, '#FFFF00', true ); ... mapviewer.addEventHandler( 'click', eventHandler ); ... function eventHandler(eventType, target, arg3, arg4, arg5) {
if( target instanceof MMPolyLineOverlay ) {
alert( "You clicked on the Line!" );
}else{
alert( "Don't know where you clicked!" );
}
}
To try and work out what the I tried just making the event handler:
function eventHandler(eventType, target, arg3, arg4, arg5) { alert( target ); }this just returns [object Object].
Can anybody point me in the right direction?!
Thanks
Aidan
Answers
- Have you found http://clients.multimap.com/share/documentation/openapi/1.2/classes/
MMPolyLineOverlay has a .reset() method that allows you to re-specify the poly. You may need to experiment, the docs don't make clear if its mandatory to give the points again, and if any {options} that you omit will stay as they are or get reset to defaults.- Marked As Answer byJohn-SheridanMSFT, ModeratorWednesday, November 11, 2009 12:34 PM
All Replies
- Hi Aidin,
I think your target instanceof check is ok, my guess is it's the clickable property as I don't know about the way you are passing the options in the polyline constructor:
polyline = new MMPolyLineOverlay( points, '#FF0000', 0.5, 1, true, '#FFFF00', true );
In the example the options are passed as an object literal and explicitly named:
polyline = new MMPolyLineOverlay( points, { color : color, opacity : opacity, thickness : thickness, closed : closed, fill : fill, clickable : true } );
Cheers,
Paul - A click on a non-clickable poly will still trigger your mapviewer click event handler, but the 'target' will be the map viewer object. You poly should be clickable and what you have should work;
I think you may need to set clickable as an option value in this way
var line = new MMPolyLineOverlay( points, {'color':blah, 'thickness':bleh, 'clickable':true} );
Arg3 will be pixel offset coordinates of the click, which can be translated to lat/long as follows -
var dims = mapviewer.getDimensions();
arg3.x -= dims.width / 2;
arg3.y -= dims.height / 2;
var latlon = mapviewer.getMapPositionAt( arg3 ); - That seems to be working... cheers guys!
- Going on from this - can anybody clear up how I'd go about changing the clickable option for an existing polyline?
- Have you found http://clients.multimap.com/share/documentation/openapi/1.2/classes/
MMPolyLineOverlay has a .reset() method that allows you to re-specify the poly. You may need to experiment, the docs don't make clear if its mandatory to give the points again, and if any {options} that you omit will stay as they are or get reset to defaults.- Marked As Answer byJohn-SheridanMSFT, ModeratorWednesday, November 11, 2009 12:34 PM
- Cheers Ross - had seen that one, but had the same confusion about whetehr you need to pass everything. Haven't been able to get it to work yet, but will have more of a play around with it.

