polygon.addPolygonEndLineHandler(new PolygonEndLineHandler() {
public void onEnd(PolygonEndLineEvent event) {
currentPolygon = polygon;
LatLng points[] = new LatLng[currentPolygon.getVertexCount()];
GWT.log("vertex count on add-p-end-line-handler=" + points.length);
for (int i = 0; i < currentPolygon.getVertexCount(); i++) {
LatLng v = currentPolygon.getVertex(i);
LatLng p = LatLng.newInstance(v.getLatitude(), v.getLongitude());
points[i] = p;
}
final RegionPolygon p = new RegionPolygon(points);
p.setRegionDetailsId(currentPolygon.getRegionDetailsId());
// add a mapCenter and mapZoomLevel to the polygon
LatLng center = event.getSender().getBounds().getCenter();
Vertex mapCenter = new Vertex();
mapCenter.setLat(center.getLatitude());
mapCenter.setLng(center.getLongitude());
int mapZoomLevel = map.getZoomLevel();
p.setMapCenter(mapCenter);
p.setMapZoomLevel(mapZoomLevel);
eventBus.fireEvent(new EndEditRegionPolygonEvent(p));
}
});
} else {
/**
* Send a copy of the RegionPolygon to RoadListing
*/
polygon.addPolygonLineUpdatedHandler(new PolygonLineUpdatedHandler() {
public void onUpdate(PolygonLineUpdatedEvent event) {
/*
* If a shape is being edited, it is the current shape
*/
currentPolygon = polygon;
/*
* Copy the currentPolygon into a new RegionPolygon
* in order to send it across the wire.
*/
LatLng points[] = new LatLng[currentPolygon.getVertexCount()];
GWT.log("vertex count on update=" + points.length);
for (int i = 0; i < currentPolygon.getVertexCount(); i++) {
LatLng v = currentPolygon.getVertex(i);
LatLng p = LatLng.newInstance(v.getLatitude(), v.getLongitude());
points[i] = p;
}
final RegionPolygon p = new RegionPolygon(points);
p.setRegionDetailsId(currentPolygon.getRegionDetailsId());
eventBus.fireEvent(new BindPolygonToRegionEvent(p));
}
});