implementing task #21946

This commit is contained in:
Francesco Mangiacrapa 2021-08-31 18:21:17 +02:00
parent 97db5d2c12
commit b2e6830bbe
12 changed files with 534 additions and 224 deletions

View File

@ -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

View File

@ -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

View File

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

View File

@ -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.
*

View File

@ -111,4 +111,17 @@ public interface GeoportalDataViewerService extends RemoteService {
*/
List<LayerConcessioneDV> 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<GeoNaSpatialQueryResult> getWFSFeatures(List<LayerObject> layerObjects, String mapSrsName,
BoundsMap selectBBOX, int maxWFSFeature, double zoomLevel);
}

View File

@ -54,4 +54,7 @@ public interface GeoportalDataViewerServiceAsync {
void getLayersForId(String itemType, String itemId,
AsyncCallback<List<LayerConcessioneDV>> asyncCallback);
void getWFSFeatures(List<LayerObject> layerObjects, String mapSrsName, BoundsMap selectBBOX, int maxWFSFeature,
double zoomLevel, AsyncCallback<List<GeoNaSpatialQueryResult>> callback);
}

View File

@ -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<LayerObject> layerObjects = new ArrayList<LayerObject>();
private Map<String, LayerObject> layerObjects = new HashMap<String, LayerObject>();
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<GeoNaSpatialQueryResult>>() {
List<LayerObject> listLO = new ArrayList<LayerObject>(layerObjects.values());
GeoportalDataViewerServiceAsync.Util.getInstance().getDataResult(listLO, olMap.getProjectionCode(),
mapBBOX, GeoportalDataViewerConstants.MAX_WFS_FEATURES, olMap.getCurrentZoomLevel(),
new AsyncCallback<List<GeoNaSpatialQueryResult>>() {
@Override
public void onFailure(Throwable caught) {
@ -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<String> 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
@ -211,35 +219,47 @@ public class LayerManager {
}
}
GWT.log("the product id is: "+theProductId);
GWT.log("the product id is: " + theProductId);
/*if(olMap.getCurrentZoomLevel()>10) {
GeoportalDataViewerServiceAsync.Util.getInstance().getLayersForId("concessione", theProductId, new AsyncCallback<List<LayerConcessioneDV>>() {
// 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<List<LayerConcessioneDV>>() {
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
}
@Override
public void onSuccess(List<LayerConcessioneDV> result) {
GWT.log("Adding layers: "+result);
for (LayerConcessioneDV layer : result) {
addLayer("concessione", layer.getLayerName(), layer.getLayerName(), layer.getWmsLink(), false, false, layer.getLayerUUID(), true);
@Override
public void onSuccess(List<LayerConcessioneDV> 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);
}
}
}
});
}
});
} 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<String, List<String>> 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<GeoInformationForWMSRequest>() {
@ -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);
// }
}
});
}

View File

@ -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,7 +57,7 @@ public class OLMapManager {
@Override
public void clickListener(MapBrowserEvent event) {
Coordinate coordinate = event.getCoordinate();
if(!olMap.mapInstancied())
if (!olMap.mapInstancied())
return;
// if (olMap.isQueryPointActive()) {
@ -65,26 +66,26 @@ public class OLMapManager {
//
// }
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();
@ -94,26 +95,26 @@ public class OLMapManager {
@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,13 +151,12 @@ 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);
}
@ -182,7 +182,7 @@ public class OLMapManager {
/**
* Check select query.
*/
private void checkSelectQuery() {
private void checkSelectQuery(MapEventType mapEventType) {
GWT.log("Zoom is:" + olMap.getCurrentZoomLevel());
@ -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) {
} else if (zoomStart != null && zoomEnd != null) {
if(zoomEnd<QUERY_MIN_ZOOM_LEVEL) {
if (zoomEnd < QUERY_MIN_ZOOM_LEVEL) {
layerManagerBus.fireEvent(new ZoomOutOverMinimumEvent(zoomStart, zoomEnd, QUERY_MIN_ZOOM_LEVEL));
}
}
@ -229,10 +228,10 @@ public class OLMapManager {
*/
private GeoQuery toDataBoxQuery(ol.Extent extent) {
return new GeoQuery(extent.getLowerLeftX(), extent.getLowerLeftY(), extent.getUpperRightX(), extent.getUpperRightY(), TYPE.BOX);
return new GeoQuery(extent.getLowerLeftX(), extent.getLowerLeftY(), extent.getUpperRightX(),
extent.getUpperRightY(), TYPE.BOX);
}
/**
* Checks if is query point active.
*
@ -249,5 +248,11 @@ public class OLMapManager {
olMap.hidePopup();
}
/**
* Removes the detail layers.
*/
public void removeDetailLayers() {
olMap.removeAllDetailLayers();
}
}

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.user.geoportaldataviewer.client.events;
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MapEventType;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoQuery;
import com.google.gwt.event.shared.GwtEvent;
@ -9,9 +10,9 @@ import ol.Coordinate;
/**
* The Class QueryDataEvent.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Oct 29, 2020
* Aug 31, 2021
*/
public class QueryDataEvent extends GwtEvent<QueryDataEventHandler> {
public static Type<QueryDataEventHandler> TYPE = new Type<QueryDataEventHandler>();
@ -19,6 +20,7 @@ public class QueryDataEvent extends GwtEvent<QueryDataEventHandler> {
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<QueryDataEventHandler> {
* @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<QueryDataEventHandler> {
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<QueryDataEventHandler> {
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<QueryDataEventHandler> {
builder.append(mongoItemId);
builder.append(", onInit=");
builder.append(onInit);
builder.append(", sourceMapEventType=");
builder.append(sourceMapEventType);
builder.append("]");
return builder.toString();
}

View File

@ -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,25 +51,49 @@ 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. */
@ -92,27 +122,30 @@ public abstract class OpenLayerOSM {
private boolean isQueryPointActive;
private java.util.Map<String, Image> 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()
*/
/**
* 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");
@ -121,36 +154,38 @@ public abstract class OpenLayerOSM {
viewOptions.setProjection(projection);
viewOptions.setMaxZoom(19);
// create a view
view = new View(viewOptions);
// create a view
view = new View(viewOptions);
// create the map
MapOptions mapOptions = OLFactory.createOptions();
mapOptions.setTarget(divTargetId);
mapOptions.setView(view);
// create the map
MapOptions mapOptions = OLFactory.createOptions();
mapOptions.setTarget(divTargetId);
mapOptions.setView(view);
map = new Map(mapOptions);
map = new Map(mapOptions);
map.addLayer(osmLayer);
// map.addLayer(tileDebugLayer);
map.addLayer(osmLayer);
//map.addLayer(tileDebugLayer);
// add some controls
map.addControl(OLFactory.createScaleLine());
MapUtils.addDefaultControls(map.getControls());
// add some controls
map.addControl(OLFactory.createScaleLine());
MapUtils.addDefaultControls(map.getControls());
Attribution attribution = new Attribution();
attribution.setCollapsed(true);
map.addControl(attribution);
Attribution attribution = new Attribution();
attribution.setCollapsed(true);
map.addControl(attribution);
// add some interactions
map.addInteraction(new KeyboardPan());
map.addInteraction(new KeyboardZoom());
// add some interactions
map.addInteraction(new KeyboardPan());
map.addInteraction(new KeyboardZoom());
bindEvents();
bindEvents();
}
}
/**
* Bind events.
*/
private void bindEvents() {
map.addClickListener(new EventListener<MapBrowserEvent>() {
@ -200,25 +235,30 @@ public abstract class OpenLayerOSM {
* @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);
}
@ -227,8 +267,11 @@ public abstract class OpenLayerOSM {
popupOverlay.setPosition(coordinate);
}
/**
* Hide popup.
*/
public void hidePopup() {
if(popupOverlay!=null) {
if (popupOverlay != null) {
Element elPopup = DOM.getElementById("popup");
elPopup.getStyle().setVisibility(Visibility.HIDDEN);
}
@ -257,7 +300,7 @@ 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,7 +314,6 @@ public abstract class OpenLayerOSM {
}-*/;
/**
* Adds the WMS layer.
*
@ -285,7 +327,7 @@ public abstract class OpenLayerOSM {
ImageWmsOptions imageWMSOptions = OLFactory.createOptions();
imageWMSOptions.setUrl(layerItem.getMapServerHost());
imageWMSOptions.setParams(imageWMSParams);
//imageWMSOptions.setRatio(1.5f);
// imageWMSOptions.setRatio(1.5f);
ImageWms imageWMSSource = new ImageWms(imageWMSOptions);
@ -294,7 +336,7 @@ public abstract class OpenLayerOSM {
Image wmsLayer = new Image(layerOptions);
//visibleLayerItems
// visibleLayerItems
map.addLayer(wmsLayer);
GWT.log("Fired the event Added Layer");
@ -302,13 +344,126 @@ public abstract class OpenLayerOSM {
}
/**
* Adds the WMS detail layer.
*
* @param layerItem the layer item
*/
public void addWMSDetailLayer(LayerItem layerItem) {
if (wmsDetailsLayerMap == null)
wmsDetailsLayerMap = new HashMap<String, Image>();
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);
@ -353,7 +508,7 @@ public abstract class OpenLayerOSM {
*/
public void removeQueryInteractions() {
Collection<Interaction> interactions = map.getInteractions();
if(interactions!=null) {
if (interactions != null) {
map.removeInteraction(queryBox);
map.removeInteraction(queryPoint);
isQueryBoxActive = false;
@ -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.
*
@ -408,13 +562,13 @@ public abstract class OpenLayerOSM {
Collection<Base> 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;
}
}
@ -422,7 +576,6 @@ public abstract class OpenLayerOSM {
return false;
}
/**
* Gets the projection code.
*
@ -432,7 +585,6 @@ public abstract class OpenLayerOSM {
return map.getView().getProjection().getCode();
}
/**
* Gets the current zoom level.
*
@ -442,8 +594,6 @@ public abstract class OpenLayerOSM {
return map.getView().getZoom();
}
/**
* Gets the bbox.
*
@ -462,25 +612,52 @@ public abstract class OpenLayerOSM {
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;
}
}

View File

@ -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<String> 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<String> 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++;
}
}

View File

@ -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<GeoNaSpatialQueryResult> getWFSFeatures(List<LayerObject> layerObjects, String mapSrsName,
BoundsMap selectBBOX, int maxWFSFeature, double zoomLevel) {
LOG.info("getWFSFeatures called");
List<GeoNaSpatialQueryResult> listDAO = new ArrayList<GeoNaSpatialQueryResult>(layerObjects.size());
for (LayerObject layerObject : layerObjects) {
GeoNaSpatialQueryResult geoDAO = new GeoNaSpatialQueryResult();
List<FeatureRow> 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;
}
}