[PATCH] handler for wms theme legend

Wald Commits scm-commit at wald.intevation.org
Wed Jan 20 19:07:04 CET 2021


# HG changeset patch
# User dnt_bjoernsen <d.tironi at bjoernsen.de>
# Date 1611166017 -3600
#      Wed Jan 20 19:06:57 2021 +0100
# Node ID b2768f367dfff4c57354426ba9886bd102caacd2
# Parent  94362af5928e72164dfdb0ae46593252728b8140
handler for wms theme legend

diff -r 94362af5928e -r b2768f367dff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java	Wed Jan 20 18:30:26 2021 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java	Wed Jan 20 19:06:57 2021 +0100
@@ -75,9 +75,9 @@
 
 	private Canvas createLegendGraphicsRow(final AttributedTheme at) {
 		final Label label = new Label(at.getDescription());
-		final Widget img = createLegendGraphics(at);
+		final HLayout row = new HLayout();
+		final Widget img = createLegendGraphics(row ,at);
 
-		final HLayout row = new HLayout();
 		row.addMember(label);
 		row.addMember(img);
 
@@ -105,7 +105,7 @@
 		row.setWidth(width);
 	}
 
-	private Widget createLegendGraphics(final AttributedTheme at) {
+	private Widget createLegendGraphics(HLayout row, final AttributedTheme at) {
 
 		final String legend = at.getAttr("legend");
 		// TEST: final Image img = new Image("/images/FLYS_Donau.png"); (funktioniert!),
@@ -115,17 +115,7 @@
 			final String imgUrl = URL.encode(GWT.getHostPageBaseURL() + "images/wms_legend/" + legend);
 
 			final Image image = new Image(imgUrl);
-			final int imageWidth = image.getWidth();
-			final int imageHeight = image.getHeight();
-			final double widthPercent = imageWidth / 400.;
-
-			// removing the limit of 150px height (legend can have an infinite height now,
-			// as long as the width is less/eq 400px; if the width is >400,
-			// the legend will be scaled to 400px width; the ratio will be kept)
-
-			// final double heightPercent = imageHeight / 150.;
-			if (widthPercent > 1)// || heightPercent > 1) {
-				image.setSize((int) (imageWidth / widthPercent) + "px", (int) (imageHeight / widthPercent) + "px");
+			new MyWMSLoadHandler(row, image);
 
 			return image;
 		}
diff -r 94362af5928e -r b2768f367dff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/MyWMSLoadHandler.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/MyWMSLoadHandler.java	Wed Jan 20 19:06:57 2021 +0100
@@ -0,0 +1,44 @@
+package org.dive4elements.river.client.client.ui.map;
+
+import com.google.gwt.event.dom.client.LoadEvent;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.user.client.ui.Image;
+import com.smartgwt.client.widgets.layout.HLayout;
+
+public class MyWMSLoadHandler implements com.google.gwt.event.dom.client.LoadHandler {
+	private Image m_image;
+	private HLayout m_row;
+	private HandlerRegistration m_handelReg;
+
+	public MyWMSLoadHandler(HLayout row, Image image) {
+		m_image = image;
+		m_row = row;
+		m_handelReg = image.addLoadHandler(this);
+	}
+
+	@Override
+	public void onLoad(LoadEvent event) {
+		setDimensions( );
+		if (m_handelReg != null)
+			m_handelReg.removeHandler();
+	}
+
+	private void setDimensions() {
+		final int imageWidth = m_image.getWidth();
+		final int imageHeight = m_image.getHeight();
+		final double widthPercent = imageWidth / 400.;
+
+		// removing the limit of 150px height (legend can have an infinite height now,
+		// as long as the width is less/eq 400px; if the width is >400,
+		// the legend will be scaled to 400px width; the ratio will be kept)
+
+		// final double heightPercent = imageHeight / 150.;
+		if (widthPercent > 1)// || heightPercent > 1) {
+			m_image.setSize((int) (imageWidth / widthPercent) + "px", (int) (imageHeight / widthPercent) + "px");
+		
+		
+		final int minHeight = 30;
+		m_row.setHeight( m_image.getHeight() < minHeight ? minHeight :  m_image.getHeight());
+		m_row.setWidth( m_image.getWidth());
+	}
+}
\ No newline at end of file


More information about the Dive4Elements-commits mailing list