484 lines
15 KiB
Java
484 lines
15 KiB
Java
package org.gcube.portlets.user.geoportaldataviewer.client;
|
|
|
|
import java.util.*;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile;
|
|
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
|
|
import org.gcube.application.geoportalcommon.shared.products.model.RecordDV;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.application.AddedLayerToMapEvent;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.application.AddedLayerToMapEvent.LAYER_TYPE;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.application.AddedLayerToMapEventHandler;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.application.ChangeBaseMapLayerEvent;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.application.ClosedViewDetailsEvent;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.application.DoActionOnDetailLayersEvent;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.application.DoActionOnDetailLayersEvent.DO_LAYER_ACTION;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.application.DoActionOnDetailLayersEvent.SwapLayer;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.application.MapExtentToEvent;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.application.SearchPerformedEvent;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.application.ShowDetailsEvent;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.application.ShowPopupOnCentroiEvent;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.application.ZoomOutOverMinimumEvent;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerMap;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.ui.GeonaDataViewMainPanel;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.util.OGCUtils;
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.GCubeCollection;
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer;
|
|
|
|
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;
|
|
import com.google.gwt.core.client.ScriptInjector;
|
|
import com.google.gwt.event.logical.shared.ResizeEvent;
|
|
import com.google.gwt.event.logical.shared.ResizeHandler;
|
|
import com.google.gwt.event.shared.HandlerManager;
|
|
import com.google.gwt.user.client.Timer;
|
|
import com.google.gwt.user.client.Window;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
import com.google.gwt.user.client.ui.RootPanel;
|
|
|
|
import ol.layer.Image;
|
|
|
|
/**
|
|
* Entry point classes define <code>onModuleLoad()</code>.
|
|
*
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
|
*
|
|
* Oct 27, 2020
|
|
*/
|
|
public class GeoportalDataViewer implements EntryPoint {
|
|
|
|
/** The Constant APP_DIV. */
|
|
public final static String APP_DIV = "geoportal-data-viewer";
|
|
|
|
/** The ol map. */
|
|
// private OpenLayerMap olMap = null;
|
|
|
|
/** The main panel. */
|
|
private GeonaDataViewMainPanel mainPanel;
|
|
|
|
private StartParameters startParameters = null;
|
|
|
|
private HandlerManager applicationBus = new HandlerManager("");
|
|
|
|
/** The layer manager. */
|
|
private LayerManager layerManager = new LayerManager(applicationBus);
|
|
|
|
|
|
private GNADataViewerConfigProfile geonaDataViewerProfile;
|
|
|
|
private OLMapManager olMapMng = null;
|
|
|
|
int attempt = 0;
|
|
|
|
private LoaderIcon loaderApp = new LoaderIcon("Loading application... please wait");
|
|
|
|
private HTML attributionDiv = new HTML();
|
|
|
|
private static List<BaseMapLayer> listBaseMapLayers = null;
|
|
|
|
// Configuration by UCD
|
|
// Map : UCID -> Collection description
|
|
private Map<String, GCubeCollection> openedCollections=new HashMap<>();
|
|
|
|
|
|
/**
|
|
* This is the entry point method.
|
|
*/
|
|
public void onModuleLoad() {
|
|
|
|
loaderApp.getElement().addClassName("loader-gna-app");
|
|
RootPanel.get(APP_DIV).add(loaderApp);
|
|
|
|
startParameters = new StartParameters(Window.Location.getParameterMap());
|
|
|
|
// Fields configurations are read on open collection event
|
|
|
|
mainPanel = new GeonaDataViewMainPanel(applicationBus, getClientHeight(),null,null,null);
|
|
RootPanel.get(APP_DIV).add(mainPanel);
|
|
|
|
initApplication();
|
|
|
|
}
|
|
|
|
private void initApplication() {
|
|
|
|
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
|
|
|
@Override
|
|
public void execute() {
|
|
|
|
//LOADING THE BASE MAP LAYERS
|
|
GeoportalDataViewerServiceAsync.Util.getInstance().getListBaseLayers(new AsyncCallback<List<BaseMapLayer>>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
RootPanel.get(APP_DIV).remove(loaderApp);
|
|
GWT.log("Failure on loading base layers", caught);
|
|
Window.alert("Sorry, an error occurred on instancing the GeoPortale Viewer. Please, contact the support");
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(List<BaseMapLayer> listBaseMapLayers) {
|
|
|
|
// ?? Maybe remove after load collection / project?
|
|
try {
|
|
RootPanel.get(APP_DIV).remove(loaderApp);
|
|
}catch (Exception e) {
|
|
loaderApp.setVisible(false);
|
|
}
|
|
|
|
//now the map is loaded and I'm sure that I can load the GeonaDataViewer Profile
|
|
GeoportalDataViewer.listBaseMapLayers = listBaseMapLayers;
|
|
mainPanel.setBaseLayers(listBaseMapLayers);
|
|
|
|
BaseMapLayer firstBaseLayer = listBaseMapLayers.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();
|
|
|
|
if(!startParameters.toOpenCollections().isEmpty()){
|
|
// Fire
|
|
}
|
|
|
|
if(!startParameters.toOpenProjects().isEmpty()){
|
|
// open projects by projectID list
|
|
}
|
|
|
|
if(!startParameters.toOpenLayers().isEmpty()){
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
}
|
|
});
|
|
|
|
Window.addResizeHandler(new ResizeHandler() {
|
|
@Override
|
|
public void onResize(ResizeEvent event) {
|
|
updateSize();
|
|
}
|
|
});
|
|
|
|
bindEvents();
|
|
|
|
RootPanel.get(APP_DIV).add(attributionDiv);
|
|
|
|
}
|
|
|
|
public static List<BaseMapLayer> getListBaseMapLayers() {
|
|
return listBaseMapLayers;
|
|
}
|
|
|
|
// private void loadGeonaDataViewerProfile() {
|
|
//
|
|
// Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
|
//
|
|
// @Override
|
|
// public void execute() {
|
|
// GeoportalDataViewerServiceAsync.Util.getInstance()
|
|
// .getGeoNaDataViewProfile(new AsyncCallback<GNADataViewerConfigProfile>() {
|
|
//
|
|
// @Override
|
|
// public void onFailure(Throwable caught) {
|
|
// Window.alert(caught.getMessage());
|
|
//
|
|
// }
|
|
//
|
|
// @Override
|
|
// public void onSuccess(GNADataViewerConfigProfile profile) {
|
|
// geonaDataViewerProfile = profile;
|
|
// GWT.log("Profile: " + geonaDataViewerProfile);
|
|
// Iterator<String> it;
|
|
// String theItemType = paramGeonaItemType;
|
|
// if (theItemType == null) {
|
|
// it = geonaDataViewerProfile.getMapLayers().keySet().iterator();
|
|
// it.hasNext();
|
|
// theItemType = it.next();
|
|
// }
|
|
//
|
|
// LayerItem layerItem = geonaDataViewerProfile.getMapLayers().get(theItemType);
|
|
//
|
|
// if (layerItem == null) {
|
|
// Window.alert("Not detected any layer with type: " + theItemType);
|
|
// return;
|
|
// }
|
|
//
|
|
// GWT.log("ON module load The layerItem is: " + layerItem);
|
|
// String layerName = URLUtil.getValueOfParameter("layers", layerItem.getWmsLink());
|
|
// layerItem.setName(layerName);
|
|
// layerManager.setBaseLayerFromIsProfile(layerItem);
|
|
// layerManager.addLayer(theItemType, null, null, layerItem.getWmsLink(), false, false,
|
|
// null, false, null, null, null);
|
|
//
|
|
// 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);
|
|
// return;
|
|
// }
|
|
// GeoNaItemRef gir = new GeoNaItemRef(paramGeonaItemID, paramGeonaItemType);
|
|
// applicationBus.fireEvent(new ShowDetailsEvent(gir, null, null));
|
|
// }
|
|
//
|
|
// }
|
|
// });
|
|
// }
|
|
// });
|
|
//
|
|
// }
|
|
|
|
/**
|
|
* Update window size.
|
|
*/
|
|
public void updateSize() {
|
|
|
|
int rootHeight = getClientHeight();
|
|
int height = rootHeight;
|
|
mainPanel.setPanelsHeight(height);
|
|
GWT.log("Set height: " + height);
|
|
|
|
}
|
|
|
|
public int getClientHeight() {
|
|
RootPanel principalDiv = RootPanel.get(APP_DIV);
|
|
int topBorder = principalDiv.getAbsoluteTop();
|
|
int rootHeight = Window.getClientHeight() - topBorder;
|
|
return rootHeight;
|
|
}
|
|
|
|
|
|
//************************************************************************************************************************
|
|
|
|
|
|
|
|
/**
|
|
* Bind events.
|
|
*/
|
|
private void bindEvents() {
|
|
|
|
|
|
//
|
|
applicationBus.addHandler(ShowDetailsEvent.TYPE, showDetailsEvent -> {
|
|
GWT.log("Fired event: " + showDetailsEvent);
|
|
|
|
String geonaMongoId = showDetailsEvent.getGeonaMongoID();
|
|
|
|
if (geonaMongoId == null) {
|
|
Window.alert("Item Id not found");
|
|
return;
|
|
}
|
|
|
|
// TODO
|
|
boolean found = false;
|
|
GWT.log("Product with id: " + geonaMongoId + " found? " + found);
|
|
|
|
if (!found) {
|
|
|
|
// if (showDetailsEvent.getGeonaItemType().equalsIgnoreCase("Concessione")) {
|
|
//
|
|
// GeoportalDataViewerServiceAsync.Util.getInstance().getConcessioneForId(geonaMongoId,
|
|
// new AsyncCallback<ConcessioneDV>() {
|
|
//
|
|
// @Override
|
|
// public void onFailure(Throwable caught) {
|
|
// Window.alert(caught.getMessage());
|
|
// mainPanel.hidePanelDetails();
|
|
//
|
|
// }
|
|
//
|
|
// @Override
|
|
// public void onSuccess(ConcessioneDV concessioneDV) {
|
|
// GWT.log("Showing: " + concessioneDV);
|
|
// mainPanel.showAsDetails(concessioneDV, showDetailsEvent.getGeonaItemRef());
|
|
// }
|
|
// });
|
|
// }
|
|
}
|
|
});
|
|
|
|
applicationBus.addHandler(AddedLayerToMapEvent.TYPE, addedLayerToMapEvent -> {
|
|
GWT.log("Fired AddedLayerToMapEvent " + addedLayerToMapEvent.getLayerItem() + "layer type: "+addedLayerToMapEvent.getLayerType());
|
|
|
|
try {
|
|
|
|
attempt = 0;
|
|
|
|
// if (paramGeonaItemID != null) {
|
|
// // waiting for record retrieved by service before calling the WFS
|
|
// final int MAX_RETRY = 15;
|
|
// Timer timer = new com.google.gwt.user.client.Timer() {
|
|
// @Override
|
|
// public void run() {
|
|
// attempt++;
|
|
// GWT.log("waiting get record: " + attempt);
|
|
// RecordDV record = mainPanel.getDisplayedRecord();
|
|
// if (record != null) {
|
|
// this.cancel();
|
|
// GWT.log("cancelled timer");
|
|
// OGCUtils.performWFSQueryOnCentroid(record);
|
|
// }
|
|
//
|
|
// if (attempt > MAX_RETRY) {
|
|
// GWT.log("MAX_RETRY reached, cancelled timer");
|
|
// this.cancel();
|
|
// }
|
|
//
|
|
// }
|
|
// };
|
|
// timer.scheduleRepeating(1000);
|
|
//
|
|
// }
|
|
} catch (Exception e) {
|
|
// TODO: handle exception
|
|
}
|
|
|
|
LAYER_TYPE layerType = addedLayerToMapEvent.getLayerType();
|
|
|
|
if (layerType != null) {
|
|
|
|
switch (layerType) {
|
|
case BASE:
|
|
|
|
break;
|
|
case OVERLAY:
|
|
mainPanel.showOverlayLayers(layerManager.getOverlayLayerManager().getPanel());
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
applicationBus.addHandler(ZoomOutOverMinimumEvent.TYPE, zoomOutEvent -> {
|
|
|
|
if (mainPanel.getDisplayedRecord() == null && !olMapMng.isQueryPointActive()) {
|
|
olMapMng.hidePopInfo();
|
|
layerManager.removeAllDetailLayers();
|
|
|
|
}
|
|
mainPanel.hideOverlayLayers();
|
|
// layerManager.getOverlayLayerManager().hide();
|
|
// hidePopupLayers();
|
|
});
|
|
|
|
|
|
applicationBus.addHandler(ClosedViewDetailsEvent.TYPE, closedViewDetailsEvent -> olMapMng.hidePopInfo());
|
|
|
|
applicationBus.addHandler(MapExtentToEvent.TYPE, mapExtentToEvent -> {// TODO Auto-generated method stub
|
|
});
|
|
|
|
applicationBus.addHandler(DoActionOnDetailLayersEvent.TYPE, doLayerActionEvent -> {
|
|
|
|
DO_LAYER_ACTION doAction = doLayerActionEvent.getDoAction();
|
|
GWT.log("event: "+doAction);
|
|
GWT.log("layer source: "+doLayerActionEvent.getLayerItem().getName());
|
|
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;
|
|
}
|
|
|
|
});
|
|
|
|
|
|
applicationBus.addHandler(ChangeBaseMapLayerEvent.TYPE, changeMapLayerEvent -> {
|
|
|
|
BaseMapLayer baseLayer = changeMapLayerEvent.getBaseMapLayer();
|
|
|
|
if (baseLayer == null)
|
|
return;
|
|
|
|
String attributionHTML = "<div class='map-credits'><div class='map-credits-container'>"
|
|
+ baseLayer.getAttribution() + "</div></div>";
|
|
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)) {
|
|
attributionDiv.setHTML(attributionHTML);
|
|
} else
|
|
attributionDiv.setHTML("");
|
|
|
|
});
|
|
|
|
applicationBus.addHandler(ShowPopupOnCentroiEvent.TYPE, showPopupOnCentroiEvent -> {
|
|
|
|
if(showPopupOnCentroiEvent.getRecord()!=null)
|
|
OGCUtils.performWFSQueryOnCentroid(showPopupOnCentroiEvent.getRecord());
|
|
|
|
});
|
|
|
|
applicationBus.addHandler(SearchPerformedEvent.TYPE, searchPerformedEvent -> {
|
|
|
|
if(searchPerformedEvent!=null) {
|
|
|
|
LinkedHashMap<String, Image> wmsMap = olMapMng.getOLMap().getWmsLayerMap();
|
|
String firstWMSKey = wmsMap.keySet().iterator().next();
|
|
List<ConcessioneDV> result = searchPerformedEvent.getData();
|
|
|
|
if(result!=null && result.size()>0) {
|
|
String cqlFilter = "product_id IN(";
|
|
for (ConcessioneDV concessioneDV : result) {
|
|
cqlFilter+="'"+concessioneDV.getItemId()+"',";
|
|
}
|
|
cqlFilter = cqlFilter.substring(0,cqlFilter.length()-1)+")";
|
|
|
|
olMapMng.getOLMap().setCQLFilterToWMSLayer(firstWMSKey, cqlFilter);
|
|
}else {
|
|
olMapMng.getOLMap().setCQLFilterToWMSLayer(firstWMSKey, null);
|
|
}
|
|
|
|
if(searchPerformedEvent.isSearchReset()) {
|
|
olMapMng.getOLMap().setCQLFilterToWMSLayer(firstWMSKey, null);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
}
|