2020-10-23 18:18:06 +02:00
package org.gcube.portlets.user.geoportaldataviewer.client ;
2020-11-19 15:19:27 +01:00
import java.util.Iterator ;
2020-11-03 13:09:08 +01:00
2020-12-02 14:39:52 +01:00
import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile ;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef ;
2020-12-02 14:43:08 +01:00
import org.gcube.application.geoportalcommon.shared.LayerItem ;
2020-11-19 15:19:27 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent ;
import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEventHandler ;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ClosedViewDetailsEvent ;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ClosedViewDetailsEventHandler ;
import org.gcube.portlets.user.geoportaldataviewer.client.events.QueryDataEvent ;
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-19 15:19:27 +01:00
import org.gcube.portlets.user.geoportaldataviewer.client.events.ZoomOutOverMinimumEvent ;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ZoomOutOverMinimumEventHandler ;
import org.gcube.portlets.user.geoportaldataviewer.client.gis.MapUtils ;
2020-10-23 18:18:06 +02:00
import org.gcube.portlets.user.geoportaldataviewer.client.ui.GeonaDataViewMainPanel ;
2020-11-19 15:19:27 +01:00
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoQuery ;
2020-11-03 13:09:08 +01:00
import org.gcube.portlets.user.geoportaldataviewer.shared.products.ConcessioneDV ;
2020-11-19 15:19:27 +01:00
import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.RecordDV ;
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-10-26 11:01:07 +01:00
import com.google.gwt.event.logical.shared.ResizeEvent ;
import com.google.gwt.event.logical.shared.ResizeHandler ;
2020-11-03 13:09:08 +01:00
import com.google.gwt.event.shared.HandlerManager ;
2020-12-02 18:48:12 +01:00
import com.google.gwt.user.client.Timer ;
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-10-23 18:18:06 +02:00
import com.google.gwt.user.client.ui.RootPanel ;
2020-11-19 15:19:27 +01:00
import ol.Coordinate ;
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 Constant APP_DIV. */
public final static String APP_DIV = " geoportal-data-viewer " ;
/** The ol map. */
2020-11-19 15:19:27 +01:00
//private OpenLayerOSM olMap = null;
2020-10-27 16:04:34 +01:00
/** 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-19 15:19:27 +01:00
//private String paramUUID;
private String paramGeonaItemType ;
2020-10-23 18:18:06 +02: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-19 15:19:27 +01:00
private HandlerManager applicationBus = new HandlerManager ( " " ) ;
2020-11-03 13:09:08 +01:00
2020-10-27 16:04:34 +01:00
/** The layer manager. */
2020-11-19 15:19:27 +01:00
private LayerManager layerManager = new LayerManager ( applicationBus ) ;
private String paramGeonaItemID ;
private GeoNaDataViewerProfile geonaDataViewerProfile ;
private OLMapManager olMapMng = null ;
2020-12-02 18:48:12 +01:00
int attempt = 0 ;
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-19 15:19:27 +01:00
mainPanel = new GeonaDataViewMainPanel ( applicationBus , getClientHeight ( ) ) ;
2020-10-27 16:04:34 +01:00
RootPanel . get ( APP_DIV ) . add ( mainPanel ) ;
Scheduler . get ( ) . scheduleDeferred ( new ScheduledCommand ( ) {
@Override
public void execute ( ) {
2020-11-19 15:19:27 +01:00
olMapMng = new OLMapManager ( mainPanel . getMapPanel ( ) . getElement ( ) . getId ( ) , layerManager . getLayerManagerBus ( ) ) ;
layerManager . setOlMap ( olMapMng . getOLOSMMap ( ) ) ;
mainPanel . setMap ( olMapMng . getOLOSMMap ( ) ) ;
updateSize ( ) ;
2020-10-27 16:04:34 +01:00
}
} ) ;
Window . addResizeHandler ( new ResizeHandler ( ) {
@Override
public void onResize ( ResizeEvent event ) {
2020-11-19 15:19:27 +01:00
updateSize ( ) ;
2020-10-27 16:04:34 +01:00
}
} ) ;
paramWmsRequest = Window . Location . getParameter ( GeoportalDataViewerConstants . GET_WMS_PARAMETER ) ;
2020-11-19 15:19:27 +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-19 15:19:27 +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-19 15:19:27 +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-12-02 17:52:06 +01:00
paramGeonaItemID = null ;
2020-11-19 15:19:27 +01:00
}
Scheduler . get ( ) . scheduleDeferred ( new ScheduledCommand ( ) {
2020-10-27 16:04:34 +01:00
2020-11-19 15:19:27 +01:00
@Override
public void execute ( ) {
GeoportalDataViewerServiceAsync . Util . getInstance ( ) . getGeoNaDataViewProfile ( new AsyncCallback < GeoNaDataViewerProfile > ( ) {
2020-10-27 16:04:34 +01:00
2020-11-19 15:19:27 +01:00
@Override
public void onFailure ( Throwable caught ) {
Window . alert ( caught . getMessage ( ) ) ;
}
2020-10-27 16:41:30 +01:00
@Override
2020-11-19 15:19:27 +01:00
public void onSuccess ( GeoNaDataViewerProfile 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 ( " 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 ;
}
GeoNaItemRef gir = new GeoNaItemRef ( new Long ( paramGeonaItemID ) , paramGeonaItemType ) ;
applicationBus . fireEvent ( new ShowDetailsEvent ( gir , null , null ) ) ;
}
2020-10-27 16:41:30 +01:00
}
} ) ;
2020-10-27 16:04:34 +01:00
}
2020-11-19 15:19:27 +01:00
} ) ;
2020-11-03 13:09:08 +01:00
bindEvents ( ) ;
}
2020-11-19 15:19:27 +01:00
/ * *
* Update window size .
* /
public void updateSize ( ) {
2020-11-03 13:09:08 +01:00
2020-11-19 15:19:27 +01:00
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 .
* /
2020-11-03 13:09:08 +01:00
private void bindEvents ( ) {
2020-11-19 15:19:27 +01:00
applicationBus . addHandler ( ShowDetailsEvent . TYPE , new ShowDetailsEventHandler ( ) {
2020-11-03 13:09:08 +01:00
@Override
public void onShowDetails ( ShowDetailsEvent showDetailsEvent ) {
2020-11-03 18:04:47 +01:00
GWT . log ( " Fired event: " + showDetailsEvent ) ;
2020-11-19 15:19:27 +01:00
Long id = showDetailsEvent . getGeonaID ( ) ;
if ( id = = null ) {
Window . alert ( " Item Id not found " ) ;
return ;
}
//TODO
boolean found = false ;
GWT . log ( " Product with id: " + id + " found? " + found ) ;
if ( ! found ) {
if ( showDetailsEvent . getGeonaItemType ( ) . equalsIgnoreCase ( " Concessione " ) ) {
GeoportalDataViewerServiceAsync . Util . getInstance ( ) . getConcessioneForId ( id , new AsyncCallback < ConcessioneDV > ( ) {
@Override
public void onFailure ( Throwable caught ) {
Window . alert ( caught . getMessage ( ) ) ;
mainPanel . hidePanelDetails ( ) ;
2020-11-05 14:05:14 +01:00
}
2020-11-19 15:19:27 +01:00
@Override
public void onSuccess ( ConcessioneDV concessioneDV ) {
GWT . log ( " Showing: " + concessioneDV ) ;
mainPanel . showAsDetails ( concessioneDV , showDetailsEvent . getGeonaItemRef ( ) ) ;
}
} ) ;
2020-11-03 13:09:08 +01:00
}
}
2020-11-19 15:19:27 +01:00
}
} ) ;
applicationBus . addHandler ( AddedLayerToMapEvent . TYPE , new AddedLayerToMapEventHandler ( ) {
@Override
public void onLayerRendered ( AddedLayerToMapEvent addedLayerToMapEvent ) {
GWT . log ( " Fired AddedLayerToMapEvent " + addedLayerToMapEvent . getLayerItem ( ) ) ;
2020-12-04 15:06:32 +01:00
//GeoportalDataViewerConstants.print("Fired AddedLayerToMapEvent "+addedLayerToMapEvent.getLayerItem());
2020-12-02 18:48:12 +01:00
try {
attempt = 0 ;
if ( paramGeonaItemID ! = null ) {
//waiting for record retrieved by service before calling the WFS
final int MAX_RETRY = 7 ;
Timer timer = new com . google . gwt . user . client . Timer ( ) {
@Override
public void run ( ) {
attempt + + ;
GWT . log ( " waiting got record tenative: " + attempt ) ;
RecordDV record = mainPanel . getDisplyedRecord ( ) ;
if ( record ! = null ) {
this . cancel ( ) ;
GWT . log ( " cancelled timer " ) ;
2020-12-04 15:06:32 +01:00
performWFSQueryOnCentroid ( record ) ;
2020-12-02 18:48:12 +01:00
}
if ( attempt > MAX_RETRY ) {
2020-12-11 09:51:20 +01:00
GWT . log ( " MAX_RETRY reached, cancelled timer " ) ;
2020-12-02 18:48:12 +01:00
this . cancel ( ) ;
}
}
} ;
timer . scheduleRepeating ( 1000 ) ;
2020-11-19 15:19:27 +01:00
}
2020-12-02 18:48:12 +01:00
} catch ( Exception e ) {
// TODO: handle exception
2020-11-19 15:19:27 +01:00
}
}
} ) ;
applicationBus . addHandler ( ZoomOutOverMinimumEvent . TYPE , new ZoomOutOverMinimumEventHandler ( ) {
@Override
public void onZoomOut ( ZoomOutOverMinimumEvent zoomOutEvent ) {
2020-11-03 13:09:08 +01:00
2020-11-19 15:19:27 +01:00
if ( mainPanel . getDisplyedRecord ( ) = = null & & ! olMapMng . isQueryPointActive ( ) ) {
olMapMng . hidePopInfo ( ) ;
}
}
} ) ;
applicationBus . addHandler ( ClosedViewDetailsEvent . TYPE , new ClosedViewDetailsEventHandler ( ) {
@Override
public void onClosed ( ClosedViewDetailsEvent closedViewDetailsEvent ) {
olMapMng . hidePopInfo ( ) ;
2020-11-03 13:09:08 +01:00
}
} ) ;
2020-10-27 16:04:34 +01:00
}
2020-12-02 18:48:12 +01:00
2020-12-04 15:06:32 +01:00
private void performWFSQueryOnCentroid ( RecordDV record ) {
if ( record ! = null ) {
2020-12-02 18:48:12 +01:00
GWT . log ( " record instanceof ConcessioneDV: " + ( record instanceof ConcessioneDV ) ) ;
2020-12-04 15:06:32 +01:00
//GeoportalDataViewerConstants.print("record instanceof ConcessioneDV: " +(record instanceof ConcessioneDV));
2020-12-02 18:48:12 +01:00
if ( record instanceof ConcessioneDV ) {
ConcessioneDV concessioneDV = ( ConcessioneDV ) record ;
Double x = concessioneDV . getCentroidLong ( ) ;
Double y = concessioneDV . getCentroidLat ( ) ;
2020-12-11 09:51:20 +01:00
GWT . log ( " X: " + x + " , Y: " + y ) ;
if ( x ! = null & & y ! = null ) {
Coordinate transfCoord = MapUtils . transformCoordiante ( new Coordinate ( x , y ) , GeoportalDataViewerConstants . EPSG_4326 , GeoportalDataViewerConstants . EPSG_3857 ) ;
GeoQuery select = olMapMng . toDataPointQuery ( transfCoord ) ;
2020-12-18 11:54:35 +01:00
GWT . log ( " GeoQuery: " + select ) ;
2020-12-11 09:51:20 +01:00
//GeoportalDataViewerConstants.print("fireEvent QueryDataEvent");
layerManager . getLayerManagerBus ( ) . fireEvent ( new QueryDataEvent ( select , transfCoord , record . getId ( ) , true ) ) ;
} else {
GeoportalDataViewerConstants . printJs ( " I cannot select the point one or both coordiantes are null. X: " + x + " , Y: " + y ) ;
}
2020-12-02 18:48:12 +01:00
}
}
}
2020-10-26 11:01:07 +01:00
2020-10-23 18:18:06 +02:00
}