ref 11708: Setting initial map location and zoom level for the spatial data inputs in SAI

https://support.d4science.org/issues/11708

Added location and zoom

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/openlayer-basic-widgets@178768 82a268e6-3cf1-43bd-a215-b396298e98cf
master
Giancarlo Panichi 5 years ago
parent 52bd941b98
commit 8810846308

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/openlayer-basic-widgets-1.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/openlayer-basic-widgets-1.3.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/openlayer-basic-widgets-1.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/openlayer-basic-widgets-1.3.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -22,7 +22,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -33,5 +33,5 @@
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="target/openlayer-basic-widgets-1.2.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/openlayer-basic-widgets-1.3.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

@ -7,7 +7,7 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate

@ -1,4 +1,9 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets.widgets.openlayer-basic-widgets.1-3-0"
date="2019-04-01">
<Change>Added location and zoom support [ticket #11708]</Change>
<Change>Added coordinates EPSG:4326 and EPSG:3857 support [ticket #11710]</Change>
</Changeset>
<Changeset component="org.gcube.portlets.widgets.openlayer-basic-widgets.1-2-0"
date="2017-06-12">
<Change>Support Java 8 compatibility [ticket #8471]</Change>

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>openlayer-basic-widgets</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
<name>openlayer-basic-widgets</name>
<description>openlayer-basic-widgets</description>
@ -38,11 +38,12 @@
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<distroDirectory>distro</distroDirectory>
<configDirectory>config</configDirectory>
<!-- Java -->
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- Java Version -->
<javaVersion>1.7</javaVersion>
<!-- GWT configuration -->
<gwtVersion>2.7.0</gwtVersion>
<gwtLogVersion>3.3.2</gwtLogVersion>
@ -198,8 +199,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${javaVersion}</source>
<target>${javaVersion}</target>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>

@ -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();
}

@ -33,9 +33,6 @@ public enum GeometryType {
return label;
}
public String getId() {
return name();
}
/**
*

@ -0,0 +1,67 @@
package org.gcube.portlets.widgets.openlayerbasicwidgets.shared.data;
import java.io.Serializable;
/**
*
* @author Giancarlo Panichi
*
*
*/
public class Coordinates implements Serializable {
private static final long serialVersionUID = -1387634056697911513L;
private String projection;
private String x;
private String y;
private String zoom;
public Coordinates() {
super();
}
public Coordinates(String projection, String x, String y, String zoom) {
super();
this.projection = projection;
this.x = x;
this.y = y;
this.zoom = zoom;
}
public String getProjection() {
return projection;
}
public void setProjection(String projection) {
this.projection = projection;
}
public String getX() {
return x;
}
public void setX(String x) {
this.x = x;
}
public String getY() {
return y;
}
public void setY(String y) {
this.y = y;
}
public String getZoom() {
return zoom;
}
public void setZoom(String zoom) {
this.zoom = zoom;
}
@Override
public String toString() {
return "Coordinate [projection=" + projection + ", x=" + x + ", y=" + y + ", zoom=" + zoom + "]";
}
}

@ -0,0 +1,42 @@
package org.gcube.portlets.widgets.openlayerbasicwidgets.shared.data;
/**
*
* @author Giancarlo Panichi
*
*
*/
public enum ProjectionType {
EPSG4326("EPSG:4326"),
EPSG3857("EPSG:3857");
private final String id;
private ProjectionType(final String id) {
this.id = id;
}
@Override
public String toString() {
return id;
}
public String getLabel() {
return id;
}
public static ProjectionType getProjectionTypeFromId(String id) {
for (ProjectionType projectionType : values()) {
if (projectionType.id.compareToIgnoreCase(id) == 0) {
return projectionType;
}
}
return null;
}
}
Loading…
Cancel
Save