v3 Documentation for path property of PolyLineOptions states:

"The ordered sequence of coordinates of the Polyline. This path may be
specified using either a simple array of LatLngs, or an MVCArray of
LatLngs. Note that if you pass a simple array, it will be converted to
an MVCArray Inserting or removing LatLngs in the MVCArray will
automatically update the polyline on the map."

I'm using an MVCArray and adding points to the array directly in
response to user input but the Polyline is not updating
automatically.

In the following example, it takes a call to setPath( ) on the
Polyline at each change to get the line to update.

Am I missing something?



var pathArray = new google.maps.MVCArray( );

var pathOptions = { clickable     : false,
                           geodesic      : true,
                           map                : null,
                           path                  :
pathArray,
                           strokeColor      : "#FFAA00",
                           strokeOpacity  : 1.0,
                           strokeWeight   : 2,
                           zIndex                : 1  } ;

var path = new google.maps.Polyline( pathOptions );

var totalDistance = 0.0;



function addPt( mouseEvent ) {

   var point = mouseEvent.latLng;
   var length = pathArray.push( point );
   path.setPath(pathArray);                      // without this call
- no polyline screen update
   if ( length >= 2 ) {
       endMarker.setPosition( point );
       totalDistance +=
point.distanceFrom( pathArray.getAt( length-2 ) );
       if ( length == 2 ) {
           endMarker.setMap( myMap );
           path.setMap( myMap );
       }
   }
   else {
       beginMarker.setPosition( point );
       beginMarker.setMap( myMap );
   }

}

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to google-maps-js-api-v3@googlegroups.com.
To unsubscribe from this group, send email to 
google-maps-js-api-v3+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to