Ask a questionAsk a question
 

AnswerMass update of Polylines

  • Wednesday, October 28, 2009 10:25 AMaidangrant Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Does anybody know of a way to set an option for all Polylines in a map in one go?

    I hav many lines with many points on my map, and need to change whetehr they are clickable or not.  I am currenlty doing this by looping through them all, but this is getting very slow as I add more polylines:

    for ( routeid in polylines){
        polylines[routeid].reset( LatLonPoints[routeid], { clickable : false } );      
    }

    (polylines is an array containing all the polylines, and LatLonPoints is an array containing the points array for each polyline)

Answers

All Replies

  • Wednesday, October 28, 2009 11:29 AMRossko57 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Why not change the approach; leave the polylines alone (as clickable) and change the behaviour of the click listener to "do nothing".
    Whether you have one or many listeners, they can examine a global "switch" variable to see if action is allowed or not.
  • Wednesday, October 28, 2009 12:12 PMaidangrant Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Could work... will let you know...
  • Wednesday, October 28, 2009 12:23 PMaidangrant Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Actually, I had already thought of something similar and ran into difficulties.  To explain....

    I already have one click handler for the "original" state, which will show a pop-up (ie make the 'routeBox' div visible) if you click on a line:

    function clickHandlerMain(eventType, target, arg3, arg4, arg5)   
    {
      if(eventType=='click'){
        if( target instanceof MMPolyLineOverlay ) {           
          document.getElementById('routeBox').style.visibility = 'visible';
        }
      }
    }

    and another for the new state, which lets you draw polylines:

    function clickHandlerDraw(eventType, target, arg3, arg4, arg5)   
    {
      if(eventType=='click'){
        curPoints.push(arg3);
        addPolyline ();
      }
    }

    So when you click "draw", it executes the following (this is currently when it also loops through making all polylines un-clickable):


      mapviewer.removeEventHandler( 'click', clickHandlerMain );
      mapviewer.addEventHandler( 'click', clickHandlerDraw );


    Now, I hoped that if I didn't bother make the polylines un-clickable, the above would act pretty much as you said - clicks on the lines would no longer show the 'routeBox' div and instead, all clicks would draw the polyline.
    The first works OK, but because the lines are still clickable, it doesn't appear to pass the arg3 variable correctly - from what I can tell it gives this in screen coordinates instead of lat/lon, though the documentation (http://clients.multimap.com/share/documentation/api/1.2/classes/) isn't clear on this...

    ...any ideas?!

  • Wednesday, October 28, 2009 1:02 PMaidangrant Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    PS - been trying to use fromPixelToLatLon to get round this, but with no success.  Again the docs are a bit limited, do you ahve an example of this in action?

    Edit - hang on, just realised you covered that in this thread http://social.msdn.microsoft.com/Forums/en-US/multimapapi/thread/e820fe3c-0ba8-4678-b286-9bd50cc0dd0e/... all workign noe, thanks for the advice Ross!