From f1f6c42b08321efe6dc6456adf4881896865ed63 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 9 Dec 2020 12:45:30 +0100 Subject: [PATCH] fixed css and center to extent by reading BBOX from wmsLink --- .../client/gis/LightOpenLayerOSM.java | 8 ++- .../client/ui/images/ImageView.java | 10 ++++ .../client/ui/images/ImageView.ui.xml | 2 +- .../client/ui/images/ThumbnailImageView.java | 2 +- .../client/ui/map/MapView.java | 22 +++++--- .../concessioni/RelazioneScavoView.java | 2 +- .../server/ConvertToDataViewModel.java | 56 ++++++++++++++++++- 7 files changed, 88 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LightOpenLayerOSM.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LightOpenLayerOSM.java index 7f8115e..5637774 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LightOpenLayerOSM.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LightOpenLayerOSM.java @@ -2,6 +2,7 @@ package org.gcube.portlets.user.geoportaldataviewer.client.gis; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants; import org.gcube.portlets.user.geoportaldataviewer.client.resources.Images; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BoundsMap; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoQuery; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoQuery.TYPE; @@ -173,13 +174,18 @@ import ol.style.TextOptions; * * @param mapServerHost the map server host * @param layerName the layer name + * @param bbox * @return the image */ - public Image addWMSLayer(String mapServerHost, String layerName) { + public Image addWMSLayer(String mapServerHost, String layerName, BoundsMap bbox) { GWT.log("Adding wmsLayer with mapServerHost: "+mapServerHost+", layerName: "+layerName); ImageWmsParams imageWMSParams = OLFactory.createOptions(); imageWMSParams.setLayers(layerName); + //imageWMSParams.setSize(new Size(400,400)); + //imageWMSParams.setVersion("1.1.0"); +// if(bbox!=null) +// imageWMSParams.set("BBOX", bbox.getLowerLeftX()+","+bbox.getLowerLeftY()+","+bbox.getUpperRightX()+","+bbox.getUpperRightY()); ImageWmsOptions imageWMSOptions = OLFactory.createOptions(); imageWMSOptions.setUrl(mapServerHost); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/images/ImageView.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/images/ImageView.java index 2a3202f..2b3b6ec 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/images/ImageView.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/images/ImageView.java @@ -13,6 +13,7 @@ import com.github.gwtbootstrap.client.ui.Paragraph; import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.github.gwtbootstrap.client.ui.constants.IconType; import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Style.TextAlign; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.uibinder.client.UiBinder; @@ -40,6 +41,9 @@ public class ImageView extends Composite { @UiField Paragraph paragraph1; + @UiField + Paragraph paragraph2; + @UiField Button openImage; @@ -54,6 +58,12 @@ public class ImageView extends Composite { heading.setText(imageDV.getTitolo()); paragraph1.setText(imageDV.getDidascalia()); + paragraph1.getElement().getStyle().setTextAlign(TextAlign.LEFT); + + if(!showView && imageDV.getLicenseID()!=null) { + paragraph2.setVisible(true); + paragraph2.setText("ID Licenza: "+imageDV.getLicenseID()); + } if(imageDV.getListWsContent()!=null && imageDV.getListWsContent().size()>0) { latest = imageDV.getListWsContent().get(imageDV.getListWsContent().size()-1); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/images/ImageView.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/images/ImageView.ui.xml index 41f977d..a38389e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/images/ImageView.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/images/ImageView.ui.xml @@ -21,7 +21,7 @@ - + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/images/ThumbnailImageView.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/images/ThumbnailImageView.java index ff93e2f..9f45b7d 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/images/ThumbnailImageView.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/images/ThumbnailImageView.java @@ -45,7 +45,7 @@ public class ThumbnailImageView extends Composite { initWidget(uiBinder.createAndBindUi(this)); ImageView imageView = new ImageView(imageDV, showView, showOpen); - String title = StringUtil.ellipsize(imageDV.getTitolo(), 20); + String title = StringUtil.ellipsize(imageDV.getTitolo(), 25); imageView.setHeading(title); String didascalia = StringUtil.ellipsize(imageDV.getDidascalia(), 50); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/map/MapView.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/map/MapView.java index 2f71783..d3ad38e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/map/MapView.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/map/MapView.java @@ -128,10 +128,12 @@ import ol.OLFactory; @Override public void execute() { - olsm.addWMSLayer(mapServerHost, layerName); - - if (bbox != null) { + ExtentWrapped ew = null; + BoundsMap theBBOX = bbox; + + if (bbox != null) { + Coordinate lower = OLFactory.createCoordinate(bbox.getLowerLeftX(), bbox.getLowerLeftY()); Coordinate lowerCoord = MapUtils.transformCoordiante(lower, GeoportalDataViewerConstants.EPSG_4326, @@ -141,12 +143,14 @@ import ol.OLFactory; Coordinate upperCoord = MapUtils.transformCoordiante(upper, GeoportalDataViewerConstants.EPSG_4326, GeoportalDataViewerConstants.EPSG_3857); - ExtentWrapped ew = new ExtentWrapped(lowerCoord.getX(), lowerCoord.getY(), upperCoord.getX(), upperCoord.getY()); - //Coordinate center = ew.getCenter(); - //GWT.log("center: "+center); - //Coordinate invertCoordinate = new Coordinate(center.getY(), center.getX()); -// Size size = new Size(300, 300); - //olsm.getMap().getView().setCenter(invertCoordinate); + ew = new ExtentWrapped(lowerCoord.getX(), lowerCoord.getY(), upperCoord.getX(), upperCoord.getY()); + theBBOX = new BoundsMap(lowerCoord.getX(), lowerCoord.getY(), upperCoord.getX(), upperCoord.getY(), null); + } + + olsm.addWMSLayer(mapServerHost, layerName, theBBOX); + + if (ew != null) { + olsm.getMap().getView().fit(ew); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/products/concessioni/RelazioneScavoView.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/products/concessioni/RelazioneScavoView.java index 598eedc..d9eef04 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/products/concessioni/RelazioneScavoView.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/products/concessioni/RelazioneScavoView.java @@ -35,7 +35,7 @@ public class RelazioneScavoView extends Composite { abstractParagraph.setText(relazioneScavoDV.getAbstractSection()); //customTable.addNextKeyValue("Created", relazioneScavoDV.getCreationTime()); - customTable.addNextKeyValue("ID Licenza", relazioneScavoDV.getLicenseID()); + //customTable.addNextKeyValue("ID Licenza", relazioneScavoDV.getLicenseID()); customTable.addNextKeyValues("Responsabili", relazioneScavoDV.getResponsabili(), GeoportalDataViewerConstants.NEW_LINE_BR); relazioneScavoPanel.add(customTable); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/ConvertToDataViewModel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/ConvertToDataViewModel.java index abb5b05..236321b 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/ConvertToDataViewModel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/ConvertToDataViewModel.java @@ -306,10 +306,16 @@ public class ConvertToDataViewModel { String wmsLink = layerConcessione.getWmsLink(); String layerName = null; + BoundsMap bounds = null; //reading layer name from wmsLink + //string bbox if(wmsLink!=null) { layerName = URLParserUtil.extractValueOfParameterFromURL("layers", wmsLink); + String bbox = URLParserUtil.extractValueOfParameterFromURL("bbox", wmsLink); + String wmsVersion = URLParserUtil.extractValueOfParameterFromURL("version", wmsLink); + bounds = toBoundMap(wmsVersion, bbox, ","); + LOG.debug("Built bounds from wmsLInk: "+bounds); } if(layerName!=null) @@ -322,7 +328,10 @@ public class ConvertToDataViewModel { theLayerConessione.setLayerID(layerConcessione.getLayerID()); theLayerConessione.setLayerUUID(layerConcessione.getLayerUUID()); theLayerConessione.setAuthors(layerConcessione.getAuthors()); - BoundsMap bounds = toBoundMap(layerConcessione.getBbox()); + + if(bounds==null) + bounds = toBoundMap(layerConcessione.getBbox()); + theLayerConessione.setBbox(bounds); theLayerConessione.setCreationTime(toDateFormatString(layerConcessione.getCreationTime())); theLayerConessione.setId(layerConcessione.getId()); @@ -378,5 +387,50 @@ public class ConvertToDataViewModel { return new BoundsMap(bbox.getMinLong(), bbox.getMinLat(), bbox.getMaxLong(), bbox.getMaxLat(), null); } + + + /** + * To bound map. + * + * @param bbox the bbox + * @return the bounds map + */ + public static BoundsMap toBoundMap(String wmsVersion, String bbox, String separator) { + + if (bbox == null) + return null; + + if(wmsVersion==null) + return null; + + if(separator==null) + separator = ","; + + try { + + String[] bboxArr = bbox.split(separator); + + if(wmsVersion.startsWith("1.3")) { + //is 1.3.x + return new BoundsMap(toDouble(bboxArr[1]), toDouble(bboxArr[0]), toDouble(bboxArr[3]), toDouble(bboxArr[2]), wmsVersion); + }else { + //should be 1.1.X + return new BoundsMap(toDouble(bboxArr[0]), toDouble(bboxArr[1]), toDouble(bboxArr[2]), toDouble(bboxArr[3]), wmsVersion); + } + }catch (Exception e) { + LOG.warn("Error on creating Bounds for wmsVersion "+wmsVersion+" and bbox "+bbox+" : ",e); + return null; + } + } + + public static Double toDouble(String value) { + try { + return Double.parseDouble(value); + }catch (Exception e) { + LOG.warn("Error on parsing "+value+" as double: ",e); + return null; + } + } + }