Ask a questionAsk a question
 

AnswerEvent Handler for Clicks on a Polyline

  • Monday, October 19, 2009 3:22 PMaidangrant Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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:

        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!" );
    }
    }
    I think the main problem is that I can't find out what values the "target" parameter takes, and how to handle it.

    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

All Replies

  • Monday, October 19, 2009 6:36 PMPaulous Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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
  • Monday, October 19, 2009 6:51 PMRossko57 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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 );
  • Monday, October 19, 2009 10:06 PMaidangrant Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    That seems to be working... cheers guys!
  • Tuesday, October 20, 2009 8:09 PMaidangrant Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Going on from this - can anybody clear up how I'd go about changing the clickable option for an existing polyline?
  • Tuesday, October 20, 2009 11:11 PMRossko57 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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.
  • Wednesday, October 21, 2009 9:27 AMaidangrant Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.