geoportal-data-viewer-app/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java

751 lines
26 KiB
Java
Raw Normal View History

2020-10-23 18:18:06 +02:00
package org.gcube.portlets.user.geoportaldataviewer.client;
import java.util.LinkedHashMap;
2021-11-12 12:37:15 +01:00
import java.util.List;
import java.util.Set;
2021-12-21 16:52:35 +01:00
import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile;
2022-10-18 17:32:12 +02:00
import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences;
2022-10-14 15:31:32 +02:00
import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV;
2022-11-03 17:03:15 +01:00
import org.gcube.application.geoportalcommon.shared.geoportal.project.RelationshipDV;
2022-10-11 15:00:39 +02:00
import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView;
2021-09-01 12:51:06 +02:00
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION;
2021-08-31 18:21:17 +02:00
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MapEventType;
import org.gcube.portlets.user.geoportaldataviewer.client.events.AddLayerToMapEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.AddLayerToMapEventHandler;
2020-11-19 15:19:27 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent;
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.client.events.AddedLayerToMapEventHandler;
2021-11-12 12:37:15 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.events.ChangeMapLayerEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ChangeMapLayerEventHandler;
2020-11-19 15:19:27 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.events.ClosedViewDetailsEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ClosedViewDetailsEventHandler;
import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent.DO_LAYER_ACTION;
import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent.SwapLayer;
import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEventHandler;
2021-09-01 16:26:07 +02:00
import org.gcube.portlets.user.geoportaldataviewer.client.events.MapExtentToEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.MapExtentToEventHandler;
2020-11-19 15:19:27 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.events.QueryDataEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.SearchPerformedEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.SearchPerformedEventHandler;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEvent.EVENT_SOURCE;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEventHandler;
2023-01-12 11:00:09 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowPopupOnCentroidEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowPopupOnCentroidEventHandler;
2022-11-03 17:03:15 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.events.TimelineProjectRelationsEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.TimelineProjectRelationsEvent.EVENT_TYPE;
import org.gcube.portlets.user.geoportaldataviewer.client.events.TimelineProjectRelationsEventHandler;
2020-11-19 15:19:27 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.events.ZoomOutOverMinimumEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ZoomOutOverMinimumEventHandler;
2022-10-17 16:52:22 +02:00
import org.gcube.portlets.user.geoportaldataviewer.client.events.collections.CloseCollectionEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.collections.CloseCollectionEventHandler;
import org.gcube.portlets.user.geoportaldataviewer.client.events.collections.OpenCollectionEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.collections.OpenCollectionEventHandler;
2021-09-08 14:40:36 +02:00
import org.gcube.portlets.user.geoportaldataviewer.client.gis.ExtentWrapped;
2020-11-19 15:19:27 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.gis.MapUtils;
2021-11-12 14:54:54 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerMap;
2022-11-03 17:03:15 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.resources.GNAImages;
2020-10-23 18:18:06 +02:00
import org.gcube.portlets.user.geoportaldataviewer.client.ui.GeonaDataViewMainPanel;
2022-11-08 10:45:39 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.project.relation.TimelineManagerStatus;
import org.gcube.portlets.user.geoportaldataviewer.client.util.ControlledCallBack;
2021-11-19 15:02:48 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon;
import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil;
import org.gcube.portlets.user.geoportaldataviewer.shared.GCubeCollection;
2022-10-17 16:52:22 +02:00
import org.gcube.portlets.user.geoportaldataviewer.shared.ItemFieldsResponse;
import org.gcube.portlets.user.geoportaldataviewer.shared.ViewerConfiguration;
2021-11-12 12:37:15 +01:00
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer;
2020-11-19 15:19:27 +01:00
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoQuery;
2020-10-23 18:18:06 +02:00
2022-11-15 10:08:02 +01:00
import com.github.gwtbootstrap.client.ui.Popover;
import com.github.gwtbootstrap.client.ui.constants.Placement;
2020-10-23 18:18:06 +02:00
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
2021-07-19 18:04:14 +02:00
import com.google.gwt.core.client.ScriptInjector;
2020-10-26 11:01:07 +01:00
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.event.shared.HandlerManager;
2022-10-24 12:23:52 +02:00
import com.google.gwt.user.client.Timer;
2020-10-26 11:01:07 +01:00
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
2022-11-28 09:49:46 +01:00
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
2022-11-28 09:49:46 +01:00
import com.google.gwt.user.client.ui.Image;
2020-10-23 18:18:06 +02:00
import com.google.gwt.user.client.ui.RootPanel;
2022-11-15 10:08:02 +01:00
import com.google.gwt.user.client.ui.Widget;
2020-10-23 18:18:06 +02:00
2020-11-19 15:19:27 +01:00
import ol.Coordinate;
2020-10-23 18:18:06 +02:00
/**
* Entry point classes define <code>onModuleLoad()</code>.
2020-10-27 16:04:34 +01:00
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Oct 27, 2020
2020-10-23 18:18:06 +02:00
*/
public class GeoportalDataViewer implements EntryPoint {
2020-10-27 16:04:34 +01:00
2022-11-03 17:03:15 +01:00
public static final String DIV_TIMELINE_DATA = "timeline-data";
public static final String APP_NOTIFIER = "app-notifier";
2022-11-03 17:03:15 +01:00
2020-10-27 16:04:34 +01:00
/** The Constant APP_DIV. */
public final static String APP_DIV = "geoportal-data-viewer";
/** The ol map. */
2021-11-12 14:54:54 +01:00
// private OpenLayerMap olMap = null;
2020-10-27 16:04:34 +01:00
/** The main panel. */
private GeonaDataViewMainPanel mainPanel;
/** The param wms request. */
private String paramWmsRequest;
2020-10-27 16:04:34 +01:00
/** The param UUID. */
// private String paramUUID;
2020-11-19 15:19:27 +01:00
private String paramGeonaItemType;
2020-10-27 16:04:34 +01:00
/** The param layer title. */
private String paramLayerTitle;
2020-11-19 15:19:27 +01:00
private HandlerManager applicationBus = new HandlerManager("");
2020-10-27 16:04:34 +01:00
/** The layer manager. */
2020-11-19 15:19:27 +01:00
private LayerManager layerManager = new LayerManager(applicationBus);
private String paramGeonaItemID;
2021-12-21 16:52:35 +01:00
private GNADataViewerConfigProfile geonaDataViewerProfile;
2020-11-19 15:19:27 +01:00
private OLMapManager olMapMng = null;
2020-12-02 18:48:12 +01:00
int attempt = 0;
2022-11-03 17:03:15 +01:00
private LoaderIcon loaderApp = new LoaderIcon("Loading application... please wait",
new com.google.gwt.user.client.ui.Image(GNAImages.ICONS.spinnerEarth()));
2021-11-12 12:37:15 +01:00
private HTML attributionDiv = new HTML();
2021-11-16 14:07:59 +01:00
private static List<BaseMapLayer> listBaseMapLayers = null;
private static ViewerStatus viewerStatus = new ViewerStatus();
2022-11-08 10:45:39 +01:00
private TimelineManagerStatus timelineMS = new TimelineManagerStatus(applicationBus);
2022-11-08 13:55:52 +01:00
private boolean initApplication;
2020-10-27 16:04:34 +01:00
/**
* This is the entry point method.
*/
public void onModuleLoad() {
2021-11-19 15:02:48 +01:00
loaderApp.getElement().addClassName("loader-gna-app");
RootPanel.get(APP_DIV).add(loaderApp);
2021-11-12 12:37:15 +01:00
paramWmsRequest = Window.Location.getParameter(GeoportalDataViewerConstants.GET_WMS_PARAMETER);
paramGeonaItemType = Window.Location.getParameter(GeoportalDataViewerConstants.GET_GEONA_ITEM_TYPE);
paramGeonaItemID = Window.Location.getParameter(GeoportalDataViewerConstants.GET_GEONA_ITEM_ID);
paramLayerTitle = Window.Location.getParameter(GeoportalDataViewerConstants.GET_LAYER_TITLE);
GWT.log(GeoportalDataViewerConstants.GET_WMS_PARAMETER + " = " + paramWmsRequest);
GWT.log(GeoportalDataViewerConstants.GET_GEONA_ITEM_TYPE + " = " + paramGeonaItemType);
GWT.log(GeoportalDataViewerConstants.GET_GEONA_ITEM_ID + " = " + paramGeonaItemID);
GWT.log(GeoportalDataViewerConstants.GET_LAYER_TITLE + " = " + paramLayerTitle);
2021-12-07 17:13:20 +01:00
2022-11-03 17:03:15 +01:00
// RootPanel.get(APP_DIV).add(loaderApp);
2022-11-08 10:45:39 +01:00
timelineMS.hideTimelineProjectRelations();
GeoportalDataViewerServiceAsync.Util.getInstance()
2022-10-27 16:18:54 +02:00
.getConfigListOfFieldsForSearching(new AsyncCallback<List<ItemFieldsResponse>>() {
2021-11-12 12:37:15 +01:00
@Override
public void onFailure(Throwable caught) {
2022-11-28 09:49:46 +01:00
RootPanel.get(APP_DIV).remove(loaderApp);
Window.alert(caught.getMessage());
RootPanel.get(APP_DIV).add(getGeneralErrorPanel());
2021-11-12 12:37:15 +01:00
}
@Override
2022-10-17 16:52:22 +02:00
public void onSuccess(List<ItemFieldsResponse> itemFieldsResult) {
GWT.log("listOfFieldsForSearching: " + itemFieldsResult);
2022-10-24 12:23:52 +02:00
mainPanel = new GeonaDataViewMainPanel(applicationBus, getClientHeight(), itemFieldsResult);
RootPanel.get(APP_DIV).add(mainPanel);
initApplication();
2022-10-17 16:52:22 +02:00
}
2021-11-12 12:37:15 +01:00
});
2021-11-16 14:07:59 +01:00
}
private void initApplication() {
2022-11-08 13:55:52 +01:00
initApplication = true;
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
GeoportalDataViewerServiceAsync.Util.getInstance()
.getInitialConfiguration(new ControlledCallBack<ViewerConfiguration>() {
2021-07-19 18:04:14 +02:00
@Override
public void onFailure(Throwable caught) {
2022-11-28 09:49:46 +01:00
RootPanel.get(APP_DIV).remove(loaderApp);
2021-07-19 18:04:14 +02:00
Window.alert(caught.getMessage());
2022-11-28 09:49:46 +01:00
RootPanel.get(APP_DIV).add(getGeneralErrorPanel());
}
@Override
public void after() {
RootPanel.get(APP_DIV).remove(loaderApp);
2020-11-19 15:19:27 +01:00
}
2021-07-19 18:04:14 +02:00
@Override
public void onSuccess(ViewerConfiguration result) {
super.onSuccess(result);
GWT.log("Received init config : " + result);
GWT.log("Loading base layers, count : " + result.getBaseLayers().size());
GeoportalDataViewer.getStatus().setConfig(result);
listBaseMapLayers = result.getBaseLayers();
mainPanel.setBaseLayers(result.getBaseLayers());
BaseMapLayer firstBaseLayer = result.getBaseLayers().get(0);
// Passing the first base map layer that will be applied as first base layer
olMapMng = new OLMapManager(mainPanel.getMapPanel().getElement().getId(),
layerManager.getLayerManagerBus(), firstBaseLayer);
OpenLayerMap olMap = olMapMng.getOLMap();
layerManager.setOLMap(olMap);
mainPanel.setMap(olMap);
updateSize();
ScriptInjector.fromUrl(
"//cdnjs.cloudflare.com/ajax/libs/nanogallery2/3.0.5/jquery.nanogallery2.min.js")
.setWindow(ScriptInjector.TOP_WINDOW).inject();
2022-11-03 17:03:15 +01:00
GWT.log("Loading collections, count " + result.getAvailableCollections().size());
mainPanel.setAvailableCollections(result.getAvailableCollections().values(),
paramGeonaItemType);
if (paramGeonaItemID != null) {
if (paramGeonaItemType == null) {
Window.alert(
"Missing parameter " + GeoportalDataViewerConstants.GET_GEONA_ITEM_TYPE
+ " (GeoNa Data Type) where to search the item id: "
+ paramGeonaItemID);
2021-07-19 18:04:14 +02:00
return;
}
2022-10-24 12:23:52 +02:00
GeoportalItemReferences gir = new GeoportalItemReferences(paramGeonaItemID,
paramGeonaItemType);
2023-01-12 11:00:09 +01:00
applicationBus.fireEvent(
new ShowDetailsEvent(gir, null, true, true, EVENT_SOURCE.LOCATE_ON_INIT));
2021-07-19 18:04:14 +02:00
}
mainPanel.openCollectionMenu();
GWT.log("DONE INIT LOAD");
2022-11-03 17:03:15 +01:00
2021-07-19 18:04:14 +02:00
}
2021-07-19 18:04:14 +02:00
});
2020-10-27 16:04:34 +01:00
}
});
Window.addResizeHandler(new ResizeHandler() {
@Override
public void onResize(ResizeEvent event) {
updateSize();
}
});
bindEvents();
RootPanel.get(APP_DIV).add(attributionDiv);
}
public static ViewerStatus getStatus() {
return viewerStatus;
}
public static List<BaseMapLayer> getListBaseMapLayers() {
return listBaseMapLayers;
}
2020-11-19 15:19:27 +01:00
/**
* Update window size.
*/
public void updateSize() {
2020-11-19 15:19:27 +01:00
int rootHeight = getClientHeight();
int height = rootHeight;
mainPanel.setPanelsHeight(height);
GWT.log("Set height: " + height);
2020-11-19 15:19:27 +01:00
}
2020-11-19 15:19:27 +01:00
public int getClientHeight() {
RootPanel principalDiv = RootPanel.get(APP_DIV);
int topBorder = principalDiv.getAbsoluteTop();
int rootHeight = Window.getClientHeight() - topBorder;
return rootHeight;
}
2020-11-19 15:19:27 +01:00
/**
* Bind events.
*/
private void bindEvents() {
2020-11-19 15:19:27 +01:00
applicationBus.addHandler(OpenCollectionEvent.TYPE, new OpenCollectionEventHandler() {
@Override
public void onOpenCollection(OpenCollectionEvent openCollectionEvent) {
2022-10-17 16:52:22 +02:00
GWT.log("OpenCollectionEvent Fired event: " + openCollectionEvent);
// Check if ID is available
String collId = openCollectionEvent.getCollectionId();
ViewerConfiguration theConfig = GeoportalDataViewer.getStatus().getViewerConfig();
Set<String> ucdIds = theConfig.getAvailableCollections().keySet();
if (!ucdIds.contains(collId)) {
GWT.log("!! Collection " + collId + " is not available");
Window.alert("Collection " + collId + " is not found.");
} else {
GCubeCollection toOpen = theConfig.getAvailableCollections().get(collId);
// Check if indexes is empty
if (toOpen.getIndexes() == null || toOpen.getIndexes().isEmpty()) {
GWT.log("Unexpected empty indexes in collection " + toOpen);
Window.alert("Cannot open collection index layer for " + toOpen.getUcd().getName() + ".");
return;
}
// TODO Get Default Index Layer
// For now we just take the first - only 1 is expected
2022-10-14 15:31:32 +02:00
IndexLayerDV layer = toOpen.getIndexes().get(0);
// Open Index Layer
layerManager.addIndexLayer(layer, toOpen.getUcd().getProfileID());
2022-11-03 17:03:15 +01:00
}
}
});
2022-10-17 16:52:22 +02:00
applicationBus.addHandler(CloseCollectionEvent.TYPE, new CloseCollectionEventHandler() {
@Override
public void onCloseCollection(CloseCollectionEvent closeCollectionEvent) {
String collId = closeCollectionEvent.getCollectionId();
2022-10-17 16:52:22 +02:00
if (collId != null) {
ViewerConfiguration theConfig = GeoportalDataViewer.getStatus().getViewerConfig();
GCubeCollection toCLose = theConfig.getAvailableCollections().get(collId);
IndexLayerDV layer = toCLose.getIndexes().get(0);
layerManager.removeIndexLayer(layer);
}
}
});
applicationBus.addHandler(AddLayerToMapEvent.TYPE, new AddLayerToMapEventHandler() {
@Override
public void onAddingLayerForProject(AddLayerToMapEvent addLayerToMapEvent) {
if (addLayerToMapEvent.getTheProjectDV() != null) {
layerManager.addLayerToMapForProject(addLayerToMapEvent.getTheProjectDV().getProfileID(),
addLayerToMapEvent.getTheProjectDV().getId(), addLayerToMapEvent.getTheProjectDV(),
addLayerToMapEvent.isNotifyClashing());
}
}
});
2020-11-19 15:19:27 +01:00
applicationBus.addHandler(ShowDetailsEvent.TYPE, new ShowDetailsEventHandler() {
@Override
2022-11-03 17:03:15 +01:00
public void onShowDetails(final ShowDetailsEvent showDetailsEvent) {
GWT.log("Fired event: " + showDetailsEvent);
String projectID = showDetailsEvent.getProjectID();
String profileID = showDetailsEvent.getProfileID();
2020-11-19 15:19:27 +01:00
2022-10-11 15:00:39 +02:00
if (projectID == null) {
2020-11-19 15:19:27 +01:00
Window.alert("Item Id not found");
return;
}
// TODO
2020-11-19 15:19:27 +01:00
boolean found = false;
2022-10-11 15:00:39 +02:00
GWT.log("Product with id: " + projectID + " found? " + found);
final EVENT_SOURCE sourceEvent = showDetailsEvent.getSourceEvent();
2023-01-12 11:00:09 +01:00
if (!sourceEvent.equals(EVENT_SOURCE.LOCATE_FROM_TIMELINE)) {
2022-12-21 11:00:12 +01:00
timelineMS.hideTimelineProjectRelations();
}
2023-01-12 11:00:09 +01:00
if (sourceEvent.equals(EVENT_SOURCE.LOCATE_SEARCHED)) {
layerManager.removeAllDetailLayers();
}
2022-12-21 11:00:12 +01:00
GeoportalDataViewerServiceAsync.Util.getInstance().getProjectViewForId(profileID, projectID,
new AsyncCallback<ProjectView>() {
@Override
public void onFailure(Throwable caught) {
2022-10-14 15:31:32 +02:00
Window.alert(caught.getMessage());
mainPanel.hidePanelDetails();
}
@Override
public void onSuccess(ProjectView result) {
mainPanel.showAsDetails(result, showDetailsEvent.getGeonaItemRef());
2022-11-03 17:03:15 +01:00
List<RelationshipDV> relationships = result.getTheProjectDV().getRelationships();
if (showDetailsEvent.isLoadTimelineRelationships() && relationships != null
&& relationships.size() > 0) {
2022-11-03 17:03:15 +01:00
GWT.log("LoadTimelineRelationships is true and the project has Relationships");
timelineMS.showTimelineProjectRelations(result.getTheProjectDV(), false);
}
2023-01-12 11:00:09 +01:00
if (sourceEvent != null) {
switch (sourceEvent) {
case LOCATE_FROM_TIMELINE:
case LOCATE_SEARCHED: {
applicationBus.fireEvent(new ShowPopupOnCentroidEvent(result));
break;
}
case LOCATE_ON_INIT: {
applicationBus.fireEvent(new ShowPopupOnCentroidEvent(result));
layerManager.fireGoToLayers();
break;
}
default:
break;
}
}
}
});
2022-10-11 15:00:39 +02:00
2020-11-19 15:19:27 +01:00
}
2020-11-19 15:19:27 +01:00
});
2020-11-19 15:19:27 +01:00
applicationBus.addHandler(AddedLayerToMapEvent.TYPE, new AddedLayerToMapEventHandler() {
2020-11-19 15:19:27 +01:00
@Override
public void onLayerRendered(AddedLayerToMapEvent addedLayerToMapEvent) {
GWT.log("Fired AddedLayerToMapEvent " + addedLayerToMapEvent.getLayerItem() + "layer type: "
+ addedLayerToMapEvent.getLayerType());
LAYER_TYPE layerType = addedLayerToMapEvent.getLayerType();
if (layerType != null) {
switch (layerType) {
case BASE:
break;
case OVERLAY:
mainPanel.showOverlayLayers(layerManager.getOverlayLayerManager().getPanel());
break;
default:
break;
}
}
2020-11-19 15:19:27 +01:00
}
});
2020-11-19 15:19:27 +01:00
applicationBus.addHandler(ZoomOutOverMinimumEvent.TYPE, new ZoomOutOverMinimumEventHandler() {
2020-11-19 15:19:27 +01:00
@Override
public void onZoomOut(ZoomOutOverMinimumEvent zoomOutEvent) {
2022-10-24 12:23:52 +02:00
if (mainPanel.getDisplayedProject() == null && !olMapMng.isQueryPointActive()) {
2020-11-19 15:19:27 +01:00
olMapMng.hidePopInfo();
2021-09-08 14:40:36 +02:00
layerManager.removeAllDetailLayers();
2020-11-19 15:19:27 +01:00
}
mainPanel.hideOverlayLayers();
2020-11-19 15:19:27 +01:00
}
});
2020-11-19 15:19:27 +01:00
applicationBus.addHandler(ClosedViewDetailsEvent.TYPE, new ClosedViewDetailsEventHandler() {
2020-11-19 15:19:27 +01:00
@Override
public void onClosed(ClosedViewDetailsEvent closedViewDetailsEvent) {
olMapMng.hidePopInfo();
2022-11-03 17:03:15 +01:00
applicationBus.fireEvent(new TimelineProjectRelationsEvent(null, EVENT_TYPE.HIDE));
}
});
2021-09-01 16:26:07 +02:00
applicationBus.addHandler(MapExtentToEvent.TYPE, new MapExtentToEventHandler() {
2021-09-01 16:26:07 +02:00
@Override
public void onExtentEvent(MapExtentToEvent mapExtentToEvent) {
// TODO Auto-generated method stub
2021-09-01 16:26:07 +02:00
}
});
2022-11-03 17:03:15 +01:00
applicationBus.addHandler(TimelineProjectRelationsEvent.TYPE, new TimelineProjectRelationsEventHandler() {
@Override
public void onTimelineRelationEvent(TimelineProjectRelationsEvent timelineProjectRelationsEvent) {
switch (timelineProjectRelationsEvent.getEventType()) {
case SHOW: {
timelineMS.showTimelineProjectRelations(timelineProjectRelationsEvent.getTheProjectDV(), true);
2022-11-03 17:03:15 +01:00
break;
}
case HIDE:
default: {
2022-11-08 10:45:39 +01:00
timelineMS.hideTimelineProjectRelations();
2022-11-03 17:03:15 +01:00
break;
}
}
}
});
applicationBus.addHandler(DoActionOnDetailLayersEvent.TYPE, new DoActionOnDetailLayersEventHandler() {
@Override
public void onDoActionOnDetailLayers(DoActionOnDetailLayersEvent doLayerActionEvent) {
DO_LAYER_ACTION doAction = doLayerActionEvent.getDoAction();
GWT.log("event: " + doAction);
GWT.log("layer source: " + doLayerActionEvent.getLayerItem().getName());
2021-11-12 14:54:54 +01:00
OpenLayerMap olMap = olMapMng.getOLMap();
switch (doAction) {
case OPACITY:
GWT.log("opacity: " + doLayerActionEvent.getOpacity());
olMap.setWMSDetailLayerOpacity(doLayerActionEvent.getLayerItem(), doLayerActionEvent.getOpacity());
break;
case SWAP:
SwapLayer swLS = doLayerActionEvent.getSourceLayerSwap();
SwapLayer swLT = doLayerActionEvent.getTargetLayerSwap();
GWT.log("SWAPPING source " + swLS.getLayerItem().getName() + ", target: "
+ swLT.getLayerItem().getName());
olMap.swapDetailsLayers(swLS, swLT);
break;
case VISIBILITY:
GWT.log("visibility: " + doLayerActionEvent.getVisibility());
olMap.setWMSDetailLayerVisible(doLayerActionEvent.getLayerItem(),
doLayerActionEvent.getVisibility());
break;
default:
break;
}
}
});
2021-11-12 12:37:15 +01:00
applicationBus.addHandler(ChangeMapLayerEvent.TYPE, new ChangeMapLayerEventHandler() {
@Override
public void onChangeBaseMapLayer(ChangeMapLayerEvent changeMapLayerEvent) {
BaseMapLayer baseLayer = changeMapLayerEvent.getBaseMapLayer();
if (baseLayer == null)
return;
String attributionHTML = "<div class='map-credits'><div class='map-credits-container'>"
+ baseLayer.getAttribution() + "</div></div>";
2021-11-12 14:54:54 +01:00
olMapMng.getOLMap().changeBaseMap(baseLayer);
// THE OSM Contributors are automatically added by gwt-ol, others ones not.
if (!baseLayer.getType().equals(BaseMapLayer.OL_BASE_MAP.OSM)) {
2021-11-12 12:37:15 +01:00
attributionDiv.setHTML(attributionHTML);
} else
2021-11-12 12:37:15 +01:00
attributionDiv.setHTML("");
}
});
2023-01-12 11:00:09 +01:00
applicationBus.addHandler(ShowPopupOnCentroidEvent.TYPE, new ShowPopupOnCentroidEventHandler() {
2022-10-25 11:35:03 +02:00
@Override
2023-01-12 11:00:09 +01:00
public void onShowPopup(ShowPopupOnCentroidEvent showPopupOnCentroiEvent) {
GWT.log("ShowPopupOnCentroidEvent: " + showPopupOnCentroiEvent);
//Showing popup after clicking on map
if (showPopupOnCentroiEvent.getProfileID() != null && showPopupOnCentroiEvent.getProjectID() != null) {
Coordinate transfCoord = MapUtils
.geoJSONTToBBoxCenter(showPopupOnCentroiEvent.getSpatialReference(), null, null);
performWFSQueryOnCentroid(showPopupOnCentroiEvent.getProjectID(), transfCoord.getX(),
transfCoord.getY());
2023-01-12 11:00:09 +01:00
//Showing popup after locate on Map
}else if(showPopupOnCentroiEvent.getProjectView()!=null) {
layerManager.showPopupInfoForCentroidLayer(showPopupOnCentroiEvent.getProjectView());
}
2022-10-25 11:35:03 +02:00
}
});
applicationBus.addHandler(SearchPerformedEvent.TYPE, new SearchPerformedEventHandler() {
@Override
public void onSearchDone(SearchPerformedEvent searchPerformedEvent) {
if (searchPerformedEvent != null) {
2022-11-28 09:49:46 +01:00
LinkedHashMap<String, ol.layer.Image> wmsMap = olMapMng.getOLMap().getWmsLayerMap();
String firstWMSKey = wmsMap.keySet().iterator().next();
2022-11-28 09:49:46 +01:00
List<String> result = searchPerformedEvent.getListProjectIDs();
ViewerConfiguration viewerConfig = GeoportalDataViewer.getStatus().getViewerConfig();
String layerName = null;
try {
2022-12-21 11:00:12 +01:00
GCubeCollection toOpen = viewerConfig.getAvailableCollections()
.get(searchPerformedEvent.getProfileID());
// Check if indexes is empty
if (toOpen.getIndexes() == null || toOpen.getIndexes().isEmpty()) {
GWT.log("SearchPerformedEvent Unexpected empty indexes in collection " + toOpen);
return;
}
// TODO Get Default Index Layer
// For now we just take the first - only 1 is expected
IndexLayerDV layer = toOpen.getIndexes().get(0);
// Open Index Layer
2022-12-21 11:00:12 +01:00
String wmsLink = layer.getLayer().getOgcLinks().get("wms");
layerName = URLUtil.extractValueOfParameterFromURL("layers", wmsLink);
2022-12-21 11:00:12 +01:00
} catch (Exception e) {
// TODO: handle exception
}
2022-12-21 11:00:12 +01:00
String setCqlFilter = null; // default
if (result != null && result.size() > 0) {
String cqlFilter = GeoportalDataViewerConstants.PROJECT_ID_KEY_FEATURE + " IN(";
2022-11-28 09:49:46 +01:00
for (String projectId : result) {
cqlFilter += "'" + projectId + "',";
}
cqlFilter = cqlFilter.substring(0, cqlFilter.length() - 1) + ")";
setCqlFilter = cqlFilter;
olMapMng.getOLMap().setCQLFilterToWMSLayer(firstWMSKey, cqlFilter);
} else {
olMapMng.getOLMap().setCQLFilterToWMSLayer(firstWMSKey, null);
2022-12-21 11:00:12 +01:00
setCqlFilter = null; // is already null
}
if (searchPerformedEvent.isSearchReset()) {
olMapMng.getOLMap().setCQLFilterToWMSLayer(firstWMSKey, null);
2022-12-21 11:00:12 +01:00
setCqlFilter = null; // is already null
}
2022-12-21 11:00:12 +01:00
if (layerName != null)
layerManager.setCQLForLayerToIndexLayer(layerName, setCqlFilter);
}
}
});
2020-10-27 16:04:34 +01:00
}
// /**
// * Handler popu closer.
// *
// * @param divId the div id
// * @param overlayId the overlay id
// */
// 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;
// };
//
// }-*/;
2022-10-25 11:35:03 +02:00
private void performWFSQueryOnCentroid(String projectID, Double centroidLong, Double centroidLat) {
GWT.log("Perform performWFSQueryOnCentroid: " + projectID + " long: " + centroidLong + ", lat: " + centroidLat);
2022-10-25 11:35:03 +02:00
if (projectID != null) {
Double x = centroidLong;
Double y = centroidLat;
2022-10-24 12:23:52 +02:00
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");
ExtentWrapped toExt = new ExtentWrapped(transfCoord.getX(), transfCoord.getY(), transfCoord.getX(),
transfCoord.getY());
2022-10-25 11:35:03 +02:00
layerManager.getLayerManagerBus().fireEvent(
new QueryDataEvent(select, toExt, projectID, true, MapEventType.ADDED_CENTROID_LAYER_TO_MAP));
2022-10-24 12:23:52 +02:00
} else {
GeoportalDataViewerConstants
.printJs("I cannot select the point one or both coordiantes are null. X: " + x + ", Y:" + y);
2020-12-02 18:48:12 +01:00
}
2022-10-24 12:23:52 +02:00
2020-12-02 18:48:12 +01:00
}
}
2022-11-15 10:08:02 +01:00
public static void showPopover(final Widget w, String message, String heading) {
final Popover popover = new Popover();
popover.setWidget(w);
popover.setText(message);
if (heading != null)
popover.setHeading(heading);
popover.setPlacement(Placement.BOTTOM);
popover.reconfigure();
popover.show();
Timer timer = new Timer() {
@Override
public void run() {
popover.hide();
}
};
timer.schedule(3000);
}
2020-10-26 11:01:07 +01:00
2022-11-28 09:49:46 +01:00
private FlowPanel getGeneralErrorPanel() {
Image geoportalError = new Image(GNAImages.ICONS.geoportaServiceError());
FlowPanel errorPanelMsg = new FlowPanel();
errorPanelMsg.getElement().addClassName("general_error");
errorPanelMsg.add(geoportalError);
errorPanelMsg.add(new HTML("D4S GeoPortal"));
HTML erroMessage = new HTML(
"Oops something went wrong, please refresh and try again. Feel free to contact us if the problem persists");
errorPanelMsg.add(erroMessage);
return errorPanelMsg;
}
2020-10-23 18:18:06 +02:00
}