]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.maps/src/org/simantics/maps/osm/OSMGetMapQuery.java
Share some projects for Simantics District
[simantics/district.git] / org.simantics.district.maps / src / org / simantics / maps / osm / OSMGetMapQuery.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.osm;
13
14 import java.awt.geom.Rectangle2D;
15 import java.net.MalformedURLException;
16
17 /**
18  * @author Tuukka Lehtonen
19  */
20 public class OSMGetMapQuery {
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 OSMGetMapQuery(int width, int height, Rectangle2D bbox,
37             String format, String... layers) throws MalformedURLException {
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 static String getTileNumber(final double lat, final double lon,
58             final int zoom) {
59         int xtile = (int) Math.floor((lon + 180) / 360 * (1 << zoom));
60         int ytile = (int) Math.floor((1 - Math.log(
61                 Math.tan(Math.toRadians(lat))
62                 + 1 / Math.cos(Math.toRadians(lat)))
63                 / Math.PI)
64                 / 2 * (1 << zoom));
65         return ("" + zoom + "/" + xtile + "/" + ytile+".png");
66     }
67
68     public String toString() {
69         return getTileNumber(bbox.getMinX(), bbox.getMinY(), 16);
70     }
71
72 }