]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.maps/src/org/simantics/maps/wms/WMSGetMapQuery.java
Share some projects for Simantics District
[simantics/district.git] / org.simantics.district.maps / src / org / simantics / maps / wms / WMSGetMapQuery.java
diff --git a/org.simantics.district.maps/src/org/simantics/maps/wms/WMSGetMapQuery.java b/org.simantics.district.maps/src/org/simantics/maps/wms/WMSGetMapQuery.java
new file mode 100644 (file)
index 0000000..dc65a53
--- /dev/null
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.maps.wms;
+
+import java.awt.geom.Rectangle2D;
+import java.net.MalformedURLException;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class WMSGetMapQuery {
+
+    String      srs = "EPSG:4326";
+
+    int         width;
+
+    int         height;
+
+    Rectangle2D bbox;
+
+    String[]    styles;
+
+    String[]    layers;
+
+    String      format;
+
+    public WMSGetMapQuery(int width, int height, Rectangle2D bbox, String format, String... layers) throws MalformedURLException {
+        super();
+        this.width = width;
+        this.height = height;
+        this.bbox = bbox;
+        this.format = format;
+        this.layers = layers;
+    }
+
+    public void setSpatialReferenceSystem(String srs) {
+        this.srs = srs;
+    }
+
+    public void setStyles(String... styles) {
+        this.styles = styles;
+    }
+
+    public void setLayers(String... layers) {
+        this.layers = layers;
+    }
+
+    public String toString() {
+        if (layers.length == 0)
+            throw new IllegalStateException("0 layers defined");
+
+        StringBuilder sb = new StringBuilder(200);
+
+        // request=GetMap&layers=global_mosaic&srs=EPSG:4326&width=512&height=512
+        // &bbox=-180,-38,-52,90
+        // &format=image/jpeg&version=1.1.1&styles=visual
+
+        sb.append("request=GetMap");
+        sb.append("&service=WMS");
+        sb.append("&layers=");
+        sb.append(layers[0]);
+        for (int i = 1; i < layers.length; ++i) {
+            sb.append(',');
+            sb.append(layers[i]);
+        }
+        sb.append("&srs=");
+        sb.append(srs);
+        sb.append("&width=");
+        sb.append(width);
+        sb.append("&height=");
+        sb.append(height);
+        sb.append("&bbox=");
+        sb.append(bbox.getMinX());
+        sb.append(',');
+        sb.append(bbox.getMinY());
+        sb.append(',');
+        sb.append(bbox.getMaxX());
+        sb.append(',');
+        sb.append(bbox.getMaxY());
+        sb.append("&format=");
+        sb.append(format);
+        sb.append("&version=1.1.1");
+        sb.append("&styles=");
+        if (styles != null && styles.length > 0) {
+            sb.append(styles[0]);
+            for (int i = 1; i < layers.length; ++i) {
+                sb.append(',');
+                sb.append(layers[i]);
+            }
+        }
+
+        return sb.toString();
+    }
+
+}