package org.gcube.portlets.user.geoportaldataviewer.client; import java.util.Iterator; import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEventHandler; import org.gcube.portlets.user.geoportaldataviewer.client.ui.GeonaDataViewMainPanel; import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaDataViewerProfile; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import org.gcube.portlets.user.geoportaldataviewer.shared.products.ConcessioneDV; import com.github.gwtbootstrap.client.ui.Tab; import com.github.gwtbootstrap.client.ui.constants.IconType; 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.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; // TODO: Auto-generated Javadoc /** * Entry point classes define onModuleLoad(). * * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * * Oct 27, 2020 */ public class GeoportalDataViewer implements EntryPoint { /** * The message displayed to the user when the server cannot be reached or * returns an error. */ private static final String SERVER_ERROR = "An error occurred while " + "attempting to contact the server. Please check your network " + "connection and try again."; /** The Constant APP_DIV. */ public final static String APP_DIV = "geoportal-data-viewer"; /** The ol map. */ //private OpenLayerOSM olMap = null; /** The main panel. */ private GeonaDataViewMainPanel mainPanel; /** The param wms request. */ private String paramWmsRequest; /** The param UUID. */ //private String paramUUID; private String paramGeonaItemType; /** The param layer title. */ private String paramLayerTitle; private HandlerManager eventBus = new HandlerManager(""); /** The layer manager. */ private LayerManager layerManager = new LayerManager(eventBus); private String paramGeonaItemID; private GeoNaDataViewerProfile geonaDataViewerProfile; private OLMapManager olMapMng = null; //https://data.d4science.org/gis-viewer-app/?wmsrequest=https%3A%2F%2Fgeona-proto.d4science.org%2Fgeoserver%2Fconcessioni_conf%2Fwms%3Fservice%3DWMS%26version%3D1.1.0%26request%3DGetMap%26layers%3Dconcessioni_conf%3Acentroids_concessioni%26styles%3D%26bbox%3D8.476%2C39.179%2C17.391%2C45.772%26width%3D768%26height%3D567%26srs%3DEPSG%3A4326%26format%3Dapplication%2Fopenlayers&zoom=6¢ermap=12.45%2C42.98 /** * This is the entry point method. */ public void onModuleLoad() { mainPanel = new GeonaDataViewMainPanel(eventBus); RootPanel.get(APP_DIV).add(mainPanel); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { olMapMng = new OLMapManager(mainPanel.getMapPanel().getElement().getId(),layerManager.getEventBus()); layerManager.setOlMap(olMapMng.getOLOSMMap()); mainPanel.setMap(olMapMng.getOLOSMMap()); } }); // Window.addResizeHandler(new ResizeHandler() { // @Override // public void onResize(ResizeEvent event) { // GWT.log("onWindowResized width: " + event.getWidth() + " height: " + event.getHeight()); // mainPanel.setMapHeight(event.getHeight() - 200); // } // }); paramWmsRequest = Window.Location.getParameter(GeoportalDataViewerConstants.GET_WMS_PARAMETER); paramGeonaItemType = Window.Location.getParameter(GeoportalDataViewerConstants.GET_GEONA_ITEM_TYPE); //paramUUID = Window.Location.getParameter(GeoportalDataViewerConstants.GET_UUID_PARAMETER); 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_UUID_PARAMETER + " = " + paramUUID); GWT.log(GeoportalDataViewerConstants.GET_LAYER_TITLE + " = " + paramLayerTitle); //VALIDATING THE LONG FORMAT FOR GID try { if(paramGeonaItemID!=null) Long.parseLong(paramGeonaItemID); }catch (Exception e) { Window.alert("Bad format for parameter "+GeoportalDataViewerConstants.GET_GEONA_ITEM_ID+". It must be a Long"); } Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { GeoportalDataViewerServiceAsync.Util.getInstance().getGeoNaDataViewProfile(new AsyncCallback() { @Override public void onFailure(Throwable caught) { Window.alert(caught.getMessage()); } @Override public void onSuccess(GeoNaDataViewerProfile profile) { geonaDataViewerProfile = profile; GWT.log("Profile: "+geonaDataViewerProfile); Iterator 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("The layerItem is: "+layerItem); layerManager.addLayer(theItemType, null, null, layerItem.getWmsLink(), false, false, null, true); 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; } eventBus.fireEvent(new ShowDetailsEvent(paramGeonaItemType, new Long(paramGeonaItemID), null, null)); } } }); } }); bindEvents(); } /** * Bind events. */ private void bindEvents() { eventBus.addHandler(ShowDetailsEvent.TYPE, new ShowDetailsEventHandler() { @Override public void onShowDetails(ShowDetailsEvent showDetailsEvent) { GWT.log("Fired event: "+showDetailsEvent); Long id = showDetailsEvent.getGeonaID(); if(id==null) { Window.alert("Item Id not found"); return; } String tabName = showDetailsEvent.getItemName()==null?"Dettagli Prodotto":showDetailsEvent.getItemName(); boolean found = mainPanel.selectTabForProductId(id); GWT.log("Product with id: "+id+" found? "+found); if(!found) { if(showDetailsEvent.getGeonaItemType().equalsIgnoreCase("Concessione")) { final Tab theTab = mainPanel.addAsTab(tabName, true, null); GeoportalDataViewerServiceAsync.Util.getInstance().getConcessioneForId(id, new AsyncCallback() { @Override public void onFailure(Throwable caught) { Window.alert(caught.getMessage()); theTab.clear(); theTab.setIcon(IconType.WARNING_SIGN); theTab.add(new HTML(caught.getMessage())); } @Override public void onSuccess(ConcessioneDV result) { GWT.log("Showing: "+result); mainPanel.renderProductIntoTab(theTab, result); } }); } } } }); } }