package org.gcube.portlets.user.geoportaldataviewer.client; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.LayerType; import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerOSM; import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoInformationForWMSRequest; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.ZAxis; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; /** * The Class LayerManager. * * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * * Oct 27, 2020 */ public class LayerManager { /** The ol map. */ private OpenLayerOSM olMap; /** The layer items. */ private List layerItems = new ArrayList(); /** * Instantiates a new layer manager. * * @param olMap the ol map */ public LayerManager(OpenLayerOSM olMap) { this.olMap = olMap; } /** * Adds the layer by wms. * * @param layerTitle the layer title * @param layerName the layer name * @param wmsRequest the wms request * @param isBase the is base * @param UUID the uuid */ public void addLayerByWms(String layerTitle, String layerName, String wmsRequest, boolean isBase, String UUID) { boolean displayInLayerSwitcher = false; if(isBase) displayInLayerSwitcher = true; addLayerByWmsRequest(layerTitle, layerName, wmsRequest, isBase, displayInLayerSwitcher, UUID, true); } /** * Adds the layer by wms request. * * @param layerTitle the layer title * @param layerName the layer name * @param wmsRequest the wms request * @param isBase the is base * @param displayInLayerSwitcher the display in layer switcher * @param UUID the uuid * @param onTop the on top */ public void addLayerByWmsRequest(final String layerTitle, final String layerName, final String wmsRequest, final boolean isBase,final boolean displayInLayerSwitcher, final String UUID, final boolean onTop) { // final LayoutContainer westPanel = (LayoutContainer) layersPanel.getParent(); // // if(layersPanel.getLayerItems().size()==0) // westPanel.mask("Adding..."+layerName, "x-mask-loading"); // else // layersPanel.mask("Adding..."+layerName, "x-mask-loading"); final LayerType featureType = isBase?LayerType.RASTER_BASELAYER:LayerType.FEATURE_TYPE; // Info.display("Adding Layer", layerName); GeoportalDataViewerServiceAsync.Util.getInstance().parseWmsRequest(wmsRequest, layerName, new AsyncCallback() { @Override public void onFailure(Throwable caught) { Window.alert(caught.getMessage()); } @Override public void onSuccess(GeoInformationForWMSRequest result) { GWT.log("Add Layer By WMS: "+result.getMapWMSNoStandard() + ", and isNCWMS? "+result.isNcWMS()); addLayerByWms(featureType, layerTitle, layerName, result.getWmsRequest(), result.getBaseWmsServiceHost(), true, isBase, displayInLayerSwitcher, (ArrayList) result.getStyles().getGeoStyles(), result.getWmsRequest(), false, result.getMapWMSNoStandard(), result.isNcWMS(), UUID, result.getZAxis()); } }); } /** * Adds the layer by wms. * * @param layerType the layer type * @param layerTitle the layer title * @param layerName the layer name * @param layerURL the layer URL * @param mapServerHost the map server host * @param isExternal the is external * @param isBase the is base * @param displayInLayerSwitcher the display in layer switcher * @param styles the styles * @param serverWmsRequest the server wms request * @param onTop the on top * @param wmsNotStandardParams the wms not standard params * @param isNcWms the is nc wms * @param UUID the uuid * @param zAxis the z axis */ private void addLayerByWms(LayerType layerType, String layerTitle, String layerName, String layerURL, String mapServerHost, boolean isExternal, boolean isBase, boolean displayInLayerSwitcher, ArrayList styles, String serverWmsRequest, boolean onTop, HashMap wmsNotStandardParams, boolean isNcWms, String UUID, ZAxis zAxis) { // GWT.log("Add addLayerByWms 1"); LayerItem l = new LayerItem(); l.setBaseLayer(isBase); l.setTitle(layerTitle); l.setName(layerName); l.setUrl(layerURL); l.setMapServerHost(mapServerHost); //l.setExternal(isExternal); l.setOpacity(1d); l.setBuffer(2); l.setServerWmsRequest(serverWmsRequest); l.setWmsNotStandardParams(wmsNotStandardParams); l.setNcWms(isNcWms); l.setUUID(UUID); l.setZAxis(zAxis); switch (layerType) { //TODO IMPLEMENT THIS CASE case RASTER_BASELAYER: // l.setHasLegend(false); l.setBaseLayer(true); l.setTrasparent(false); l.setClickData(false); break; case FEATURE_TYPE: //CASE FEATURE TYPE l.setBaseLayer(false); l.setClickData(true); l.setTrasparent(true); break; } GWT.log("styles "+styles); if(styles!=null && styles.size()>0){ l.setHasLegend(true); l.setDefaultStyle(styles.get(0)); l.setStyle(styles.get(0)); l.setStyles(styles); }else{ String style = URLUtil.getValueOfParameter("styles", serverWmsRequest); if(style!=null){ //CASE OF STYLE =""; //TENTATIVE TO GET LEGEND l.setHasLegend(true); } } GWT.log("Built layer: "+l); layerItems.add(l); olMap.addWMSLayer(l.getMapServerHost(), layerName); // openLayersMap.addLayerItemByWms(l, displayInLayerSwitcher); // layersPanel.addLayerItems(layerItems, onTop); // layersPanel.updateLayersOrder(); } }