2020-10-26 11:01:07 +01:00
|
|
|
package org.gcube.portlets.user.geoportaldataviewer.client.gis;
|
|
|
|
|
2021-09-07 17:29:56 +02:00
|
|
|
import java.util.ArrayList;
|
2021-08-31 18:21:17 +02:00
|
|
|
import java.util.HashMap;
|
2021-09-07 17:29:56 +02:00
|
|
|
import java.util.List;
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2021-09-07 17:29:56 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
|
2021-09-01 12:51:06 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION;
|
2020-11-19 15:19:27 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent;
|
2021-10-11 18:01:09 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent.LAYER_TYPE;
|
2020-11-19 15:19:27 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
|
2020-10-23 18:18:06 +02:00
|
|
|
|
2020-10-28 11:19:12 +01:00
|
|
|
import com.google.gwt.core.client.GWT;
|
2020-11-19 15:19:27 +01:00
|
|
|
import com.google.gwt.dom.client.Style.Visibility;
|
2020-10-29 15:18:14 +01:00
|
|
|
import com.google.gwt.event.shared.HandlerManager;
|
2021-09-07 17:29:56 +02:00
|
|
|
import com.google.gwt.json.client.JSONObject;
|
|
|
|
import com.google.gwt.json.client.JSONParser;
|
|
|
|
import com.google.gwt.json.client.JSONValue;
|
2020-10-27 10:19:32 +01:00
|
|
|
import com.google.gwt.user.client.DOM;
|
|
|
|
import com.google.gwt.user.client.Element;
|
|
|
|
import com.google.gwt.user.client.Event;
|
|
|
|
|
2020-10-26 17:40:38 +01:00
|
|
|
import ol.Collection;
|
2020-10-23 18:18:06 +02:00
|
|
|
import ol.Coordinate;
|
2021-08-31 18:21:17 +02:00
|
|
|
import ol.Feature;
|
|
|
|
import ol.FeatureOptions;
|
2020-10-23 18:18:06 +02:00
|
|
|
import ol.Map;
|
2020-10-26 17:40:38 +01:00
|
|
|
import ol.MapBrowserEvent;
|
2020-11-19 15:19:27 +01:00
|
|
|
import ol.MapEvent;
|
2020-10-23 18:18:06 +02:00
|
|
|
import ol.MapOptions;
|
|
|
|
import ol.OLFactory;
|
2020-10-26 17:40:38 +01:00
|
|
|
import ol.Overlay;
|
|
|
|
import ol.OverlayOptions;
|
2020-11-19 15:19:27 +01:00
|
|
|
import ol.Size;
|
2020-10-23 18:18:06 +02:00
|
|
|
import ol.View;
|
|
|
|
import ol.ViewOptions;
|
|
|
|
import ol.control.Attribution;
|
2020-10-26 17:40:38 +01:00
|
|
|
import ol.event.EventListener;
|
2021-08-31 18:21:17 +02:00
|
|
|
import ol.geom.Geometry;
|
2020-10-26 17:40:38 +01:00
|
|
|
import ol.interaction.Draw;
|
|
|
|
import ol.interaction.DrawOptions;
|
|
|
|
import ol.interaction.Extent;
|
|
|
|
import ol.interaction.ExtentOptions;
|
|
|
|
import ol.interaction.Interaction;
|
2020-10-23 18:18:06 +02:00
|
|
|
import ol.interaction.KeyboardPan;
|
|
|
|
import ol.interaction.KeyboardZoom;
|
2020-10-29 15:18:14 +01:00
|
|
|
import ol.layer.Base;
|
2020-10-23 18:18:06 +02:00
|
|
|
import ol.layer.Image;
|
|
|
|
import ol.layer.LayerOptions;
|
|
|
|
import ol.layer.Tile;
|
2021-08-31 18:21:17 +02:00
|
|
|
import ol.layer.VectorLayerOptions;
|
2020-10-23 18:18:06 +02:00
|
|
|
import ol.proj.Projection;
|
|
|
|
import ol.proj.ProjectionOptions;
|
|
|
|
import ol.source.ImageWms;
|
|
|
|
import ol.source.ImageWmsOptions;
|
|
|
|
import ol.source.ImageWmsParams;
|
|
|
|
import ol.source.Osm;
|
2021-09-07 17:29:56 +02:00
|
|
|
import ol.source.Source;
|
2020-10-26 17:40:38 +01:00
|
|
|
import ol.source.Vector;
|
2020-10-23 18:18:06 +02:00
|
|
|
import ol.source.XyzOptions;
|
|
|
|
|
|
|
|
/**
|
2020-10-27 16:04:34 +01:00
|
|
|
* The Class OpenLayerOSM.
|
2020-10-23 18:18:06 +02:00
|
|
|
*
|
2020-10-27 16:04:34 +01:00
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
|
|
|
*
|
2021-08-31 18:21:17 +02:00
|
|
|
* Oct 27, 2020
|
2020-10-23 18:18:06 +02:00
|
|
|
*/
|
2020-11-19 15:19:27 +01:00
|
|
|
public abstract class OpenLayerOSM {
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2021-09-08 16:15:36 +02:00
|
|
|
public static final int MAX_ZOOM = 21;
|
|
|
|
|
2021-08-31 18:21:17 +02:00
|
|
|
/**
|
|
|
|
* Click listener.
|
|
|
|
*
|
|
|
|
* @param event the event
|
|
|
|
*/
|
2020-11-19 15:19:27 +01:00
|
|
|
public abstract void clickListener(MapBrowserEvent event);
|
2021-08-31 18:21:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Move end listener.
|
|
|
|
*
|
|
|
|
* @param event the event
|
|
|
|
*/
|
2020-11-19 15:19:27 +01:00
|
|
|
public abstract void moveEndListener(MapEvent event);
|
2021-08-31 18:21:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Move start listener.
|
|
|
|
*
|
|
|
|
* @param event the event
|
|
|
|
*/
|
2020-11-19 15:19:27 +01:00
|
|
|
public abstract void moveStartListener(MapEvent event);
|
2021-08-31 18:21:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Map zoom listener.
|
|
|
|
*
|
|
|
|
* @param event the event
|
|
|
|
*/
|
2020-11-19 15:19:27 +01:00
|
|
|
public abstract void mapZoomListener(MapEvent event);
|
2021-08-31 18:21:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Map zoom end listener.
|
|
|
|
*
|
|
|
|
* @param event the event
|
|
|
|
*/
|
2020-11-19 15:19:27 +01:00
|
|
|
public abstract void mapZoomEndListener(MapEvent event);
|
|
|
|
|
2020-10-27 16:04:34 +01:00
|
|
|
/** The map. */
|
2020-10-23 18:18:06 +02:00
|
|
|
private Map map;
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-27 16:04:34 +01:00
|
|
|
/** The view. */
|
2020-10-23 18:18:06 +02:00
|
|
|
private View view;
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-27 16:04:34 +01:00
|
|
|
/** The view options. */
|
2020-10-23 18:18:06 +02:00
|
|
|
private ViewOptions viewOptions = OLFactory.createOptions();
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-27 16:04:34 +01:00
|
|
|
/** The projection options. */
|
2020-10-23 18:18:06 +02:00
|
|
|
private ProjectionOptions projectionOptions = OLFactory.createOptions();
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-27 16:04:34 +01:00
|
|
|
/** The point draw. */
|
2020-10-28 11:19:12 +01:00
|
|
|
private Draw queryPoint;
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-28 11:19:12 +01:00
|
|
|
private Extent queryBox;
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-27 16:04:34 +01:00
|
|
|
/** The popup overlay. */
|
2020-10-27 10:19:32 +01:00
|
|
|
private Overlay popupOverlay;
|
2020-10-23 18:18:06 +02:00
|
|
|
|
2020-10-29 15:18:14 +01:00
|
|
|
private HandlerManager eventBus;
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-29 15:18:14 +01:00
|
|
|
private boolean isQueryBoxActive;
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-29 15:18:14 +01:00
|
|
|
private boolean isQueryPointActive;
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2021-10-08 18:06:32 +02:00
|
|
|
private HashMap<String, Image> wmsDetailsLayerMap;
|
|
|
|
|
|
|
|
private Integer[] wmsDetailsLayerZIndex = new Integer[100];
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2021-09-08 14:40:36 +02:00
|
|
|
private HashMap<String, Image> wmsLayerMap;
|
|
|
|
|
2021-08-31 18:21:17 +02:00
|
|
|
/**
|
|
|
|
* 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()
|
|
|
|
*/
|
2020-10-29 15:18:14 +01:00
|
|
|
public OpenLayerOSM(String divTargetId, HandlerManager eventBus) {
|
|
|
|
this.eventBus = eventBus;
|
2020-10-23 18:18:06 +02:00
|
|
|
|
2021-10-08 18:06:32 +02:00
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
wmsDetailsLayerZIndex[i] = 1000 + i;
|
|
|
|
}
|
|
|
|
|
2021-08-31 18:21:17 +02:00
|
|
|
// create a OSM-layer
|
2021-09-22 12:18:58 +02:00
|
|
|
XyzOptions xyzOptions = OLFactory.createOptions();
|
2021-09-03 18:22:42 +02:00
|
|
|
// osmSourceOptions.setCrossOrigin("Anonymous");
|
|
|
|
// osmSourceOptions.setTileLoadFunction(null);
|
2021-09-07 17:29:56 +02:00
|
|
|
|
2021-09-22 12:18:58 +02:00
|
|
|
Osm osmSource = new Osm(xyzOptions);
|
2021-08-31 18:21:17 +02:00
|
|
|
LayerOptions osmLayerOptions = OLFactory.createOptions();
|
|
|
|
osmLayerOptions.setSource(osmSource);
|
2021-10-08 18:06:32 +02:00
|
|
|
|
2021-08-31 18:21:17 +02:00
|
|
|
Tile osmLayer = new Tile(osmLayerOptions);
|
2020-10-23 18:18:06 +02:00
|
|
|
// create a projection
|
2021-09-01 12:51:06 +02:00
|
|
|
projectionOptions.setCode(MAP_PROJECTION.EPSG_3857.getName());
|
2020-10-23 18:18:06 +02:00
|
|
|
projectionOptions.setUnits("m");
|
|
|
|
|
|
|
|
Projection projection = new Projection(projectionOptions);
|
|
|
|
viewOptions.setProjection(projection);
|
2021-09-08 16:15:36 +02:00
|
|
|
viewOptions.setMaxZoom(MAX_ZOOM);
|
2021-08-31 18:21:17 +02:00
|
|
|
|
|
|
|
// create a view
|
|
|
|
view = new View(viewOptions);
|
|
|
|
|
|
|
|
// create the map
|
|
|
|
MapOptions mapOptions = OLFactory.createOptions();
|
|
|
|
mapOptions.setTarget(divTargetId);
|
|
|
|
mapOptions.setView(view);
|
|
|
|
|
|
|
|
map = new Map(mapOptions);
|
|
|
|
|
|
|
|
map.addLayer(osmLayer);
|
|
|
|
// 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());
|
|
|
|
|
|
|
|
bindEvents();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bind events.
|
|
|
|
*/
|
2020-11-19 15:19:27 +01:00
|
|
|
private void bindEvents() {
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
map.addClickListener(new EventListener<MapBrowserEvent>() {
|
|
|
|
|
2020-10-26 17:40:38 +01:00
|
|
|
@Override
|
|
|
|
public void onEvent(MapBrowserEvent event) {
|
2020-11-19 15:19:27 +01:00
|
|
|
clickListener(event);
|
2020-10-26 17:40:38 +01:00
|
|
|
}
|
|
|
|
});
|
2020-10-23 18:18:06 +02:00
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
map.addMoveEndListener(new EventListener<MapEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEvent(MapEvent event) {
|
|
|
|
moveEndListener(event);
|
|
|
|
}
|
|
|
|
});
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
map.addMoveStartListener(new EventListener<MapEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEvent(MapEvent event) {
|
|
|
|
moveStartListener(event);
|
|
|
|
}
|
|
|
|
});
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
map.addMapZoomListener(new EventListener<MapEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEvent(MapEvent event) {
|
|
|
|
mapZoomListener(event);
|
|
|
|
}
|
|
|
|
});
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
map.addMapZoomEndListener(new EventListener<MapEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEvent(MapEvent event) {
|
|
|
|
mapZoomEndListener(event);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
/**
|
|
|
|
* Sets the center.
|
|
|
|
*
|
|
|
|
* @param centerCoordinate the new center
|
|
|
|
*/
|
|
|
|
public void setCenter(Coordinate centerCoordinate) {
|
2021-08-31 18:21:17 +02:00
|
|
|
view.setCenter(centerCoordinate);
|
2020-11-19 15:19:27 +01:00
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-11-19 15:19:27 +01:00
|
|
|
/**
|
|
|
|
* Sets the center.
|
|
|
|
*
|
2021-08-31 18:21:17 +02:00
|
|
|
* @param zoom the new zoom
|
2020-11-19 15:19:27 +01:00
|
|
|
*/
|
|
|
|
public void setZoom(int zoom) {
|
2021-08-31 18:21:17 +02:00
|
|
|
view.setZoom(zoom);
|
2020-11-19 15:19:27 +01:00
|
|
|
}
|
2020-10-23 18:18:06 +02:00
|
|
|
|
2021-08-31 18:21:17 +02:00
|
|
|
/**
|
|
|
|
* Show popup.
|
|
|
|
*
|
|
|
|
* @param html the html
|
|
|
|
* @param coordinate the coordinate
|
|
|
|
*/
|
2020-10-29 15:18:14 +01:00
|
|
|
public void showPopup(String html, Coordinate coordinate) {
|
2021-08-31 18:21:17 +02:00
|
|
|
GWT.log("Showing popup on: " + coordinate);
|
|
|
|
// GeoportalDataViewerConstants.print("Showing popup on: "+coordinate);
|
2020-11-19 15:19:27 +01:00
|
|
|
Element elPopup = DOM.getElementById("popup");
|
|
|
|
elPopup.getStyle().setVisibility(Visibility.VISIBLE);
|
2021-08-31 18:21:17 +02:00
|
|
|
if (popupOverlay == null) {
|
2020-10-29 15:18:14 +01:00
|
|
|
popupOverlay = addOverlay(elPopup);
|
|
|
|
addPopupCloserHandelr(popupOverlay);
|
|
|
|
}
|
|
|
|
Element popContent = DOM.getElementById("popup-content");
|
|
|
|
popContent.setInnerHTML(html);
|
|
|
|
popupOverlay.setPosition(coordinate);
|
2020-10-28 11:19:12 +01:00
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide popup.
|
|
|
|
*/
|
2020-11-19 15:19:27 +01:00
|
|
|
public void hidePopup() {
|
2021-08-31 18:21:17 +02:00
|
|
|
if (popupOverlay != null) {
|
2020-11-19 15:19:27 +01:00
|
|
|
Element elPopup = DOM.getElementById("popup");
|
|
|
|
elPopup.getStyle().setVisibility(Visibility.HIDDEN);
|
|
|
|
}
|
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-27 16:04:34 +01:00
|
|
|
/**
|
|
|
|
* Adds the popup closer handelr.
|
|
|
|
*
|
|
|
|
* @param popupOverlay the popup overlay
|
|
|
|
*/
|
2020-10-27 10:19:32 +01:00
|
|
|
private void addPopupCloserHandelr(Overlay popupOverlay) {
|
|
|
|
Element elPopupCloser = DOM.getElementById("popup-closer");
|
|
|
|
Event.sinkEvents(elPopupCloser, Event.ONCLICK);
|
|
|
|
Event.setEventListener(elPopupCloser, new com.google.gwt.user.client.EventListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBrowserEvent(Event event) {
|
|
|
|
if (Event.ONCLICK == event.getTypeInt()) {
|
|
|
|
popupOverlay.setPosition(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-27 16:04:34 +01:00
|
|
|
/**
|
|
|
|
* Handler popu closer.
|
|
|
|
*
|
2021-08-31 18:21:17 +02:00
|
|
|
* @param divId the div id
|
2020-10-27 16:04:34 +01:00
|
|
|
* @param overlayId the overlay id
|
|
|
|
*/
|
2020-10-27 10:19:32 +01:00
|
|
|
public static native void handlerPopuCloser(String divId, String overlayId) /*-{
|
|
|
|
var closer = $doc.getElementById(divId);
|
|
|
|
var overlay = $doc.getElementById(overlayId);
|
|
|
|
closer.onclick = function() {
|
|
|
|
overlay.setPosition(undefined);
|
|
|
|
closer.blur();
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
}-*/;
|
|
|
|
|
2020-10-27 16:04:34 +01:00
|
|
|
/**
|
|
|
|
* Adds the WMS layer.
|
2020-10-29 15:18:14 +01:00
|
|
|
*
|
2020-11-19 15:19:27 +01:00
|
|
|
* @param layerItem the layer item
|
2020-10-27 16:04:34 +01:00
|
|
|
*/
|
2020-11-19 15:19:27 +01:00
|
|
|
public void addWMSLayer(LayerItem layerItem) {
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2021-09-08 14:40:36 +02:00
|
|
|
if (wmsLayerMap == null)
|
|
|
|
wmsLayerMap = new HashMap<String, Image>();
|
|
|
|
|
|
|
|
String key = layerItem.getName();
|
2020-10-23 18:18:06 +02:00
|
|
|
|
2021-09-08 14:40:36 +02:00
|
|
|
Image layer = wmsLayerMap.get(key);
|
|
|
|
if (layer == null) {
|
|
|
|
ImageWmsParams imageWMSParams = OLFactory.createOptions();
|
|
|
|
imageWMSParams.setLayers(layerItem.getName());
|
2020-10-23 18:18:06 +02:00
|
|
|
|
2021-09-08 14:40:36 +02:00
|
|
|
ImageWmsOptions imageWMSOptions = OLFactory.createOptions();
|
|
|
|
imageWMSOptions.setUrl(layerItem.getMapServerHost());
|
|
|
|
imageWMSOptions.setParams(imageWMSParams);
|
|
|
|
// imageWMSOptions.setRatio(1.5f);
|
2020-10-23 18:18:06 +02:00
|
|
|
|
2021-09-08 14:40:36 +02:00
|
|
|
ImageWms imageWMSSource = new ImageWms(imageWMSOptions);
|
2021-09-07 17:29:56 +02:00
|
|
|
|
2021-09-08 14:40:36 +02:00
|
|
|
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);
|
2020-10-23 18:18:06 +02:00
|
|
|
|
2021-09-08 14:40:36 +02:00
|
|
|
// visibleLayerItems
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2021-09-08 14:40:36 +02:00
|
|
|
map.addLayer(wmsLayer);
|
|
|
|
wmsLayerMap.put(key, wmsLayer);
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2021-09-08 14:40:36 +02:00
|
|
|
GWT.log("Added WMSLayer for layer: " + layerItem.getName());
|
2021-10-11 18:01:09 +02:00
|
|
|
eventBus.fireEvent(new AddedLayerToMapEvent(layerItem, LAYER_TYPE.BASE));
|
2021-09-08 14:40:36 +02:00
|
|
|
} else {
|
|
|
|
GWT.log("The WMS layer with key: " + key + " already exists, skipping");
|
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the WMS detail layer.
|
|
|
|
*
|
|
|
|
* @param layerItem the layer item
|
|
|
|
*/
|
|
|
|
public void addWMSDetailLayer(LayerItem layerItem) {
|
|
|
|
|
|
|
|
if (wmsDetailsLayerMap == null)
|
|
|
|
wmsDetailsLayerMap = new HashMap<String, Image>();
|
|
|
|
|
2021-10-08 18:06:32 +02:00
|
|
|
String key = layerItem.getName();
|
2021-08-31 18:21:17 +02:00
|
|
|
|
|
|
|
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);
|
2021-09-07 17:29:56 +02:00
|
|
|
// Settings MIN and MAX Resolution
|
|
|
|
if (layerItem.getMinResolution() != null) {
|
2021-09-02 12:54:39 +02:00
|
|
|
layerOptions.setMinResolution(layerItem.getMinResolution());
|
|
|
|
}
|
2021-09-07 17:29:56 +02:00
|
|
|
if (layerItem.getMaxResolution() != null) {
|
2021-09-02 12:54:39 +02:00
|
|
|
layerOptions.setMaxResolution(layerItem.getMaxResolution());
|
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
|
|
|
Image wmsLayer = new Image(layerOptions);
|
|
|
|
map.addLayer(wmsLayer);
|
|
|
|
wmsDetailsLayerMap.put(key, wmsLayer);
|
2021-10-11 18:39:59 +02:00
|
|
|
|
2021-09-07 17:29:56 +02:00
|
|
|
GWT.log("Added WMSDetailLayer for layer name: " + layerItem.getName());
|
2021-10-11 18:01:09 +02:00
|
|
|
eventBus.fireEvent(new AddedLayerToMapEvent(layerItem, LAYER_TYPE.OVERLAY));
|
2021-08-31 18:21:17 +02:00
|
|
|
} else {
|
2021-09-08 14:40:36 +02:00
|
|
|
GWT.log("The WMS detail layer with key: " + key + " already exists, skipping");
|
2021-08-31 18:21:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-09-02 18:15:15 +02:00
|
|
|
/**
|
|
|
|
* Removes the all detail layers.
|
|
|
|
*/
|
2021-08-31 18:21:17 +02:00
|
|
|
public void removeAllDetailLayers() {
|
2021-09-01 12:51:06 +02:00
|
|
|
|
2021-09-07 17:29:56 +02:00
|
|
|
// NOT NEEDED ANYMORE.. I'M USING MIN/MAX LAYER RESOLUTION
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2021-09-08 14:40:36 +02:00
|
|
|
if (wmsDetailsLayerMap == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GWT.log("Removing layers: " + wmsDetailsLayerMap.keySet() + " from map");
|
|
|
|
|
|
|
|
for (String key : wmsDetailsLayerMap.keySet()) {
|
|
|
|
Image layer = wmsDetailsLayerMap.get(key);
|
|
|
|
map.removeLayer(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
wmsDetailsLayerMap.clear();
|
2021-08-31 18:21:17 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
2020-10-23 18:18:06 +02:00
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-27 16:04:34 +01:00
|
|
|
/**
|
|
|
|
* Adds the point vector source.
|
|
|
|
*
|
|
|
|
* @return the draw
|
|
|
|
*/
|
2020-10-26 17:40:38 +01:00
|
|
|
public Draw addPointVectorSource() {
|
2021-08-31 18:21:17 +02:00
|
|
|
if (queryPoint == null)
|
2020-10-26 17:40:38 +01:00
|
|
|
initPointInteraction();
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-28 11:19:12 +01:00
|
|
|
map.addInteraction(queryPoint);
|
2020-10-29 15:18:14 +01:00
|
|
|
isQueryPointActive = true;
|
2020-10-28 11:19:12 +01:00
|
|
|
return queryPoint;
|
2020-10-26 17:40:38 +01:00
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-27 16:04:34 +01:00
|
|
|
/**
|
|
|
|
* Inits the point interaction.
|
|
|
|
*/
|
2020-10-26 17:40:38 +01:00
|
|
|
private void initPointInteraction() {
|
|
|
|
Vector vectorSource = new Vector();
|
|
|
|
DrawOptions drawOptions = new DrawOptions();
|
|
|
|
drawOptions.setSource(vectorSource);
|
|
|
|
drawOptions.setType("Point");
|
|
|
|
drawOptions.setMaxPoints(1);
|
|
|
|
drawOptions.setMinPoints(1);
|
|
|
|
drawOptions.setWrapX(false);
|
2020-10-28 11:19:12 +01:00
|
|
|
queryPoint = new Draw(drawOptions);
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-28 11:19:12 +01:00
|
|
|
queryPoint.addChangeListener(new EventListener<ol.events.Event>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEvent(ol.events.Event event) {
|
|
|
|
GWT.log(event.getType());
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-28 11:19:12 +01:00
|
|
|
}
|
|
|
|
});
|
2020-10-26 17:40:38 +01:00
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-27 16:04:34 +01:00
|
|
|
/**
|
|
|
|
* Removes the interaction.
|
|
|
|
*
|
|
|
|
* @param interaction the interaction
|
|
|
|
*/
|
2020-10-26 17:40:38 +01:00
|
|
|
public void removeInteraction(Interaction interaction) {
|
2021-08-31 18:21:17 +02:00
|
|
|
map.removeInteraction(interaction);
|
2020-10-26 17:40:38 +01:00
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-27 16:04:34 +01:00
|
|
|
/**
|
|
|
|
* Removes the interactions.
|
|
|
|
*/
|
2020-10-28 11:19:12 +01:00
|
|
|
public void removeQueryInteractions() {
|
2020-10-26 17:40:38 +01:00
|
|
|
Collection<Interaction> interactions = map.getInteractions();
|
2021-08-31 18:21:17 +02:00
|
|
|
if (interactions != null) {
|
2020-10-28 11:19:12 +01:00
|
|
|
map.removeInteraction(queryBox);
|
|
|
|
map.removeInteraction(queryPoint);
|
2020-10-29 15:18:14 +01:00
|
|
|
isQueryBoxActive = false;
|
|
|
|
isQueryPointActive = false;
|
2020-10-26 17:40:38 +01:00
|
|
|
}
|
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-27 16:04:34 +01:00
|
|
|
/**
|
|
|
|
* Adds the extent interaction.
|
|
|
|
*
|
|
|
|
* @return the extent
|
|
|
|
*/
|
2020-10-26 17:40:38 +01:00
|
|
|
public Extent addExtentInteraction() {
|
|
|
|
ExtentOptions extentOptions = new ExtentOptions();
|
|
|
|
extentOptions.setWrapX(false);
|
2021-08-31 18:21:17 +02:00
|
|
|
// StyleOptions styleOptions = new StyleOptions();
|
|
|
|
// styleOptions.setStroke(stroke);
|
|
|
|
// styleOptions.set
|
|
|
|
// extentOptions.setBoxStyle(new ol.style.Style(styleOptions));
|
2020-10-28 11:19:12 +01:00
|
|
|
queryBox = new Extent(extentOptions);
|
|
|
|
map.addInteraction(queryBox);
|
2020-10-29 15:18:14 +01:00
|
|
|
isQueryBoxActive = true;
|
2020-10-28 11:19:12 +01:00
|
|
|
return queryBox;
|
2020-10-26 17:40:38 +01:00
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-27 16:04:34 +01:00
|
|
|
/**
|
|
|
|
* Adds the overlay.
|
|
|
|
*
|
|
|
|
* @param element the element
|
|
|
|
* @return the overlay
|
|
|
|
*/
|
2021-10-11 18:01:09 +02:00
|
|
|
public Overlay addOverlay(Element element) {
|
2020-10-26 17:40:38 +01:00
|
|
|
/**
|
|
|
|
* Create an overlay to anchor the popup to the map.
|
|
|
|
*/
|
|
|
|
OverlayOptions overlayOptions = new OverlayOptions();
|
|
|
|
overlayOptions.setAutoPan(true);
|
|
|
|
Overlay overlay = new Overlay(overlayOptions);
|
2020-10-27 10:19:32 +01:00
|
|
|
overlay.setElement(element);
|
2020-10-26 17:40:38 +01:00
|
|
|
map.addOverlay(overlay);
|
2020-10-27 10:19:32 +01:00
|
|
|
return overlay;
|
2020-10-26 17:40:38 +01:00
|
|
|
}
|
2020-10-29 15:18:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if is layer visible.
|
|
|
|
*
|
|
|
|
* @param layerName the layer name
|
|
|
|
* @return true, if is layer visible
|
|
|
|
*/
|
|
|
|
public boolean isLayerVisible(String layerName) {
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-29 15:18:14 +01:00
|
|
|
Collection<Base> layers = map.getLayers();
|
2021-08-31 18:21:17 +02:00
|
|
|
|
|
|
|
if (layers != null) {
|
2020-10-29 15:18:14 +01:00
|
|
|
Base[] layersArr = layers.getArray();
|
|
|
|
for (int i = 0; i < layersArr.length; i++) {
|
|
|
|
Base layer = layersArr[i];
|
|
|
|
String theLayerName = (String) layer.get("name");
|
2021-09-02 18:15:15 +02:00
|
|
|
GWT.log("The Layer name is: " + theLayerName);
|
2021-08-31 18:21:17 +02:00
|
|
|
if (theLayerName != null && theLayerName.equals(layerName))
|
2020-10-29 15:18:14 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-29 15:18:14 +01:00
|
|
|
return false;
|
|
|
|
}
|
2021-09-02 18:15:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the layer property.
|
|
|
|
*
|
|
|
|
* @param layerName the layer name
|
2021-09-07 17:29:56 +02:00
|
|
|
* @param property the property
|
2021-09-02 18:15:15 +02:00
|
|
|
* @return the layer property
|
|
|
|
*/
|
|
|
|
public String getLayerProperty(String layerName, String property) {
|
|
|
|
|
|
|
|
Collection<Base> layers = map.getLayers();
|
|
|
|
|
|
|
|
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))
|
|
|
|
return layer.get(property);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2020-10-28 11:19:12 +01:00
|
|
|
|
2020-10-29 15:18:14 +01:00
|
|
|
/**
|
|
|
|
* Gets the projection code.
|
|
|
|
*
|
|
|
|
* @return the projection code
|
|
|
|
*/
|
|
|
|
public String getProjectionCode() {
|
|
|
|
return map.getView().getProjection().getCode();
|
|
|
|
}
|
2020-10-28 11:19:12 +01:00
|
|
|
|
2020-10-29 15:18:14 +01:00
|
|
|
/**
|
|
|
|
* Gets the current zoom level.
|
|
|
|
*
|
|
|
|
* @return the current zoom level
|
|
|
|
*/
|
|
|
|
public double getCurrentZoomLevel() {
|
|
|
|
return map.getView().getZoom();
|
2020-10-28 11:19:12 +01:00
|
|
|
}
|
2021-09-07 17:29:56 +02:00
|
|
|
|
2021-09-02 12:54:39 +02:00
|
|
|
/**
|
|
|
|
* Gets the current zoom level.
|
|
|
|
*
|
|
|
|
* @return the current zoom level
|
|
|
|
*/
|
|
|
|
public double getCurrentResolution() {
|
|
|
|
return map.getView().getResolution();
|
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-29 15:18:14 +01:00
|
|
|
/**
|
|
|
|
* Gets the bbox.
|
|
|
|
*
|
|
|
|
* @return the bbox
|
|
|
|
*/
|
|
|
|
public ol.Extent getBBOX() {
|
|
|
|
return getExtent();
|
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
2020-10-29 15:18:14 +01:00
|
|
|
/**
|
|
|
|
* Gets the extent.
|
|
|
|
*
|
|
|
|
* @return the extent
|
|
|
|
*/
|
|
|
|
public ol.Extent getExtent() {
|
|
|
|
return this.map.getView().calculateExtent(map.getSize());
|
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
2020-10-29 17:08:29 +01:00
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if is query box active.
|
|
|
|
*
|
|
|
|
* @return true, if is query box active
|
|
|
|
*/
|
2020-11-19 15:19:27 +01:00
|
|
|
public boolean isQueryBoxActive() {
|
|
|
|
return isQueryBoxActive;
|
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if is query point active.
|
|
|
|
*
|
|
|
|
* @return true, if is query point active
|
|
|
|
*/
|
2020-11-19 15:19:27 +01:00
|
|
|
public boolean isQueryPointActive() {
|
|
|
|
return isQueryPointActive;
|
|
|
|
}
|
2021-08-31 18:21:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the size.
|
|
|
|
*
|
|
|
|
* @return the size
|
|
|
|
*/
|
2020-11-19 15:19:27 +01:00
|
|
|
public Size getSize() {
|
|
|
|
return map.getSize();
|
|
|
|
}
|
|
|
|
|
2021-08-31 18:21:17 +02:00
|
|
|
/**
|
|
|
|
* Map instancied.
|
|
|
|
*
|
|
|
|
* @return true, if successful
|
|
|
|
*/
|
2020-11-19 15:19:27 +01:00
|
|
|
public boolean mapInstancied() {
|
2021-08-31 18:21:17 +02:00
|
|
|
return this.map != null;
|
|
|
|
}
|
2020-10-23 18:18:06 +02:00
|
|
|
|
2021-09-07 17:29:56 +02:00
|
|
|
/**
|
2021-09-08 14:40:36 +02:00
|
|
|
* Gets the layers from map.
|
2021-09-07 17:29:56 +02:00
|
|
|
*
|
2021-09-08 14:40:36 +02:00
|
|
|
* @return the layers from map
|
2021-09-07 17:29:56 +02:00
|
|
|
*/
|
2021-09-08 14:40:36 +02:00
|
|
|
public List<String> getLayersFromMap() {
|
2021-09-07 17:29:56 +02:00
|
|
|
Collection<Base> layers = map.getLayers();
|
|
|
|
List<String> layerNames = null;
|
|
|
|
if (layers != null) {
|
|
|
|
Base[] layersArr = layers.getArray();
|
|
|
|
layerNames = new ArrayList<String>(layersArr.length);
|
|
|
|
for (int i = 0; i < layersArr.length; i++) {
|
|
|
|
Base layer = layersArr[i];
|
|
|
|
if (layer instanceof Image) {
|
|
|
|
Image layerImage = (Image) layer;
|
|
|
|
|
|
|
|
Source source = layerImage.getSource();
|
|
|
|
// GWT.log("source: "+source.toString());
|
2021-09-08 14:40:36 +02:00
|
|
|
// GeoportalDataViewerConstants.printJsObj(source);
|
2021-09-07 17:29:56 +02:00
|
|
|
String sorceRootObj = GeoportalDataViewerConstants.toJsonObj(source);
|
|
|
|
JSONValue jsonObj = JSONParser.parseStrict(sorceRootObj);
|
|
|
|
// GWT.log("jsonObj: " + jsonObj.toString());
|
|
|
|
JSONObject jsonSourceObj = (JSONObject) jsonObj;
|
|
|
|
|
|
|
|
JSONObject jsonParamsObj = (JSONObject) jsonSourceObj.get("params_");
|
|
|
|
// GWT.log("jsonParamsObj is: "+jsonParamsObj);
|
|
|
|
JSONValue jsonLayers = jsonParamsObj.get("LAYERS");
|
|
|
|
GWT.log("theLayerName name is: " + jsonLayers);
|
|
|
|
layerNames.add(jsonLayers.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return layerNames;
|
|
|
|
}
|
|
|
|
|
2021-09-08 14:40:36 +02:00
|
|
|
/**
|
|
|
|
* Gets the wms details layer map.
|
|
|
|
*
|
|
|
|
* @return the wms details layer map
|
|
|
|
*/
|
|
|
|
public java.util.Map<String, Image> getWmsDetailsLayerMap() {
|
|
|
|
return wmsDetailsLayerMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the wms layer map.
|
|
|
|
*
|
|
|
|
* @return the wms layer map
|
|
|
|
*/
|
|
|
|
public HashMap<String, Image> getWmsLayerMap() {
|
|
|
|
return wmsLayerMap;
|
|
|
|
}
|
2021-10-11 18:01:09 +02:00
|
|
|
|
2021-10-08 18:06:32 +02:00
|
|
|
public void setWMSDetailLayerVisible(LayerItem layerItem, boolean visible) {
|
|
|
|
String key = layerItem.getName();
|
2021-10-11 18:39:59 +02:00
|
|
|
GWT.log("current layers: "+wmsDetailsLayerMap.keySet());
|
2021-10-08 18:06:32 +02:00
|
|
|
Image layer = wmsDetailsLayerMap.get(key);
|
|
|
|
layer.setVisible(visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setWMSDetailLayerOpacity(LayerItem layerItem, int opacity) {
|
|
|
|
String key = layerItem.getName();
|
|
|
|
Image layer = wmsDetailsLayerMap.get(key);
|
|
|
|
layer.setOpacity(opacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void swapLayers(LayerItem layerItem, LayerItem layerItem2) {
|
|
|
|
String key1 = layerItem.getName();
|
|
|
|
Image layer1 = wmsDetailsLayerMap.get(key1);
|
2021-10-11 18:01:09 +02:00
|
|
|
|
2021-10-08 18:06:32 +02:00
|
|
|
String key2 = layerItem.getName();
|
|
|
|
Image layer2 = wmsDetailsLayerMap.get(key2);
|
2021-10-11 18:01:09 +02:00
|
|
|
|
2021-10-08 18:06:32 +02:00
|
|
|
int zIndex1 = layer1.getZIndex();
|
|
|
|
int zIndex2 = layer2.getZIndex();
|
|
|
|
layer1.setZIndex(zIndex2);
|
|
|
|
layer2.setZIndex(zIndex1);
|
|
|
|
}
|
2021-09-08 14:40:36 +02:00
|
|
|
|
2020-10-23 18:18:06 +02:00
|
|
|
}
|