@Override
public void onLoad(LoadCurrentStudyRegionEvent event) {
for (Iterator iterator = studyRegionList.iterator(); iterator
.hasNext();) {
StudyRegion studyRegion = (StudyRegion) iterator.next();
if( studyRegion.isCurrentRegion() )
{
loadRegionDetails(studyRegion);
}
}
}
});
eventBus.addHandler(SentUpdatedRegionPolygonEvent.TYPE, new SentUpdatedRegionPolygonEventHandler() {
@Override
public void onSentUpdatedPolygon(SentUpdatedRegionPolygonEvent event) {
currentPolygon = event.regionPolygon;
}
});
eventBus.addHandler(CacheRegionMapMetaDataEvent.TYPE, new CacheRegionMapMetaDataEventHandler() {
@Override
public void onCache(CacheRegionMapMetaDataEvent event) {
GWT.log("DUPE CacheRegionMapMetaDataEventHandler");
GWT.log("DUPE Apply mapCenter and zoomLevel to currentStudyRegionId:" + currentStudyRegionId);
for (Iterator<StudyRegion> iterator = studyRegionList.iterator(); iterator
.hasNext();) {
StudyRegion studyRegion = (StudyRegion) iterator.next();
if( studyRegion.getId().equals(currentStudyRegionId))
{
LatLng center = event.center;
int mapZoomLevel = event.zoomLevel;
// convert LatLng to Vertex
Vertex mapCenter = new Vertex();
mapCenter.setLat(center.getLatitude());
mapCenter.setLng(center.getLongitude());
studyRegion.setMapCenter(mapCenter);
studyRegion.setMapZoomLevel(mapZoomLevel);
GWT.log("DUPE Study region now has map view:" + studyRegion);
break;
}
}
// now, it makes sense to save the study region here automatically
// rather than forcing the user to do it
GWT.log("DUPE call saveStudyRegion");
saveStudyRegion();
}
});
eventBus.addHandler(CancelRegionEvent.TYPE, new CancelRegionEventHandler() {
@Override
public void onCancelRegion(CancelRegionEvent event) {
clearRegionEditView();
}
});
eventBus.addHandler(TAMTResizeEvent.TYPE, new TAMTResizeEventHandler() {
@Override
public void onTAMTResize(TAMTResizeEvent event) {
GWT.log("SIZE: RegionListing scroll panel height within: " + event.height);
int h = event.height - 500; // account for other study region UI (was 392)
if( h > -1 )
{
String height = Integer.toString(h) + "px";
GWT.log("SIZE: RegionListing scroll panel height: " + height);
scrollPanel.setHeight(height);
}
}
});
eventBus.addHandler(BindPolygonToRegionEvent.TYPE,
new BindPolygonToRegionEventHandler() {
public void onBindPolygonToRegion(BindPolygonToRegionEvent event) {
RegionPolygon p = event.getPolygon();
currentPolygon = p;
GWT.log("DUPE BindPolygonToRegionEventHandler currentPolygon="+currentPolygon);
polygonHash.put(p.getRegionDetailsId(), p);
String n = "";
for (Iterator iterator = studyRegionList.iterator(); iterator
.hasNext();) {
StudyRegion studyRegion = (StudyRegion) iterator.next();
if(studyRegion.getId().equals(currentPolygon.getRegionDetailsId()))
{
n = studyRegion.getName();
}
}
vertices.setText("Current polygon in RegionListing=" + n);
}
});
eventBus.addHandler(EndEditRegionPolygonEvent.TYPE,
new EndEditRegionPolygonEventHandler() {
public void onEndEditRegionPolygon(EndEditRegionPolygonEvent event) {
RegionPolygon p = event.polygon;
currentPolygon = p;
GWT.log("DUPE EndEditRegionPolygonEventHandler currentPolygon="+currentPolygon);
currentStudyRegionId = p.getRegionDetailsId();
polygonHash.put(p.getRegionDetailsId(), p);
// create a minimal StudyRegion with mapCenter and mapZoomLevel
// and put it into the studyRegion list. This handler is only
// run after a new StudyRegion is drawn, so we can safely add
// it to the study region list
StudyRegion minimal = new StudyRegion();
minimal.setId(currentStudyRegionId);
minimal.setMapCenter(p.getMapCenter());
minimal.setMapZoomLevel(p.getMapZoomLevel());
studyRegionList.add(minimal);
/*
* Debug: is the currentStudyRegionId the same as the currentPolygon.getRegionDetailsId()?
*/
GWT.log("DUPE currentStudyRegionId("+currentStudyRegionId+"), currentPolygon.getRegionDetailsId("+currentPolygon.getRegionDetailsId()+") ");
polyline.setText(p.getRegionDetailsId());
String n = "";
for (Iterator iterator = studyRegionList.iterator(); iterator
.hasNext();) {
StudyRegion studyRegion = (StudyRegion) iterator.next();
if(studyRegion.getId().equals(currentPolygon.getRegionDetailsId()))
{
n = studyRegion.getName();
}
}
vertices.setText("Current polygon in RegionListing=" + n);
String regionName = Window.prompt("Name this region", "");
if( regionName == null)
{
eventBus.fireEvent(new CancelRegionEvent(p.getRegionDetailsId()));
} else {
name.setText(regionName);
description.setText("");
description.setFocus(true);
}
GWT.log("DUPE id("+currentPolygon.getRegionDetailsId()+"), name("+regionName+")");
}
});
eventBus.addHandler(GetRegionsEvent.TYPE, new GetRegionsEventHandler() {
public void onGetRegions(GetRegionsEvent event) {
clearRegionEditView();
refreshStudyRegions = true;
fetchStudyRegions();
}
});
eventBus.addHandler(EditRegionDetailsBySegmentEvent.TYPE,
new EditRegionDetailsBySegmentEventHandler() {
@Override
public void onEditRegionDetailsBySegment(EditRegionDetailsBySegmentEvent event) {
currentPolygon = event.regionPolygon;
GWT.log("DUPE EditRegionDetailsBySegmentEventHandler currentPolygon=" + currentPolygon);
if( currentPolygon == null )
{
clearRegionEditView();
return;
}
// find the roadDetails with this id in
for (Iterator iterator = studyRegionList.iterator(); iterator
.hasNext();) {
StudyRegion studyRegion = (StudyRegion) iterator.next();
//GWT.log("EDIT road details loop, working on id=" + roadDetails.getId());
if( studyRegion.getId().equals(currentPolygon.getRegionDetailsId()))
{
loadRegionDetails(studyRegion);
break;
}
}