Polyline not updating automatically when performing insert/remove on underlying MVCArray

110 views
Skip to first unread message

kjh21

unread,
Feb 15, 2011, 2:27:36 PM2/15/11
to Google Maps JavaScript API v3


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 );
}

}

Rossko

unread,
Feb 15, 2011, 2:32:52 PM2/15/11
to Google Maps JavaScript API v3
> Am I missing something?

Sart here, "READ THIS FIRST"
http://groups.google.com/group/google-maps-js-api-v3/t/2b3f101fd509919e
Might be a scope issue, can't tell from your snippet
Reply all
Reply to author
Forward
0 new messages