From 143fed7c79fe2cb503f549f53619de830238d2a0 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 11 Nov 2021 16:32:49 +0100 Subject: [PATCH] moved to gwt-ol3 v8.1.0-gwt2_9. Implementing Map credits (it is buggy in the gwt-ol3) --- .classpath | 6 +- .../com.gwtplugins.gdt.eclipse.core.prefs | 2 +- .settings/org.eclipse.wst.common.component | 44 ++++--- CHANGELOG.md | 1 + pom.xml | 4 +- .../client/GeoportalDataViewer.java | 11 ++ .../client/OLMapManager.java | 1 - .../client/gis/MapUtils.java | 5 + .../client/gis/OpenLayerOSM.java | 93 +++++++++++---- .../client/ui/GeonaDataViewMainPanel.java | 84 ++++++++------ .../client/ui/GeonaDataViewMainPanel.ui.xml | 5 +- .../shared/gis/BaseMapLayer.java | 109 ++++++++++++++++++ src/main/webapp/GeoportalDataViewer.css | 15 +++ 13 files changed, 297 insertions(+), 83 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/BaseMapLayer.java diff --git a/.classpath b/.classpath index 1b3eb3f..3f84059 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -35,5 +35,5 @@ - + diff --git a/.settings/com.gwtplugins.gdt.eclipse.core.prefs b/.settings/com.gwtplugins.gdt.eclipse.core.prefs index aaa6c87..4c65c64 100644 --- a/.settings/com.gwtplugins.gdt.eclipse.core.prefs +++ b/.settings/com.gwtplugins.gdt.eclipse.core.prefs @@ -1,4 +1,4 @@ eclipse.preferences.version=1 -lastWarOutDir=/home/francescomangiacrapa/git/geoportal-data-viewer-app/target/geoportal-data-viewer-app-2.0.0 +lastWarOutDir=/home/francescomangiacrapa/git/geoportal-data-viewer-app/target/geoportal-data-viewer-app-2.1.0-SNAPSHOT warSrcDir=src/main/webapp warSrcDirIsOutput=false diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 66ff2c7..72174ae 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,21 +1,31 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index e3c32bf..58dcb6d 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 #### Enhancements - [#22370] Use a max-height for preview image shown in the pop-up +- Moved to gwt-ol3 v8.1.0-gwt2_9 ## [v2.0.1] - 2021-11-10 diff --git a/pom.xml b/pom.xml index 4b017dc..eccb30a 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.gcube.portlets.user geoportal-data-viewer-app war - 2.0.1 + 2.1.0-SNAPSHOT GeoPortal Data Viewer App The GeoPortal Data Viewer App is an application to access, discovery and navigate the GeoNa products by a Web-Map Interface @@ -122,7 +122,7 @@ com.github.tdesjardins gwt-ol3 - 8.0.0-gwt2_9 + 8.1.0-gwt2_9 com.github.gwtbootstrap 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 d0ddc0b..301bb46 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 @@ -43,6 +43,7 @@ import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.RootPanel; import ol.Coordinate; @@ -105,6 +106,16 @@ public class GeoportalDataViewer implements EntryPoint { layerManager.getLayerManagerBus()); layerManager.setOlMap(olMapMng.getOLOSMMap()); mainPanel.setMap(olMapMng.getOLOSMMap()); + + + String attributionHTML = "
" + +olMapMng.getOLOSMMap().getMapAttribution()+ + "
"; + + + RootPanel.get(APP_DIV).add(new HTML(attributionHTML)); + + //mainPanel.setMapAttribution(olMapMng.getOLOSMMap().getMapAttribution()); updateSize(); ScriptInjector.fromUrl("//cdnjs.cloudflare.com/ajax/libs/nanogallery2/3.0.5/jquery.nanogallery2.min.js") .setWindow(ScriptInjector.TOP_WINDOW).inject(); 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 ed15837..a379883 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 @@ -39,7 +39,6 @@ public class OLMapManager { 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 = 18.5; - /** * Instantiates a new OL map manager. diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/MapUtils.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/MapUtils.java index 15ccd71..08406ff 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/MapUtils.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/MapUtils.java @@ -2,6 +2,7 @@ package org.gcube.portlets.user.geoportaldataviewer.client.gis; import ol.Collection; import ol.Coordinate; +import ol.control.Attribution; import ol.control.Control; import ol.control.FullScreen; import ol.control.MousePosition; @@ -32,6 +33,10 @@ public final class MapUtils { MousePosition mousePosition = new MousePosition(); mousePosition.setCoordinateFormat(Coordinate.createStringXY(5)); controls.push(mousePosition); + + Attribution attribution = new Attribution(); + attribution.setCollapsed(true); + controls.push(attribution); //controls.push(new ZoomToExtent()); } 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 4971b9d..7b5c71a 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 @@ -8,6 +8,7 @@ import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerCon 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.DoActionOnDetailLayersEvent.SwapLayer; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import com.google.gwt.core.client.GWT; @@ -35,7 +36,6 @@ import ol.OverlayOptions; import ol.Size; import ol.View; import ol.ViewOptions; -import ol.control.Attribution; import ol.event.EventListener; import ol.geom.Geometry; import ol.interaction.Draw; @@ -47,6 +47,7 @@ import ol.interaction.KeyboardPan; import ol.interaction.KeyboardZoom; import ol.layer.Base; import ol.layer.Image; +import ol.layer.Layer; import ol.layer.LayerOptions; import ol.layer.Tile; import ol.layer.VectorLayerOptions; @@ -58,6 +59,7 @@ import ol.source.ImageWmsParams; import ol.source.Osm; import ol.source.Source; import ol.source.Vector; +import ol.source.Xyz; import ol.source.XyzOptions; /** @@ -138,6 +140,10 @@ public abstract class OpenLayerOSM { private LinkedHashMap wmsLayerMap; + private Layer baseLayerTile; + + private String mapAttribution; + /** * Instantiates a new open layer OSM. * @@ -156,16 +162,6 @@ public abstract class OpenLayerOSM { wmsDetailsLayerZIndex[i] = 1000 + i; } - // create a OSM-layer - XyzOptions xyzOptions = OLFactory.createOptions(); -// osmSourceOptions.setCrossOrigin("Anonymous"); -// osmSourceOptions.setTileLoadFunction(null); - - Osm osmSource = new Osm(xyzOptions); - LayerOptions osmLayerOptions = OLFactory.createOptions(); - osmLayerOptions.setSource(osmSource); - - Tile osmLayer = new Tile(osmLayerOptions); // create a projection projectionOptions.setCode(MAP_PROJECTION.EPSG_3857.getName()); projectionOptions.setUnits("m"); @@ -184,25 +180,72 @@ public abstract class OpenLayerOSM { map = new Map(mapOptions); - map.addLayer(osmLayer); + //map.addLayer(baseLayerTile); // map.addLayer(tileDebugLayer); // 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()); + + + String attribution = "© Mapbox © OpenStreetMap Improve this map"; + BaseMapLayer baseLayer = new BaseMapLayer( + "https://{a-d}.tiles.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiZDRzY2llbmNlIiwiYSI6ImNpcW1nZjE4MDAwMXNod25rdHJsemRoNTQifQ.YPNkNLb8EzjThpvJl1tg4w", + attribution, BaseMapLayer.OL_BASE_MAP.MAPBOX); + + //applying base map + changeBaseMap(baseLayer); bindEvents(); } + public void changeBaseMap(BaseMapLayer baseLayer) { + + BaseMapLayer.OL_BASE_MAP baseMap = baseLayer.getType() == null ? BaseMapLayer.OL_BASE_MAP.OSM + : baseLayer.getType(); + this.mapAttribution = baseLayer.getAttribution(); + + try { + if (baseLayerTile != null) + map.removeLayer(baseLayerTile); + } catch (Exception e) { + // TODO: handle exception + } + + switch (baseMap) { + case OSM: + XyzOptions xyzOptions = OLFactory.createOptions(); + Osm osmSource = new Osm(xyzOptions); + LayerOptions layerOptions = OLFactory.createOptions(); + layerOptions.setSource(osmSource); + baseLayerTile = new Tile(layerOptions); + + break; + case MAPBOX: + case OTHER: + + XyzOptions xyzOptions2 = OLFactory.createOptions(); + Xyz xyz = new Xyz(xyzOptions2); + xyz.setAttributions(mapAttribution); + xyz.setUrl(baseLayer.getUrl()); + LayerOptions layerOptions2 = OLFactory.createOptions(); + layerOptions2.setSource(xyz); + baseLayerTile = new Tile(layerOptions2); + + break; + } + + // map == null at init time + if (map != null) + map.addLayer(baseLayerTile); + + } + /** * Bind events. */ @@ -830,15 +873,15 @@ public abstract class OpenLayerOSM { Image layer1 = wmsDetailsLayerMap.get(layerSource); Image layer2 = wmsDetailsLayerMap.get(layerTarget); - int zIndexS = swapLSource.getPosition()+1; - int zIndexT = swapLTarget.getPosition()+1; - GWT.log("new zindex source: "+zIndexS+", new zTarget: "+zIndexT); + int zIndexS = swapLSource.getPosition() + 1; + int zIndexT = swapLTarget.getPosition() + 1; + GWT.log("new zindex source: " + zIndexS + ", new zTarget: " + zIndexT); layer1.setZIndex(zIndexT); layer2.setZIndex(zIndexS); - - GWT.log("layer1 source: "+layerSource+", new zIndex: "+layer1.getZIndex()); - GWT.log("layer1 target: "+layerTarget+", new zIndex: "+layer2.getZIndex()); - + + GWT.log("layer1 source: " + layerSource + ", new zIndex: " + layer1.getZIndex()); + GWT.log("layer1 target: " + layerTarget + ", new zIndex: " + layer2.getZIndex()); + } /** @@ -852,4 +895,8 @@ public abstract class OpenLayerOSM { return map.get((map.keySet().toArray())[index]); } + public String getMapAttribution() { + return mapAttribution; + } + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java index df0ddfa..c8cd6f5 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java @@ -12,6 +12,7 @@ import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.ExtentMapUtil.L import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.NavLink; +import com.github.gwtbootstrap.client.ui.Paragraph; import com.github.gwtbootstrap.client.ui.constants.IconType; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Style.Unit; @@ -25,6 +26,7 @@ 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.Label; import com.google.gwt.user.client.ui.ScrollPanel; import com.google.gwt.user.client.ui.Widget; @@ -69,7 +71,7 @@ public class GeonaDataViewMainPanel extends Composite { @UiField Button extentToItaly; - + @UiField Button extentToEarth; @@ -79,6 +81,9 @@ public class GeonaDataViewMainPanel extends Composite { @UiField ScrollPanel overlayLayersPanel; + @UiField + HTMLPanel panelAttribution; + private MapPanel mapPanel; private OpenLayerOSM map; @@ -102,39 +107,39 @@ public class GeonaDataViewMainPanel extends Composite { dataPointSelection.setIcon(IconType.SCREENSHOT); dataBoxSelection.setIcon(IconType.BOOKMARK); removeQuery.setIcon(IconType.REMOVE); - + Image italyImg = new Image(Images.ICONS.italyIcon()); italyImg.getElement().getStyle().setPaddingLeft(20, Unit.PX); extentToItaly.getElement().appendChild(italyImg.getElement()); extentToItaly.setWidth("140px"); - + Image worldImg = new Image(Images.ICONS.worldIcon()); worldImg.getElement().getStyle().setPaddingLeft(20, Unit.PX); extentToEarth.getElement().appendChild(worldImg.getElement()); extentToEarth.setWidth("140px"); - - //layersDDB.setToggle(true); + + // layersDDB.setToggle(true); bindEvents(); } private void bindEvents() { - + layersDDB.addClickHandler(new ClickHandler() { - + @Override public void onClick(ClickEvent event) { - + GWT.log("layersDDB clicked"); - - if(overlayLayersPanel.isVisible()) { + + if (overlayLayersPanel.isVisible()) { overlayLayersPanel.setVisible(false); - }else { + } else { overlayLayersPanel.setVisible(true); } } }); - + } /** @@ -146,15 +151,15 @@ public class GeonaDataViewMainPanel extends Composite { String toH = height + "px"; mapPanel.setMapHeight(height); detailsPanel.setHeight(toH); - + setOverlayPanelMaxHeight(); } - + private void setOverlayPanelMaxHeight() { - - String overlMH = mapPanel.getOffsetHeight()-130+"px"; - GWT.log("overlayLayersPanel maxHeight: "+overlMH); + + String overlMH = mapPanel.getOffsetHeight() - 130 + "px"; + GWT.log("overlayLayersPanel maxHeight: " + overlMH); overlayLayersPanel.getElement().getStyle().setProperty("maxHeight", overlMH); } @@ -227,7 +232,7 @@ public class GeonaDataViewMainPanel extends Composite { } }); - + extentToEarth.addClickHandler(new ClickHandler() { @Override @@ -286,37 +291,46 @@ public class GeonaDataViewMainPanel extends Composite { */ public void showOverlayLayers(FlowPanel panel) { GWT.log("showOverlayLayers"); - //layersDDB.setVisible(true); + // layersDDB.setVisible(true); overlayLayersPanel.setVisible(true); overlayLayersPanel.clear(); - + setOverlayPanelMaxHeight(); overlayLayersPanel.add(panel); - //layersDDBClickEvent(); + // layersDDBClickEvent(); } - + private void layersDDBClickEvent() { - layersDDB.fireEvent( new GwtEvent() { - @Override - public com.google.gwt.event.shared.GwtEvent.Type getAssociatedType() { - return ClickEvent.getType(); - } - @Override - protected void dispatch(ClickHandler handler) { - handler.onClick(null); - } - }); + layersDDB.fireEvent(new GwtEvent() { + @Override + public com.google.gwt.event.shared.GwtEvent.Type 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); + // layersDDB.setVisible(false); overlayLayersPanel.setVisible(false); - //layersDDBClickEvent(); + // layersDDBClickEvent(); + } + + public void setMapAttribution(String attribution) { + panelAttribution.clear(); + Label label = new Label("Base Map Credits"); + Paragraph p = new Paragraph(attribution); + panelAttribution.add(label); + panelAttribution.add(p); } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml index 3052b86..5701faf 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml @@ -17,7 +17,7 @@ - Map Interactions @@ -30,6 +30,9 @@ Click on the Points shown on the Map to view their features + +