531 lines
16 KiB
Java
531 lines
16 KiB
Java
package org.gcube.portlets.user.geoportaldataviewer.client;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile;
|
|
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.application.ClosedViewDetailsEvent;
|
|
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.events.collections.OpenCollectionEvent;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.collections.OpenCollectionEventHandler;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.layers.AddedLayerToMapEvent;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.layers.ChangeBaseMapLayerEvent;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.layers.DoActionOnDetailLayersEvent;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.layers.AddedLayerToMapEvent.LAYER_TYPE;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.layers.DoActionOnDetailLayersEvent.DO_LAYER_ACTION;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.layers.DoActionOnDetailLayersEvent.SwapLayer;
|
|
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.ControlledCallBack;
|
|
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.ViewerConfiguration;
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer;
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.IndexLayer;
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject;
|
|
|
|
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.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 HandlerManager applicationBus = new HandlerManager("");
|
|
|
|
/** The layer manager. */
|
|
private LayerManager layerManager = new LayerManager(applicationBus);
|
|
|
|
private OLMapManager olMapMng = null;
|
|
|
|
|
|
int attempt = 0;
|
|
|
|
private LoaderIcon loaderApp = new LoaderIcon("Loading application... please wait");
|
|
|
|
private HTML attributionDiv = new HTML();
|
|
|
|
|
|
private static ViewerStatus viewerStatus=new ViewerStatus();
|
|
|
|
/**
|
|
* This is the entry point method.
|
|
*/
|
|
public void onModuleLoad() {
|
|
|
|
loaderApp.getElement().addClassName("loader-gna-app");
|
|
RootPanel.get(APP_DIV).add(loaderApp);
|
|
|
|
// Fields configurations are read on open collection event
|
|
|
|
mainPanel = new GeonaDataViewMainPanel(applicationBus, getClientHeight());
|
|
RootPanel.get(APP_DIV).add(mainPanel);
|
|
|
|
initApplication();
|
|
|
|
}
|
|
|
|
private void initApplication() {
|
|
|
|
|
|
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
|
@Override
|
|
public void execute() {
|
|
|
|
Map<String,List<String>> queryParameters = new HashMap<String,List<String>> ();
|
|
queryParameters.putAll(Window.Location.getParameterMap());
|
|
|
|
GWT.log("Sending query params : "+ queryParameters);
|
|
// Load Initial Configuration
|
|
GeoportalDataViewerServiceAsync.Util.getInstance().getInitialConfiguration(queryParameters, new ControlledCallBack<ViewerConfiguration>() {
|
|
|
|
@Override
|
|
public void after() {RootPanel.get(APP_DIV).remove(loaderApp);}
|
|
|
|
@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);
|
|
|
|
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();
|
|
|
|
|
|
GWT.log("Loading collections, count "+result.getAvailableCollections().size());
|
|
|
|
mainPanel.setAvailableCollections(result.getAvailableCollections().values());
|
|
|
|
// TODO LOAD INITIAL LAYERS
|
|
|
|
GWT.log("DONE INIT LOAD");
|
|
}
|
|
|
|
});
|
|
}
|
|
});
|
|
|
|
Window.addResizeHandler(new ResizeHandler() {
|
|
@Override
|
|
public void onResize(ResizeEvent event) {
|
|
updateSize();
|
|
}
|
|
});
|
|
|
|
bindEvents();
|
|
|
|
RootPanel.get(APP_DIV).add(attributionDiv);
|
|
|
|
}
|
|
|
|
|
|
public static ViewerStatus getStatus() {
|
|
return viewerStatus;
|
|
}
|
|
|
|
|
|
// 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() {
|
|
|
|
// ************************** COLLECTIONS
|
|
|
|
|
|
applicationBus.addHandler(OpenCollectionEvent.TYPE, openCollectionEvent ->{
|
|
GWT.log("Fired event: " + openCollectionEvent);
|
|
// Check if ID is available
|
|
String collId=openCollectionEvent.getCollectionId();
|
|
if(!GeoportalDataViewer.getStatus().getConfig().getAvailableCollections().containsKey(collId)) {
|
|
GWT.log("!! Collection "+collId+" is not available");
|
|
Window.alert("Collection "+collId+" is not found.");
|
|
}else {
|
|
try {
|
|
|
|
GCubeCollection toOpen = GeoportalDataViewer.getStatus().getConfig().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()+".");
|
|
}
|
|
// TODO Get Default Index Layer
|
|
// For now we just take the first - only 1 is expected
|
|
IndexLayer layer = toOpen.getIndexes().get(0);
|
|
// Open Index Layer
|
|
|
|
GWT.log("Opening index "+layer);
|
|
|
|
LayerObject toAdd = new LayerObject(toOpen.getUcd().getId(), layer, LayerItem.fromIndex(layer));
|
|
layerManager.addLayer(toAdd);
|
|
|
|
}catch(Throwable t) {
|
|
GWT.log("Unable to open collection.",t);
|
|
Window.alert("Unable to open collection. Please contact administrators.");
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
|
|
// ************************* LAYERS
|
|
|
|
applicationBus.addHandler(AddedLayerToMapEvent.TYPE, addedLayerToMapEvent -> {
|
|
GWT.log("Fired AddedLayerToMapEvent " + addedLayerToMapEvent.getLayerItem() + "layer type: "+addedLayerToMapEvent.getLayerType());
|
|
|
|
// ???
|
|
// Open details popup (if called on startup)
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
|
|
//**************************** User actions On MAP
|
|
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(ClosedViewDetailsEvent.TYPE, closedViewDetailsEvent -> olMapMng.hidePopInfo());
|
|
|
|
|
|
|
|
applicationBus.addHandler(ZoomOutOverMinimumEvent.TYPE, zoomOutEvent -> {
|
|
|
|
|
|
|
|
// TODO
|
|
if (mainPanel.getDisplayedRecord() == null && !olMapMng.isQueryPointActive()) {
|
|
olMapMng.hidePopInfo();
|
|
layerManager.removeAllDetailLayers();
|
|
|
|
}
|
|
mainPanel.hideOverlayLayers();
|
|
// layerManager.getOverlayLayerManager().hide();
|
|
// hidePopupLayers();
|
|
});
|
|
|
|
|
|
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());
|
|
|
|
});
|
|
|
|
|
|
|
|
// ******************************* SEARCH
|
|
|
|
// 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);
|
|
// }
|
|
//
|
|
// }
|
|
//
|
|
//
|
|
// });
|
|
|
|
}
|
|
|
|
|
|
}
|