2054: Geo-Utility: an utility class to work with geo-spatial data

Task-Url: https://support.d4science.org/issues/2054

Gis Viewer Application has been integrated with geo-utility library

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/gis-viewer-app@122467 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-01-22 16:23:21 +00:00
parent 6521c1453f
commit 0ac3230e38
10 changed files with 286 additions and 219 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/gis-viewer-app-1.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/gis-viewer-app-1.3.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
@ -30,5 +30,5 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/gis-viewer-app-1.2.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/gis-viewer-app-1.3.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -3,7 +3,10 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<dependent-module archiveName="gis-viewer-3.9.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gis-viewer-TRUNK/gis-viewer-TRUNK">
<dependent-module archiveName="geo-utility-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geo-utility/geo-utility">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="gis-viewer-3.10.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gis-viewer-TRUNK/gis-viewer-TRUNK">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>

View File

@ -14,7 +14,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gis-viewer-app</artifactId>
<packaging>war</packaging>
<version>1.2.0-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
<name>Gis Viewer App</name>
<description>
The Gis Viewer App
@ -70,6 +70,12 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>geo-utility</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- GCUBE GIS VIEWER -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.portlets.user</groupId> -->

View File

@ -1,5 +1,5 @@
/**
*
*
*/
package org.gcube.portlets.user.gisviewerapp.client;
@ -33,7 +33,7 @@ import com.google.gwt.user.client.ui.RootPanel;
public class ApplicationController {
/**
*
*
*/
private GisViewerPanel gisViewerPanel; // for normal mode
// private GCubeGisViewerPanel gisViewerPanel; // for gcube mode
@ -48,7 +48,7 @@ public class ApplicationController {
@SuppressWarnings("unused")
private RootPanel gwtRootPanel;
/**
*
*
*/
public ApplicationController() {
mainPanel = new LayoutContainer();
@ -61,54 +61,49 @@ public class ApplicationController {
wmsRequestConverter = new WmsRequestConverter(gisViewerPanel);
mainPanel.add(gisViewerContentPanel);
}
private void initGisViewerParameters(){
gisViewerParameters = new GisViewerParameters();
gisViewerParameters.setProjection("");
gisViewerParameters.setOpenDataPanelAtStart(false);
gisViewerParameters.setDataPanelOpenListener(new DataPanelOpenListener() {
@Override
public void dataPanelOpen(boolean isOpen, int panelHeight) {
// OLD CODE
// int gisViewerHeight = gisViewerContentPanel.getHeight()+ (isOpen ? panelHeight-24 : -panelHeight+24);
// ConstantGisViewerApp.logger.log(Level.INFO, "Set heigth: "+gisViewerHeight);
// gisViewerContentPanel.setHeight(gisViewerHeight);
int dataPanelHeight = isOpen ? panelHeight+24 : 24;
int gisViewerHeight;
if(gisViewerContentPanel.getHeight()>Constants.minGisViewerHeight)
gisViewerHeight = gisViewerContentPanel.getHeight();
else
gisViewerHeight = Constants.minGisViewerHeight+dataPanelHeight;
if(gisViewerContentPanel.getHeight()>Constants.minGisViewerHeight) {
gisViewerHeight = gisViewerContentPanel.getHeight();
}
else {
gisViewerHeight = Constants.minGisViewerHeight+dataPanelHeight;
}
gisViewerContentPanel.setHeight(gisViewerHeight);
}
});
}
private void initGisViewerContentPanel(){
gisViewerContentPanel = new ContentPanel() {
@Override
protected void onExpand() {
super.onExpand();
if (gisViewerPanel!=null)
if (gisViewerPanel!=null) {
gisViewerPanel.updateOpenLayersSize();
}
}
@Override
protected void onCollapse() {
super.onCollapse();
}
};
gisViewerContentPanel.setLayout(new FitLayout());
gisViewerContentPanel.setHeading(ConstantGisViewerApp.GIS_VIEWER_APP);
gisViewerContentPanel.setHeaderVisible(false);
@ -123,39 +118,38 @@ public class ApplicationController {
public void go(final RootPanel rootPanel) {
this.gwtRootPanel = rootPanel;
rootPanel.add(mainPanel);
String wmsRequest = Window.Location.getParameter(ConstantGisViewerApp.GET_WMS_PARAMETER);
ConstantGisViewerApp.logger.log(Level.INFO, ConstantGisViewerApp.GET_WMS_PARAMETER+ " is "+wmsRequest);
// String replacement = Window.Location.getParameter(ConstantGisViewerApp.WMS_PARAM_SEPARATOR_REPLACEMENT_KEY);
// ConstantGisViewerApp.logger.log(Level.INFO, ConstantGisViewerApp.WMS_PARAM_SEPARATOR_REPLACEMENT_KEY+ " is "+replacement);
if(wmsRequest!=null && !wmsRequest.isEmpty()){
// if(replacement!=null && !replacement.isEmpty()){
// ConstantGisViewerApp.logger.log(Level.INFO, "Replacing all "+replacement);
// wmsRequest = wmsRequest.replaceAll(replacement, wmsRequest);
// }
try {
wmsRequestConverter.parseRequest(wmsRequest,null);
wmsRequestConverter.addRequestToGisViewer();
wmsRequestConverter.addRequestToGisViewer(wmsRequest,null);
} catch (Exception e) {
ConstantGisViewerApp.logger.log(Level.INFO, "An error occurred on adding wmsrequest :"+wmsRequest);
e.printStackTrace();
}
}
rootPanel.add(lcWMS);
lcWMS.setId("WMS");
Command cmd = new Command() {
@Override
public void execute() {
final DialogBox box = new DialogBox(true);
box.setText("Add External WMS Layer");
box.getElement().getStyle().setZIndex(10000);
WmsForm form = new WmsForm() {
@Override
@ -165,9 +159,9 @@ public class ApplicationController {
@Override
public void subtmitHandler(String title, String name, String wmsRequest) {
//TODO UPDATE
gisViewerPanel.addLayerByWms(title, name, wmsRequest, false, false, false);
//TODO UPDATE
gisViewerPanel.addLayerByWms(title, name, wmsRequest, false, false, null);
box.hide();
}
};
@ -176,16 +170,16 @@ public class ApplicationController {
box.center();
}
};
balloonWMS = new BaloonPanel("+WMS", false, cmd);
SetZIndex setZIndex = new SetZIndex();
safeFunctionCallOn(lcWMS,setZIndex);
}
/**
*
*
* @param wmsRequest
* @return
*/
@ -203,9 +197,9 @@ public class ApplicationController {
public GisViewerPanel getGisViewerPanel() {
return gisViewerPanel;
}
/**
*
*
*/
public void moveWMSBalloonPosition(){
balloonWMS.hide();
@ -248,7 +242,7 @@ public class ApplicationController {
c.addListener(Events.Render, lsnr);
}
}
public interface Function {
public void execute();
}
@ -257,7 +251,7 @@ public class ApplicationController {
/*
* (non-Javadoc)
*
*
* @see
* org.gcube.portlets.user.gisviewerapp.client.ApplicationController
* .Function#execute()
@ -266,17 +260,17 @@ public class ApplicationController {
public void execute() {
final Timer tm = new Timer() {
@Override
public void run() {
int zi = lcWMS.el().getZIndex();
GWT.log("zindex: "+zi);
int zIndex = zi<300?300:zi;
balloonWMS.getElement().getStyle().setZIndex(zIndex);
}
};
tm.schedule(1000);
}
}

View File

@ -1,18 +1,19 @@
/**
*
*
*/
package org.gcube.portlets.user.gisviewerapp.client;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.gcube.portlets.user.gisviewer.client.GisViewerPanel;
import org.gcube.portlets.user.gisviewer.client.GisViewerPanel.LayerType;
import org.gcube.portlets.user.gisviewer.client.commons.utils.WmsUrlValidator;
import org.gcube.portlets.user.gisviewerapp.client.rpc.GisViewerAppServiceAsync;
import org.gcube.portlets.user.gisviewerapp.shared.GeoStyles;
import org.gcube.spatial.data.geoutility.bean.WmsParameters;
import org.gcube.spatial.data.geoutility.wms.WmsUrlValidator;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
@ -22,22 +23,21 @@ import com.google.gwt.user.client.Window;
* Dec 10, 2015
*/
public class WmsRequestConverter {
private GisViewerPanel gisViewer;
private LayerType layerType = LayerType.FEATURETYPE;
private String title;
private String displayLayerName;
private String url;
private String url;
private boolean isExternal = false;
private boolean isBase = false;
private boolean displayInLayerSwitcher = false;
private boolean onTop = true;
private ArrayList<String> listStyles;
private String wmsRequest;
private HashMap<String, String> noWMSParams;
private boolean isNcWMS = false;
private WmsUrlValidator urlValidator;
/**
* Instantiates a new wms request converter.
*
@ -46,7 +46,7 @@ public class WmsRequestConverter {
public WmsRequestConverter(GisViewerPanel gisViewerPanel) {
this.gisViewer = gisViewerPanel;
}
/**
* Parses the request.
*
@ -54,52 +54,69 @@ public class WmsRequestConverter {
* @param displayName the display name
* @throws Exception the exception
*/
public void parseRequest(String wmsRequest, String displayName) throws Exception{
public void addRequestToGisViewer(String wmsRequest, String displayName) throws Exception{
this.wmsRequest = wmsRequest;
//FIND BASE URL
int indexStart = wmsRequest.indexOf("?");
if(indexStart>=0){
url = wmsRequest.substring(0, indexStart); //get only parameters
url = wmsRequest.substring(0, indexStart); //get only base uri
url = url.trim(); //string trim
}else{
Window.alert("Bad wms request '?' not found!");
// throw new Exception("Bad server request '?' not found!");
}
WmsUrlValidator urlValidator = new WmsUrlValidator(wmsRequest);
urlValidator = new WmsUrlValidator(wmsRequest);
urlValidator.parseWmsRequest(true,false);
String layerName = urlValidator.getValueOfParsedWMSParameter(org.gcube.portlets.user.gisviewer.client.commons.utils.WmsParameters.LAYERS);
String layerName = urlValidator.getValueOfParsedWMSParameter(WmsParameters.LAYERS);
if(layerName==null || layerName.isEmpty()){
Window.alert("Bad wms request LAYER parameter not found!");
throw new Exception("Layer name not found!");
}else{
displayLayerName = layerName;
title = layerName;
if(displayName!=null && !displayName.isEmpty())
if(displayName!=null && !displayName.isEmpty()) {
displayLayerName = displayName;
}
}
this.listStyles = new ArrayList<String>();
GisViewerAppServiceAsync.Util.getInstance().getStylesForWmsRequest(wmsRequest, new AsyncCallback<GeoStyles>() {
@Override
public void onSuccess(GeoStyles result) {
addRequestToGisViewer((ArrayList<String>) result.getStyles(), result.isNcWMS());
}
@Override
public void onFailure(Throwable caught) {
addRequestToGisViewer(new ArrayList<String>(1), false);
}
});
/*this.listStyles = new ArrayList<String>();
String style = urlValidator.getValueOfParsedWMSParameter(org.gcube.portlets.user.gisviewer.client.commons.utils.WmsParameters.STYLES);
GWT.log("Wms request, style "+style);
if(style!=null)
if(style!=null) {
this.listStyles.add(style);
}
Map<String, String> noWms = urlValidator.getMapWmsNotStandardParams();
this.noWMSParams = new HashMap<String, String>();
if(noWms!=null && noWms.size()>0){
this.noWMSParams.putAll(noWms);
this.isNcWMS = true;
}
}*/
}
/**
* Adds the request to gis viewer.
* @param listStyles
*/
public void addRequestToGisViewer(){
gisViewer.addLayerByWms(GisViewerPanel.LayerType.FEATURETYPE, displayLayerName, title, url, isExternal, isBase, displayInLayerSwitcher, listStyles, wmsRequest, onTop, noWMSParams, isNcWMS);
public void addRequestToGisViewer(ArrayList<String> styles, boolean ncWMS){
gisViewer.addLayerByWms(GisViewerPanel.LayerType.FEATURETYPE, displayLayerName, title, url, isExternal, isBase, displayInLayerSwitcher, styles, wmsRequest, onTop, urlValidator.getParametersMap(), ncWMS, null);
// gisViewer.addLayerByWms(title, displayLayerName, wmsRequest, isBase, displayInLayerSwitcher, null);
}
/**
@ -174,15 +191,6 @@ public class WmsRequestConverter {
return onTop;
}
/**
* Gets the list styles.
*
* @return the list styles
*/
public ArrayList<String> getListStyles() {
return listStyles;
}
/**
* Sets the layer type.
*
@ -254,48 +262,4 @@ public class WmsRequestConverter {
public void setOnTop(boolean onTop) {
this.onTop = onTop;
}
/**
* Sets the list styles.
*
* @param listStyles the new list styles
*/
public void setListStyles(ArrayList<String> listStyles) {
this.listStyles = listStyles;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("WmsRequestConverter [gisViewer=");
builder.append(gisViewer);
builder.append(", layerType=");
builder.append(layerType);
builder.append(", title=");
builder.append(title);
builder.append(", displayLayerName=");
builder.append(displayLayerName);
builder.append(", url=");
builder.append(url);
builder.append(", isExternal=");
builder.append(isExternal);
builder.append(", isBase=");
builder.append(isBase);
builder.append(", displayInLayerSwitcher=");
builder.append(displayInLayerSwitcher);
builder.append(", onTop=");
builder.append(onTop);
builder.append(", listStyles=");
builder.append(listStyles);
builder.append(", wmsRequest=");
builder.append(wmsRequest);
builder.append(", noWMSParams=");
builder.append(noWMSParams);
builder.append("]");
return builder.toString();
}
}

View File

@ -1,12 +1,26 @@
package org.gcube.portlets.user.gisviewerapp.client.rpc;
import org.gcube.portlets.user.gisviewerapp.shared.GeoStyles;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/**
* The client side stub for the RPC service.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jan 22, 2016
*/
@RemoteServiceRelativePath("gisapp")
public interface GisViewerAppService extends RemoteService {
String greetServer(String name) throws IllegalArgumentException;
/**
* Gets the styles for wms request.
*
* @param wmsRequest the wms request
* @return the styles for wms request
*/
GeoStyles getStylesForWmsRequest(String wmsRequest);
}

View File

@ -1,25 +1,34 @@
package org.gcube.portlets.user.gisviewerapp.client.rpc;
import org.gcube.portlets.user.gisviewerapp.shared.GeoStyles;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* The Interface GisViewerAppServiceAsync.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jan 22, 2016
*/
public interface GisViewerAppServiceAsync
{
/**
* GWT-RPC service asynchronous (client-side) interface
* @see org.gcube.portlets.user.gisviewerapp.client.rpc.GisViewerAppService
* Utility class to get the RPC Async interface from client-side code.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jan 22, 2016
*/
void greetServer( java.lang.String name, AsyncCallback<java.lang.String> callback );
/**
* Utility class to get the RPC Async interface from client-side code
*/
public static final class Util
{
public static final class Util
{
private static GisViewerAppServiceAsync instance;
/**
* Gets the single instance of Util.
*
* @return single instance of Util
*/
public static final GisViewerAppServiceAsync getInstance()
{
if ( instance == null )
@ -29,9 +38,24 @@ public interface GisViewerAppServiceAsync
return instance;
}
/**
* Instantiates a new util.
*/
private Util()
{
// Utility class should not be instanciated
}
}
/**
* Gets the styles for wms request.
*
* @param wmsRequest the wms request
* @param callback the callback
* @return the styles for wms request
*/
void getStylesForWmsRequest(
String wmsRequest, AsyncCallback<GeoStyles> callback);
}

View File

@ -1,18 +1,43 @@
package org.gcube.portlets.user.gisviewerapp.server;
import org.apache.log4j.Logger;
import org.gcube.portlets.user.gisviewerapp.client.rpc.GisViewerAppService;
import org.gcube.portlets.user.gisviewerapp.shared.GeoStyles;
import org.gcube.spatial.data.geoutility.GeoGetStyles;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
* The server side implementation of the RPC service.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jan 22, 2016
*/
@SuppressWarnings("serial")
public class GisViewerAppServiceImpl extends RemoteServiceServlet implements
GisViewerAppService {
public class GisViewerAppServiceImpl extends RemoteServiceServlet implements GisViewerAppService {
public String greetServer(String input) throws IllegalArgumentException {
return "";
}
private static Logger logger =Logger.getLogger(GisViewerAppServiceImpl.class);
/* (non-Javadoc)
* @see org.gcube.portlets.user.gisviewerapp.client.rpc.GisViewerAppService#getStylesForWmsRequest(java.lang.String)
*/
@Override
public GeoStyles getStylesForWmsRequest(String wmsRequest) {
try {
logger.info("Tentative get styles for wmsRequest: "+wmsRequest);
GeoGetStyles geoGetStyles = new GeoGetStyles(wmsRequest);
GeoStyles geo = new GeoStyles();
geo.setStyles(geoGetStyles.getGeoStyles());
geo.setNcWMS(geoGetStyles.isNcWms());
return geo;
}
catch (Exception e) {
logger.error("An error occurred during get styles, returning an empty GeoStyles: ",e);
return new GeoStyles();
}
}
}

View File

@ -0,0 +1,106 @@
/**
*
*/
package org.gcube.portlets.user.gisviewerapp.shared;
import java.io.Serializable;
import java.util.List;
/**
* The Class GeoStyles.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jan 22, 2016
*/
public class GeoStyles implements Serializable {
/**
*
*/
private static final long serialVersionUID = 7307380872802285337L;
List<String> styles;
boolean isNcWMS = false;
/**
* Instantiates a new geo styles.
*/
public GeoStyles() {
}
/**
* Instantiates a new geo styles.
*
* @param styles the styles
* @param isNcWMS the is nc wms
*/
public GeoStyles(List<String> styles, boolean isNcWMS) {
super();
this.styles = styles;
this.isNcWMS = isNcWMS;
}
/**
* Gets the styles.
*
* @return the styles
*/
public List<String> getStyles() {
return styles;
}
/**
* Checks if is nc wms.
*
* @return the isNcWMS
*/
public boolean isNcWMS() {
return isNcWMS;
}
/**
* Sets the styles.
*
* @param styles the styles to set
*/
public void setStyles(List<String> styles) {
this.styles = styles;
}
/**
* Sets the nc wms.
*
* @param isNcWMS the isNcWMS to set
*/
public void setNcWMS(boolean isNcWMS) {
this.isNcWMS = isNcWMS;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GeoStyles [styles=");
builder.append(styles);
builder.append(", isNcWMS=");
builder.append(isNcWMS);
builder.append("]");
return builder.toString();
}
}

View File

@ -1,69 +0,0 @@
package org.gcube.portlets.user.gisviewerapp.shared;
/**
*
* Param Mandatory
* service Yes Service name. Value is WMS.
* version Yes Service version. Value is one of 1.0.0, 1.1.0, 1.1.1, 1.3.
* request Yes Operation name. Value is GetMap.
* layers Yes Layers to display on map. Value is a comma-separated list of layer names.
* styles Yes Styles in which layers are to be rendered. Value is a comma-separated list of style names, or empty if default styling is required. Style names may be empty in the list, to use default layer styling.
* srs or crs Yes Spatial Reference System for map output. Value is in form EPSG:nnn. crs is the parameter key used in WMS 1.3.0.
* bbox Yes Bounding box for map extent. Value is minx,miny,maxx,maxy in units of the SRS.
* width Yes Width of map output, in pixels.
* height Yes Height of map output, in pixels.
* format Yes Format for the map output. See WMS output formats for supported values.
* transparent No Whether the map background should be transparent. Values are true or false. Default is false
* bgcolor No Background color for the map image. Value is in the form RRGGBB. Default is FFFFFF (white).
* exceptions No Format in which to report exceptions. Default value is application/vnd.ogc.se_xml.
* time No Time value or range for map data. See Time Support in Geoserver WMS for more information.
* sld No A URL referencing a StyledLayerDescriptor XML file which controls or enhances map layers and styling
* sld_body No A URL-encoded StyledLayerDescriptor XML document which controls or enhances map layers and styling
*
*/
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Apr 26, 2013
*
*/
public enum WmsParameters {
SERVICE("SERVICE", "WMS"),
VERSION("VERSION", "1.1.0"),
REQUEST("REQUEST", "GetMap"),
LAYERS("LAYERS", ""),
STYLES("STYLES",""),
BBOX("BBOX","-180,-90,180,90"),
WIDTH("WIDTH","676"),
HEIGHT("HEIGHT","230"),
SRS("SRS","EPSG:4326"),
CRS("CRS","EPSG:4326"), //WMS 1.3.0 COMPLIANT
FORMAT("FORMAT","image/png"),
TRANSPARENT("TRANSPARENT","true");
private String parameter;
private String value;
WmsParameters(String parameter, String value){
this.parameter = parameter;
this.value = value;
}
public String getParameter() {
return parameter;
}
public void setParameter(String parameter) {
this.parameter = parameter;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}