Fixing the CORSE issue #24506#note-2

This commit is contained in:
Francesco Mangiacrapa 2023-01-31 14:48:38 +01:00
parent aaed3cf9f4
commit 619c67c5ec
8 changed files with 251 additions and 84 deletions

View File

@ -20,7 +20,7 @@
<properties>
<!-- Convenience property to set the GWT version -->
<gwt.version>2.9.0</gwt.version>
<gwt.version>2.10.0</gwt.version>
<gwt.compiler.style>PRETTY</gwt.compiler.style>
<gson.version>2.6.2</gson.version>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>

View File

@ -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<String, String> layerFeaturesCache = new HashMap<String, String>();
/**
* 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<BaseMapLayer> 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<String>() {
@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<String>() {
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);
}
}
}

View File

@ -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);
}

View File

@ -79,4 +79,7 @@ public interface GeoportalDataViewerServiceAsync {
void getWFSRequest(LayerItem layerItem, String mapSrsName, BoundsMap mapBBOX, int maxFeatures, String outputFormat,
AsyncCallback<String> callback);
void getWFSResponse(LayerItem layerItem, String mapSrsName, BoundsMap mapBBOX, int maxFeatures, String outputFormat,
AsyncCallback<String> callback);
}

View File

@ -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 GwtEvent<DoActionOnDetailLayers
private SwapLayer sourceLayerSwap;
private SwapLayer targetLayerSwap;
private LayerObject layerObject;
private DragDropLayer sourceEventUI;
/**
* The Class SwapLayer.
@ -211,6 +213,25 @@ public class DoActionOnDetailLayersEvent extends GwtEvent<DoActionOnDetailLayers
return visibility;
}
/**
* Sets the UI event source.
*
* @param sourceEventUI the new UI event source
*/
public void setUIEventSource(DragDropLayer sourceEventUI) {
this.sourceEventUI = sourceEventUI;
}
/**
* Gets the source event UI.
*
* @return the source event UI
*/
public DragDropLayer getSourceEventUI() {
return sourceEventUI;
}
/**
* To string.
*

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -10,6 +10,7 @@ import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetai
import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent.SwapLayer;
import org.gcube.portlets.user.geoportaldataviewer.client.resources.GNAImages;
import org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.project.ProjectUtil;
import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon;
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;
@ -56,6 +57,10 @@ public class DragDropLayer extends FlowPanel {
private Image imgLocateNone = new Image(GNAImages.ICONS.locateNone());
private boolean locateEnabled = false;
private HTML buttonLocate = new HTML();
private DragDropLayer INSTANCE = this;
private LoaderIcon loaderIcon = new LoaderIcon("Loading features", null);
private Button draggableButton = new Button();
private HandlerManager applicationBus;
@ -70,7 +75,7 @@ public class DragDropLayer extends FlowPanel {
this.layerObject = layerObject;
this.layerItem = layerObject.getLayerItem();
GWT.log("DragDropLayer for projectDV: " + layerObject.getProjectDV());
// Checking the spatial reference
if (layerObject.getProjectDV() != null && layerObject.getProjectDV().getSpatialReference() == null) {
GeoportalDataViewerServiceAsync.Util.getInstance().getSpatialReference(layerObject.getProfileID(),
@ -172,14 +177,16 @@ public class DragDropLayer extends FlowPanel {
HorizontalPanel hp0 = new HorizontalPanel();
HorizontalPanel hpFunct = new HorizontalPanel();
vpInner.getElement().getStyle().setMarginLeft(47, Unit.PX);
hp0.add(draggableButton);
labelProject.getElement().getStyle().setMarginLeft(10, Unit.PX);
labelProject.getElement().getStyle().setFontWeight(FontWeight.BOLD);
hp0.add(labelProject);
hpFunct.add(buttonLayerVisibility);
hpFunct.add(buttonLocate);
hpFunct.add(loaderIcon);
setVisibleLoaderFeatures(false, null);
if (layerObject.getProjectDV().getTemporalReference() != null) {
TemporalReferenceDV tempRef = layerObject.getProjectDV().getTemporalReference();
// ft.setWidget(ft.getRowCount() + 1, 2, new HTML(ProjectUtil.toHTMLCode(tempRef)));
@ -187,14 +194,14 @@ public class DragDropLayer extends FlowPanel {
}
vpInner.add(labelLayerName);
//vpInner.add(new SimplePanel(rs));
// vpInner.add(new SimplePanel(rs));
vp.add(hp0);
hpFunct.getElement().getStyle().setMarginTop(5, Unit.PX);
vpInner.add(hpFunct);
vpInner.add(new SimplePanel(rs));
vp.add(vpInner);
add(vp);
// add(ft);
@ -221,6 +228,8 @@ public class DragDropLayer extends FlowPanel {
setLocateEnabledButtonImage();
DoActionOnDetailLayersEvent dae = new DoActionOnDetailLayersEvent(DO_LAYER_ACTION.LOCATE_LAYER,
layerItem, layerObject);
dae.setUIEventSource(INSTANCE);
setVisibleLoaderFeatures(true, null);
applicationBus.fireEvent(dae);
}
});
@ -242,10 +251,10 @@ public class DragDropLayer extends FlowPanel {
buttonLocate.getElement().removeAllChildren();
if (locateEnabled) {
buttonLocate.getElement().appendChild(imgLocate.getElement());
buttonLocate.setTitle("Unselect the layer");
buttonLocate.setTitle("Unselect the layer features");
} else {
buttonLocate.getElement().appendChild(imgLocateNone.getElement());
buttonLocate.setTitle("Highlight the layer");
buttonLocate.setTitle("Highlight the layer features");
}
}
@ -330,4 +339,17 @@ public class DragDropLayer extends FlowPanel {
return layerItem;
}
/**
* Sets the visible loader features.
*
* @param bool the bool
* @param msg the msg
*/
public void setVisibleLoaderFeatures(boolean bool, String msg) {
loaderIcon.setVisible(bool);
if(msg!=null)
loaderIcon.setText(msg);
}
}

View File

@ -3,6 +3,10 @@ package org.gcube.portlets.user.geoportaldataviewer.server;
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.projects;
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.useCaseDescriptors;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -1542,14 +1546,13 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
return null;
}
/**
* Gets the WFS request.
*
* @param layerItem the layer item
* @param mapSrsName the map srs name
* @param mapBBOX the map BBOX
* @param maxFeatures the max features. If 0 means all feature
* @param layerItem the layer item
* @param mapSrsName the map srs name
* @param mapBBOX the map BBOX
* @param maxFeatures the max features. If 0 means all feature
* @param outputFormat the output format
* @return the WFS request
*/
@ -1557,15 +1560,70 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
public String getWFSRequest(LayerItem layerItem, String mapSrsName, BoundsMap mapBBOX, int maxFeatures,
String outputFormat) {
LOG.info("getWFSRequest called");
if (LOG.isDebugEnabled()) {
LOG.debug("getWFSRequest parameters layerItem name: " + layerItem.getName(),
", mapSrsName: " + mapSrsName + ", mapBBOX: " + mapBBOX + ", maxFeatures: " + maxFeatures
+ ", outputFormat: " + outputFormat);
LOG.debug("getWFSRequest parameters layerItem name: " + layerItem.getName(), ", mapSrsName: " + mapSrsName
+ ", mapBBOX: " + mapBBOX + ", maxFeatures: " + maxFeatures + ", outputFormat: " + outputFormat);
}
String url = GisMakers.buildWFSFeatureQuery(layerItem, mapSrsName, mapBBOX, maxFeatures, outputFormat);
LOG.info("returning WFSRequest: "+url);
LOG.info("returning WFSRequest: " + url);
return url;
}
/**
* 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
*/
@Override
public String getWFSResponse(LayerItem layerItem, String mapSrsName, BoundsMap mapBBOX, int maxFeatures,
String outputFormat) {
LOG.info("getWFSResponse called");
if (LOG.isDebugEnabled()) {
LOG.debug("getWFSResponse parameters layerItem name: " + layerItem.getName(), ", mapSrsName: " + mapSrsName
+ ", mapBBOX: " + mapBBOX + ", maxFeatures: " + maxFeatures + ", outputFormat: " + outputFormat);
}
String url = getWFSRequest(layerItem, mapSrsName, mapBBOX, maxFeatures, outputFormat);
StringBuffer response = new StringBuffer();
String theResponseString = "";
HttpURLConnection con = null;
LOG.debug("Built URL: " + url);
try {
URL obj = new URL(url);
con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
LOG.debug("GET Response Code: " + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) { // success
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
} else {
LOG.info("GET request did not work.");
}
theResponseString = response.toString();
//LOG.trace(theResponseString);
if (LOG.isDebugEnabled()) {
LOG.debug("getWFSResponse is empty? " + theResponseString.isEmpty());
}
} catch (Exception e) {
LOG.error("Error on performing the request to URL: " + url, e);
} finally {
}
return theResponseString;
}
}