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.gis.MapUtils; import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerOSM; 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; import ol.Coordinate; import ol.OLFactory; // 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 geonaItemType; /** The param layer title. */ private String paramLayerTitle; private HandlerManager eventBus = new HandlerManager(""); /** The layer manager. */ private LayerManager layerManager = new LayerManager(eventBus); private String geonaItemID; private GeoNaDataViewerProfile geonaDataViewerProfile; //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() { olMap = new OpenLayerOSM(mainPanel.getMapPanel().getElement().getId(),layerManager.getEventBus()); layerManager.setOlMap(olMap); mainPanel.setMap(olMap); //EPSG_4326_TO_ITALY Coordinate centerCoordinate = OLFactory.createCoordinate(GeoportalDataViewerConstants.ITALY_CENTER_LONG, GeoportalDataViewerConstants.ITALY_CENTER_LAT); Coordinate transformedCenterCoordinate = MapUtils.transformCoordiante(centerCoordinate, GeoportalDataViewerConstants.EPSG_4326, GeoportalDataViewerConstants.EPSG_3857); olMap.setCenter(transformedCenterCoordinate); olMap.setZoom(GeoportalDataViewerConstants.ITALY_FIT_ZOOM_ON); } }); // 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); geonaItemType = Window.Location.getParameter(GeoportalDataViewerConstants.GET_GEONA_ITEM_TYPE); paramUUID = Window.Location.getParameter(GeoportalDataViewerConstants.GET_UUID_PARAMETER); geonaItemID = 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 + " = " + geonaItemType); GWT.log(GeoportalDataViewerConstants.GET_GEONA_ITEM_ID + " = " + geonaItemID); GWT.log(GeoportalDataViewerConstants.GET_UUID_PARAMETER + " = " + paramUUID); GWT.log(GeoportalDataViewerConstants.GET_LAYER_TITLE + " = " + paramLayerTitle); 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; if(geonaItemType==null) { it = geonaDataViewerProfile.getMapLayers().keySet().iterator(); it.hasNext(); geonaItemType= it.next(); } LayerItem layerItem = geonaDataViewerProfile.getMapLayers().get(geonaItemType); if(layerItem==null) { Window.alert("Not detected any layer with type: "+geonaItemType); return; } GWT.log("The layerItem is: "+layerItem); layerManager.addLayer(geonaItemType, null, null, layerItem.getWmsLink(), false, false, null, true); } }); } }); bindEvents(); } /** * Bind events. */ private void bindEvents() { // eventBus.addHandler(ShowDetailsEvent.TYPE, new ShowDetailsEventHandler() { // // @Override // public void onShowDetails(ShowDetailsEvent showDetailsEvent) { // GWT.log("Fired event: "+showDetailsEvent); // FeatureRow fRow = showDetailsEvent.getFeatureRow(); // if(fRow!=null) { // if(showDetailsEvent.getProductType().equals(ProductType.CONCESSIONE)) { // List productIds = fRow.getMapProperties().get("product_id"); // if(productIds!=null && productIds.size()>0) { // long id = Long.parseLong(productIds.get(0)); // String tabName = "Dettagli Prodotto"; // List listName = fRow.getMapProperties().get("nome"); // if(listName!=null && listName.size()>0) { // tabName = listName.get(0); // } // // boolean found = mainPanel.selectTabForProductId(id); // GWT.log("Product with id: "+id+" found? "+found); // if(!found) { // // 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); // // } // }); // }else // Window.alert("No product id found"); // } // // } // } // // } // }); 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); } }); } } } }); } }