]> gerrit.simantics Code Review - simantics/district.git/blob - 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
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.maps.wms;
13
14 import java.awt.geom.Rectangle2D;
15 import java.net.MalformedURLException;
16
17 /**
18  * @author Tuukka Lehtonen
19  */
20 public class WMSGetMapQuery {
21
22     String      srs = "EPSG:4326";
23
24     int         width;
25
26     int         height;
27
28     Rectangle2D bbox;
29
30     String[]    styles;
31
32     String[]    layers;
33
34     String      format;
35
36     public WMSGetMapQuery(int width, int height, Rectangle2D bbox, String format, String... layers) throws MalformedURLException {
37         super();
38         this.width = width;
39         this.height = height;
40         this.bbox = bbox;
41         this.format = format;
42         this.layers = layers;
43     }
44
45     public void setSpatialReferenceSystem(String srs) {
46         this.srs = srs;
47     }
48
49     public void setStyles(String... styles) {
50         this.styles = styles;
51     }
52
53     public void setLayers(String... layers) {
54         this.layers = layers;
55     }
56
57     public String toString() {
58         if (layers.length == 0)
59             throw new IllegalStateException("0 layers defined");
60
61         StringBuilder sb = new StringBuilder(200);
62
63         // request=GetMap&layers=global_mosaic&srs=EPSG:4326&width=512&height=512
64         // &bbox=-180,-38,-52,90
65         // &format=image/jpeg&version=1.1.1&styles=visual
66
67         sb.append("request=GetMap");
68         sb.append("&service=WMS");
69         sb.append("&layers=");
70         sb.append(layers[0]);
71         for (int i = 1; i < layers.length; ++i) {
72             sb.append(',');
73             sb.append(layers[i]);
74         }
75         sb.append("&srs=");
76         sb.append(srs);
77         sb.append("&width=");
78         sb.append(width);
79         sb.append("&height=");
80         sb.append(height);
81         sb.append("&bbox=");
82         sb.append(bbox.getMinX());
83         sb.append(',');
84         sb.append(bbox.getMinY());
85         sb.append(',');
86         sb.append(bbox.getMaxX());
87         sb.append(',');
88         sb.append(bbox.getMaxY());
89         sb.append("&format=");
90         sb.append(format);
91         sb.append("&version=1.1.1");
92         sb.append("&styles=");
93         if (styles != null && styles.length > 0) {
94             sb.append(styles[0]);
95             for (int i = 1; i < layers.length; ++i) {
96                 sb.append(',');
97                 sb.append(layers[i]);
98             }
99         }
100
101         return sb.toString();
102     }
103
104 }