You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
175 lines
6.1 KiB
Java
175 lines
6.1 KiB
Java
package org.gcube.portlets.user.geoportaldataviewer.client;
|
|
|
|
import java.util.List;
|
|
|
|
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.OpenLayerOSM;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.ui.GeonaDataViewMainPanel;
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil;
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.ProductType;
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.FeatureRow;
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.products.ConcessioneDV;
|
|
|
|
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.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.RootPanel;
|
|
|
|
// TODO: Auto-generated Javadoc
|
|
/**
|
|
* 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 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;
|
|
|
|
/** The param layer title. */
|
|
private String paramLayerTitle;
|
|
|
|
private HandlerManager eventBus = new HandlerManager("");
|
|
|
|
/** The layer manager. */
|
|
private LayerManager layerManager = new LayerManager(eventBus);
|
|
|
|
//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);
|
|
|
|
}
|
|
});
|
|
|
|
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);
|
|
paramUUID = Window.Location.getParameter(GeoportalDataViewerConstants.GET_UUID_PARAMETER);
|
|
paramLayerTitle = Window.Location.getParameter(GeoportalDataViewerConstants.GET_LAYER_TITLE);
|
|
GWT.log(GeoportalDataViewerConstants.GET_WMS_PARAMETER + " = " + paramWmsRequest);
|
|
GWT.log(GeoportalDataViewerConstants.GET_UUID_PARAMETER + " = " + paramUUID);
|
|
GWT.log(GeoportalDataViewerConstants.GET_LAYER_TITLE + " = " + paramLayerTitle);
|
|
|
|
if (paramWmsRequest != null && !paramWmsRequest.isEmpty()) {
|
|
|
|
try {
|
|
//wmsRequestConverter.addRequestToGisViewer(paramWmsRequest, paramLayerTitle, paramUUID);
|
|
//FIND BASE URL
|
|
int indexStart = paramWmsRequest.indexOf("?");
|
|
String url;
|
|
if(indexStart>=0){
|
|
url = paramWmsRequest.substring(0, indexStart); //get only base uri
|
|
url = url.trim(); //string trim
|
|
}else{
|
|
Window.alert("Bad wms request '?' not found!");
|
|
// throw new Exception("Bad server request '?' not found!");
|
|
}
|
|
|
|
String layerName = URLUtil.getValueOfParameter("layers", paramWmsRequest);
|
|
String displayName = paramLayerTitle==null || paramLayerTitle.isEmpty()?layerName:paramLayerTitle;
|
|
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
|
|
|
@Override
|
|
public void execute() {
|
|
layerManager.addLayerByWmsRequest(displayName, layerName, paramWmsRequest, false, false, paramUUID, true);
|
|
}
|
|
});
|
|
|
|
} catch (Exception e) {
|
|
GWT.log("An error occurred on adding wmsrequest :" + paramWmsRequest, e);
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
bindEvents();
|
|
}
|
|
|
|
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<String> productIds = fRow.getMapProperties().get("product_id");
|
|
if(productIds!=null && productIds.size()>0) {
|
|
long id = Long.parseLong(productIds.get(0));
|
|
GeoportalDataViewerServiceAsync.Util.getInstance().getConcessioneForId(id, new AsyncCallback<ConcessioneDV>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
GWT.log("QUI: "+caught.toString());
|
|
Window.alert(caught.getMessage());
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(ConcessioneDV result) {
|
|
GWT.log("Concessione is: "+result);
|
|
mainPanel.addNewTab(result);
|
|
|
|
}
|
|
});
|
|
}else
|
|
Window.alert("No product id found");
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
}
|