From 619c67c5ecbfdf7a1f354109236920ef3e201edb Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 31 Jan 2023 14:48:38 +0100 Subject: [PATCH] Fixing the CORSE issue #24506#note-2 --- pom.xml | 2 +- .../client/GeoportalDataViewer.java | 180 +++++++++++------- .../client/GeoportalDataViewerService.java | 13 ++ .../GeoportalDataViewerServiceAsync.java | 3 + .../events/DoActionOnDetailLayersEvent.java | 21 ++ .../client/resources/locate.png | Bin 1226 -> 1178 bytes .../client/ui/dandd/DragDropLayer.java | 38 +++- .../GeoportalDataViewerServiceImpl.java | 78 +++++++- 8 files changed, 251 insertions(+), 84 deletions(-) diff --git a/pom.xml b/pom.xml index 5f58c1d..d4dda5d 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ - 2.9.0 + 2.10.0 PRETTY 2.6.2 ${project.build.directory}/${project.build.finalName} 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 fa3e149..1ce4008 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 @@ -2,6 +2,7 @@ package org.gcube.portlets.user.geoportaldataviewer.client; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Set; @@ -73,11 +74,6 @@ import com.google.gwt.core.client.ScriptInjector; import com.google.gwt.event.logical.shared.ResizeEvent; import com.google.gwt.event.logical.shared.ResizeHandler; import com.google.gwt.event.shared.HandlerManager; -import com.google.gwt.http.client.Request; -import com.google.gwt.http.client.RequestBuilder; -import com.google.gwt.http.client.RequestCallback; -import com.google.gwt.http.client.RequestException; -import com.google.gwt.http.client.Response; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -155,6 +151,9 @@ public class GeoportalDataViewer implements EntryPoint { private boolean initApplication; + // A cache (Layer_ID, GeoJSON) of layer features loaded via GetFeature Request + private HashMap layerFeaturesCache = new HashMap(); + /** * This is the entry point method. */ @@ -200,6 +199,9 @@ public class GeoportalDataViewer implements EntryPoint { } + /** + * Inits the application. + */ private void initApplication() { initApplication = true; @@ -300,10 +302,20 @@ public class GeoportalDataViewer implements EntryPoint { RootPanel.get(APP_DIV).add(attributionDiv); } + /** + * Gets the status. + * + * @return the status + */ public static ViewerStatus getStatus() { return viewerStatus; } + /** + * Gets the list base map layers. + * + * @return the list base map layers + */ public static List getListBaseMapLayers() { return listBaseMapLayers; } @@ -320,6 +332,11 @@ public class GeoportalDataViewer implements EntryPoint { } + /** + * Gets the client height. + * + * @return the client height + */ public int getClientHeight() { RootPanel principalDiv = RootPanel.get(APP_DIV); int topBorder = principalDiv.getAbsoluteTop(); @@ -585,76 +602,53 @@ public class GeoportalDataViewer implements EntryPoint { break; case LOCATE_LAYER: - + final LayerItem layerItem = doLayerActionEvent.getLayerItem(); - + boolean layerHighlighted = olMap.areLayerFeaturesAsHighlight(layerItem); - - if(layerHighlighted) { + + if (layerHighlighted) { + doLayerActionEvent.getSourceEventUI().setVisibleLoaderFeatures(false, null); olMap.removeLayerFeaturesAsHighlight(layerItem.getName()); return; } - - GeoportalDataViewerServiceAsync.Util.getInstance().getWFSRequest(layerItem, - olMap.getProjectionCode(), null, 0, "json", - new AsyncCallback() { - @Override - public void onFailure(Throwable caught) { - // TODO Auto-generated method stub + final String geoJSONFeatures = layerFeaturesCache.get(layerItem.getName()); - } + if (geoJSONFeatures == null) { - @Override - public void onSuccess(String wmsRequestURL) { - GWT.log("wmsRequestURL: "+wmsRequestURL); - - RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, wmsRequestURL); + GeoportalDataViewerServiceAsync.Util.getInstance().getWFSResponse(layerItem, + olMap.getProjectionCode(), null, 0, "json", new AsyncCallback() { - try { - Request response = builder.sendRequest(null, new RequestCallback() { - public void onError(Request request, Throwable exception) { - // Code omitted for clarity - } + @Override + public void onFailure(Throwable caught) { + doLayerActionEvent.getSourceEventUI().setVisibleLoaderFeatures(false, null); - public void onResponseReceived(Request request, Response response) { - GWT.log("GeoJSON: "+response.getText()); + } - GeoJsonFeatureOptions fo = new GeoJsonFeatureOptions(); - ProjectionOptions projectionOptions = new ProjectionOptions(); - projectionOptions.setCode(MAP_PROJECTION.EPSG_4326.getName()); - Projection fp = new Projection(projectionOptions); - fo.setFeatureProjection(fp); - fo.setDataProjection(fp); - GeoJsonOptions geoJsonOpt = new GeoJsonOptions(); - geoJsonOpt.setDefaultDataProjection(fp); - geoJsonOpt.setFeatureProjection(fp); - GeoJson geoJson = OLFactory.createGeoJSON(geoJsonOpt); - - Feature[] features = geoJson.readFeatures(response.getText()); - GWT.log("features: "+features); - //Feature[] features = new GeoJson().readFeatures(jsonObject, projectionOptions); - olMap.addLayerFeaturesAsHighlight(layerItem, features); - - ProjectDV projectDV = doLayerActionEvent.getLayerObject().getProjectDV(); - if(projectDV!=null) { - GeoJSON spatialReference = projectDV.getSpatialReference(); - - GWT.log("spatialReference is: "+spatialReference); - Coordinate transfCoord = MapUtils.geoJSONTToBBoxCenter(spatialReference, MAP_PROJECTION.EPSG_4326.getName(), - MAP_PROJECTION.EPSG_3857.getName()); - GWT.log("transfCoord is: "+transfCoord); - if(transfCoord!=null) - olMap.setCenter(transfCoord); - } - } - }); + @Override + public void onSuccess(String geoJSONFeaturesResp) { + doLayerActionEvent.getSourceEventUI().setVisibleLoaderFeatures(false, null); - } catch (RequestException e) { - - } - } - }); + if (geoJSONFeaturesResp != null && !geoJSONFeaturesResp.isEmpty()) { + layerFeaturesCache.put(layerItem.getName(), geoJSONFeaturesResp); + + GWT.log("GeoJSON: " + geoJSONFeaturesResp); + + showLayerFeatures(layerItem, geoJSONFeaturesResp, + doLayerActionEvent.getLayerObject().getProjectDV()); + + } + } + + }); + } else { + + doLayerActionEvent.getSourceEventUI().setVisibleLoaderFeatures(false, null); + showLayerFeatures(layerItem, geoJSONFeatures, + doLayerActionEvent.getLayerObject().getProjectDV()); + + } break; @@ -664,7 +658,7 @@ public class GeoportalDataViewer implements EntryPoint { } }); - + applicationBus.addHandler(ChangeMapLayerEvent.TYPE, new ChangeMapLayerEventHandler() { @Override @@ -774,11 +768,11 @@ public class GeoportalDataViewer implements EntryPoint { } - /** * Sets the. * * @param json the json + * @return the object */ public static native Object toJSON(String json) /*-{ var jsonObj = JSON.parse(json); @@ -802,6 +796,13 @@ public class GeoportalDataViewer implements EntryPoint { // // }-*/; + /** + * Perform WFS query on centroid. + * + * @param projectID the project ID + * @param centroidLong the centroid long + * @param centroidLat the centroid lat + */ private void performWFSQueryOnCentroid(String projectID, Double centroidLong, Double centroidLat) { GWT.log("Perform performWFSQueryOnCentroid: " + projectID + " long: " + centroidLong + ", lat: " + centroidLat); if (projectID != null) { @@ -826,6 +827,13 @@ public class GeoportalDataViewer implements EntryPoint { } } + /** + * Show popover. + * + * @param w the w + * @param message the message + * @param heading the heading + */ public static void showPopover(final Widget w, String message, String heading) { final Popover popover = new Popover(); @@ -847,6 +855,11 @@ public class GeoportalDataViewer implements EntryPoint { timer.schedule(3000); } + /** + * Gets the general error panel. + * + * @return the general error panel + */ private FlowPanel getGeneralErrorPanel() { Image geoportalError = new Image(GNAImages.ICONS.geoportaServiceError()); FlowPanel errorPanelMsg = new FlowPanel(); @@ -859,4 +872,41 @@ public class GeoportalDataViewer implements EntryPoint { return errorPanelMsg; } + /** + * Show layer features. + * + * @param layerItem the layer item + * @param geoJSONFeatures the geo JSON features + * @param projectDV the project DV + */ + private void showLayerFeatures(LayerItem layerItem, String geoJSONFeatures, ProjectDV projectDV) { + + GeoJsonFeatureOptions fo = new GeoJsonFeatureOptions(); + ProjectionOptions projectionOptions = new ProjectionOptions(); + projectionOptions.setCode(MAP_PROJECTION.EPSG_4326.getName()); + Projection fp = new Projection(projectionOptions); + fo.setFeatureProjection(fp); + fo.setDataProjection(fp); + GeoJsonOptions geoJsonOpt = new GeoJsonOptions(); + geoJsonOpt.setDefaultDataProjection(fp); + geoJsonOpt.setFeatureProjection(fp); + GeoJson geoJson = OLFactory.createGeoJSON(geoJsonOpt); + + Feature[] features = geoJson.readFeatures(geoJSONFeatures); + + GWT.log("features: " + features); + olMapMng.getOLMap().addLayerFeaturesAsHighlight(layerItem, features); + + if (projectDV != null) { + GeoJSON spatialReference = projectDV.getSpatialReference(); + + GWT.log("spatialReference is: " + spatialReference); + Coordinate transfCoord = MapUtils.geoJSONTToBBoxCenter(spatialReference, MAP_PROJECTION.EPSG_4326.getName(), + MAP_PROJECTION.EPSG_3857.getName()); + GWT.log("transfCoord is: " + transfCoord); + if (transfCoord != null) + olMapMng.getOLMap().setCenter(transfCoord); + } + } + } 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 05c25cf..b4d2e98 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 @@ -193,4 +193,17 @@ public interface GeoportalDataViewerService extends RemoteService { String getWFSRequest(LayerItem layerItem, String mapSrsName, BoundsMap mapBBOX, int maxFeatures, String outputFormat); + /** + * Gets the WFS response. + * + * @param layerItem the layer item + * @param mapSrsName the map srs name + * @param mapBBOX the map BBOX + * @param maxFeatures the max features + * @param outputFormat the output format + * @return the WFS response + */ + String getWFSResponse(LayerItem layerItem, String mapSrsName, BoundsMap mapBBOX, int maxFeatures, + String outputFormat); + } 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 4ceb4c4..8a69080 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 @@ -79,4 +79,7 @@ public interface GeoportalDataViewerServiceAsync { void getWFSRequest(LayerItem layerItem, String mapSrsName, BoundsMap mapBBOX, int maxFeatures, String outputFormat, AsyncCallback callback); + void getWFSResponse(LayerItem layerItem, String mapSrsName, BoundsMap mapBBOX, int maxFeatures, String outputFormat, + AsyncCallback callback); + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/DoActionOnDetailLayersEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/DoActionOnDetailLayersEvent.java index 52bde9c..71221f3 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/DoActionOnDetailLayersEvent.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/DoActionOnDetailLayersEvent.java @@ -1,5 +1,6 @@ package org.gcube.portlets.user.geoportaldataviewer.client.events; +import org.gcube.portlets.user.geoportaldataviewer.client.ui.dandd.DragDropLayer; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject; @@ -33,6 +34,7 @@ public class DoActionOnDetailLayersEvent extends GwtEventkwz$g7fD1xR7i=fmR)QVRTRhn=ib@vew4QR(Sj{dQ%Vb{5f!RLUx+kD zUix4uVoa16Y_zGG5J`M9K1zao7&S(WiXjT92{EFTNJumaHPMo2DyEG#wP|-dyW8$| zXFulN<3njJ-R|sC`+uAB^}BP=+{uKgk!f7r4N!!r5R0`SDDRb;(RRe9BmFf%bz=d6zS(Z(O?jGD`1aG?{T>dimsXTFhM)B0-4)d)I{Q>}7Re>*78Ug_1@=Nkpo&x}? z?HTMs;Py`;jFslhO50G0kxqksp%s*5kLB!5M((Ma(4{j^w4juSq zI~i{0J^_|srG9gYAj1pP)LjZZGf>dWaL=zT6kK-^((OngWnZIU&-Hd$v$n5PFz3?@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