layer_switcher #3

Closed
francesco.mangiacrapa wants to merge 12 commits from layer_switcher into master
21 changed files with 1066 additions and 452 deletions

View File

@ -1,197 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="geoportal-data-viewer-app-2.0.0-SNAPSHOT">
<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="/target/generated-sources/gwt"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="geoportal-data-common-1.2.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-common/geoportal-data-common">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/geoportal-data-viewer-app/target/geoportal-data-viewer-app-0.0.1-SNAPSHOT/WEB-INF/classes"/>
<property name="context-root" value="geoportal-data-viewer-app"/>
</wb-module>
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="geoportal-data-viewer-app-2.0.0-SNAPSHOT">
<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="/target/generated-sources/gwt"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="geoportal-data-common-1.2.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-common/geoportal-data-common">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/geoportal-data-viewer-app/target/geoportal-data-viewer-app-0.0.1-SNAPSHOT/WEB-INF/classes"/>
<property name="context-root" value="geoportal-data-viewer-app"/>
</wb-module>
</project-modules>

View File

@ -4,7 +4,7 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v2.0.0-SNAPSHOT] - 2021-07-30
## [v2.0.0] - 2021-07-30
#### Enhancements
@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- [#22042] Implemented the public access
- [#22040] Revisited the "Abstract and Relazione di Scavo"
- [#22041] Files have been ported to FileSet model
- [#21991] Implement the Layer Switcher
## [v1.2.0-SNAPSHOT] - 2021-07-19

View File

@ -14,7 +14,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>geoportal-data-viewer-app</artifactId>
<packaging>war</packaging>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.0</version>
<name>GeoPortal Data Viewer App</name>
<description>The GeoPortal Data Viewer App is an application to access, discovery and navigate the GeoNa products by a Web-Map Interface</description>
@ -54,7 +54,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>3.6.3-SNAPSHOT</version>
<version>3.6.3</version>
<type>pom</type>
<scope>import</scope>
<exclusions>

View File

@ -6,7 +6,7 @@
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard' /> -->
<inherits name='com.google.gwt.user.theme.standard.Standard' />
<inherits name='ol.GwtOL' />

View File

@ -10,9 +10,13 @@ import org.gcube.application.geoportalcommon.shared.products.model.RecordDV;
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION;
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MapEventType;
import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent.LAYER_TYPE;
import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEventHandler;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ClosedViewDetailsEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ClosedViewDetailsEventHandler;
import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent.DO_LAYER_ACTION;
import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEventHandler;
import org.gcube.portlets.user.geoportaldataviewer.client.events.MapExtentToEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.MapExtentToEventHandler;
import org.gcube.portlets.user.geoportaldataviewer.client.events.QueryDataEvent;
@ -22,6 +26,7 @@ import org.gcube.portlets.user.geoportaldataviewer.client.events.ZoomOutOverMini
import org.gcube.portlets.user.geoportaldataviewer.client.events.ZoomOutOverMinimumEventHandler;
import org.gcube.portlets.user.geoportaldataviewer.client.gis.ExtentWrapped;
import org.gcube.portlets.user.geoportaldataviewer.client.gis.MapUtils;
import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerOSM;
import org.gcube.portlets.user.geoportaldataviewer.client.ui.GeonaDataViewMainPanel;
import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoQuery;
@ -87,9 +92,7 @@ public class GeoportalDataViewer implements EntryPoint {
* This is the entry point method.
*/
public void onModuleLoad() {
mainPanel = new GeonaDataViewMainPanel(applicationBus, getClientHeight());
RootPanel.get(APP_DIV).add(mainPanel);
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@ -173,7 +176,7 @@ public class GeoportalDataViewer implements EntryPoint {
layerItem.setName(layerName);
layerManager.setBaseLayerFromIsProfile(layerItem);
layerManager.addLayer(theItemType, null, null, layerItem.getWmsLink(), false, false,
null, false, null, null,null);
null, false, null, null, null);
if (paramGeonaItemID != null) {
if (paramGeonaItemType == null) {
@ -193,7 +196,6 @@ public class GeoportalDataViewer implements EntryPoint {
});
bindEvents();
}
/**
@ -267,7 +269,7 @@ public class GeoportalDataViewer implements EntryPoint {
@Override
public void onLayerRendered(AddedLayerToMapEvent addedLayerToMapEvent) {
GWT.log("Fired AddedLayerToMapEvent " + addedLayerToMapEvent.getLayerItem());
GWT.log("Fired AddedLayerToMapEvent " + addedLayerToMapEvent.getLayerItem() + "layer type: "+addedLayerToMapEvent.getLayerType());
// GeoportalDataViewerConstants.print("Fired AddedLayerToMapEvent
// "+addedLayerToMapEvent.getLayerItem());
@ -304,6 +306,23 @@ public class GeoportalDataViewer implements EntryPoint {
// TODO: handle exception
}
LAYER_TYPE layerType = addedLayerToMapEvent.getLayerType();
if (layerType != null) {
switch (layerType) {
case BASE:
break;
case OVERLAY:
mainPanel.showOverlayLayers(layerManager.getOverlayLayerManager().getPanel());
break;
default:
break;
}
}
}
});
@ -315,8 +334,13 @@ public class GeoportalDataViewer implements EntryPoint {
if (mainPanel.getDisplyedRecord() == null && !olMapMng.isQueryPointActive()) {
olMapMng.hidePopInfo();
layerManager.removeAllDetailLayers();
}
mainPanel.hideOverlayLayers();
// layerManager.getOverlayLayerManager().hide();
// hidePopupLayers();
}
});
@ -337,8 +361,63 @@ public class GeoportalDataViewer implements EntryPoint {
}
});
applicationBus.addHandler(DoActionOnDetailLayersEvent.TYPE, new DoActionOnDetailLayersEventHandler() {
@Override
public void onDoActionOnDetailLayers(DoActionOnDetailLayersEvent doLayerActionEvent) {
DO_LAYER_ACTION doAction = doLayerActionEvent.getDoAction();
GWT.log("event: "+doAction);
GWT.log("layer source: "+doLayerActionEvent.getLayerItem().getName());
OpenLayerOSM olMap = olMapMng.getOLOSMMap();
switch (doAction) {
case OPACITY:
GWT.log("opacity: "+doLayerActionEvent.getOpacity());
olMap.setWMSDetailLayerOpacity(doLayerActionEvent.getLayerItem(),
doLayerActionEvent.getOpacity());
break;
case SWAP:
org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem sourceLayerSwap = doLayerActionEvent.getSourceLayerSwap();
org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem target = doLayerActionEvent.getTargetLayerSwap();
GWT.log("SWAPPING source "+sourceLayerSwap.getName() +", target: "+target.getName());
olMap.swapDetailsLayers(sourceLayerSwap.getName(), target.getName());
break;
case VISIBILITY:
GWT.log("visibility: "+doLayerActionEvent.getVisibility());
olMap.setWMSDetailLayerVisible(doLayerActionEvent.getLayerItem(),
doLayerActionEvent.getVisibility());
break;
default:
break;
}
}
});
}
// /**
// * Handler popu closer.
// *
// * @param divId the div id
// * @param overlayId the overlay id
// */
// public static native void handlerPopuCloser(String divId, String overlayId) /*-{
// var closer = $doc.getElementById(divId);
// var overlay = $doc.getElementById(overlayId);
// closer.onclick = function() {
// overlay.setPosition(undefined);
// closer.blur();
// return false;
// };
//
// }-*/;
private void performWFSQueryOnCentroid(RecordDV record) {
if (record != null) {
GWT.log("record instanceof ConcessioneDV: " + (record instanceof ConcessioneDV) + " with mongo item id: "
@ -356,9 +435,10 @@ public class GeoportalDataViewer implements EntryPoint {
GeoQuery select = olMapMng.toDataPointQuery(transfCoord, false);
GWT.log("GeoQuery: " + select);
// GeoportalDataViewerConstants.print("fireEvent QueryDataEvent");
ExtentWrapped toExt = new ExtentWrapped(transfCoord.getX(), transfCoord.getY(), transfCoord.getX(), transfCoord.getY());
layerManager.getLayerManagerBus().fireEvent(new QueryDataEvent(select, toExt,
record.getItemId(), true, MapEventType.ADDED_CENTROID_LAYER_TO_MAP));
ExtentWrapped toExt = new ExtentWrapped(transfCoord.getX(), transfCoord.getY(), transfCoord.getX(),
transfCoord.getY());
layerManager.getLayerManagerBus().fireEvent(new QueryDataEvent(select, toExt, record.getItemId(),
true, MapEventType.ADDED_CENTROID_LAYER_TO_MAP));
} else {
GeoportalDataViewerConstants.printJs(
"I cannot select the point one or both coordiantes are null. X: " + x + ", Y:" + y);

View File

@ -4,6 +4,7 @@
package org.gcube.portlets.user.geoportaldataviewer.client;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -89,6 +90,8 @@ public class LayerManager {
private org.gcube.application.geoportalcommon.shared.LayerItem baseLayerFromISProfile;
private OverlayLayerManager overlayLayerManager;
/**
* Instantiates a new layer manager.
*
@ -96,6 +99,7 @@ public class LayerManager {
*/
public LayerManager(HandlerManager applicationBus) {
this.applicationBus = applicationBus;
overlayLayerManager = new OverlayLayerManager(applicationBus);
bindEvents();
}
@ -118,11 +122,6 @@ public class LayerManager {
GWT.log("(" + selectDataInfo.getX1() + "," + selectDataInfo.getY1() + ")(" + selectDataInfo.getX2()
+ "," + selectDataInfo.getY2() + ")");
// for (LayerObject layerObj : layerObjects.values()) {
// // TODO
// isLayerVisible(layerObj.getLayerItem());
// }
BoundsMap mapBBOX = new BoundsMap();
double minX = queryEvent.getGeoQuery().getX1();
double minY = queryEvent.getGeoQuery().getY1();
@ -154,7 +153,30 @@ public class LayerManager {
// for querying detail layers only in this case
if (olMap.getCurrentResolution() < OLMapManager.LAYER_DETAIL_MAX_RESOLUTION) {
listLO.addAll(mapDetailLayerObjects.values());
Collection<LayerObject> collLO = mapDetailLayerObjects.values();
listLO.addAll(collLO);
ArrayList<LayerObject> layerVisibility = new ArrayList<LayerObject>(collLO.size());
layerVisibility.addAll(collLO);
//Managing layer visibility. If a layer is not visible has to be not queryable
for (LayerObject layerObject : layerVisibility) {
String layerName = layerObject.getLayerItem().getName();
boolean isLayerVisible = olMap.isLayerVisible(layerName);
if(!isLayerVisible) {
GWT.log("From querying removing layername: "+layerName + ", it is not visible");
listLO.remove(layerObject);
}
// else {
// ExtentWrapped layerExtent = olMap.getSourceExtentForLayer(layerName);
// if(layerExtent!=null) {
// ExtentWrapped centerQueryPoint = new ExtentWrapped(minX, minY, maxX,maxY);
//
// boolean contains = layerExtent.containsExtent(centerQueryPoint);
// GWT.log("layer: "+layerName + " contains the queried BBOX: "+contains);
// }
// }
//
}
}
GeoportalDataViewerServiceAsync.Util.getInstance().getDataResult(listLO, olMap.getProjectionCode(),
@ -309,9 +331,13 @@ public class LayerManager {
});
}
/**
* Removes the all detail layers.
*/
public void removeAllDetailLayers() {
mapDetailLayerObjects.clear();
olMap.removeAllDetailLayers();
overlayLayerManager.resetLayers();
}
/**
@ -422,6 +448,8 @@ public class LayerManager {
if (dlo == null) {
mapDetailLayerObjects.put(key, lo);
olMap.addWMSDetailLayer(layerItem);
overlayLayerManager.addLayerItem(lo);
//overlayLayerManager.show();
} else {
GWT.log("Skipping detail layer " + key + " already added to Map");
}
@ -517,15 +545,14 @@ public class LayerManager {
/**
* Show popup info for layer.
*
* @param geoNaDataObject the geo na data object
* @param feature the feature
* @param onFailureCenterTo the on failure center to
* @param listGeoNaDataObject the list geo na data object
* @param queryClick the query click
*/
public void showPopupInfoForLayer(List<GeoNaSpatialQueryResult> listGeoNaDataObject, ExtentWrapped queryClick) {
ScrollPanel scrollPanel = new ScrollPanel();
FlowPanel flowPanel = new FlowPanel();
//flowPanel.getElement().getStyle().setProperty("maxHeight", "600px");
// flowPanel.getElement().getStyle().setProperty("maxHeight", "600px");
scrollPanel.add(flowPanel);
String prevConcessioneName = "";
@ -543,6 +570,12 @@ public class LayerManager {
continue;
}
List<FeatureRow> features = geoNaSpatialQueryResult.getFeatures();
if (features == null || features.isEmpty()) {
continue;
}
String nomeConcessione = lo.getSourceConcessione().getNome();
if (prevConcessioneName.compareTo(nomeConcessione) != 0) {
String concessioneIntro = StringUtil.ellipsize(lo.getSourceConcessione().getNome(), 40);
@ -559,13 +592,15 @@ public class LayerManager {
Label layerLabel = new Label();
layerLabel.setType(LabelType.INFO);
layerLabel.setText(layerSourceName);
String layerName = StringUtil.fullNameToLayerName(layerSourceName, ":");
layerLabel.setText(layerName);
layerLabel.setTitle(layerSourceName);
layerLabel.getElement().getStyle().setMarginTop(10, Unit.PX);
layerLabel.getElement().getStyle().setMarginBottom(5, Unit.PX);
flowPanel.add(layerLabel);
List<FeatureRow> features = geoNaSpatialQueryResult.getFeatures();
/*
if (features == null || features.isEmpty()) {
FlexTable flex = new FlexTable();
flex.setCellPadding(1);
@ -575,9 +610,9 @@ public class LayerManager {
flowPanel.add(flex);
continue;
// olMap.showPopup(vpPanel.toString(), onFailureCenterTo);
}
}*/
GWT.log("Displaying "+features.size() + " features");
GWT.log("Displaying " + features.size() + " features");
FlexTable intFlex = new FlexTable();
intFlex.setCellPadding(1);
intFlex.setCellSpacing(1);
@ -593,8 +628,8 @@ public class LayerManager {
Map<String, List<String>> entries = feature.getMapProperties();
if (entries.size() == 0) {
//Adding this row to show "no property" for feature
//intFlex.setHTML(i + 1, 1, new HTML("<i>No property</i>").toString());
// Adding this row to show "no property" for feature
// intFlex.setHTML(i + 1, 1, new HTML("<i>No property</i>").toString());
}
int j = 0;
for (String key : entries.keySet()) {
@ -619,7 +654,7 @@ public class LayerManager {
}
flowPanel.add(intFlex);
} catch (Exception e) {
GeoportalDataViewerConstants.printJs("Error: "+e.getMessage());
GeoportalDataViewerConstants.printJs("Error: " + e.getMessage());
}
}
@ -627,106 +662,6 @@ public class LayerManager {
}
// /**
// * Show popup info for layer.
// *
// * @param geoNaDataObject the geo na data object
// * @param feature the feature
// * @param onFailureCenterTo the on failure center to
// */
// public void showPopupInfoForLayer(List<GeoNaSpatialQueryResult> listGeoNaDataObject,
// ExtentWrapped queryClick) {
//
// ScrollPanel scrollPanel = new ScrollPanel();
// VerticalPanel vpPanel = new VerticalPanel();
// scrollPanel.add(vpPanel);
//
// String prevConcessioneName = "";
// for (GeoNaSpatialQueryResult geoNaSpatialQueryResult : listGeoNaDataObject) {
//
// GWT.log("baseLayerFromISProfile.getName() :"+baseLayerFromISProfile.getName());
// LayerObject lo = geoNaSpatialQueryResult.getSourceLayerObject();
// LayerItem sourceLI = lo.getLayerItem();
//
// String layerSourceName = sourceLI.getName();
//
// //skipping centroid layer
// if(layerSourceName==null || layerSourceName.compareToIgnoreCase(baseLayerFromISProfile.getName())==0) {
// continue;
// }
//
// String nomeConcessione = lo.getSourceConcessione().getNome();
// if(prevConcessioneName.compareTo(nomeConcessione)!=0) {
// String concessioneIntro = StringUtil.ellipsize(lo.getSourceConcessione().getNome(), 40);
// Heading heading = new Heading(4, concessioneIntro);
// heading.getElement().getStyle().setMarginBottom(10, Unit.PX);
// vpPanel.add(heading);
// HTML subText = new HTML("<p style=\"color:#999; font-size:14px; margin:5px 0 5px 0;\">Layers and Properties</p>");
// vpPanel.add(subText);
// }
//
// prevConcessioneName = nomeConcessione;
//
// Label layerLabel = new Label();
// layerLabel.setType(LabelType.INFO);
//
// layerLabel.setText(layerSourceName);
// layerLabel.getElement().getStyle().setMarginTop(10, Unit.PX);
// layerLabel.getElement().getStyle().setMarginBottom(5, Unit.PX);
// vpPanel.add(layerLabel);
//
// List<FeatureRow> features = geoNaSpatialQueryResult.getFeatures();
//
// if (features == null || features.isEmpty()) {
// FlexTable flex = new FlexTable();
// flex.setCellPadding(1);
// flex.setCellSpacing(1);
// flex.getElement().addClassName("table-feature");
// flex.setHTML(0, 0, new HTML("No data available").toString());
// vpPanel.add(flex);
// continue;
// //olMap.showPopup(vpPanel.toString(), onFailureCenterTo);
// }
//
// for (FeatureRow feature : features) {
//
// FlexTable intFlex = new FlexTable();
// intFlex.setCellPadding(1);
// intFlex.setCellSpacing(1);
// intFlex.getElement().addClassName("table-feature");
//
// intFlex.setHTML(0, 0, new HTML("Feature Id").toString());
// intFlex.setHTML(1, 0, new HTML(feature.getId()).toString());
//
// // Showing properties belonging to concessioni centroid layer
// Map<String, List<String>> entries = feature.getMapProperties();
//
// if (entries.size() == 0) {
// intFlex.setHTML(1, 1, new HTML("No property available").toString());
// }
// int j = 1;
// for (String key : entries.keySet()) {
// List<String> theValues = entries.get(key);
// String valueToDisplay = "";
// for (String value : theValues) {
// valueToDisplay+=value+", ";
//
// }
// valueToDisplay = valueToDisplay.substring(0,valueToDisplay.length()-2);
// intFlex.setHTML(0, j, new HTML(key).toString());
// intFlex.setHTML(1, j, new HTML(valueToDisplay).toString());
// j++;
//
// }
//
// vpPanel.add(intFlex);
// }
// }
//
// olMap.showPopup(scrollPanel.toString(), queryClick.getCenter());
//
// }
/**
* Show popup info for centroid layer.
*
@ -900,16 +835,6 @@ public class LayerManager {
}
/**
* Checks if is layer visible.
*
* @param layerItem the layer item
* @return true, if is layer visible
*/
public boolean isLayerVisible(LayerItem layerItem) {
return olMap.isLayerVisible(layerItem.getName());
}
/**
* Sets the ol map.
*
@ -928,12 +853,31 @@ public class LayerManager {
return layerManagerBus;
}
/**
* Sets the base layer from is profile.
*
* @param layerItem the new base layer from is profile
*/
public void setBaseLayerFromIsProfile(org.gcube.application.geoportalcommon.shared.LayerItem layerItem) {
this.baseLayerFromISProfile = layerItem;
}
/**
* Gets the base layer from IS proile.
*
* @return the base layer from IS proile
*/
public org.gcube.application.geoportalcommon.shared.LayerItem getBaseLayerFromISProile() {
return baseLayerFromISProfile;
}
/**
* Gets the overlay layer manager.
*
* @return the overlay layer manager
*/
public OverlayLayerManager getOverlayLayerManager() {
return overlayLayerManager;
}
}

View File

@ -38,7 +38,7 @@ public class OLMapManager {
private ol.Extent dragEndExtent = null;
public static final int QUERY_MIN_ZOOM_LEVEL = 13;
public static final Double LAYER_DETAIL_MIN_RESOLUTION = 0.01;
public static final Double LAYER_DETAIL_MAX_RESOLUTION = 13.0;
public static final Double LAYER_DETAIL_MAX_RESOLUTION = 18.5;
/**
@ -255,11 +255,4 @@ public class OLMapManager {
olMap.hidePopup();
}
// /**
// * Removes the detail layers.
// */
// public void removeDetailLayers() {
// olMap.removeAllDetailLayers();
// }
}

View File

@ -0,0 +1,37 @@
package org.gcube.portlets.user.geoportaldataviewer.client;
import java.util.ArrayList;
import org.gcube.portlets.user.geoportaldataviewer.client.ui.dandd.DragDropLayer;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.ui.FlowPanel;
public class OverlayLayerManager {
private ArrayList<LayerObject> layers = new ArrayList<LayerObject>();
private FlowPanel fp = new FlowPanel();
private HandlerManager applicationBus;
public OverlayLayerManager(HandlerManager applicationBus) {
this.applicationBus = applicationBus;
//fp.addStyleName("layers-panel");
}
void addLayerItem(LayerObject lo) {
DragDropLayer dandd = new DragDropLayer(applicationBus, lo, true, true);
layers.add(lo);
fp.add(dandd);
}
public void resetLayers() {
layers.clear();
fp.clear();
}
public FlowPanel getPanel() {
return fp;
}
}

View File

@ -4,26 +4,38 @@ import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
import com.google.gwt.event.shared.GwtEvent;
/**
* The Class AddedLayerToMapEvent.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Nov 18, 2020
* Nov 18, 2020
*/
public class AddedLayerToMapEvent extends GwtEvent<AddedLayerToMapEventHandler> {
public static Type<AddedLayerToMapEventHandler> TYPE = new Type<AddedLayerToMapEventHandler>();
private LayerItem layerItem;
private LAYER_TYPE layerType;
/**
* The Enum LAYER_TYPE.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Oct 11, 2021
*/
public enum LAYER_TYPE {
BASE, OVERLAY
}
/**
* Instantiates a new added layer to map event.
*
* @param layerItem the layer item
* @param layerType the layer type
*/
public AddedLayerToMapEvent(LayerItem layerItem) {
public AddedLayerToMapEvent(LayerItem layerItem, LAYER_TYPE layerType) {
this.layerItem = layerItem;
this.layerType = layerType;
}
/**
@ -56,5 +68,13 @@ public class AddedLayerToMapEvent extends GwtEvent<AddedLayerToMapEventHandler>
return layerItem;
}
/**
* Gets the layer type.
*
* @return the layer type
*/
public LAYER_TYPE getLayerType() {
return layerType;
}
}

View File

@ -0,0 +1,175 @@
package org.gcube.portlets.user.geoportaldataviewer.client.events;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
import com.google.gwt.event.shared.GwtEvent;
/**
* The Class DoActionOnDetailLayersEvent.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Oct 12, 2021
*/
public class DoActionOnDetailLayersEvent extends GwtEvent<DoActionOnDetailLayersEventHandler> {
public static Type<DoActionOnDetailLayersEventHandler> TYPE = new Type<DoActionOnDetailLayersEventHandler>();
/**
* The Enum DO_LAYER_ACTION.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Oct 12, 2021
*/
public static enum DO_LAYER_ACTION {
VISIBILITY, SWAP, OPACITY
}
private DO_LAYER_ACTION doAction;
private LayerItem layerItem;
private double opacity;
private boolean visibility;
private LayerItem sourceLayerSwap;
private LayerItem targetLayerSwap;
/**
* Instantiates a new do action on detail layers event.
*
* @param action the action
* @param layerItem the layer item
*/
public DoActionOnDetailLayersEvent(DO_LAYER_ACTION action, LayerItem layerItem) {
this.layerItem = layerItem;
this.doAction = action;
}
/**
* Sets the swap layers.
*
* @param sourceLayerItem the source layer item
* @param targetLayerItem the target layer item
*/
public void setSwapLayers(LayerItem sourceLayerItem, LayerItem targetLayerItem) {
this.sourceLayerSwap = sourceLayerItem;
this.targetLayerSwap = targetLayerItem;
}
/**
* Sets the opacity.
*
* @param opacity the new opacity
*/
public void setOpacity(double opacity) {
this.opacity = opacity;
}
/**
* Sets the visibility.
*
* @param visibility the new visibility
*/
public void setVisibility(boolean visibility) {
this.visibility = visibility;
}
/**
* Gets the associated type.
*
* @return the associated type
*/
@Override
public Type<DoActionOnDetailLayersEventHandler> getAssociatedType() {
return TYPE;
}
/**
* Dispatch.
*
* @param handler the handler
*/
@Override
protected void dispatch(DoActionOnDetailLayersEventHandler handler) {
handler.onDoActionOnDetailLayers(this);
}
/**
* Gets the do action.
*
* @return the do action
*/
public DO_LAYER_ACTION getDoAction() {
return doAction;
}
/**
* Gets the layer item.
*
* @return the layer item
*/
public LayerItem getLayerItem() {
return layerItem;
}
/**
* Gets the source layer swap.
*
* @return the source layer swap
*/
public LayerItem getSourceLayerSwap() {
return sourceLayerSwap;
}
/**
* Gets the target layer swap.
*
* @return the target layer swap
*/
public LayerItem getTargetLayerSwap() {
return targetLayerSwap;
}
/**
* Gets the opacity.
*
* @return the opacity
*/
public double getOpacity() {
return opacity;
}
/**
* Gets the visibility.
*
* @return the visibility
*/
public boolean getVisibility() {
return visibility;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("DoActionOnDetailLayersEvent [doAction=");
builder.append(doAction);
builder.append(", layerItem=");
builder.append(layerItem);
builder.append(", opacity=");
builder.append(opacity);
builder.append(", visibility=");
builder.append(visibility);
builder.append(", sourceLayerSwap=");
builder.append(sourceLayerSwap);
builder.append(", targetLayerSwap=");
builder.append(targetLayerSwap);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,21 @@
package org.gcube.portlets.user.geoportaldataviewer.client.events;
import com.google.gwt.event.shared.EventHandler;
/**
* The Interface DoActionOnDetailLayersEventHandler.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Oct 8, 2021
*/
public interface DoActionOnDetailLayersEventHandler extends EventHandler {
/**
* On do action on detail layers.
*
* @param doActionOnDetailLayersEvent the do action on detail layers event
*/
void onDoActionOnDetailLayers(DoActionOnDetailLayersEvent doActionOnDetailLayersEvent);
}

View File

@ -1,17 +1,18 @@
package org.gcube.portlets.user.geoportaldataviewer.client.gis;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.LinkedHashMap;
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION;
import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent.LAYER_TYPE;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Visibility;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;
@ -58,7 +59,6 @@ import ol.source.Source;
import ol.source.Vector;
import ol.source.XyzOptions;
// TODO: Auto-generated Javadoc
/**
* The Class OpenLayerOSM.
*
@ -131,9 +131,11 @@ public abstract class OpenLayerOSM {
private boolean isQueryPointActive;
private java.util.Map<String, Image> wmsDetailsLayerMap;
private LinkedHashMap<String, Image> wmsDetailsLayerMap;
private HashMap<String, Image> wmsLayerMap;
private Integer[] wmsDetailsLayerZIndex = new Integer[100];
private LinkedHashMap<String, Image> wmsLayerMap;
/**
* Instantiates a new open layer OSM.
@ -149,6 +151,10 @@ public abstract class OpenLayerOSM {
public OpenLayerOSM(String divTargetId, HandlerManager eventBus) {
this.eventBus = eventBus;
for (int i = 0; i < 100; i++) {
wmsDetailsLayerZIndex[i] = 1000 + i;
}
// create a OSM-layer
XyzOptions xyzOptions = OLFactory.createOptions();
// osmSourceOptions.setCrossOrigin("Anonymous");
@ -335,11 +341,11 @@ public abstract class OpenLayerOSM {
public void addWMSLayer(LayerItem layerItem) {
if (wmsLayerMap == null)
wmsLayerMap = new HashMap<String, Image>();
wmsLayerMap = new LinkedHashMap<String, Image>();
String key = layerItem.getName();
Image layer = wmsLayerMap.get(key);
Image layer = wmsLayerMap.get(layerItem.getName());
if (layer == null) {
ImageWmsParams imageWMSParams = OLFactory.createOptions();
imageWMSParams.setLayers(layerItem.getName());
@ -370,7 +376,7 @@ public abstract class OpenLayerOSM {
wmsLayerMap.put(key, wmsLayer);
GWT.log("Added WMSLayer for layer: " + layerItem.getName());
eventBus.fireEvent(new AddedLayerToMapEvent(layerItem));
eventBus.fireEvent(new AddedLayerToMapEvent(layerItem, LAYER_TYPE.BASE));
} else {
GWT.log("The WMS layer with key: " + key + " already exists, skipping");
}
@ -385,9 +391,9 @@ public abstract class OpenLayerOSM {
public void addWMSDetailLayer(LayerItem layerItem) {
if (wmsDetailsLayerMap == null)
wmsDetailsLayerMap = new HashMap<String, Image>();
wmsDetailsLayerMap = new LinkedHashMap<String, Image>();
String key = layerItem.getName();
String key = layerItem.getName();
Image layer = wmsDetailsLayerMap.get(key);
@ -414,14 +420,12 @@ public abstract class OpenLayerOSM {
}
Image wmsLayer = new Image(layerOptions);
// visibleLayerItems
wmsLayer.setZIndex(wmsDetailsLayerMap.size() + 1);
map.addLayer(wmsLayer);
wmsDetailsLayerMap.put(key, wmsLayer);
GWT.log("Added WMSDetailLayer for layer name: " + layerItem.getName());
eventBus.fireEvent(new AddedLayerToMapEvent(layerItem));
eventBus.fireEvent(new AddedLayerToMapEvent(layerItem, LAYER_TYPE.OVERLAY));
} else {
GWT.log("The WMS detail layer with key: " + key + " already exists, skipping");
}
@ -562,7 +566,7 @@ public abstract class OpenLayerOSM {
* @param element the element
* @return the overlay
*/
private Overlay addOverlay(Element element) {
public Overlay addOverlay(Element element) {
/**
* Create an overlay to anchor the popup to the map.
*/
@ -574,55 +578,6 @@ public abstract class OpenLayerOSM {
return overlay;
}
/**
* Checks if is layer visible.
*
* @param layerName the layer name
* @return true, if is layer visible
*/
public boolean isLayerVisible(String layerName) {
Collection<Base> layers = map.getLayers();
if (layers != null) {
Base[] layersArr = layers.getArray();
for (int i = 0; i < layersArr.length; i++) {
Base layer = layersArr[i];
String theLayerName = (String) layer.get("name");
GWT.log("The Layer name is: " + theLayerName);
if (theLayerName != null && theLayerName.equals(layerName))
return true;
}
}
return false;
}
/**
* Gets the layer property.
*
* @param layerName the layer name
* @param property the property
* @return the layer property
*/
public String getLayerProperty(String layerName, String property) {
Collection<Base> layers = map.getLayers();
if (layers != null) {
Base[] layersArr = layers.getArray();
for (int i = 0; i < layersArr.length; i++) {
Base layer = layersArr[i];
String theLayerName = (String) layer.get("name");
GWT.log("The Layer name is: " + layerName);
if (theLayerName != null && theLayerName.equals(layerName))
return layer.get(property);
}
}
return null;
}
/**
* Gets the projection code.
*
@ -716,15 +671,14 @@ public abstract class OpenLayerOSM {
return this.map != null;
}
/**
* Gets the layers from map.
*
* @return the layers from map
*/
public List<String> getLayersFromMap() {
public ArrayList<String> getLayersFromMap() {
Collection<Base> layers = map.getLayers();
List<String> layerNames = null;
ArrayList<String> layerNames = null;
if (layers != null) {
Base[] layersArr = layers.getArray();
layerNames = new ArrayList<String>(layersArr.length);
@ -734,30 +688,78 @@ public abstract class OpenLayerOSM {
Image layerImage = (Image) layer;
Source source = layerImage.getSource();
// GWT.log("source: "+source.toString());
// GeoportalDataViewerConstants.printJsObj(source);
String sorceRootObj = GeoportalDataViewerConstants.toJsonObj(source);
JSONValue jsonObj = JSONParser.parseStrict(sorceRootObj);
// GWT.log("jsonObj: " + jsonObj.toString());
JSONObject jsonSourceObj = (JSONObject) jsonObj;
GeoportalDataViewerConstants.printJsObj(jsonSourceObj);
JSONObject jsonParamsObj = (JSONObject) jsonSourceObj.get("params_");
// GWT.log("jsonParamsObj is: "+jsonParamsObj);
JSONValue jsonLayers = jsonParamsObj.get("LAYERS");
GWT.log("theLayerName name is: " + jsonLayers);
layerNames.add(jsonLayers.toString());
JSONObject imagesParamsObj = (JSONObject) jsonSourceObj.get("image_");
JSONArray extent = (JSONArray) imagesParamsObj.get("extent");
GWT.log("extentLayer: " + extent.toString());
}
}
}
return layerNames;
}
/**
* Gets the source extent for layer.
*
* @param layerName the layer name
* @return the source extent for layer
*/
public ExtentWrapped getSourceExtentForLayer(String layerName) {
Collection<Base> layers = map.getLayers();
if (layers != null) {
Base[] layersArr = layers.getArray();
for (int i = 0; i < layersArr.length; i++) {
Base layer = layersArr[i];
if (layer instanceof Image) {
Image layerImage = (Image) layer;
Source source = layerImage.getSource();
// GeoportalDataViewerConstants.printJsObj(source);
String sorceRootObj = GeoportalDataViewerConstants.toJsonObj(source);
JSONValue jsonObj = JSONParser.parseStrict(sorceRootObj);
// GWT.log("jsonObj: " + jsonObj.toString());
JSONObject jsonSourceObj = (JSONObject) jsonObj;
// GeoportalDataViewerConstants.printJsObj(jsonSourceObj);
JSONObject jsonParamsObj = (JSONObject) jsonSourceObj.get("params_");
// GWT.log("jsonParamsObj is: "+jsonParamsObj);
JSONValue jsonLayers = jsonParamsObj.get("LAYERS");
String layerNameIntoMap = jsonLayers.toString().replaceAll("\"", "");
if (layerName.compareTo(layerNameIntoMap) == 0) {
JSONObject imagesParamsObj = (JSONObject) jsonSourceObj.get("image_");
JSONArray extent = (JSONArray) imagesParamsObj.get("extent");
// GWT.log("extentLayer: "+extent.toString());
double minX = Double.parseDouble(extent.get(0).toString());
double minY = Double.parseDouble(extent.get(1).toString());
double maxX = Double.parseDouble(extent.get(2).toString());
double maxY = Double.parseDouble(extent.get(3).toString());
return new ExtentWrapped(minX, minY, maxX, maxY);
}
}
}
}
return null;
}
/**
* Gets the wms details layer map.
*
* @return the wms details layer map
*/
public java.util.Map<String, Image> getWmsDetailsLayerMap() {
public LinkedHashMap<String, Image> getWmsDetailsLayerMap() {
return wmsDetailsLayerMap;
}
@ -766,8 +768,80 @@ public abstract class OpenLayerOSM {
*
* @return the wms layer map
*/
public HashMap<String, Image> getWmsLayerMap() {
public LinkedHashMap<String, Image> getWmsLayerMap() {
return wmsLayerMap;
}
/**
* Checks if is layer visible.
*
* @param layerName the layer name
* @return true, if is layer visible
*/
public boolean isLayerVisible(String layerName) {
String key = layerName;
Image layer = wmsLayerMap.get(key);
if (layer != null)
return layer.getVisible();
layer = wmsDetailsLayerMap.get(key);
if (layer != null)
return layer.getVisible();
return false;
}
/**
* Sets the WMS detail layer visible.
*
* @param layerItem the layer item
* @param visible the visible
*/
public void setWMSDetailLayerVisible(LayerItem layerItem, boolean visible) {
String key = layerItem.getName();
Image layer = wmsDetailsLayerMap.get(key);
layer.setVisible(visible);
}
/**
* Sets the WMS detail layer opacity.
*
* @param layerItem the layer item
* @param opacity the opacity
*/
public void setWMSDetailLayerOpacity(LayerItem layerItem, double opacity) {
String key = layerItem.getName();
Image layer = wmsDetailsLayerMap.get(key);
layer.setOpacity(opacity);
}
/**
* Swap details layers.
*
* @param layerSource the source index
* @param layerTarget the target index
*/
public void swapDetailsLayers(String layerSource, String layerTarget) {
Image layer1 = wmsDetailsLayerMap.get(layerSource);
Image layer2 = wmsDetailsLayerMap.get(layerTarget);
int zIndex1 = layer1.getZIndex();
int zIndex2 = layer2.getZIndex();
layer1.setZIndex(zIndex2);
layer2.setZIndex(zIndex1);
}
/**
* Gets the layer by index.
*
* @param map the map
* @param index the index
* @return the layer by index
*/
private Image getLayerByIndex(LinkedHashMap<String, Image> map, int index) {
return map.get((map.keySet().toArray())[index]);
}
}

View File

@ -17,10 +17,12 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;
@ -70,6 +72,12 @@ public class GeonaDataViewMainPanel extends Composite {
@UiField
Button extentToEarth;
@UiField
Button layersDDB;
@UiField
FlowPanel overlayLayersPanel;
private MapPanel mapPanel;
private OpenLayerOSM map;
@ -104,6 +112,28 @@ public class GeonaDataViewMainPanel extends Composite {
extentToEarth.getElement().appendChild(worldImg.getElement());
extentToEarth.setWidth("140px");
//layersDDB.setToggle(true);
bindEvents();
}
private void bindEvents() {
layersDDB.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
GWT.log("layersDDB clicked");
if(overlayLayersPanel.isVisible()) {
overlayLayersPanel.setVisible(false);
}else {
overlayLayersPanel.setVisible(true);
}
}
});
}
/**
@ -229,4 +259,51 @@ public class GeonaDataViewMainPanel extends Composite {
return detailsPanel.getDisplayedRecord();
}
/**
* Gets the layers DDB.
*
* @return the layers DDB
*/
public Button getLayersDDB() {
return layersDDB;
}
/**
* Show overlay layers.
*
* @param panel the panel
*/
public void showOverlayLayers(FlowPanel panel) {
GWT.log("showOverlayLayers");
//layersDDB.setVisible(true);
overlayLayersPanel.setVisible(true);
overlayLayersPanel.clear();
overlayLayersPanel.add(panel);
//layersDDBClickEvent();
}
private void layersDDBClickEvent() {
layersDDB.fireEvent( new GwtEvent<ClickHandler>() {
@Override
public com.google.gwt.event.shared.GwtEvent.Type<ClickHandler> getAssociatedType() {
return ClickEvent.getType();
}
@Override
protected void dispatch(ClickHandler handler) {
handler.onClick(null);
}
});
}
/**
* Hide overlay layers.
*/
public void hideOverlayLayers() {
GWT.log("hideOverlayLayers");
overlayLayersPanel.clear();
//layersDDB.setVisible(false);
overlayLayersPanel.setVisible(false);
//layersDDBClickEvent();
}
}

View File

@ -32,8 +32,8 @@
</b:Paragraph>
</g:HTMLPanel>
</b:DropdownButton>
<b:DropdownButton type="LINK" text="Preset Location"
icon="TH_LARGE">
<b:DropdownButton type="LINK"
text="Preset Location" icon="TH_LARGE">
<b:Nav>
<b:Button type="LINK" ui:field="extentToItaly"
text="Italy" title="Center to Italy"></b:Button>
@ -55,6 +55,10 @@
</b:DropdownButton>
<b:Button type="LINK" ui:field="removeQuery"
text="Remove Query" visible="false"></b:Button>
<b:Button type="LINK" text="Layers" ui:field="layersDDB">
</b:Button>
<g:FlowPanel ui:field="overlayLayersPanel"
addStyleNames="layers-panel" visible="false"></g:FlowPanel>
</g:HTMLPanel>
</g:HTMLPanel>
<c:DetailsPanel ui:field="detailsPanel"

View File

@ -2,7 +2,6 @@
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:style>
.map-style {
width: 100%;
}

View File

@ -0,0 +1,184 @@
package org.gcube.portlets.user.geoportaldataviewer.client.ui.dandd;
import org.gcube.application.geoportalcommon.shared.products.BaseConcessioneDV;
import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent.DO_LAYER_ACTION;
import org.gcube.portlets.user.geoportaldataviewer.client.util.StringUtil;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.CheckBox;
import com.github.gwtbootstrap.client.ui.Label;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.github.gwtbootstrap.client.ui.constants.LabelType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.DragLeaveEvent;
import com.google.gwt.event.dom.client.DragLeaveHandler;
import com.google.gwt.event.dom.client.DragOverEvent;
import com.google.gwt.event.dom.client.DragOverHandler;
import com.google.gwt.event.dom.client.DragStartEvent;
import com.google.gwt.event.dom.client.DragStartHandler;
import com.google.gwt.event.dom.client.DropEvent;
import com.google.gwt.event.dom.client.DropHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
public class DragDropLayer extends FlowPanel {
private static DragDropLayer dragging = null;
private static DragDropLayer draggingTarget = null;
final boolean droppable;
private Label labelLayerName;
private CheckBox checkBoxVisibility = new CheckBox();
private Button draggableButton = new Button();
private HandlerManager applicationBus;
private LayerObject layerObject;
private LayerItem layerItem;
public DragDropLayer(HandlerManager applicationBus, LayerObject layerObject, boolean draggable, boolean droppable) {
this.applicationBus = applicationBus;
this.layerObject = layerObject;
this.layerItem = layerObject.getLayerItem();
String layerName = StringUtil.fullNameToLayerName(layerItem.getName(), ":");
this.labelLayerName = new Label(layerName);
this.labelLayerName.setTitle(layerItem.getName());
this.labelLayerName.setType(LabelType.INFO);
BaseConcessioneDV refConcessione = layerObject.getSourceConcessione();
String nameConcessione = StringUtil.ellipsize(refConcessione.getNome(),40);
com.google.gwt.user.client.ui.Label labelConcessione = new com.google.gwt.user.client.ui.Label(nameConcessione);
labelConcessione.setTitle(refConcessione.getNome());
getElement().getStyle().setMarginTop(5, Unit.PX);
getElement().getStyle().setMarginBottom(10, Unit.PX);
this.getElement().addClassName("dand-layer");
if (draggable) {
initDrag();
}
if (droppable) {
initDrop();
}
this.droppable = droppable;
if (droppable) {
draggableButton.addStyleName("droppable");
} else if (draggable) {
draggableButton.addStyleName("draggable");
}
RangeSlider rs = new RangeSlider(applicationBus, layerItem);
rs.getElement().addClassName("range-slider ");
FlexTable ft = new FlexTable();
ft.setWidget(0, 0, draggableButton);
draggableButton.setTitle("Drag and Drop me up or down to change my position on the Map");
checkBoxVisibility.getElement().getStyle().setMarginLeft(10, Unit.PX);
checkBoxVisibility.setValue(true);
//labelLayerName.getElement().getStyle().setMarginLeft(10, Unit.PX);
ft.setWidget(0, 1, checkBoxVisibility);
ft.setWidget(0, 2, labelConcessione);
ft.setWidget(1, 2, labelLayerName);
ft.setWidget(2, 2, new SimplePanel(rs));
add(ft);
draggableButton.setIcon(IconType.MOVE);
checkBoxVisibility.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
DoActionOnDetailLayersEvent dae = new DoActionOnDetailLayersEvent(DO_LAYER_ACTION.VISIBILITY, layerItem);
dae.setVisibility(checkBoxVisibility.getValue());
applicationBus.fireEvent(dae);
}
});
}
private void initDrag() {
draggableButton.getElement().setDraggable(Element.DRAGGABLE_TRUE);
addDomHandler(new DragStartHandler() {
@Override
public void onDragStart(DragStartEvent event) {
dragging = DragDropLayer.this;
event.setData("ID", "UniqueIdentifier");
event.getDataTransfer().setDragImage(getElement(), 10, 10);
}
}, DragStartEvent.getType());
}
private void initDrop() {
addDomHandler(new DragOverHandler() {
@Override
public void onDragOver(DragOverEvent event) {
draggableButton.addStyleName("dropping-over");
GWT.log("drag over");
draggingTarget = (DragDropLayer) event.getSource();
}
}, DragOverEvent.getType());
addDomHandler(new DragLeaveHandler() {
@Override
public void onDragLeave(DragLeaveEvent event) {
draggableButton.removeStyleName("dropping-over");
GWT.log("drag leave");
// draggingTarget = (DragDropLayer) event.getSource();
}
}, DragLeaveEvent.getType());
addDomHandler(new DropHandler() {
@Override
public void onDrop(DropEvent event) {
event.preventDefault();
Object dropTarget = event.getSource();
GWT.log("on drop");
draggableButton.removeStyleName("dropping-over");
if (dragging != null) {
Widget source = null;
Widget target = null;
FlowPanel tree = (FlowPanel) DragDropLayer.this.getParent();
source = dragging;
int sourceIndex = tree.getWidgetIndex(source);
int targetIndex = tree.getWidgetIndex(draggingTarget);
GWT.log("sourceIndex: " + sourceIndex+", sourceItem: "+dragging.getLayerItem().getName());
GWT.log("targetIndex: " + targetIndex+", targetItem: "+draggingTarget.getLayerItem().getName());
if (sourceIndex != targetIndex && targetIndex >= 0) {
tree.remove(source);
target = tree;
if (source != null && target != null) {
tree.insert(source, targetIndex);
// target.setState(true);
DoActionOnDetailLayersEvent actionSwapLayers = new DoActionOnDetailLayersEvent(
DO_LAYER_ACTION.SWAP, layerItem);
actionSwapLayers.setSwapLayers(dragging.getLayerItem(), draggingTarget.getLayerItem());
applicationBus.fireEvent(actionSwapLayers);
}
dragging = null;
}
}
}
}, DropEvent.getType());
}
public LayerItem getLayerItem() {
return layerItem;
}
}

View File

@ -0,0 +1,71 @@
package org.gcube.portlets.user.geoportaldataviewer.client.ui.dandd;
import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent.DO_LAYER_ACTION;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.EventListener;
import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
public class RangeSlider extends Composite {
private static RangeSliderUiBinder uiBinder = GWT.create(RangeSliderUiBinder.class);
interface RangeSliderUiBinder extends UiBinder<Widget, RangeSlider> {
}
@UiField
Element theSlider;
private String sliderId;
private HandlerManager applicationBus;
private LayerItem layer;
public RangeSlider(HandlerManager applicationBus, LayerItem layer) {
this.applicationBus = applicationBus;
this.layer = layer;
initWidget(uiBinder.createAndBindUi(this));
sliderId = "slider-" + Random.nextInt();
theSlider.addClassName("slider");
theSlider.setId(sliderId);
theSlider.setTitle("Set opacity of "+layer.getName());
bindEvents();
}
private void bindEvents() {
Event.sinkEvents(theSlider, Event.ONMOUSEUP);
Event.setEventListener(theSlider, new EventListener() {
@Override
public void onBrowserEvent(Event event) {
if (Event.ONMOUSEUP == event.getTypeInt()) {
GWT.log("Event.ONMOUSEUP");
DoActionOnDetailLayersEvent actionChangeOpacity = new DoActionOnDetailLayersEvent(
DO_LAYER_ACTION.OPACITY, layer);
int value = Integer.parseInt((String) theSlider.getPropertyObject("value"));
//GWT.log("opacity int value: "+value);
double opacity = (double) ((double) value/100);
GWT.log("opacity double value: "+opacity);
actionChangeOpacity.setOpacity(opacity);
applicationBus.fireEvent(actionChangeOpacity);
}
}
});
}
}

View File

@ -0,0 +1,16 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:style>
.important {
font-weight: bold;
}
.slidecontainer {
width: 100%;
}
</ui:style>
<g:HTMLPanel addStyleNames="{style.slidecontainer}">
<input type="range" min="1" max="100" value="100" class="slider" ui:field="theSlider"></input>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -12,7 +12,7 @@ import com.google.gwt.i18n.client.DateTimeFormat;
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Nov 16, 2020
* Nov 16, 2020
*/
public class StringUtil {
@ -21,42 +21,62 @@ public class StringUtil {
/**
* Ellipsize.
*
* @param input the input string that may be subjected to shortening
* @param maxCharacters the maximum characters that must be returned for the input string
* @param input the input string that may be subjected to shortening
* @param maxCharacters the maximum characters that must be returned for the
* input string
* @return the string
* @throws Exception the exception
*/
public static String ellipsize(String input, int maxCharacters) {
if(input==null)
return "";
if (input == null)
return "";
if (input.length() < maxCharacters)
return input;
if (input.length() < maxCharacters)
return input;
return input.substring(0, maxCharacters)+"...";
return input.substring(0, maxCharacters) + "...";
}
public static String formatDate(String date) {
if(date==null)
if (date == null)
return date;
Date theDate = null;
try {
if(date.endsWith(NO_TIME)) {
if (date.endsWith(NO_TIME)) {
date = date.replaceAll(NO_TIME, "");
theDate = DateTimeFormat.getFormat("yyyyMMdd").parse(date);
}else {
} else {
theDate = DateTimeFormat.getFormat("yyyyMMdd_HH-mm-ss").parse(date);
}
}catch (Exception e) {
//Window.alert(e.toString());
} catch (Exception e) {
// Window.alert(e.toString());
}
if(theDate!=null) {
if (theDate != null) {
return DateTimeFormat.getFormat("dd-MM-yyyy").format(theDate);
}
return date;
}
/**
* Full name to layer name.
*
* @param layerFullName the layer full name
* @param splitChar the split char
* @return the string
*/
public static String fullNameToLayerName(String layerFullName, String splitChar) {
if (layerFullName == null || layerFullName.isEmpty())
return layerFullName;
int layerSep = layerFullName.lastIndexOf(splitChar);
return layerSep > 0 && (layerSep + 1) < layerFullName.length()
? layerFullName.substring(layerSep + 1, layerFullName.length())
: layerFullName;
}
}

View File

@ -6,7 +6,7 @@
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard' /> -->
<inherits name='com.google.gwt.user.theme.standard.Standard' />
<inherits name='ol.GwtOL' />

View File

@ -277,3 +277,83 @@ body {
.table-feature tr:first-child {
font-weight: bold;
}
.dropping-over {
background-color: #fcfcfc;
opacity: 0.4;
}
.droppable:not(:hover), .droppable:not(:active) {
border: 0px !important;
box-shadow: none !important;
}
.dropping-leave {
border: 0px !important;
box-shadow: 0px !important;
}
.droppable:hover, .droppable:active {
padding-left: 15px;
cursor: move; /* fallback if grab cursor is unsupported */
cursor: grab;
cursor: -moz-grab;
cursor: -webkit-grab;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 8px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 12px;
height: 12px;
border-radius: 50%;
background: #04AA6D;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 12px;
height: 12px;
border-radius: 50%;
background: #04AA6D;
cursor: pointer;
}
.myOverlayLayerManager{
border-radius: 20px;
}
.layers-panel {
margin-top: 10px;
background-color: white;
opacity: 80%;
padding: 10px;
}
.dand-layer {
width: 400px;
}
.range-slider {
width: 300px;
}
.range-slider input {
width: 280px;
}