private void displayOverlay() {
map.clearOverlays();
LatLngBounds bounds = map.getBounds();
LatLng southWest = bounds.getSouthWest();
LatLng northEast = bounds.getNorthEast();
double lngSpan = northEast.getLongitude() - southWest.getLongitude();
double latSpan = northEast.getLatitude() - southWest.getLatitude();
LatLng[] points = new LatLng[NUM_POINTS];
for (int i = 0; i < NUM_POINTS; i++) {
points[i] = LatLng.newInstance(southWest.getLatitude() + latSpan * Math.random(),
southWest.getLongitude() + lngSpan * Math.random());
GWT.log("points[" + i + "] = " + points[i] + " z-index = "
+ Marker.getZIndex(points[i].getLatitude()), null);
}
OverlayDemos selected = OverlayDemos.values()[actionListBox.getSelectedIndex()];
switch (selected) {
case TEST_TEN_MARKERS: {
// Add markers in random locations on the map
for (int i = 0; i < NUM_POINTS; i++) {
map.addOverlay(new Marker(points[i]));
}
}
break;
case TEST_POLYLINE_ONE: {
// Add a polyline with NUM_POINTS random points. Sort the points by
// longitude so that the line does not intersect itself.
Arrays.sort(points, new Comparator<LatLng>() {
public int compare(LatLng p1, LatLng p2) {
return new Double(p1.getLongitude()).compareTo(new Double(
p2.getLongitude()));
}
});
Polyline pline = new Polyline(points);
map.addOverlay(pline);
if (pline.getVertexCount() != NUM_POINTS) {
Window.alert("Created polyline with " + NUM_POINTS
+ " vertices, but now it has " + pline.getVertexCount());
}
}
break;
case TEST_POLYLINE_ENCODED: {
// Add a polyline encoded in a string
map.setCenter(LatLng.newInstance(40.71213418976525, -73.96785736083984), 15);
Polyline pline = Polyline.fromEncoded("#3333cc", 10, 1.0,
ENCODED_POINTS, 32, ENCODED_LEVELS, 4);
map.addOverlay(pline);
}
break;
case TEST_POLYLINE_GEODESIC: {
LatLng nycToZurich[] = {LatLng.newInstance(40.75, -73.90), // New York
LatLng.newInstance(47.3, 8.5) // Zurich
};
map.setCenter(LatLng.newInstance(40, -25), 2);
Polyline pline = new Polyline(nycToZurich, "#FF0000", 1, .75,
PolylineOptions.newInstance(false, true));