#21946 managed detail layer with min/max resolution

task_21890
Francesco Mangiacrapa 3 years ago
parent 94d1ffbe05
commit 6900a988f2

@ -44,7 +44,7 @@ import ol.Coordinate;
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Oct 27, 2020
* Oct 27, 2020
*/
public class GeoportalDataViewer implements EntryPoint {
@ -52,37 +52,36 @@ public class GeoportalDataViewer implements EntryPoint {
public final static String APP_DIV = "geoportal-data-viewer";
/** The ol map. */
//private OpenLayerOSM olMap = null;
// private OpenLayerOSM olMap = null;
/** The main panel. */
private GeonaDataViewMainPanel mainPanel;
/** The param wms request. */
private String paramWmsRequest;
/** The param UUID. */
//private String paramUUID;
// private String paramUUID;
private String paramGeonaItemType;
/** The param layer title. */
private String paramLayerTitle;
private HandlerManager applicationBus = new HandlerManager("");
/** The layer manager. */
private LayerManager layerManager = new LayerManager(applicationBus);
private String paramGeonaItemID;
private GeoNaDataViewerProfile geonaDataViewerProfile;
private OLMapManager olMapMng = null;
int attempt = 0;
//https://data.d4science.org/gis-viewer-app/?wmsrequest=https%3A%2F%2Fgeona-proto.d4science.org%2Fgeoserver%2Fconcessioni_conf%2Fwms%3Fservice%3DWMS%26version%3D1.1.0%26request%3DGetMap%26layers%3Dconcessioni_conf%3Acentroids_concessioni%26styles%3D%26bbox%3D8.476%2C39.179%2C17.391%2C45.772%26width%3D768%26height%3D567%26srs%3DEPSG%3A4326%26format%3Dapplication%2Fopenlayers&zoom=6&centermap=12.45%2C42.98
// https://data.d4science.org/gis-viewer-app/?wmsrequest=https%3A%2F%2Fgeona-proto.d4science.org%2Fgeoserver%2Fconcessioni_conf%2Fwms%3Fservice%3DWMS%26version%3D1.1.0%26request%3DGetMap%26layers%3Dconcessioni_conf%3Acentroids_concessioni%26styles%3D%26bbox%3D8.476%2C39.179%2C17.391%2C45.772%26width%3D768%26height%3D567%26srs%3DEPSG%3A4326%26format%3Dapplication%2Fopenlayers&zoom=6&centermap=12.45%2C42.98
/**
* This is the entry point method.
@ -171,7 +170,7 @@ public class GeoportalDataViewer implements EntryPoint {
GWT.log("The layerItem is: " + layerItem);
layerManager.addLayer(theItemType, null, null, layerItem.getWmsLink(), false, false,
null, false);
null, false, null, null);
if (paramGeonaItemID != null) {
if (paramGeonaItemType == null) {
@ -193,9 +192,7 @@ public class GeoportalDataViewer implements EntryPoint {
bindEvents();
}
/**
* Update window size.
*/
@ -204,91 +201,93 @@ public class GeoportalDataViewer implements EntryPoint {
int rootHeight = getClientHeight();
int height = rootHeight;
mainPanel.setPanelsHeight(height);
GWT.log("Set height: "+height);
GWT.log("Set height: " + height);
}
public int getClientHeight() {
RootPanel principalDiv = RootPanel.get(APP_DIV);
int topBorder = principalDiv.getAbsoluteTop();
int rootHeight = Window.getClientHeight() - topBorder;
return rootHeight;
}
/**
* Bind events.
*/
private void bindEvents() {
applicationBus.addHandler(ShowDetailsEvent.TYPE, new ShowDetailsEventHandler() {
@Override
public void onShowDetails(ShowDetailsEvent showDetailsEvent) {
GWT.log("Fired event: "+showDetailsEvent);
GWT.log("Fired event: " + showDetailsEvent);
String geonaMongoId = showDetailsEvent.getGeonaMongoID();
if(geonaMongoId==null) {
if (geonaMongoId == null) {
Window.alert("Item Id not found");
return;
}
//TODO
// TODO
boolean found = false;
GWT.log("Product with id: "+geonaMongoId+" found? "+found);
if(!found) {
if(showDetailsEvent.getGeonaItemType().equalsIgnoreCase("Concessione")) {
GeoportalDataViewerServiceAsync.Util.getInstance().getConcessioneForId(geonaMongoId, new AsyncCallback<ConcessioneDV>() {
@Override
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
mainPanel.hidePanelDetails();
}
@Override
public void onSuccess(ConcessioneDV concessioneDV) {
GWT.log("Showing: "+concessioneDV);
mainPanel.showAsDetails(concessioneDV, showDetailsEvent.getGeonaItemRef());
}
});
GWT.log("Product with id: " + geonaMongoId + " found? " + found);
if (!found) {
if (showDetailsEvent.getGeonaItemType().equalsIgnoreCase("Concessione")) {
GeoportalDataViewerServiceAsync.Util.getInstance().getConcessioneForId(geonaMongoId,
new AsyncCallback<ConcessioneDV>() {
@Override
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
mainPanel.hidePanelDetails();
}
@Override
public void onSuccess(ConcessioneDV concessioneDV) {
GWT.log("Showing: " + concessioneDV);
mainPanel.showAsDetails(concessioneDV, showDetailsEvent.getGeonaItemRef());
}
});
}
}
}
});
applicationBus.addHandler(AddedLayerToMapEvent.TYPE, new AddedLayerToMapEventHandler() {
@Override
public void onLayerRendered(AddedLayerToMapEvent addedLayerToMapEvent) {
GWT.log("Fired AddedLayerToMapEvent "+addedLayerToMapEvent.getLayerItem());
//GeoportalDataViewerConstants.print("Fired AddedLayerToMapEvent "+addedLayerToMapEvent.getLayerItem());
GWT.log("Fired AddedLayerToMapEvent " + addedLayerToMapEvent.getLayerItem());
// GeoportalDataViewerConstants.print("Fired AddedLayerToMapEvent
// "+addedLayerToMapEvent.getLayerItem());
try {
attempt = 0;
if(paramGeonaItemID!=null) {
//waiting for record retrieved by service before calling the WFS
if (paramGeonaItemID != null) {
// waiting for record retrieved by service before calling the WFS
final int MAX_RETRY = 7;
Timer timer = new com.google.gwt.user.client.Timer() {
@Override
public void run() {
attempt++;
GWT.log("waiting got record tenative: "+attempt);
GWT.log("waiting got record tenative: " + attempt);
RecordDV record = mainPanel.getDisplyedRecord();
if(record!=null) {
if (record != null) {
this.cancel();
GWT.log("cancelled timer");
performWFSQueryOnCentroid(record);
}
if(attempt>MAX_RETRY) {
if (attempt > MAX_RETRY) {
GWT.log("MAX_RETRY reached, cancelled timer");
this.cancel();
}
@ -296,65 +295,69 @@ public class GeoportalDataViewer implements EntryPoint {
}
};
timer.scheduleRepeating(1000);
}
}catch (Exception e) {
} catch (Exception e) {
// TODO: handle exception
}
}
});
applicationBus.addHandler(ZoomOutOverMinimumEvent.TYPE, new ZoomOutOverMinimumEventHandler() {
@Override
public void onZoomOut(ZoomOutOverMinimumEvent zoomOutEvent) {
if(mainPanel.getDisplyedRecord()==null && !olMapMng.isQueryPointActive()) {
if (mainPanel.getDisplyedRecord() == null && !olMapMng.isQueryPointActive()) {
olMapMng.hidePopInfo();
olMapMng.removeDetailLayers();
}
}
});
applicationBus.addHandler(ClosedViewDetailsEvent.TYPE, new ClosedViewDetailsEventHandler() {
@Override
public void onClosed(ClosedViewDetailsEvent closedViewDetailsEvent) {
olMapMng.hidePopInfo();
}
});
applicationBus.addHandler(MapExtentToEvent.TYPE, new MapExtentToEventHandler() {
@Override
public void onExtentEvent(MapExtentToEvent mapExtentToEvent) {
// TODO Auto-generated method stub
}
});
}
private void performWFSQueryOnCentroid(RecordDV record) {
if(record!=null) {
GWT.log("record instanceof ConcessioneDV: " +(record instanceof ConcessioneDV) +" with mongo item id: "+record.getItemId());
//GeoportalDataViewerConstants.print("record instanceof ConcessioneDV: " +(record instanceof ConcessioneDV));
if(record instanceof ConcessioneDV) {
if (record != null) {
GWT.log("record instanceof ConcessioneDV: " + (record instanceof ConcessioneDV) + " with mongo item id: "
+ record.getItemId());
// GeoportalDataViewerConstants.print("record instanceof ConcessioneDV: "
// +(record instanceof ConcessioneDV));
if (record instanceof ConcessioneDV) {
ConcessioneDV concessioneDV = (ConcessioneDV) record;
Double x = concessioneDV.getCentroidLong();
Double y = concessioneDV.getCentroidLat();
GWT.log("X: "+x +", Y:"+y);
if(x!=null && y!=null) {
Coordinate transfCoord = MapUtils.transformCoordiante(new Coordinate(x, y), MAP_PROJECTION.EPSG_4326.getName(), MAP_PROJECTION.EPSG_3857.getName());
GeoQuery select = olMapMng.toDataPointQuery(transfCoord,false);
GWT.log("GeoQuery: "+select);
//GeoportalDataViewerConstants.print("fireEvent QueryDataEvent");
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);
GWT.log("X: " + x + ", Y:" + y);
if (x != null && y != null) {
Coordinate transfCoord = MapUtils.transformCoordiante(new Coordinate(x, y),
MAP_PROJECTION.EPSG_4326.getName(), MAP_PROJECTION.EPSG_3857.getName());
GeoQuery select = olMapMng.toDataPointQuery(transfCoord, false);
GWT.log("GeoQuery: " + select);
// GeoportalDataViewerConstants.print("fireEvent QueryDataEvent");
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);
}
}
}

@ -221,7 +221,8 @@ public class LayerManager {
GWT.log("the product id is: " + theProductId);
// retrieving and showing WMS layers of a concessione if the ZOOM level is > QUERY_MIN_ZOOM_LEVEL
// 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,
@ -239,27 +240,25 @@ public class LayerManager {
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);
false, false, layer.getLayerUUID(), true,
OLMapManager.LAYER_DETAIL_MIN_RESOLUTION,
OLMapManager.LAYER_DETAIL_MAX_RESOLUTION);
}
}
});
} else {
// removing all WMS detail layers if the ZOOM level is < QUERY_MIN_ZOOM_LEVEL
// 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
// Showing properties belonging to concessioni centroid layer
Map<String, List<String>> entries = feature.getMapProperties();
String nome = "";
@ -455,10 +454,12 @@ public class LayerManager {
* @param displayInLayerSwitcher the display in layer switcher
* @param UUID the uuid
* @param asDetailLayer the as detail layer
* @param minResolution the min resolution
* @param maxResolution the max resolution
*/
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 asDetailLayer) {
final boolean asDetailLayer, Double minResolution, Double maxResolution) {
// final LayoutContainer westPanel = (LayoutContainer) layersPanel.getParent();
//
@ -469,12 +470,12 @@ public class LayerManager {
final LayerType featureType = isBase ? LayerType.RASTER_BASELAYER : LayerType.FEATURE_TYPE;
// Info.display("Adding Layer", layerName);
if(wmsLink==null || wmsLink.isEmpty()) {
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<GeoInformationForWMSRequest>() {
@ -498,23 +499,23 @@ public class LayerManager {
geoInfoWMS.getWmsRequest(), geoInfoWMS.getBaseWmsServiceHost(), true, isBase,
displayInLayerSwitcher, (ArrayList<String>) geoInfoWMS.getStyles().getGeoStyles(),
geoInfoWMS.getWmsRequest(), false, geoInfoWMS.getMapWMSNoStandard(),
geoInfoWMS.isNcWMS(), UUID, geoInfoWMS.getZAxis());
geoInfoWMS.isNcWMS(), UUID, geoInfoWMS.getZAxis(), minResolution, maxResolution);
LayerObject lo = new LayerObject();
lo.setLayerItem(layerItem);
lo.setItemType(geonaItemType);
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 {
// if a detail layer checking if it is already added to map
if (asDetailLayer && layerObjects.containsKey(key)) {
GWT.log("Skipping layer " + key + " already added to Map");
} else {
layerObjects.put(key, lo);
if (!asDetailLayer)
olMap.addWMSLayer(layerItem);
else
olMap.addWMSDetailLayer(layerItem);
// }
}
}
});
}
@ -537,12 +538,14 @@ public class LayerManager {
* @param isNcWms the is nc wms
* @param UUID the uuid
* @param zAxis the z axis
* @param minResolution the min resolution
* @param maxResolution the max resolution
* @return the layer item
*/
private LayerItem toLayerItem(LayerType layerType, String layerTitle, String layerName, String layerURL,
String mapServerHost, boolean isExternal, boolean isBase, boolean displayInLayerSwitcher,
ArrayList<String> styles, String wmsLink, boolean onTop, HashMap<String, String> wmsNotStandardParams,
boolean isNcWms, String UUID, ZAxis zAxis) {
boolean isNcWms, String UUID, ZAxis zAxis, Double minResolution, Double maxResolution) {
// GWT.log("Add addLayerByWms 1");
LayerItem layerItem = new LayerItem();
@ -559,6 +562,8 @@ public class LayerManager {
layerItem.setNcWms(isNcWms);
layerItem.setUUID(UUID);
layerItem.setZAxis(zAxis);
layerItem.setMinResolution(minResolution);
layerItem.setMaxResolution(maxResolution);
switch (layerType) {

@ -37,6 +37,9 @@ public class OLMapManager {
private Double zoomEnd = null;
private ol.Extent dragEndExtent = null;
public static final int QUERY_MIN_ZOOM_LEVEL = 13;
public static final Double LAYER_DETAIL_MIN_RESOLUTION = 0.10;
public static final Double LAYER_DETAIL_MAX_RESOLUTION = 13.0;
/**
* Instantiates a new OL map manager.
@ -192,6 +195,7 @@ public class OLMapManager {
private void checkSelectQuery(MapEventType mapEventType) {
GWT.log("Zoom is:" + olMap.getCurrentZoomLevel());
GWT.log("Resolution is:" + olMap.getCurrentResolution());
if (dragStartExtent != null && olMap.getCurrentZoomLevel() > QUERY_MIN_ZOOM_LEVEL) {
dragEndExtent = olMap.getExtent();

@ -333,13 +333,21 @@ public abstract class OpenLayerOSM {
LayerOptions layerOptions = OLFactory.createOptions();
layerOptions.setSource(imageWMSSource);
//Settings MIN and MAX Resolution
if(layerItem.getMinResolution()!=null) {
layerOptions.setMinResolution(layerItem.getMinResolution());
}
if(layerItem.getMaxResolution()!=null) {
layerOptions.setMaxResolution(layerItem.getMaxResolution());
}
Image wmsLayer = new Image(layerOptions);
// visibleLayerItems
map.addLayer(wmsLayer);
GWT.log("Fired the event Added Layer");
GWT.log("Added WMSLayer for layer: "+layerItem.getName());
eventBus.fireEvent(new AddedLayerToMapEvent(layerItem));
}
@ -372,6 +380,13 @@ public abstract class OpenLayerOSM {
LayerOptions layerOptions = OLFactory.createOptions();
layerOptions.setSource(imageWMSSource);
//Settings MIN and MAX Resolution
if(layerItem.getMinResolution()!=null) {
layerOptions.setMinResolution(layerItem.getMinResolution());
}
if(layerItem.getMaxResolution()!=null) {
layerOptions.setMaxResolution(layerItem.getMaxResolution());
}
Image wmsLayer = new Image(layerOptions);
@ -380,7 +395,7 @@ public abstract class OpenLayerOSM {
map.addLayer(wmsLayer);
wmsDetailsLayerMap.put(key, wmsLayer);
GWT.log("Fired the event Added Layer");
GWT.log("Added WMSDetailLayer for layer name: "+layerItem.getName());
eventBus.fireEvent(new AddedLayerToMapEvent(layerItem));
} else {
GWT.log("The detail layer with key: " + key + " already exists, skipping");
@ -389,6 +404,9 @@ public abstract class OpenLayerOSM {
}
public void removeAllDetailLayers() {
/*
if (wmsDetailsLayerMap == null)
return;
@ -400,6 +418,7 @@ public abstract class OpenLayerOSM {
}
wmsDetailsLayerMap.clear();
*/
}
@ -595,6 +614,15 @@ public abstract class OpenLayerOSM {
public double getCurrentZoomLevel() {
return map.getView().getZoom();
}
/**
* Gets the current zoom level.
*
* @return the current zoom level
*/
public double getCurrentResolution() {
return map.getView().getResolution();
}
/**
* Gets the bbox.

@ -9,7 +9,6 @@ import org.gcube.application.geoportalcommon.shared.gis.BoundsMap;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.Property;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.ZAxis;
// TODO: Auto-generated Javadoc
/**
* The Class LayerItem.
*
@ -115,6 +114,10 @@ public class LayerItem implements Serializable, Cloneable {
/** The Constant INT_TYPE. */
public static final String INT_TYPE = "xsd:int";
public Double minResolution;
public Double maxResolution;
/**
* Instantiates a new layer item.
*/
@ -849,6 +852,47 @@ public class LayerItem implements Serializable, Cloneable {
this.zAxisSelected = zAxisSelected;
}
/**
* Sets the max resolution.
*
* @param maxResolution the new max resolution
*/
public void setMaxResolution(Double maxResolution) {
this.maxResolution = maxResolution;
}
/**
* Sets the min resolution.
*
* @param minResolution the new min resolution
*/
public void setMinResolution(Double minResolution) {
this.minResolution = minResolution;
}
/**
* Gets the min resolution.
*
* @return the min resolution
*/
public Double getMinResolution() {
return minResolution;
}
/**
* Gets the max resolution.
*
* @return the max resolution
*/
public Double getMaxResolution() {
return maxResolution;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
@ -910,9 +954,12 @@ public class LayerItem implements Serializable, Cloneable {
builder.append(zAxis);
builder.append(", zAxisSelected=");
builder.append(zAxisSelected);
builder.append(", minResolution=");
builder.append(minResolution);
builder.append(", maxResolution=");
builder.append(maxResolution);
builder.append("]");
return builder.toString();
}
}

Loading…
Cancel
Save