X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.maps%2Fsrc%2Forg%2Fsimantics%2Fmaps%2Fwms%2FWMSGetMapQuery.java;fp=org.simantics.district.maps%2Fsrc%2Forg%2Fsimantics%2Fmaps%2Fwms%2FWMSGetMapQuery.java;h=dc65a535d17df8eb64d65eed3c22cb2312795552;hb=e9f74f09e0cedb603c0b4de9e542de8dd64a5ce3;hp=0000000000000000000000000000000000000000;hpb=16ee01dc5a40981c58fd5b478b89552e5814e8bb;p=simantics%2Fdistrict.git 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 index 00000000..dc65a535 --- /dev/null +++ b/org.simantics.district.maps/src/org/simantics/maps/wms/WMSGetMapQuery.java @@ -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(); + } + +}