I use the following code to group and display a list of ship positions on a map:
function configure_ship_polylines() {
var shipPoints = new Array();
for (var ScenarioPositionID in __data['scenarioPositions']) {
var scenarioPosition = __data['scenarioPositions'][ScenarioPositionID];
var key = "ShipID_" + scenarioPosition.ShipID;
if (shipPoints[key] == null) {
shipPoints[key] = new Array();
}
var latLong = new GLatLng(scenarioPosition.Latitude, scenarioPosition.Longitude);
shipPoints[key].push(latLong);
}
for (var key in shipPoints) {
var points = shipPoints[key];
var ShipID = key.substring(7);
if (points.length > 1) {
var shipPolyline = new GPolyline(points);
__mapItems['shipPolylines'][key] = shipPolyline;
__map.addOverlay(shipPolyline);
}
}
}
It happens that only one of the polylines is displayed on the map. The rest are invisible or not added at all (I'm not quite sure how to debug Google maps to find out). I used firebug many times to debug this, but everything seems fine.
If I create polylines manually, I can add them to the map, and everything will be fine. If I create markers at each point instead of polylines, then the markers appear in the right places.
I'm mad at this because I almost spent a full day trying to figure out what the hell was going on. Any ideas?
source
share