X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.maps%2Fsrc%2Forg%2Fsimantics%2Fmaps%2Fosm%2FOSMGetMapQuery.java;fp=org.simantics.district.maps%2Fsrc%2Forg%2Fsimantics%2Fmaps%2Fosm%2FOSMGetMapQuery.java;h=02dd42f984fe459e1ca8ceb7c641e098ae4c7060;hb=e9f74f09e0cedb603c0b4de9e542de8dd64a5ce3;hp=0000000000000000000000000000000000000000;hpb=16ee01dc5a40981c58fd5b478b89552e5814e8bb;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.maps/src/org/simantics/maps/osm/OSMGetMapQuery.java b/org.simantics.district.maps/src/org/simantics/maps/osm/OSMGetMapQuery.java new file mode 100644 index 00000000..02dd42f9 --- /dev/null +++ b/org.simantics.district.maps/src/org/simantics/maps/osm/OSMGetMapQuery.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * 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); + } + +}