From b2e6830bbe7bc7744c394183841766113713b3de Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 31 Aug 2021 18:21:17 +0200 Subject: [PATCH] implementing task #21946 --- CHANGELOG.md | 1 + README.md | 5 + .../client/GeoportalDataViewer.java | 6 +- .../client/GeoportalDataViewerConstants.java | 2 + .../client/GeoportalDataViewerService.java | 13 + .../GeoportalDataViewerServiceAsync.java | 3 + .../client/LayerManager.java | 105 +++-- .../client/OLMapManager.java | 99 +++-- .../client/events/QueryDataEvent.java | 37 +- .../client/gis/OpenLayerOSM.java | 419 +++++++++++++----- .../client/ui/gallery/ImagesGallery.java | 32 +- .../GeoportalDataViewerServiceImpl.java | 36 +- 12 files changed, 534 insertions(+), 224 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1d3320..4c5f138 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm [#21890] Porting to ConcessioniManagerI and pass to mongoID [#20595] Porting and using the model view provided by geoportal-common +[#21946] Show layers of a concessione automatically on map according to zoom level ## [v1.2.0-SNAPSHOT] - 2021-07-19 diff --git a/README.md b/README.md index 76b58a0..847a6d1 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,11 @@ The GeoPortal Data Viewer App is an application to access, discovery and navigat * [OpenJDK](https://openjdk.java.net/) - The JDK used * [Maven](https://maven.apache.org/) - Dependency Management +** Uses ** + +* [GWT-OL3](https://github.com/TDesjardins/gwt-ol) GWT-OpenLayers 3+ v.8.0.0-gwt2_9 +* [OpenLayers](https://openlayers.org/) OpenLayers v.6.X + ## Documentation N/A diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java index 1a24ba3..71936ed 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java @@ -7,6 +7,7 @@ import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; import org.gcube.application.geoportalcommon.shared.LayerItem; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.model.RecordDV; +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.AddedLayerToMapEventHandler; import org.gcube.portlets.user.geoportaldataviewer.client.events.ClosedViewDetailsEvent; @@ -167,7 +168,7 @@ public class GeoportalDataViewer implements EntryPoint { GWT.log("The layerItem is: " + layerItem); layerManager.addLayer(theItemType, null, null, layerItem.getWmsLink(), false, false, - null, true); + null, false); if (paramGeonaItemID != null) { if (paramGeonaItemType == null) { @@ -308,6 +309,7 @@ public class GeoportalDataViewer implements EntryPoint { if(mainPanel.getDisplyedRecord()==null && !olMapMng.isQueryPointActive()) { olMapMng.hidePopInfo(); + olMapMng.removeDetailLayers(); } } @@ -337,7 +339,7 @@ public class GeoportalDataViewer implements EntryPoint { GeoQuery select = olMapMng.toDataPointQuery(transfCoord,false); GWT.log("GeoQuery: "+select); //GeoportalDataViewerConstants.print("fireEvent QueryDataEvent"); - layerManager.getLayerManagerBus().fireEvent(new QueryDataEvent(select, transfCoord, record.getItemId(), true)); + layerManager.getLayerManagerBus().fireEvent(new QueryDataEvent(select, transfCoord, record.getItemId(), true, MapEventType.ADDED_LAYER_TO_MAP)); }else { GeoportalDataViewerConstants.printJs("I cannot select the point one or both coordiantes are null. X: "+x +", Y:"+y); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerConstants.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerConstants.java index f1c3bc9..caccf86 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerConstants.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerConstants.java @@ -28,6 +28,8 @@ public class GeoportalDataViewerConstants { public static final String GET_ZOOM = OpenLayersMapParameters.OL_MAP_PARAM.zoom.name(); public static final String GET_CENTER_MAP_TO_LONG_LAT = OpenLayersMapParameters.OL_MAP_PARAM.centermap.name(); + public static enum MapEventType {INIT, MAP_ZOOM_END, MOVE_END, ADDED_LAYER_TO_MAP} + /** * The Enum LayerType. * diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerService.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerService.java index 6ed194f..0167a55 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerService.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerService.java @@ -111,4 +111,17 @@ public interface GeoportalDataViewerService extends RemoteService { */ List getLayersForId(String itemType, String itemId) throws Exception; + /** + * Gets the WFS features. + * + * @param layerObjects the layer objects + * @param mapSrsName the map srs name + * @param selectBBOX the select BBOX + * @param maxWFSFeature the max WFS feature + * @param zoomLevel the zoom level + * @return the WFS features + */ + List getWFSFeatures(List layerObjects, String mapSrsName, + BoundsMap selectBBOX, int maxWFSFeature, double zoomLevel); + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerServiceAsync.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerServiceAsync.java index 3e76450..564b6dd 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerServiceAsync.java @@ -54,4 +54,7 @@ public interface GeoportalDataViewerServiceAsync { void getLayersForId(String itemType, String itemId, AsyncCallback> asyncCallback); + void getWFSFeatures(List layerObjects, String mapSrsName, BoundsMap selectBBOX, int maxWFSFeature, + double zoomLevel, AsyncCallback> callback); + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/LayerManager.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/LayerManager.java index 38feb24..35a000c 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/LayerManager.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/LayerManager.java @@ -10,8 +10,10 @@ import java.util.Map; import org.gcube.application.geoportalcommon.shared.gis.BoundsMap; import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV; +import org.gcube.application.geoportalcommon.shared.products.model.LayerConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.LayerType; +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.AddedLayerToMapEventHandler; import org.gcube.portlets.user.geoportaldataviewer.client.events.QueryDataEvent; @@ -63,7 +65,7 @@ public class LayerManager { /** The ol map. */ private OpenLayerOSM olMap; - private List layerObjects = new ArrayList(); + private Map layerObjects = new HashMap(); private HandlerManager layerManagerBus = new HandlerManager(""); @@ -98,7 +100,7 @@ public class LayerManager { GWT.log("(" + selectDataInfo.getX1() + "," + selectDataInfo.getY1() + ")(" + selectDataInfo.getX2() + "," + selectDataInfo.getY2() + ")"); - for (LayerObject layerObj : layerObjects) { + for (LayerObject layerObj : layerObjects.values()) { // TODO isLayerVisible(layerObj.getLayerItem()); @@ -141,10 +143,10 @@ public class LayerManager { GWT.log("Bounds is: " + mapBBOX); GWT.log("MAX_WFS_FEATURES is: " + GeoportalDataViewerConstants.MAX_WFS_FEATURES); // GeoportalDataViewerConstants.print("calling getDataResult"); - - GeoportalDataViewerServiceAsync.Util.getInstance().getDataResult(layerObjects, - olMap.getProjectionCode(), mapBBOX, GeoportalDataViewerConstants.MAX_WFS_FEATURES, - olMap.getCurrentZoomLevel(), new AsyncCallback>() { + List listLO = new ArrayList(layerObjects.values()); + GeoportalDataViewerServiceAsync.Util.getInstance().getDataResult(listLO, olMap.getProjectionCode(), + mapBBOX, GeoportalDataViewerConstants.MAX_WFS_FEATURES, olMap.getCurrentZoomLevel(), + new AsyncCallback>() { @Override public void onFailure(Throwable caught) { @@ -169,7 +171,7 @@ public class LayerManager { flex.getElement().addClassName("popup-table"); boolean featureFound = false; FeatureRow feature = null; - + // TODO SWTCH FOR EARCH ITEM TYPE for (GeoNaSpatialQueryResult geoNaDataObject : listGeonaDataObjects) { List features = geoNaDataObject.getFeatures(); @@ -184,7 +186,7 @@ public class LayerManager { .get("product_id"); theProductId = productIdLst.get(0); try { - //long productId = Long.parseLong(thePID); + // long productId = Long.parseLong(thePID); if (theProductId == mongoItemId) { feature = fRow; GWT.log("Found recorId == product_id with id: " @@ -202,6 +204,12 @@ public class LayerManager { feature = features.get(0); List productIdLst = feature.getMapProperties() .get("product_id"); + if (productIdLst == null) { + // in this case the feature returned is a (detail) layer belonging + // to a record/concessione (not centroid layer), + // so returning + return; + } theProductId = productIdLst.get(0); } else { // the recordId to show has been passed but not found into list of @@ -210,36 +218,48 @@ public class LayerManager { return; } } - - GWT.log("the product id is: "+theProductId); - - /*if(olMap.getCurrentZoomLevel()>10) { - GeoportalDataViewerServiceAsync.Util.getInstance().getLayersForId("concessione", theProductId, new AsyncCallback>() { - @Override - public void onFailure(Throwable caught) { - // TODO Auto-generated method stub - - } + GWT.log("the product id is: " + theProductId); - @Override - public void onSuccess(List result) { - GWT.log("Adding layers: "+result); - for (LayerConcessioneDV layer : result) { - addLayer("concessione", layer.getLayerName(), layer.getLayerName(), layer.getWmsLink(), false, false, layer.getLayerUUID(), true); + // retrieving and showing WMS layers of a concessione if the ZOOM level is > QUERY_MIN_ZOOM_LEVEL + if (olMap.getCurrentZoomLevel() > OLMapManager.QUERY_MIN_ZOOM_LEVEL) { + GeoportalDataViewerServiceAsync.Util.getInstance().getLayersForId( + "concessione", theProductId, + new AsyncCallback>() { + + @Override + public void onFailure(Throwable caught) { + // TODO Auto-generated method stub + + } + + @Override + public void onSuccess(List result) { + GWT.log("Adding layers: " + result); + for (LayerConcessioneDV layer : result) { + addLayer("concessione", layer.getLayerName(), + layer.getLayerName(), layer.getWmsLink(), + false, false, layer.getLayerUUID(), true); // LayerItem li = new LayerItem(); // li.setBaseLayer(false); // li.setWmsLink(layer.getWmsLink()); // li.setTitle(layer.getLayerName()); // olMap.addWMSLayer(li); - } - - } - }); - return; - }*/ - + } + } + }); + } else { + // removing all WMS detail layers if the ZOOM level is < QUERY_MIN_ZOOM_LEVEL + olMap.removeAllDetailLayers(); + } + + if(queryEvent.getSourceMapEventType() != null && queryEvent.getSourceMapEventType().equals(MapEventType.MAP_ZOOM_END)) { + GWT.log("EVENT IS "+MapEventType.MAP_ZOOM_END +" retuning"); + return; + } + + //Showing properties belonging to concessioni centroid layer Map> entries = feature.getMapProperties(); String nome = ""; @@ -433,11 +453,11 @@ public class LayerManager { * @param isBase the is base * @param displayInLayerSwitcher the display in layer switcher * @param UUID the uuid - * @param onTop the on top + * @param asDetailLayer the as detail layer */ public void addLayer(final String geonaItemType, final String layerTitle, final String layerName, final String wmsLink, final boolean isBase, final boolean displayInLayerSwitcher, final String UUID, - final boolean onTop) { + final boolean asDetailLayer) { // final LayoutContainer westPanel = (LayoutContainer) layersPanel.getParent(); // @@ -448,6 +468,12 @@ public class LayerManager { final LayerType featureType = isBase ? LayerType.RASTER_BASELAYER : LayerType.FEATURE_TYPE; // Info.display("Adding Layer", layerName); + + if(wmsLink==null || wmsLink.isEmpty()) { + GeoportalDataViewerConstants.printJs("Skipping add layer for wmsLink as null or empty"); + return; + } + GeoportalDataViewerServiceAsync.Util.getInstance().parseWmsRequest(wmsLink, layerName, new AsyncCallback() { @@ -475,8 +501,19 @@ public class LayerManager { LayerObject lo = new LayerObject(); lo.setLayerItem(layerItem); lo.setItemType(geonaItemType); - layerObjects.add(lo); - olMap.addWMSLayer(layerItem); + + String key = layerItem.getMapServerHost() + "/layer/" + layerItem.getName(); + +// //if a detail layer checking if it is already added to map +// if (asDetailLayer && layerObjects.containsKey(key)) { +// GWT.log("Skipping layer already added to Map"); +// } else { + layerObjects.put(key, lo); + if (!asDetailLayer) + olMap.addWMSLayer(layerItem); + else + olMap.addWMSDetailLayer(layerItem); +// } } }); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/OLMapManager.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/OLMapManager.java index 41e13da..d5aa4e8 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/OLMapManager.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/OLMapManager.java @@ -1,5 +1,6 @@ package org.gcube.portlets.user.geoportaldataviewer.client; +import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MapEventType; import org.gcube.portlets.user.geoportaldataviewer.client.events.QueryDataEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.ZoomOutOverMinimumEvent; import org.gcube.portlets.user.geoportaldataviewer.client.gis.ExtentWrapped; @@ -21,7 +22,7 @@ import ol.OLFactory; * * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * - * Nov 19, 2020 + * Nov 19, 2020 */ public class OLMapManager { @@ -32,12 +33,12 @@ public class OLMapManager { private Double zoomStart = null; private Double zoomEnd = null; private ol.Extent dragEndExtent = null; - private static final int QUERY_MIN_ZOOM_LEVEL = 13; + public static final int QUERY_MIN_ZOOM_LEVEL = 13; /** * Instantiates a new OL map manager. * - * @param targetId the target id + * @param targetId the target id * @param layerManagerBus the layer manager bus */ public OLMapManager(String targetId, HandlerManager layerManagerBus) { @@ -56,64 +57,64 @@ public class OLMapManager { @Override public void clickListener(MapBrowserEvent event) { Coordinate coordinate = event.getCoordinate(); - if(!olMap.mapInstancied()) + if (!olMap.mapInstancied()) return; - + // if (olMap.isQueryPointActive()) { // GeoQuery select = toDataPointQuery(coordinate); // layerManagerBus.fireEvent(new QueryDataEvent(select, coordinate)); // // } - - GeoQuery select = toDataPointQuery(coordinate,true); - layerManagerBus.fireEvent(new QueryDataEvent(select, coordinate, null, true)); + + GeoQuery select = toDataPointQuery(coordinate, true); + layerManagerBus.fireEvent(new QueryDataEvent(select, coordinate, null, true, MapEventType.INIT)); } @Override public void moveEndListener(MapEvent event) { - //onInit - if(!olMap.mapInstancied()) + // onInit + if (!olMap.mapInstancied()) return; - - checkSelectQuery(); + + checkSelectQuery(MapEventType.MOVE_END); } @Override public void moveStartListener(MapEvent event) { - - //onInit - if(!olMap.mapInstancied()) + + // onInit + if (!olMap.mapInstancied()) return; setDragStart(); - + } @Override public void mapZoomListener(MapEvent event) { - - //onInit - if(!olMap.mapInstancied()) + + // onInit + if (!olMap.mapInstancied()) return; - + setDragStart(); zoomStart = olMap.getCurrentZoomLevel(); - GWT.log("zoomStart: "+zoomStart); + GWT.log("zoomStart: " + zoomStart); } @Override public void mapZoomEndListener(MapEvent event) { - //onInit - if(!olMap.mapInstancied()) + // onInit + if (!olMap.mapInstancied()) return; - + setDragStart(); zoomEnd = olMap.getCurrentZoomLevel(); - GWT.log("zoomEnd: "+zoomEnd); - checkSelectQuery(); + GWT.log("zoomEnd: " + zoomEnd); + checkSelectQuery(MapEventType.MAP_ZOOM_END); } @@ -140,7 +141,7 @@ public class OLMapManager { double lon = coordinate.getX(); double lat = coordinate.getY(); - GWT.log("To quey DP: "+coordinate); + GWT.log("To quey DP: " + coordinate); int w = (int) olMap.getSize().getWidth(); int h = (int) olMap.getSize().getHeight(); @@ -150,16 +151,15 @@ public class OLMapManager { // where 10px is the pixel diameter dimension of the clicked point double bboxWidth = Math.abs(olMap.getExtent().getLowerLeftX() - olMap.getExtent().getUpperRightX()); double geoWidth = 0; - //adding a tolerance in case of manual click - if(manualClick) { - //adding a tolerance for clicking + // adding a tolerance in case of manual click + if (manualClick) { + // adding a tolerance for clicking geoWidth = (bboxWidth / w) * (14 / 2); - } - else { - //data point selection for coordinate loaded from concessione + } else { + // data point selection for coordinate loaded from concessione geoWidth = (bboxWidth / w) * (2); } - + double x1 = Math.min(lon + geoWidth, lon - geoWidth); double x2 = Math.max(lon + geoWidth, lon - geoWidth); double y1 = Math.min(lat + geoWidth, lat - geoWidth); @@ -182,8 +182,8 @@ public class OLMapManager { /** * Check select query. */ - private void checkSelectQuery() { - + private void checkSelectQuery(MapEventType mapEventType) { + GWT.log("Zoom is:" + olMap.getCurrentZoomLevel()); if (dragStartExtent != null && olMap.getCurrentZoomLevel() > QUERY_MIN_ZOOM_LEVEL) { @@ -199,12 +199,11 @@ public class OLMapManager { GWT.log("the distance is: " + dist); if (dist > 5000 || startExt.containsExtent(endExt)) { GeoQuery select = toDataBoxQuery(dragEndExtent); - layerManagerBus.fireEvent(new QueryDataEvent(select, endExt.getCenter(), null, false)); + layerManagerBus.fireEvent(new QueryDataEvent(select, endExt.getCenter(), null, false, mapEventType)); } - } - else if(zoomStart!=null && zoomEnd!=null) { - - if(zoomEnd { public static Type TYPE = new Type(); @@ -19,6 +20,7 @@ public class QueryDataEvent extends GwtEvent { private Coordinate onFailureCenterTo; private String mongoItemId; private boolean onInit; + private MapEventType sourceMapEventType; /** * Instantiates a new query data event. @@ -27,12 +29,15 @@ public class QueryDataEvent extends GwtEvent { * @param onFailureCenterTo the on failure center to * @param mongoItemId the mongo item id * @param onInit the on init + * @param mapEventType the map event type */ - public QueryDataEvent(GeoQuery select, Coordinate onFailureCenterTo, String mongoItemId, boolean onInit) { + public QueryDataEvent(GeoQuery select, Coordinate onFailureCenterTo, String mongoItemId, boolean onInit, + MapEventType mapEventType) { this.select = select; this.onFailureCenterTo = onFailureCenterTo; this.mongoItemId = mongoItemId; this.onInit = onInit; + this.sourceMapEventType = mapEventType; } /** @@ -45,6 +50,11 @@ public class QueryDataEvent extends GwtEvent { return TYPE; } + /** + * Gets the mongo item id. + * + * @return the mongo item id + */ public String getMongoItemId() { return mongoItemId; } @@ -78,10 +88,29 @@ public class QueryDataEvent extends GwtEvent { return select; } + /** + * Gets the on failure center to. + * + * @return the on failure center to + */ public Coordinate getOnFailureCenterTo() { return onFailureCenterTo; } + /** + * Gets the source map event type. + * + * @return the source map event type + */ + public MapEventType getSourceMapEventType() { + return sourceMapEventType; + } + + /** + * To string. + * + * @return the string + */ @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -93,6 +122,8 @@ public class QueryDataEvent extends GwtEvent { builder.append(mongoItemId); builder.append(", onInit="); builder.append(onInit); + builder.append(", sourceMapEventType="); + builder.append(sourceMapEventType); builder.append("]"); return builder.toString(); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerOSM.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerOSM.java index 6bb974a..2c254e6 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerOSM.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerOSM.java @@ -1,5 +1,7 @@ package org.gcube.portlets.user.geoportaldataviewer.client.gis; +import java.util.HashMap; + import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants; import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; @@ -13,6 +15,8 @@ import com.google.gwt.user.client.Event; import ol.Collection; import ol.Coordinate; +import ol.Feature; +import ol.FeatureOptions; import ol.Map; import ol.MapBrowserEvent; import ol.MapEvent; @@ -25,6 +29,7 @@ import ol.View; import ol.ViewOptions; import ol.control.Attribution; import ol.event.EventListener; +import ol.geom.Geometry; import ol.interaction.Draw; import ol.interaction.DrawOptions; import ol.interaction.Extent; @@ -36,6 +41,7 @@ import ol.layer.Base; import ol.layer.Image; import ol.layer.LayerOptions; import ol.layer.Tile; +import ol.layer.VectorLayerOptions; import ol.proj.Projection; import ol.proj.ProjectionOptions; import ol.source.ImageWms; @@ -45,74 +51,101 @@ import ol.source.Osm; import ol.source.Vector; import ol.source.XyzOptions; - // TODO: Auto-generated Javadoc /** * The Class OpenLayerOSM. * * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * - * Oct 27, 2020 + * Oct 27, 2020 */ public abstract class OpenLayerOSM { - + + /** + * Click listener. + * + * @param event the event + */ public abstract void clickListener(MapBrowserEvent event); - + + /** + * Move end listener. + * + * @param event the event + */ public abstract void moveEndListener(MapEvent event); - + + /** + * Move start listener. + * + * @param event the event + */ public abstract void moveStartListener(MapEvent event); - + + /** + * Map zoom listener. + * + * @param event the event + */ public abstract void mapZoomListener(MapEvent event); - + + /** + * Map zoom end listener. + * + * @param event the event + */ public abstract void mapZoomEndListener(MapEvent event); /** The map. */ private Map map; - + /** The view. */ private View view; - + /** The view options. */ private ViewOptions viewOptions = OLFactory.createOptions(); - + /** The projection options. */ private ProjectionOptions projectionOptions = OLFactory.createOptions(); - + /** The point draw. */ private Draw queryPoint; - + private Extent queryBox; - + /** The popup overlay. */ private Overlay popupOverlay; private HandlerManager eventBus; - - private boolean isQueryBoxActive; - - private boolean isQueryPointActive; - - /** - * Instantiates a new open layer OSM. - * - * @param divTargetId the div target id - * @param eventBus the event bus - */ - /* (non-Javadoc) - * @see de.desjardins.ol3.demo.client.example.Example#show() - */ + private boolean isQueryBoxActive; + + private boolean isQueryPointActive; + + private java.util.Map wmsDetailsLayerMap; + + /** + * Instantiates a new open layer OSM. + * + * @param divTargetId the div target id + * @param eventBus the event bus + */ + /* + * (non-Javadoc) + * + * @see de.desjardins.ol3.demo.client.example.Example#show() + */ public OpenLayerOSM(String divTargetId, HandlerManager eventBus) { this.eventBus = eventBus; - // create a OSM-layer - XyzOptions osmSourceOptions = OLFactory.createOptions(); + // create a OSM-layer + XyzOptions osmSourceOptions = OLFactory.createOptions(); - Osm osmSource = new Osm(osmSourceOptions); - LayerOptions osmLayerOptions = OLFactory.createOptions(); - osmLayerOptions.setSource(osmSource); + Osm osmSource = new Osm(osmSourceOptions); + LayerOptions osmLayerOptions = OLFactory.createOptions(); + osmLayerOptions.setSource(osmSource); - Tile osmLayer = new Tile(osmLayerOptions); + Tile osmLayer = new Tile(osmLayerOptions); // create a projection projectionOptions.setCode(GeoportalDataViewerConstants.EPSG_3857); projectionOptions.setUnits("m"); @@ -120,39 +153,41 @@ public abstract class OpenLayerOSM { Projection projection = new Projection(projectionOptions); viewOptions.setProjection(projection); viewOptions.setMaxZoom(19); - - // create a view - view = new View(viewOptions); - - // create the map - MapOptions mapOptions = OLFactory.createOptions(); - mapOptions.setTarget(divTargetId); - mapOptions.setView(view); + // create a view + view = new View(viewOptions); - map = new Map(mapOptions); + // create the map + MapOptions mapOptions = OLFactory.createOptions(); + mapOptions.setTarget(divTargetId); + mapOptions.setView(view); - map.addLayer(osmLayer); - //map.addLayer(tileDebugLayer); + map = new Map(mapOptions); - // add some controls - map.addControl(OLFactory.createScaleLine()); - MapUtils.addDefaultControls(map.getControls()); + map.addLayer(osmLayer); + // map.addLayer(tileDebugLayer); - Attribution attribution = new Attribution(); - attribution.setCollapsed(true); - map.addControl(attribution); - - // add some interactions - map.addInteraction(new KeyboardPan()); - map.addInteraction(new KeyboardZoom()); - - bindEvents(); + // add some controls + map.addControl(OLFactory.createScaleLine()); + MapUtils.addDefaultControls(map.getControls()); - } - + Attribution attribution = new Attribution(); + attribution.setCollapsed(true); + map.addControl(attribution); + + // add some interactions + map.addInteraction(new KeyboardPan()); + map.addInteraction(new KeyboardZoom()); + + bindEvents(); + + } + + /** + * Bind events. + */ private void bindEvents() { - + map.addClickListener(new EventListener() { @Override @@ -168,7 +203,7 @@ public abstract class OpenLayerOSM { moveEndListener(event); } }); - + map.addMoveStartListener(new EventListener() { @Override @@ -176,7 +211,7 @@ public abstract class OpenLayerOSM { moveStartListener(event); } }); - + map.addMapZoomListener(new EventListener() { @Override @@ -184,7 +219,7 @@ public abstract class OpenLayerOSM { mapZoomListener(event); } }); - + map.addMapZoomEndListener(new EventListener() { @Override @@ -193,32 +228,37 @@ public abstract class OpenLayerOSM { } }); } - + /** * Sets the center. * * @param centerCoordinate the new center */ public void setCenter(Coordinate centerCoordinate) { - view.setCenter(centerCoordinate); + view.setCenter(centerCoordinate); } - + /** * Sets the center. * - * @param centerCoordinate the new center + * @param zoom the new zoom */ public void setZoom(int zoom) { - view.setZoom(zoom); + view.setZoom(zoom); } - + /** + * Show popup. + * + * @param html the html + * @param coordinate the coordinate + */ public void showPopup(String html, Coordinate coordinate) { - GWT.log("Showing popup on: "+coordinate); - //GeoportalDataViewerConstants.print("Showing popup on: "+coordinate); + GWT.log("Showing popup on: " + coordinate); + // GeoportalDataViewerConstants.print("Showing popup on: "+coordinate); Element elPopup = DOM.getElementById("popup"); elPopup.getStyle().setVisibility(Visibility.VISIBLE); - if(popupOverlay==null) { + if (popupOverlay == null) { popupOverlay = addOverlay(elPopup); addPopupCloserHandelr(popupOverlay); } @@ -226,14 +266,17 @@ public abstract class OpenLayerOSM { popContent.setInnerHTML(html); popupOverlay.setPosition(coordinate); } - + + /** + * Hide popup. + */ public void hidePopup() { - if(popupOverlay!=null) { + if (popupOverlay != null) { Element elPopup = DOM.getElementById("popup"); elPopup.getStyle().setVisibility(Visibility.HIDDEN); } } - + /** * Adds the popup closer handelr. * @@ -253,11 +296,11 @@ public abstract class OpenLayerOSM { } }); } - + /** * Handler popu closer. * - * @param divId the div id + * @param divId the div id * @param overlayId the overlay id */ public static native void handlerPopuCloser(String divId, String overlayId) /*-{ @@ -271,21 +314,20 @@ public abstract class OpenLayerOSM { }-*/; - /** * Adds the WMS layer. * * @param layerItem the layer item */ public void addWMSLayer(LayerItem layerItem) { - + ImageWmsParams imageWMSParams = OLFactory.createOptions(); imageWMSParams.setLayers(layerItem.getName()); ImageWmsOptions imageWMSOptions = OLFactory.createOptions(); imageWMSOptions.setUrl(layerItem.getMapServerHost()); imageWMSOptions.setParams(imageWMSParams); - //imageWMSOptions.setRatio(1.5f); + // imageWMSOptions.setRatio(1.5f); ImageWms imageWMSSource = new ImageWms(imageWMSOptions); @@ -293,29 +335,142 @@ public abstract class OpenLayerOSM { layerOptions.setSource(imageWMSSource); Image wmsLayer = new Image(layerOptions); - - //visibleLayerItems - + + // visibleLayerItems + map.addLayer(wmsLayer); GWT.log("Fired the event Added Layer"); eventBus.fireEvent(new AddedLayerToMapEvent(layerItem)); - + } - + + /** + * Adds the WMS detail layer. + * + * @param layerItem the layer item + */ + public void addWMSDetailLayer(LayerItem layerItem) { + + if (wmsDetailsLayerMap == null) + wmsDetailsLayerMap = new HashMap(); + + String key = layerItem.getMapServerHost() + "/layer/" + layerItem.getName(); + + Image layer = wmsDetailsLayerMap.get(key); + + if (layer == null) { + GWT.log("The detail layer with key: " + key + " does not exist, creating and adding it to map"); + ImageWmsParams imageWMSParams = OLFactory.createOptions(); + imageWMSParams.setLayers(layerItem.getName()); + + ImageWmsOptions imageWMSOptions = OLFactory.createOptions(); + imageWMSOptions.setUrl(layerItem.getMapServerHost()); + imageWMSOptions.setParams(imageWMSParams); + // imageWMSOptions.setRatio(1.5f); + + ImageWms imageWMSSource = new ImageWms(imageWMSOptions); + + LayerOptions layerOptions = OLFactory.createOptions(); + layerOptions.setSource(imageWMSSource); + + Image wmsLayer = new Image(layerOptions); + + // visibleLayerItems + + map.addLayer(wmsLayer); + wmsDetailsLayerMap.put(key, wmsLayer); + + GWT.log("Fired the event Added Layer"); + eventBus.fireEvent(new AddedLayerToMapEvent(layerItem)); + } else { + GWT.log("The detail layer with key: " + key + " already exists, skipping"); + } + + } + + public void removeAllDetailLayers() { + if (wmsDetailsLayerMap == null) + return; + + for (String key : wmsDetailsLayerMap.keySet()) { + Image layer = wmsDetailsLayerMap.get(key); + map.removeLayer(layer); + } + + wmsDetailsLayerMap.clear(); + + } + +// public void addGeometry(Geometry theGeom) { +// +// if(theGeom==null) +// return; +// +// if(geometryLayer==null) { +// geometryLayer = new Vector("Feature selected"); +// geometryLayer.setDisplayInLayerSwitcher(false); +// map.addLayer(geometryLayer); +// }else { +// geometryLayer.removeAllFeatures(); +// } +// Style style = new Style(); +// style.setFillColor("#00FF00"); +// style.setGraphicName("circle"); +// style.setPointRadius(10); +// VectorFeature vf = new VectorFeature(theGeom, style); +// geometryLayer.addFeature(vf); +// } +// +// +// protected void removeGeometries() { +// if(geometryLayer!=null) +// geometryLayer.removeAllFeatures(); +// } + + /** + * Adds the vector. + * + * @param geometry the geometry + */ + public void addVector(Geometry geometry) { + + VectorLayerOptions vectorLayerOptions = new VectorLayerOptions(); + vectorLayerOptions.setMap(map); + +// Style style = new Style(); +// FillOptions fillOptions = new FillOptions(); +// Color color = new Color(0, 0, 255, 1.0); +// fillOptions.setColor(color); +// Fill fill = new Fill(fillOptions); +// style.setFill(fill); + + FeatureOptions featureOptions = new FeatureOptions(); + featureOptions.setGeometry(geometry); + Feature feature = OLFactory.createFeature(featureOptions); + + Vector vectorSource = OLFactory.createVectorSource(); + vectorSource.addFeature(feature); + vectorLayerOptions.setSource(vectorSource); + + ol.layer.Vector vector = OLFactory.createVector(vectorLayerOptions); + + map.addLayer(vector); + } + /** * Adds the point vector source. * * @return the draw */ public Draw addPointVectorSource() { - if(queryPoint==null) + if (queryPoint == null) initPointInteraction(); - + map.addInteraction(queryPoint); isQueryPointActive = true; return queryPoint; } - + /** * Inits the point interaction. */ @@ -328,39 +483,39 @@ public abstract class OpenLayerOSM { drawOptions.setMinPoints(1); drawOptions.setWrapX(false); queryPoint = new Draw(drawOptions); - + queryPoint.addChangeListener(new EventListener() { @Override public void onEvent(ol.events.Event event) { GWT.log(event.getType()); - + } }); } - + /** * Removes the interaction. * * @param interaction the interaction */ public void removeInteraction(Interaction interaction) { - map.removeInteraction(interaction); + map.removeInteraction(interaction); } - + /** * Removes the interactions. */ public void removeQueryInteractions() { Collection interactions = map.getInteractions(); - if(interactions!=null) { + if (interactions != null) { map.removeInteraction(queryBox); map.removeInteraction(queryPoint); isQueryBoxActive = false; isQueryPointActive = false; } } - + /** * Adds the extent interaction. * @@ -369,17 +524,16 @@ public abstract class OpenLayerOSM { public Extent addExtentInteraction() { ExtentOptions extentOptions = new ExtentOptions(); extentOptions.setWrapX(false); - //StyleOptions styleOptions = new StyleOptions(); - //styleOptions.setStroke(stroke); - //styleOptions.set - //extentOptions.setBoxStyle(new ol.style.Style(styleOptions)); + // StyleOptions styleOptions = new StyleOptions(); + // styleOptions.setStroke(stroke); + // styleOptions.set + // extentOptions.setBoxStyle(new ol.style.Style(styleOptions)); queryBox = new Extent(extentOptions); map.addInteraction(queryBox); isQueryBoxActive = true; return queryBox; } - - + /** * Adds the overlay. * @@ -405,23 +559,22 @@ public abstract class OpenLayerOSM { * @return true, if is layer visible */ public boolean isLayerVisible(String layerName) { - + Collection layers = map.getLayers(); - - if(layers!=null) { + + 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)) + GWT.log("The Layer name is: " + layerName); + if (theLayerName != null && theLayerName.equals(layerName)) return true; } } - + return false; } - /** * Gets the projection code. @@ -431,7 +584,6 @@ public abstract class OpenLayerOSM { public String getProjectionCode() { return map.getView().getProjection().getCode(); } - /** * Gets the current zoom level. @@ -441,9 +593,7 @@ public abstract class OpenLayerOSM { public double getCurrentZoomLevel() { return map.getView().getZoom(); } - - - + /** * Gets the bbox. * @@ -452,7 +602,7 @@ public abstract class OpenLayerOSM { public ol.Extent getBBOX() { return getExtent(); } - + /** * Gets the extent. * @@ -461,26 +611,53 @@ public abstract class OpenLayerOSM { public ol.Extent getExtent() { return this.map.getView().calculateExtent(map.getSize()); } - - public Coordinate transform (Coordinate centerCoordinate, String source, String target){ - return Projection.transform(centerCoordinate, source, target); + + /** + * Transform. + * + * @param centerCoordinate the center coordinate + * @param source the source + * @param target the target + * @return the coordinate + */ + public Coordinate transform(Coordinate centerCoordinate, String source, String target) { + return Projection.transform(centerCoordinate, source, target); } - + + /** + * Checks if is query box active. + * + * @return true, if is query box active + */ public boolean isQueryBoxActive() { return isQueryBoxActive; } - + + /** + * Checks if is query point active. + * + * @return true, if is query point active + */ public boolean isQueryPointActive() { return isQueryPointActive; } - + + /** + * Gets the size. + * + * @return the size + */ public Size getSize() { return map.getSize(); } + /** + * Map instancied. + * + * @return true, if successful + */ public boolean mapInstancied() { - return this.map!=null; - } + return this.map != null; + } } - diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/gallery/ImagesGallery.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/gallery/ImagesGallery.java index 414fb96..b226ec3 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/gallery/ImagesGallery.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/gallery/ImagesGallery.java @@ -140,22 +140,24 @@ public class ImagesGallery { JSONArray jsonArray = new JSONArray(); int index = 0; for (UploadedImageDV image : listImages) { - for (WorkspaceContentDV imageContent : image.getListWsContent()) { - JSONObject json = new JSONObject(); - json.put("src", new JSONString(imageContent.getLink())); - json.put("srct", new JSONString(imageContent.getLink())); - List listAuthors = image.getResponsabili(); - String txtAuthors = listAuthors.size()>1 ? "Authors: ": "Author: "; - for (String author : listAuthors) { - txtAuthors+= " "+author +","; + if(image.getListWsContent()!=null) { + for (WorkspaceContentDV imageContent : image.getListWsContent()) { + JSONObject json = new JSONObject(); + json.put("src", new JSONString(imageContent.getLink())); + json.put("srct", new JSONString(imageContent.getLink())); + List listAuthors = image.getResponsabili(); + String txtAuthors = listAuthors.size()>1 ? "Authors: ": "Author: "; + for (String author : listAuthors) { + txtAuthors+= " "+author +","; + } + txtAuthors = txtAuthors.substring(0,txtAuthors.length()-2); + String description = txtAuthors + ". ID Licenza: "+image.getLicenseID(); + json.put("title", new JSONString(image.getDidascalia())); + json.put("description", new JSONString(description)); + json.put("downloadURL", new JSONString(imageContent.getLink())); + jsonArray.set(index, json); + index++; } - txtAuthors = txtAuthors.substring(0,txtAuthors.length()-2); - String description = txtAuthors + ". ID Licenza: "+image.getLicenseID(); - json.put("title", new JSONString(image.getDidascalia())); - json.put("description", new JSONString(description)); - json.put("downloadURL", new JSONString(imageContent.getLink())); - jsonArray.set(index, json); - index++; } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java index aad93aa..83b63de 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java @@ -230,8 +230,8 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme /** * Gets the layers for id. * - * @param itemType the item type - * @param itemId the item id + * @param itemType the item type + * @param itemId the item id * @return the layers for id * @throws Exception the exception */ @@ -469,4 +469,36 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme return SessionUtil.isSessionExpired(this.getThreadLocalRequest()); } + /** + * Gets the WFS features. + * + * @param layerObjects the layer objects + * @param mapSrsName the map srs name + * @param selectBBOX the select BBOX + * @param maxWFSFeature the max WFS feature + * @param zoomLevel the zoom level + * @return the WFS features + */ + @Override + public List getWFSFeatures(List layerObjects, String mapSrsName, + BoundsMap selectBBOX, int maxWFSFeature, double zoomLevel) { + LOG.info("getWFSFeatures called"); + + List listDAO = new ArrayList(layerObjects.size()); + + for (LayerObject layerObject : layerObjects) { + GeoNaSpatialQueryResult geoDAO = new GeoNaSpatialQueryResult(); + List features = FeatureParser.getWFSFeatures(layerObject.getLayerItem(), mapSrsName, selectBBOX, + maxWFSFeature); + LOG.debug("For layer name: " + layerObject.getLayerItem().getName() + " got features: " + features); + geoDAO.setFeatures(features); + geoDAO.setSourceLayerObject(layerObject); + LOG.info("For layer name: " + layerObject.getLayerItem().getName() + " got " + features.size() + + " feature/s"); + listDAO.add(geoDAO); + } + LOG.info("returning " + listDAO + " geona data objects"); + return listDAO; + } + }