2020-10-23 18:18:06 +02:00
package org.gcube.portlets.user.geoportaldataviewer.client ;
2020-11-12 18:25:24 +01:00
import java.util.Iterator ;
2020-11-03 13:09:08 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEvent ;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEventHandler ;
2020-11-12 12:03:22 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.gis.MapUtils ;
2020-10-27 16:04:34 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerOSM ;
2020-10-23 18:18:06 +02:00
import org.gcube.portlets.user.geoportaldataviewer.client.ui.GeonaDataViewMainPanel ;
2020-11-12 18:25:24 +01:00
import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaDataViewerProfile ;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem ;
2020-11-03 13:09:08 +01:00
import org.gcube.portlets.user.geoportaldataviewer.shared.products.ConcessioneDV ;
2020-10-23 18:18:06 +02:00
2020-11-05 14:05:14 +01:00
import com.github.gwtbootstrap.client.ui.Tab ;
import com.github.gwtbootstrap.client.ui.constants.IconType ;
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 ;
2020-11-03 13:09:08 +01:00
import com.google.gwt.event.shared.HandlerManager ;
2020-10-26 11:01:07 +01:00
import com.google.gwt.user.client.Window ;
2020-11-03 13:09:08 +01:00
import com.google.gwt.user.client.rpc.AsyncCallback ;
2020-11-05 14:05:14 +01:00
import com.google.gwt.user.client.ui.HTML ;
2020-10-23 18:18:06 +02:00
import com.google.gwt.user.client.ui.RootPanel ;
2020-11-12 12:03:22 +01:00
import ol.Coordinate ;
import ol.OLFactory ;
2020-10-27 16:04:34 +01:00
// TODO: Auto-generated Javadoc
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
/ * *
* 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 ;
2020-10-23 18:18:06 +02:00
2020-10-27 16:04:34 +01:00
/** The param UUID. */
2020-11-13 17:14:08 +01:00
//private String paramUUID;
2020-10-23 18:18:06 +02:00
2020-11-13 17:14:08 +01:00
private String paramGeonaItemType ;
2020-11-12 18:25:24 +01:00
2020-10-27 16:04:34 +01:00
/** The param layer title. */
private String paramLayerTitle ;
2020-10-26 12:24:23 +01:00
2020-11-03 13:09:08 +01:00
private HandlerManager eventBus = new HandlerManager ( " " ) ;
2020-10-27 16:04:34 +01:00
/** The layer manager. */
2020-11-03 13:09:08 +01:00
private LayerManager layerManager = new LayerManager ( eventBus ) ;
2020-11-13 16:37:34 +01:00
2020-11-13 17:14:08 +01:00
private String paramGeonaItemID ;
2020-11-13 16:37:34 +01:00
private GeoNaDataViewerProfile geonaDataViewerProfile ;
2020-10-29 15:18:14 +01:00
//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
2020-10-27 16:04:34 +01:00
/ * *
* This is the entry point method .
* /
public void onModuleLoad ( ) {
2020-11-03 13:09:08 +01:00
mainPanel = new GeonaDataViewMainPanel ( eventBus ) ;
2020-10-27 16:04:34 +01:00
RootPanel . get ( APP_DIV ) . add ( mainPanel ) ;
Scheduler . get ( ) . scheduleDeferred ( new ScheduledCommand ( ) {
@Override
public void execute ( ) {
2020-10-29 15:18:14 +01:00
olMap = new OpenLayerOSM ( mainPanel . getMapPanel ( ) . getElement ( ) . getId ( ) , layerManager . getEventBus ( ) ) ;
2020-10-27 16:41:30 +01:00
layerManager . setOlMap ( olMap ) ;
2020-10-27 16:04:34 +01:00
mainPanel . setMap ( olMap ) ;
2020-11-12 12:03:22 +01:00
//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 ) ;
2020-10-27 16:04:34 +01:00
}
} ) ;
2020-11-12 12:27:00 +01:00
// Window.addResizeHandler(new ResizeHandler() {
// @Override
// public void onResize(ResizeEvent event) {
// GWT.log("onWindowResized width: " + event.getWidth() + " height: " + event.getHeight());
// mainPanel.setMapHeight(event.getHeight() - 200);
// }
// });
2020-10-27 16:04:34 +01:00
paramWmsRequest = Window . Location . getParameter ( GeoportalDataViewerConstants . GET_WMS_PARAMETER ) ;
2020-11-13 17:14:08 +01:00
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 ) ;
2020-10-27 16:04:34 +01:00
paramLayerTitle = Window . Location . getParameter ( GeoportalDataViewerConstants . GET_LAYER_TITLE ) ;
GWT . log ( GeoportalDataViewerConstants . GET_WMS_PARAMETER + " = " + paramWmsRequest ) ;
2020-11-13 17:14:08 +01:00
GWT . log ( GeoportalDataViewerConstants . GET_GEONA_ITEM_TYPE + " = " + paramGeonaItemType ) ;
GWT . log ( GeoportalDataViewerConstants . GET_GEONA_ITEM_ID + " = " + paramGeonaItemID ) ;
//GWT.log(GeoportalDataViewerConstants.GET_UUID_PARAMETER + " = " + paramUUID);
2020-10-27 16:04:34 +01:00
GWT . log ( GeoportalDataViewerConstants . GET_LAYER_TITLE + " = " + paramLayerTitle ) ;
2020-11-12 18:25:24 +01:00
2020-11-13 17:14:08 +01:00
//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 " ) ;
}
2020-11-12 18:25:24 +01:00
Scheduler . get ( ) . scheduleDeferred ( new ScheduledCommand ( ) {
@Override
public void execute ( ) {
GeoportalDataViewerServiceAsync . Util . getInstance ( ) . getGeoNaDataViewProfile ( new AsyncCallback < GeoNaDataViewerProfile > ( ) {
2020-10-27 16:04:34 +01:00
2020-11-12 18:25:24 +01:00
@Override
public void onFailure ( Throwable caught ) {
Window . alert ( caught . getMessage ( ) ) ;
}
2020-10-27 16:41:30 +01:00
@Override
2020-11-13 16:37:34 +01:00
public void onSuccess ( GeoNaDataViewerProfile profile ) {
geonaDataViewerProfile = profile ;
GWT . log ( " Profile: " + geonaDataViewerProfile ) ;
2020-11-12 18:25:24 +01:00
Iterator < String > it ;
2020-11-13 17:14:08 +01:00
String theItemType = paramGeonaItemType ;
if ( theItemType = = null ) {
2020-11-13 16:37:34 +01:00
it = geonaDataViewerProfile . getMapLayers ( ) . keySet ( ) . iterator ( ) ;
2020-11-12 18:25:24 +01:00
it . hasNext ( ) ;
2020-11-13 17:14:08 +01:00
theItemType = it . next ( ) ;
2020-11-12 18:25:24 +01:00
}
2020-11-13 17:14:08 +01:00
LayerItem layerItem = geonaDataViewerProfile . getMapLayers ( ) . get ( theItemType ) ;
2020-11-12 18:25:24 +01:00
if ( layerItem = = null ) {
2020-11-13 17:14:08 +01:00
Window . alert ( " Not detected any layer with type: " + theItemType ) ;
2020-11-12 18:25:24 +01:00
return ;
}
2020-11-13 17:14:08 +01:00
2020-11-12 18:25:24 +01:00
GWT . log ( " The layerItem is: " + layerItem ) ;
2020-11-13 17:14:08 +01:00
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 ) ) ;
}
2020-10-27 16:41:30 +01:00
}
} ) ;
2020-10-27 16:04:34 +01:00
}
2020-11-12 18:25:24 +01:00
} ) ;
2020-11-03 13:09:08 +01:00
bindEvents ( ) ;
}
2020-11-13 16:37:34 +01:00
/ * *
* Bind events .
* /
2020-11-03 13:09:08 +01:00
private void bindEvents ( ) {
2020-11-13 17:14:08 +01:00
2020-11-03 13:09:08 +01:00
eventBus . addHandler ( ShowDetailsEvent . TYPE , new ShowDetailsEventHandler ( ) {
@Override
public void onShowDetails ( ShowDetailsEvent showDetailsEvent ) {
2020-11-03 18:04:47 +01:00
GWT . log ( " Fired event: " + showDetailsEvent ) ;
2020-11-13 16:37:34 +01:00
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 < ConcessioneDV > ( ) {
2020-11-05 14:05:14 +01:00
2020-11-13 16:37:34 +01:00
@Override
public void onFailure ( Throwable caught ) {
Window . alert ( caught . getMessage ( ) ) ;
theTab . clear ( ) ;
theTab . setIcon ( IconType . WARNING_SIGN ) ;
theTab . add ( new HTML ( caught . getMessage ( ) ) ) ;
}
2020-11-05 14:05:14 +01:00
2020-11-13 16:37:34 +01:00
@Override
public void onSuccess ( ConcessioneDV result ) {
GWT . log ( " Showing: " + result ) ;
mainPanel . renderProductIntoTab ( theTab , result ) ;
}
} ) ;
2020-11-03 13:09:08 +01:00
}
}
}
2020-11-13 16:37:34 +01:00
2020-11-03 13:09:08 +01:00
} ) ;
2020-10-27 16:04:34 +01:00
}
2020-10-26 11:01:07 +01:00
2020-10-23 18:18:06 +02:00
}