kjh21
unread,Feb 15, 2011, 2:27:36 PM2/15/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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 );
}
}