--- /dev/null
+/*******************************************************************************
+ * 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.osm;
+
+import java.awt.geom.Rectangle2D;
+import java.net.MalformedURLException;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class OSMGetMapQuery {
+
+ String srs = "EPSG:4326";
+
+ int width;
+
+ int height;
+
+ Rectangle2D bbox;
+
+ String[] styles;
+
+ String[] layers;
+
+ String format;
+
+ public OSMGetMapQuery(int width, int height, Rectangle2D bbox,
+ String format, String... layers) throws MalformedURLException {
+ 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 static String getTileNumber(final double lat, final double lon,
+ final int zoom) {
+ int xtile = (int) Math.floor((lon + 180) / 360 * (1 << zoom));
+ int ytile = (int) Math.floor((1 - Math.log(
+ Math.tan(Math.toRadians(lat))
+ + 1 / Math.cos(Math.toRadians(lat)))
+ / Math.PI)
+ / 2 * (1 << zoom));
+ return ("" + zoom + "/" + xtile + "/" + ytile+".png");
+ }
+
+ public String toString() {
+ return getTileNumber(bbox.getMinX(), bbox.getMinY(), 16);
+ }
+
+}