|
|
|
@ -4,6 +4,8 @@ import org.gcube.portlets.widgets.openlayerbasicwidgets.client.event.SelectAreaD
|
|
|
|
|
import org.gcube.portlets.widgets.openlayerbasicwidgets.client.event.SelectAreaDialogEventType;
|
|
|
|
|
import org.gcube.portlets.widgets.openlayerbasicwidgets.client.resource.OLBasicResources;
|
|
|
|
|
import org.gcube.portlets.widgets.openlayerbasicwidgets.client.util.GWTMessages;
|
|
|
|
|
import org.gcube.portlets.widgets.openlayerbasicwidgets.shared.data.Coordinates;
|
|
|
|
|
import org.gcube.portlets.widgets.openlayerbasicwidgets.shared.data.ProjectionType;
|
|
|
|
|
|
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
|
|
|
import com.google.gwt.dom.client.Element;
|
|
|
|
@ -37,8 +39,7 @@ import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
SelectAreaDialogEvent.HasSelectAreaDialogEventHandler {
|
|
|
|
|
public class AreaSelectionDialog extends DialogBox implements SelectAreaDialogEvent.HasSelectAreaDialogEventHandler {
|
|
|
|
|
private static final String COMBO_GEOMETY_TYPE_WIDTH = "406px";
|
|
|
|
|
private static final boolean RESIZABLE = false;
|
|
|
|
|
private static final boolean COLLAPSIBLE = true;
|
|
|
|
@ -52,7 +53,8 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
private ListBox comboGeometryType;
|
|
|
|
|
private TextArea wktGeometry;
|
|
|
|
|
private String wktData;
|
|
|
|
|
private GeometryType initialGeometry;
|
|
|
|
|
private GeometryType geometryType;
|
|
|
|
|
private Coordinates coordinates;
|
|
|
|
|
|
|
|
|
|
public void setWktGeometry(String wktData) {
|
|
|
|
|
// wktData = wktData;
|
|
|
|
@ -64,7 +66,8 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
public AreaSelectionDialog() {
|
|
|
|
|
try {
|
|
|
|
|
ShowAllGeometryGeometry = true;
|
|
|
|
|
initialGeometry = GeometryType.Polygon;
|
|
|
|
|
this.geometryType = GeometryType.Polygon;
|
|
|
|
|
this.coordinates = null;
|
|
|
|
|
initWindow();
|
|
|
|
|
initHandler();
|
|
|
|
|
addToolIcon();
|
|
|
|
@ -78,7 +81,24 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
public AreaSelectionDialog(GeometryType geometryType) {
|
|
|
|
|
try {
|
|
|
|
|
ShowAllGeometryGeometry = false;
|
|
|
|
|
initialGeometry = geometryType;
|
|
|
|
|
this.geometryType = geometryType;
|
|
|
|
|
this.coordinates = null;
|
|
|
|
|
dialogTitle = "Draw a " + geometryType.getLabel();
|
|
|
|
|
initWindow();
|
|
|
|
|
initHandler();
|
|
|
|
|
addToolIcon();
|
|
|
|
|
create();
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
GWT.log(e.getLocalizedMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AreaSelectionDialog(GeometryType geometryType, Coordinates coordinates) {
|
|
|
|
|
try {
|
|
|
|
|
ShowAllGeometryGeometry = false;
|
|
|
|
|
this.geometryType = geometryType;
|
|
|
|
|
this.coordinates = coordinates;
|
|
|
|
|
dialogTitle = "Draw a " + geometryType.getLabel();
|
|
|
|
|
initWindow();
|
|
|
|
|
initHandler();
|
|
|
|
@ -101,23 +121,21 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initHandler() {
|
|
|
|
|
resizeHandlerRegistration = Window
|
|
|
|
|
.addResizeHandler(new ResizeHandler() {
|
|
|
|
|
resizeHandlerRegistration = Window.addResizeHandler(new ResizeHandler() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onResize(ResizeEvent event) {
|
|
|
|
|
center();
|
|
|
|
|
@Override
|
|
|
|
|
public void onResize(ResizeEvent event) {
|
|
|
|
|
center();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void create() {
|
|
|
|
|
|
|
|
|
|
SimplePanel areaSelectionPanel = new SimplePanel();
|
|
|
|
|
areaSelectionPanel.setStyleName(OLBasicResources.INSTANCE.olBasicCSS()
|
|
|
|
|
.getAreaSelectionPanel());
|
|
|
|
|
areaSelectionPanel.setStyleName(OLBasicResources.INSTANCE.olBasicCSS().getAreaSelectionPanel());
|
|
|
|
|
|
|
|
|
|
HTML mapContainer = new HTML(
|
|
|
|
|
"<div id='openLayerMap' class='openLayerMap' style='width:500px;height:250px;'></div>");
|
|
|
|
@ -125,11 +143,14 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
if (ShowAllGeometryGeometry) {
|
|
|
|
|
comboGeometryType = new ListBox();
|
|
|
|
|
comboGeometryType.getElement().setId("combo-geometry-type");
|
|
|
|
|
|
|
|
|
|
//comboGeometryType.getElement().getStyle().setProperty("width", "406px!important");
|
|
|
|
|
|
|
|
|
|
/*comboGeometryType.addStyleName(OLBasicResources.INSTANCE
|
|
|
|
|
.olBasicCSS().getComboGeometryType());*/
|
|
|
|
|
|
|
|
|
|
// comboGeometryType.getElement().getStyle().setProperty("width",
|
|
|
|
|
// "406px!important");
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* comboGeometryType.addStyleName(OLBasicResources.INSTANCE
|
|
|
|
|
* .olBasicCSS().getComboGeometryType());
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
comboGeometryType.setWidth(COMBO_GEOMETY_TYPE_WIDTH);
|
|
|
|
|
comboGeometryType.setTabIndex(10001);
|
|
|
|
@ -138,7 +159,7 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
comboGeometryType.addItem(gType.getLabel());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comboGeometryType.setSelectedIndex(initialGeometry.ordinal());
|
|
|
|
|
comboGeometryType.setSelectedIndex(geometryType.ordinal());
|
|
|
|
|
comboGeometryType.addChangeHandler(new ChangeHandler() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -146,9 +167,8 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
int selected = comboGeometryType.getSelectedIndex();
|
|
|
|
|
if (selected >= 0) {
|
|
|
|
|
String geoLabel = comboGeometryType.getValue(selected);
|
|
|
|
|
GeometryType gType = GeometryType
|
|
|
|
|
.getFromLabel(geoLabel);
|
|
|
|
|
onChangeTypeSelect(gType.getId());
|
|
|
|
|
GeometryType gType = GeometryType.getFromLabel(geoLabel);
|
|
|
|
|
onChangeTypeSelect(gType.name());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -161,19 +181,18 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
wktGeometry.setVisibleLines(5);
|
|
|
|
|
wktGeometry.setTabIndex(10002);
|
|
|
|
|
wktGeometry.getElement().setId("wkt-geometry-text-area");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
wktGeometry.addStyleName(OLBasicResources.INSTANCE.olBasicCSS()
|
|
|
|
|
.getWKTGeometryTextArea());
|
|
|
|
|
*/
|
|
|
|
|
* wktGeometry.addStyleName(OLBasicResources.INSTANCE.olBasicCSS()
|
|
|
|
|
* .getWKTGeometryTextArea());
|
|
|
|
|
*/
|
|
|
|
|
// ////////
|
|
|
|
|
// Form
|
|
|
|
|
FlexTable layout = new FlexTable();
|
|
|
|
|
layout.setCellSpacing(10);
|
|
|
|
|
|
|
|
|
|
FlexTable selectGeometryFlexTable = new FlexTable();
|
|
|
|
|
selectGeometryFlexTable.setStyleName(OLBasicResources.INSTANCE
|
|
|
|
|
.olBasicCSS().getAreaSelectionContent());
|
|
|
|
|
selectGeometryFlexTable.setStyleName(OLBasicResources.INSTANCE.olBasicCSS().getAreaSelectionContent());
|
|
|
|
|
selectGeometryFlexTable.setCellSpacing(2);
|
|
|
|
|
|
|
|
|
|
if (ShowAllGeometryGeometry) {
|
|
|
|
@ -197,12 +216,10 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
dialogContents.setSpacing(4);
|
|
|
|
|
|
|
|
|
|
dialogContents.add(mapContainer);
|
|
|
|
|
dialogContents.setCellHorizontalAlignment(mapContainer,
|
|
|
|
|
HasHorizontalAlignment.ALIGN_CENTER);
|
|
|
|
|
dialogContents.setCellHorizontalAlignment(mapContainer, HasHorizontalAlignment.ALIGN_CENTER);
|
|
|
|
|
|
|
|
|
|
dialogContents.add(areaSelectionPanel);
|
|
|
|
|
dialogContents.setCellHorizontalAlignment(areaSelectionPanel,
|
|
|
|
|
HasHorizontalAlignment.ALIGN_CENTER);
|
|
|
|
|
dialogContents.setCellHorizontalAlignment(areaSelectionPanel, HasHorizontalAlignment.ALIGN_CENTER);
|
|
|
|
|
|
|
|
|
|
// Add Button
|
|
|
|
|
Button btnSave = new Button("Save");
|
|
|
|
@ -237,8 +254,7 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
buttonPack.add(btnClose);
|
|
|
|
|
|
|
|
|
|
dialogContents.add(buttonPack);
|
|
|
|
|
dialogContents.setCellHorizontalAlignment(buttonPack,
|
|
|
|
|
HasHorizontalAlignment.ALIGN_CENTER);
|
|
|
|
|
dialogContents.setCellHorizontalAlignment(buttonPack, HasHorizontalAlignment.ALIGN_CENTER);
|
|
|
|
|
|
|
|
|
|
setWidget(dialogContents);
|
|
|
|
|
|
|
|
|
@ -248,13 +264,49 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
public void show() {
|
|
|
|
|
super.show();
|
|
|
|
|
center();
|
|
|
|
|
initMap(this, initialGeometry.getId());
|
|
|
|
|
String projection=null;
|
|
|
|
|
String longitude= null;
|
|
|
|
|
String latitude = null;
|
|
|
|
|
String zoom = null;
|
|
|
|
|
if (coordinates == null) {
|
|
|
|
|
projection = ProjectionType.EPSG4326.getLabel();
|
|
|
|
|
longitude = "0";
|
|
|
|
|
latitude = "0";
|
|
|
|
|
zoom = "0";
|
|
|
|
|
} else {
|
|
|
|
|
if (coordinates.getProjection() == null || coordinates.getProjection().isEmpty()) {
|
|
|
|
|
projection = ProjectionType.EPSG4326.getLabel();
|
|
|
|
|
} else {
|
|
|
|
|
if (coordinates.getProjection().compareTo(ProjectionType.EPSG4326.getLabel()) == 0
|
|
|
|
|
|| coordinates.getProjection().compareTo(ProjectionType.EPSG3857.getLabel()) == 0) {
|
|
|
|
|
projection = coordinates.getProjection();
|
|
|
|
|
} else {
|
|
|
|
|
projection = ProjectionType.EPSG4326.getLabel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (coordinates.getX() == null || coordinates.getX().isEmpty()) {
|
|
|
|
|
longitude = "0";
|
|
|
|
|
} else {
|
|
|
|
|
longitude = coordinates.getX();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (coordinates.getY() == null || coordinates.getY().isEmpty()) {
|
|
|
|
|
latitude = "0";
|
|
|
|
|
} else {
|
|
|
|
|
latitude = coordinates.getY();
|
|
|
|
|
}
|
|
|
|
|
if (coordinates.getZoom() == null || coordinates.getZoom().isEmpty()) {
|
|
|
|
|
zoom = "0";
|
|
|
|
|
} else {
|
|
|
|
|
zoom = coordinates.getZoom();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
initMap(this, geometryType.name(), projection, longitude, latitude, zoom);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void btnClosePressed() {
|
|
|
|
|
SelectAreaDialogEvent event = new SelectAreaDialogEvent(
|
|
|
|
|
SelectAreaDialogEventType.Aborted);
|
|
|
|
|
SelectAreaDialogEvent event = new SelectAreaDialogEvent(SelectAreaDialogEventType.Aborted);
|
|
|
|
|
fireEvent(event);
|
|
|
|
|
hide();
|
|
|
|
|
|
|
|
|
@ -265,8 +317,7 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
if (area == null || area.isEmpty()) {
|
|
|
|
|
GWTMessages.alert("Attention", "Select a valid area!", zIndex);
|
|
|
|
|
} else {
|
|
|
|
|
SelectAreaDialogEvent event = new SelectAreaDialogEvent(
|
|
|
|
|
SelectAreaDialogEventType.Completed);
|
|
|
|
|
SelectAreaDialogEvent event = new SelectAreaDialogEvent(SelectAreaDialogEventType.Completed);
|
|
|
|
|
event.setArea(area);
|
|
|
|
|
fireEvent(event);
|
|
|
|
|
hide();
|
|
|
|
@ -280,9 +331,14 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
$wnd.addInteraction(value);
|
|
|
|
|
}-*/;
|
|
|
|
|
|
|
|
|
|
private static native void initMap(AreaSelectionDialog instance,
|
|
|
|
|
String initialGeometry) /*-{
|
|
|
|
|
|
|
|
|
|
private static native void initMap(AreaSelectionDialog instance, String geometryName, String projectionName,
|
|
|
|
|
String initX, String initY, String initZoom) /*-{
|
|
|
|
|
console.log(geometryName);
|
|
|
|
|
console.log(projectionName);
|
|
|
|
|
console.log(initX);
|
|
|
|
|
console.log(initY);
|
|
|
|
|
console.log(initZoom);
|
|
|
|
|
|
|
|
|
|
//window.alert("ol: "+$wnd.ol);
|
|
|
|
|
var ol = $wnd.ol;
|
|
|
|
|
$wnd.raster = new ol.layer.Tile({
|
|
|
|
@ -312,17 +368,25 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// coords=ol.proj.fromLonLat(coords);
|
|
|
|
|
// longitude first, then latitude
|
|
|
|
|
var coords=[initX,initY];
|
|
|
|
|
console.log(coords);
|
|
|
|
|
|
|
|
|
|
//window.alert("Retrieve map Id: "+$doc.getElementById('map'));
|
|
|
|
|
|
|
|
|
|
$wnd.mapView=new ol.View({
|
|
|
|
|
projection : projectionName,
|
|
|
|
|
center : coords,
|
|
|
|
|
zoom : initZoom
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log($wnd.mapView);
|
|
|
|
|
$wnd.olMap = new ol.Map({
|
|
|
|
|
layers : [ $wnd.raster, $wnd.vector ],
|
|
|
|
|
target : 'openLayerMap',
|
|
|
|
|
view : new ol.View({
|
|
|
|
|
projection: 'EPSG:4326',
|
|
|
|
|
center : [ 0, 0 ],
|
|
|
|
|
zoom : 0
|
|
|
|
|
})
|
|
|
|
|
view : $wnd.mapView
|
|
|
|
|
});
|
|
|
|
|
console.log($wnd.olMap);
|
|
|
|
|
//window.alert("olMap: "+$wnd.olMap);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
@ -412,7 +476,7 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
// addInteraction();
|
|
|
|
|
//};
|
|
|
|
|
|
|
|
|
|
$wnd.addInteraction(initialGeometry);
|
|
|
|
|
$wnd.addInteraction(geometryName);
|
|
|
|
|
}-*/;
|
|
|
|
|
|
|
|
|
|
private void addToolIcon() {
|
|
|
|
@ -421,16 +485,9 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
Element dialogTopRight = getCellElement(0, 2);
|
|
|
|
|
|
|
|
|
|
// close button image html
|
|
|
|
|
dialogTopRight.setInnerHTML("<div class='"
|
|
|
|
|
+ OLBasicResources.INSTANCE.olBasicCSS()
|
|
|
|
|
.getDialogToolButtonText()
|
|
|
|
|
+ "'>"
|
|
|
|
|
+ "<img src='"
|
|
|
|
|
+ OLBasicResources.INSTANCE.toolButtonClose20().getSafeUri()
|
|
|
|
|
.asString()
|
|
|
|
|
+ "' class='"
|
|
|
|
|
+ OLBasicResources.INSTANCE.olBasicCSS()
|
|
|
|
|
.getDialogToolButtonIcon() + "' /></div>");
|
|
|
|
|
dialogTopRight.setInnerHTML("<div class='" + OLBasicResources.INSTANCE.olBasicCSS().getDialogToolButtonText()
|
|
|
|
|
+ "'>" + "<img src='" + OLBasicResources.INSTANCE.toolButtonClose20().getSafeUri().asString()
|
|
|
|
|
+ "' class='" + OLBasicResources.INSTANCE.olBasicCSS().getDialogToolButtonIcon() + "' /></div>");
|
|
|
|
|
|
|
|
|
|
// set the event target
|
|
|
|
|
closeEventTarget = dialogTopRight.getChild(0).getChild(0);
|
|
|
|
@ -449,10 +506,8 @@ public class AreaSelectionDialog extends DialogBox implements
|
|
|
|
|
protected void onPreviewNativeEvent(NativePreviewEvent event) {
|
|
|
|
|
NativeEvent nativeEvent = event.getNativeEvent();
|
|
|
|
|
|
|
|
|
|
if (!event.isCanceled() && (event.getTypeInt() == Event.ONCLICK)
|
|
|
|
|
&& isCloseEvent(nativeEvent)) {
|
|
|
|
|
final SelectAreaDialogEvent wizardEvent = new SelectAreaDialogEvent(
|
|
|
|
|
SelectAreaDialogEventType.Aborted);
|
|
|
|
|
if (!event.isCanceled() && (event.getTypeInt() == Event.ONCLICK) && isCloseEvent(nativeEvent)) {
|
|
|
|
|
final SelectAreaDialogEvent wizardEvent = new SelectAreaDialogEvent(SelectAreaDialogEventType.Aborted);
|
|
|
|
|
fireEvent(wizardEvent);
|
|
|
|
|
this.hide();
|
|
|
|
|
}
|
|
|
|
|