diff --git a/vtm-android-example/AndroidManifest.xml b/vtm-android-example/AndroidManifest.xml
index 1b8a0e84..2c0c14c8 100644
--- a/vtm-android-example/AndroidManifest.xml
+++ b/vtm-android-example/AndroidManifest.xml
@@ -67,6 +67,11 @@
android:name="org.oscim.android.test.JeoIndoorMapActivity"
android:label="@string/title_activity_map" >
+
+
+
\ No newline at end of file
diff --git a/vtm-android-example/build.gradle b/vtm-android-example/build.gradle
index c94d62e1..f2cd45f0 100644
--- a/vtm-android-example/build.gradle
+++ b/vtm-android-example/build.gradle
@@ -12,6 +12,7 @@ apply plugin: 'android'
dependencies {
compile project(':vtm-android')
compile project(':vtm-jeo')
+ compile project(':vtm-extras')
compile project(':vtm-themes')
}
@@ -31,9 +32,15 @@ android {
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
- packagingOptions {
- exclude 'META-INF/services/org.jeo.data.Driver'
+ // remove duplicates
+ packagingOptions {
+ exclude 'META-INF/services/org.jeo.data.Driver'
+ exclude 'META-INF/LICENSE'
+ exclude 'META-INF/NOTICE'
}
+
+ // ignore deprecated
+ lintOptions.abortOnError false
}
// Including configurations into Eclipse
diff --git a/vtm-android-example/src/org/oscim/android/test/OsmJsonMapActivity.java b/vtm-android-example/src/org/oscim/android/test/OsmJsonMapActivity.java
new file mode 100644
index 00000000..e417321e
--- /dev/null
+++ b/vtm-android-example/src/org/oscim/android/test/OsmJsonMapActivity.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.android.test;
+
+import org.oscim.android.MapActivity;
+import org.oscim.android.MapView;
+import org.oscim.layers.TileGridLayer;
+import org.oscim.layers.tile.bitmap.BitmapTileLayer;
+import org.oscim.layers.tile.vector.BuildingLayer;
+import org.oscim.layers.tile.vector.VectorTileLayer;
+import org.oscim.renderer.MapRenderer;
+import org.oscim.theme.IRenderTheme;
+import org.oscim.theme.ThemeLoader;
+import org.oscim.theme.VtmThemes;
+import org.oscim.tiling.TileSource;
+import org.oscim.tiling.source.bitmap.DefaultSources.StamenToner;
+import org.oscim.tiling.source.geojson.HighroadJsonTileSource;
+import org.oscim.tiling.source.geojson.OsmBuildingJsonTileSource;
+import org.oscim.tiling.source.geojson.OsmLanduseJsonTileSource;
+import org.oscim.tiling.source.geojson.OsmWaterJsonTileSource;
+
+import android.os.Bundle;
+
+public class OsmJsonMapActivity extends MapActivity {
+
+ MapView mMapView;
+ VectorTileLayer mBaseLayer;
+ TileSource mTileSource;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_map);
+
+ mMapView = (MapView) findViewById(R.id.mapView);
+ registerMapView(mMapView);
+
+ mTileSource = new OsmWaterJsonTileSource();
+
+ mMap.setBackgroundMap(new BitmapTileLayer(mMap, new StamenToner()));
+ mMap.layers().add(new TileGridLayer(mMap));
+
+ IRenderTheme theme = ThemeLoader.load(VtmThemes.OSMARENDER);
+ MapRenderer.setBackgroundColor(theme.getMapBackground());
+
+ VectorTileLayer l;
+ l = new VectorTileLayer(mMap, new OsmLanduseJsonTileSource());
+ l.setRenderTheme(theme);
+ l.tileRenderer().setOverdrawColor(0);
+ mMap.layers().add(l);
+
+ l = new VectorTileLayer(mMap, new HighroadJsonTileSource());
+ l.setRenderTheme(theme);
+ l.tileRenderer().setOverdrawColor(0);
+ mMap.layers().add(l);
+
+ l = new VectorTileLayer(mMap, new OsmBuildingJsonTileSource());
+ l.setRenderTheme(theme);
+ l.tileRenderer().setOverdrawColor(0);
+ mMap.layers().add(l);
+ mMap.layers().add(new BuildingLayer(mMap, l));
+
+ mMap.setMapPosition(53.08, 8.83, Math.pow(2, 16));
+ }
+}
diff --git a/vtm-android-example/src/org/oscim/android/test/Samples.java b/vtm-android-example/src/org/oscim/android/test/Samples.java
index c63d89dd..8312f753 100644
--- a/vtm-android-example/src/org/oscim/android/test/Samples.java
+++ b/vtm-android-example/src/org/oscim/android/test/Samples.java
@@ -48,6 +48,7 @@ public class Samples extends Activity {
linearLayout.addView(createButton(ThemeStylerActivity.class));
linearLayout.addView(createButton(S3DBMapActivity.class));
linearLayout.addView(createButton(JeoIndoorMapActivity.class));
+ linearLayout.addView(createButton(OsmJsonMapActivity.class));
}
private Button createButton(final Class> clazz) {
diff --git a/vtm-extras/src/org/oscim/tiling/source/geojson/GeoJsonTileDecoder.java b/vtm-extras/src/org/oscim/tiling/source/geojson/GeoJsonTileDecoder.java
new file mode 100644
index 00000000..341bd577
--- /dev/null
+++ b/vtm-extras/src/org/oscim/tiling/source/geojson/GeoJsonTileDecoder.java
@@ -0,0 +1,357 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source.geojson;
+
+import static com.fasterxml.jackson.core.JsonToken.END_ARRAY;
+import static com.fasterxml.jackson.core.JsonToken.END_OBJECT;
+import static com.fasterxml.jackson.core.JsonToken.FIELD_NAME;
+import static com.fasterxml.jackson.core.JsonToken.START_ARRAY;
+import static com.fasterxml.jackson.core.JsonToken.START_OBJECT;
+import static com.fasterxml.jackson.core.JsonToken.VALUE_NUMBER_FLOAT;
+import static com.fasterxml.jackson.core.JsonToken.VALUE_NUMBER_INT;
+import static com.fasterxml.jackson.core.JsonToken.VALUE_STRING;
+import static org.oscim.core.MercatorProjection.latitudeToY;
+import static org.oscim.core.MercatorProjection.longitudeToX;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.LinkedHashMap;
+import java.util.zip.GZIPInputStream;
+
+import org.oscim.core.GeometryBuffer.GeometryType;
+import org.oscim.core.MapElement;
+import org.oscim.core.Tile;
+import org.oscim.tiling.ITileDataSink;
+import org.oscim.tiling.source.ITileDecoder;
+import org.oscim.utils.ArrayUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+public class GeoJsonTileDecoder implements ITileDecoder {
+ static final Logger log = LoggerFactory.getLogger(GeoJsonTileDecoder.class);
+
+ private final MapElement mMapElement;
+ private final GeoJsonTileSource mTileSource;
+ private final LinkedHashMap mTagMap;
+ private final JsonFactory mJsonFactory;
+
+ private final static char[] FIELD_FEATURES = "features".toCharArray();
+ private final static char[] FIELD_GEOMETRY = "geometry".toCharArray();
+ private final static char[] FIELD_PROPERTIES = "properties".toCharArray();
+ private final static char[] FIELD_COORDINATES = "coordinates".toCharArray();
+ private final static char[] FIELD_TYPE = "type".toCharArray();
+
+ private final static char[] LINETRING = "LineString".toCharArray();
+ private final static char[] POLYGON = "Polygon".toCharArray();
+ private final static char[] POINT = "Point".toCharArray();
+ private final static char[] MULTI_LINESTRING = "MultiLineString".toCharArray();
+ private final static char[] MULTI_POLYGON = "MultiPolygon".toCharArray();
+ private final static char[] MULTI_POINT = "MultiPoint".toCharArray();
+
+ private ITileDataSink mTileDataSink;
+
+ private double mTileY, mTileX, mTileScale;
+
+ public GeoJsonTileDecoder(GeoJsonTileSource tileSource) {
+ mTileSource = tileSource;
+ mTagMap = new LinkedHashMap();
+ mJsonFactory = new JsonFactory();
+
+ mMapElement = new MapElement();
+ mMapElement.layer = 5;
+ }
+
+ @Override
+ public boolean decode(Tile tile, ITileDataSink sink, InputStream is) throws IOException {
+ mTileDataSink = sink;
+ mTileScale = 1 << tile.zoomLevel;
+ mTileX = tile.tileX / mTileScale;
+ mTileY = tile.tileY / mTileScale;
+ mTileScale *= Tile.SIZE;
+
+ is = new GZIPInputStream(is);
+
+ JsonParser jp = mJsonFactory.createParser(new InputStreamReader(is));
+
+ for (JsonToken t; (t = jp.nextToken()) != null;) {
+
+ if (t == FIELD_NAME) {
+
+ if (match(jp, FIELD_FEATURES)) {
+ if (jp.nextToken() != START_ARRAY)
+ continue;
+
+ while ((t = jp.nextToken()) != null) {
+ if (t == START_OBJECT)
+ parseFeature(jp);
+
+ if (t == END_ARRAY)
+ break;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ private void parseFeature(JsonParser jp)
+ throws JsonParseException, IOException {
+
+ mMapElement.clear();
+ mMapElement.tags.clear();
+ mTagMap.clear();
+
+ for (JsonToken t; (t = jp.nextToken()) != null;) {
+
+ if (t == FIELD_NAME) {
+
+ if (match(jp, FIELD_GEOMETRY)) {
+ if (jp.nextToken() == START_OBJECT)
+ parseGeometry(jp);
+ }
+
+ if (match(jp, FIELD_PROPERTIES)) {
+ if (jp.nextToken() == START_OBJECT)
+ parseProperties(jp);
+ }
+ continue;
+ }
+ if (t == END_OBJECT)
+ break;
+ }
+
+ //add tag information
+ mTileSource.decodeTags(mMapElement, mTagMap);
+ if (mMapElement.tags.numTags == 0)
+ return;
+
+ mTileSource.postGeomHook(mMapElement);
+
+ if (mMapElement.type == GeometryType.NONE)
+ return;
+
+ //process this element
+ mTileDataSink.process(mMapElement);
+ }
+
+ private void parseProperties(JsonParser jp)
+ throws JsonParseException, IOException {
+ for (JsonToken t; (t = jp.nextToken()) != null;) {
+ if (t == FIELD_NAME) {
+ String text = jp.getCurrentName();
+
+ t = jp.nextToken();
+ if (t == VALUE_STRING) {
+ mTagMap.put(text, jp.getText());
+ } else if (t == VALUE_NUMBER_INT) {
+ mTagMap.put(text, jp.getNumberValue());
+ }
+ continue;
+ }
+ if (t == END_OBJECT)
+ break;
+ }
+ }
+
+ private void parseGeometry(JsonParser jp)
+ throws JsonParseException, IOException {
+
+ boolean multi = false;
+ GeometryType type = GeometryType.NONE;
+
+ for (JsonToken t; (t = jp.nextToken()) != null;) {
+ if (t == FIELD_NAME) {
+ if (match(jp, FIELD_COORDINATES)) {
+ if (jp.nextToken() != START_ARRAY)
+ continue;
+ if (multi) {
+ parseMulti(jp, type);
+ } else {
+ if (type == GeometryType.POLY)
+ parsePolygon(jp);
+
+ if (type == GeometryType.LINE)
+ parseLineString(jp);
+
+ if (type == GeometryType.POINT)
+ parseCoordinate(jp);
+
+ }
+ } else if (match(jp, FIELD_TYPE)) {
+ multi = false;
+
+ jp.nextToken();
+
+ if (match(jp, LINETRING))
+ type = GeometryType.LINE;
+ else if (match(jp, POLYGON))
+ type = GeometryType.POLY;
+ else if (match(jp, POINT))
+ type = GeometryType.POINT;
+ else if (match(jp, MULTI_LINESTRING)) {
+ type = GeometryType.LINE;
+ multi = true;
+ }
+ else if (match(jp, MULTI_POLYGON)) {
+ type = GeometryType.POLY;
+ multi = true;
+ }
+ else if (match(jp, MULTI_POINT)) {
+ type = GeometryType.POINT;
+ multi = true;
+ }
+
+ if (type == GeometryType.POINT)
+ mMapElement.startPoints();
+ }
+ continue;
+ }
+ if (t == END_OBJECT)
+ break;
+ }
+ }
+
+ private void parseMulti(JsonParser jp, GeometryType type)
+ throws JsonParseException, IOException {
+
+ for (JsonToken t; (t = jp.nextToken()) != null;) {
+ if (t == END_ARRAY)
+ break;
+
+ if (t == START_ARRAY) {
+ if (type == GeometryType.POLY)
+ parsePolygon(jp);
+
+ else if (type == GeometryType.LINE)
+ parseLineString(jp);
+
+ else if (type == GeometryType.POINT)
+ parseCoordinate(jp);;
+
+ } else {
+ //....
+ }
+ }
+ }
+
+ private void parsePolygon(JsonParser jp)
+ throws JsonParseException, IOException {
+ int ring = 0;
+
+ for (JsonToken t; (t = jp.nextToken()) != null;) {
+ if (t == START_ARRAY) {
+ if (ring == 0)
+ mMapElement.startPolygon();
+ else
+ mMapElement.startHole();
+
+ ring++;
+ parseCoordSequence(jp);
+ removeLastPoint();
+ continue;
+ }
+
+ if (t == END_ARRAY)
+ break;
+ }
+ }
+
+ private void removeLastPoint() {
+ mMapElement.pointPos -= 2;
+ mMapElement.index[mMapElement.indexPos] -= 2;
+ }
+
+ private void parseLineString(JsonParser jp)
+ throws JsonParseException, IOException {
+ mMapElement.startLine();
+ parseCoordSequence(jp);
+ }
+
+ private void parseCoordSequence(JsonParser jp)
+ throws JsonParseException, IOException {
+
+ for (JsonToken t; (t = jp.nextToken()) != null;) {
+
+ if (t == START_ARRAY) {
+ parseCoordinate(jp);
+ continue;
+ }
+
+ if (t == END_ARRAY)
+ break;
+
+ }
+ }
+
+ private void parseCoordinate(JsonParser jp)
+ throws JsonParseException, IOException {
+ int pos = 0;
+ double x = 0, y = 0; //, z = 0;
+
+ for (JsonToken t; (t = jp.nextToken()) != null;) {
+ if (t == VALUE_NUMBER_FLOAT || t == VALUE_NUMBER_INT) {
+
+ // avoid String allocation (by getDouble...)
+ char[] val = jp.getTextCharacters();
+ int offset = jp.getTextOffset();
+ int length = jp.getTextLength();
+ double c = ArrayUtils.parseNumber(val, offset, offset + length);
+
+ if (pos == 0)
+ x = c;
+ if (pos == 1)
+ y = c;
+ //if (pos == 2)
+ //z = c;
+
+ pos++;
+ continue;
+ }
+
+ if (t == END_ARRAY)
+ break;
+ }
+
+ mMapElement.addPoint((float) ((longitudeToX(x) - mTileX) * mTileScale),
+ (float) ((latitudeToY(y) - mTileY) * mTileScale));
+
+ }
+
+ private final static boolean match(JsonParser jp, char[] fieldName)
+ throws JsonParseException, IOException {
+
+ int length = jp.getTextLength();
+ if (length != fieldName.length)
+ return false;
+
+ char[] val = jp.getTextCharacters();
+ int offset = jp.getTextOffset();
+
+ for (int i = 0; i < length; i++) {
+ if (fieldName[i] != val[i + offset])
+ return false;
+ }
+
+ return true;
+ }
+}
diff --git a/vtm-extras/src/org/oscim/tiling/source/geojson/GeoJsonTileSource.java b/vtm-extras/src/org/oscim/tiling/source/geojson/GeoJsonTileSource.java
new file mode 100644
index 00000000..e381f6a1
--- /dev/null
+++ b/vtm-extras/src/org/oscim/tiling/source/geojson/GeoJsonTileSource.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source.geojson;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.oscim.core.MapElement;
+import org.oscim.core.Tag;
+import org.oscim.tiling.ITileDataSource;
+import org.oscim.tiling.source.LwHttp;
+import org.oscim.tiling.source.UrlTileDataSource;
+import org.oscim.tiling.source.UrlTileSource;
+
+public abstract class GeoJsonTileSource extends UrlTileSource {
+
+ public GeoJsonTileSource(String url) {
+ super(url);
+ setExtension(".json");
+ }
+
+ public GeoJsonTileSource(String url, int zoomMin, int zoomMax) {
+ super(url, zoomMin, zoomMax);
+ setExtension(".json");
+ }
+
+ @Override
+ public ITileDataSource getDataSource() {
+ Map opt = new HashMap();
+ opt.put("Accept-Encoding", "gzip");
+ return new UrlTileDataSource(this, new GeoJsonTileDecoder(this), new LwHttp(getUrl(), opt));
+ }
+
+ public Tag getFeatureTag() {
+ return null;
+ }
+
+ /** allow overriding tag handling */
+ public abstract void decodeTags(MapElement mapElement, Map properties);
+
+ public Tag rewriteTag(String key, Object value) {
+
+ if (value == null)
+ return null;
+
+ String val = (value instanceof String) ? (String) value : String.valueOf(value);
+
+ return new Tag(key, val);
+ }
+
+ /** modify mapElement before process() */
+ public void postGeomHook(MapElement mapElement) {
+
+ }
+}
diff --git a/vtm-extras/src/org/oscim/tiling/source/geojson/HighroadJsonTileSource.java b/vtm-extras/src/org/oscim/tiling/source/geojson/HighroadJsonTileSource.java
new file mode 100644
index 00000000..4d00d2fe
--- /dev/null
+++ b/vtm-extras/src/org/oscim/tiling/source/geojson/HighroadJsonTileSource.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source.geojson;
+
+import java.util.Map;
+
+import org.oscim.core.MapElement;
+import org.oscim.core.Tag;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HighroadJsonTileSource extends GeoJsonTileSource {
+
+ static final Logger log = LoggerFactory.getLogger(HighroadJsonTileSource.class);
+
+ Tag mTagTunnel = new Tag("tunnel", "yes");
+ Tag mTagBridge = new Tag("bridge", "yes");
+
+ public HighroadJsonTileSource() {
+ super("http://tile.openstreetmap.us/vectiles-highroad");
+ }
+
+ @Override
+ public void decodeTags(MapElement mapElement, Map properties) {
+ String highway = null;
+ boolean isLink = false;
+
+ mapElement.layer = 5;
+
+ for (Map.Entry entry : properties.entrySet()) {
+ String key = entry.getKey();
+ Object value = entry.getValue();
+ //log.debug(key + " : " + String.valueOf(value));
+
+ if (value == null)
+ continue;
+
+ if ("no".equals(value))
+ continue;
+
+ if ("highway".equals(key) && value instanceof String) {
+ highway = (String) entry.getValue();
+ }
+ else if ("is_link".equals(key)) {
+ isLink = "yes".equals(value);
+ }
+ else if ("is_tunnel".equals(key)) {
+ mapElement.tags.add(mTagTunnel);
+ }
+ else if ("is_bridge".equals(key)) {
+ mapElement.tags.add(mTagBridge);
+ }
+ else if ("sort_key".equals(key)) {
+ if (value instanceof Integer)
+ mapElement.layer = 5 + (Integer) value;
+ }
+ else if ("railway".equals(key) && value instanceof String) {
+ mapElement.tags.add(new Tag("railway", (String) value));
+ }
+ }
+
+ if (highway == null)
+ return;
+
+ if (isLink)
+ highway += "_link";
+
+ mapElement.tags.add(new Tag("highway", highway));
+
+ }
+
+ @Override
+ public Tag rewriteTag(String key, Object value) {
+ if ("kind".equals(key))
+ return null;
+
+ if (value == null)
+ return null;
+
+ String val = (value instanceof String) ? (String) value : String.valueOf(value);
+
+ return new Tag(key, val);
+ }
+}
diff --git a/vtm-extras/src/org/oscim/tiling/source/geojson/OsmBuildingJsonTileSource.java b/vtm-extras/src/org/oscim/tiling/source/geojson/OsmBuildingJsonTileSource.java
new file mode 100644
index 00000000..9ad02bac
--- /dev/null
+++ b/vtm-extras/src/org/oscim/tiling/source/geojson/OsmBuildingJsonTileSource.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source.geojson;
+
+import java.util.Map;
+
+import org.oscim.core.MapElement;
+import org.oscim.core.Tag;
+
+public class OsmBuildingJsonTileSource extends GeoJsonTileSource {
+
+ public OsmBuildingJsonTileSource() {
+ super("http://tile.openstreetmap.us/vectiles-buildings");
+ }
+
+ Tag mTagBuilding = new Tag("building", "yes");
+
+ @Override
+ public void decodeTags(MapElement mapElement, Map properties) {
+
+ mapElement.tags.add(mTagBuilding);
+
+ }
+}
diff --git a/vtm-extras/src/org/oscim/tiling/source/geojson/OsmLanduseJsonTileSource.java b/vtm-extras/src/org/oscim/tiling/source/geojson/OsmLanduseJsonTileSource.java
new file mode 100644
index 00000000..fb8d7049
--- /dev/null
+++ b/vtm-extras/src/org/oscim/tiling/source/geojson/OsmLanduseJsonTileSource.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source.geojson;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.oscim.core.GeometryBuffer.GeometryType;
+import org.oscim.core.MapElement;
+import org.oscim.core.Tag;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OsmLanduseJsonTileSource extends GeoJsonTileSource {
+ static final Logger log = LoggerFactory.getLogger(OsmLanduseJsonTileSource.class);
+
+ public OsmLanduseJsonTileSource() {
+ super("http://tile.openstreetmap.us/vectiles-land-usages");
+ }
+
+ private static LinkedHashMap mappings =
+ new LinkedHashMap();
+
+ static void addMapping(String key, String val) {
+ mappings.put(val, new Tag(key, val));
+ }
+
+ static {
+ addMapping("landuse", "residential");
+ addMapping("landuse", "commercial");
+ addMapping("landuse", "retail");
+ addMapping("landuse", "railway");
+ addMapping("landuse", "grass");
+ addMapping("landuse", "meadow");
+ addMapping("landuse", "forest");
+ addMapping("landuse", "farm");
+ addMapping("landuse", "allotments");
+ addMapping("landuse", "cemetery");
+ addMapping("landuse", "farmyard");
+ addMapping("landuse", "farmland");
+ addMapping("landuse", "quarry");
+ addMapping("landuse", "military");
+ addMapping("landuse", "industrial");
+ addMapping("landuse", "greenfield");
+ addMapping("landuse", "village_green");
+ addMapping("landuse", "recreation_ground");
+ addMapping("landuse", "conservation");
+ addMapping("landuse", "landfill");
+ addMapping("landuse", "construction");
+
+ addMapping("leisure", "common");
+ addMapping("leisure", "park");
+ addMapping("leisure", "pitch");
+ addMapping("leisure", "garden");
+ addMapping("leisure", "sports_centre");
+ addMapping("leisure", "playground");
+ addMapping("leisure", "nature_reserve");
+ addMapping("leisure", "golf_course");
+ addMapping("leisure", "stadium");
+
+ addMapping("amenity", "hospital");
+ addMapping("amenity", "cinema");
+ addMapping("amenity", "school");
+ addMapping("amenity", "college");
+ addMapping("amenity", "university");
+ addMapping("amenity", "theatre");
+ addMapping("amenity", "library");
+ addMapping("amenity", "parking");
+ addMapping("amenity", "place_of_worship");
+
+ addMapping("highway", "pedestrian");
+ addMapping("highway", "footway");
+ addMapping("highway", "service");
+ addMapping("highway", "street");
+
+ addMapping("natural", "scrub");
+ addMapping("natural", "wood");
+
+ mappings.put("urban area", new Tag("landuse", "urban"));
+ mappings.put("park or protected land", new Tag("leisure", "park"));
+ }
+
+ private final static Tag mTagArea = new Tag("area", "yes");
+
+ @Override
+ public void decodeTags(MapElement mapElement, Map properties) {
+
+ for (Map.Entry entry : properties.entrySet()) {
+ String key = entry.getKey();
+
+ if (!"kind".equals(key))
+ continue;
+
+ String value = (String) entry.getValue();
+
+ Tag tag = mappings.get(value);
+ if (tag == null) {
+ System.out.println("unmatched " + value);
+ } else {
+ mapElement.tags.add(tag);
+ }
+ break;
+ }
+ }
+
+ @Override
+ public void postGeomHook(MapElement mapElement) {
+ //if (mapElement.type != GeometryType.POLY) {
+ mapElement.type = GeometryType.POLY;
+ mapElement.tags.add(mTagArea);
+ //}
+ }
+}
diff --git a/vtm-extras/src/org/oscim/tiling/source/geojson/OsmWaterJsonTileSource.java b/vtm-extras/src/org/oscim/tiling/source/geojson/OsmWaterJsonTileSource.java
new file mode 100644
index 00000000..70a087f9
--- /dev/null
+++ b/vtm-extras/src/org/oscim/tiling/source/geojson/OsmWaterJsonTileSource.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source.geojson;
+
+import java.util.Map;
+
+import org.oscim.core.MapElement;
+import org.oscim.core.Tag;
+
+public class OsmWaterJsonTileSource extends GeoJsonTileSource {
+
+ public OsmWaterJsonTileSource() {
+ super("http://tile.openstreetmap.us/vectiles-water-areas");
+ }
+
+ Tag mTagWater = new Tag("natural", "water");
+
+ @Override
+ public void decodeTags(MapElement mapElement, Map properties) {
+
+ mapElement.tags.add(mTagWater);
+
+ }
+}
diff --git a/vtm-extras/src/org/oscim/tiling/source/geojson/RiverJsonTileSource.java b/vtm-extras/src/org/oscim/tiling/source/geojson/RiverJsonTileSource.java
new file mode 100644
index 00000000..7db9cc6c
--- /dev/null
+++ b/vtm-extras/src/org/oscim/tiling/source/geojson/RiverJsonTileSource.java
@@ -0,0 +1,22 @@
+package org.oscim.tiling.source.geojson;
+
+import java.util.Map;
+
+import org.oscim.core.MapElement;
+import org.oscim.core.Tag;
+
+public class RiverJsonTileSource extends GeoJsonTileSource {
+
+ public RiverJsonTileSource() {
+ super("http://www.somebits.com:8001/rivers");
+ }
+
+ Tag mTagWater = new Tag("waterway", "river");
+
+ @Override
+ public void decodeTags(MapElement mapElement, Map properties) {
+
+ mapElement.tags.add(mTagWater);
+
+ }
+}
diff --git a/vtm-themes/resources/assets/styles/osmarender.xml b/vtm-themes/resources/assets/styles/osmarender.xml
index 855443aa..93d65266 100644
--- a/vtm-themes/resources/assets/styles/osmarender.xml
+++ b/vtm-themes/resources/assets/styles/osmarender.xml
@@ -275,10 +275,13 @@
-
-
+
+
-
+
+
+
+
diff --git a/vtm-web-js/build.gradle b/vtm-web-js/build.gradle
index a04cda3f..846e2821 100644
--- a/vtm-web-js/build.gradle
+++ b/vtm-web-js/build.gradle
@@ -24,6 +24,7 @@ sourceSets {
dependencies {
providedCompile project(':vtm-web')
+ providedCompile project(':vtm-extras')
providedCompile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
providedCompile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
providedCompile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
diff --git a/vtm-web-js/src/org/oscim/web/js/JsOsmLanduseJsonTileSource.java b/vtm-web-js/src/org/oscim/web/js/JsOsmLanduseJsonTileSource.java
new file mode 100644
index 00000000..871463e9
--- /dev/null
+++ b/vtm-web-js/src/org/oscim/web/js/JsOsmLanduseJsonTileSource.java
@@ -0,0 +1,11 @@
+package org.oscim.web.js;
+
+import org.oscim.tiling.source.geojson.OsmLanduseJsonTileSource;
+import org.timepedia.exporter.client.ExportOverlay;
+import org.timepedia.exporter.client.ExportPackage;
+
+@ExportPackage("vtm")
+public class JsOsmLanduseJsonTileSource implements ExportOverlay {
+ public JsOsmLanduseJsonTileSource() {
+ }
+}
diff --git a/vtm-web-js/src/org/oscim/web/js/JsOverlays.java b/vtm-web-js/src/org/oscim/web/js/JsOverlays.java
index dd60152d..2b647706 100644
--- a/vtm-web-js/src/org/oscim/web/js/JsOverlays.java
+++ b/vtm-web-js/src/org/oscim/web/js/JsOverlays.java
@@ -13,12 +13,15 @@ import org.oscim.map.Map;
import org.oscim.renderer.LayerRenderer;
import org.oscim.theme.IRenderTheme;
import org.oscim.tiling.TileSource;
+import org.oscim.tiling.source.geojson.HighroadJsonTileSource;
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
import org.timepedia.exporter.client.Export;
import org.timepedia.exporter.client.ExportOverlay;
import org.timepedia.exporter.client.ExportPackage;
+import org.timepedia.exporter.client.Exportable;
-public final class JsOverlays {
+@ExportPackage("")
+public class JsOverlays implements Exportable {
@ExportPackage("vtm")
@Export("Layers")
public interface XLayers extends ExportOverlay {
@@ -66,20 +69,6 @@ public final class JsOverlays {
}
}
- @ExportPackage("vtm")
- @Export("VectorTileLayer")
- public static class XVectorTileLayer implements ExportOverlay {
- public XVectorTileLayer(Map map, TileSource tileSource) {
- }
-
- public boolean setTileSource(TileSource tileSource) {
- return false;
- }
-
- public void setRenderTheme(IRenderTheme theme) {
- }
- }
-
@ExportPackage("vtm")
@Export("OsmTileLayer")
public static class XOsmTileLayer implements ExportOverlay {
@@ -94,21 +83,13 @@ public final class JsOverlays {
}
}
- // @ExportPackage("vtm")
- // @Export("OsmLanduseJsonTileSource")
- // public static class XOsmLanduseJsonTileSource implements
- // ExportOverlay {
- // public XOsmLanduseJsonTileSource() {
- // }
- // }
- //
- // @ExportPackage("vtm")
- // @Export("HighroadJsonTileSource")
- // public static class XHighroadJsonTileSource implements
- // ExportOverlay {
- // public XHighroadJsonTileSource() {
- // }
- // }
+ @ExportPackage("vtm")
+ @Export("HighroadJsonTileSource")
+ public static class XHighroadJsonTileSource implements
+ ExportOverlay {
+ public XHighroadJsonTileSource() {
+ }
+ }
@ExportPackage("vtm")
@Export("OSciMap4TileSource")
diff --git a/vtm-web-js/src/org/oscim/web/js/JsVectorTileLayer.java b/vtm-web-js/src/org/oscim/web/js/JsVectorTileLayer.java
new file mode 100644
index 00000000..7b569d7b
--- /dev/null
+++ b/vtm-web-js/src/org/oscim/web/js/JsVectorTileLayer.java
@@ -0,0 +1,21 @@
+package org.oscim.web.js;
+
+import org.oscim.layers.tile.vector.VectorTileLayer;
+import org.oscim.map.Map;
+import org.oscim.theme.IRenderTheme;
+import org.oscim.tiling.TileSource;
+import org.timepedia.exporter.client.ExportOverlay;
+import org.timepedia.exporter.client.ExportPackage;
+
+@ExportPackage("vtm")
+public class JsVectorTileLayer implements ExportOverlay {
+ public JsVectorTileLayer(Map map, TileSource tileSource) {
+ }
+
+ public boolean setTileSource(TileSource tileSource) {
+ return false;
+ }
+
+ public void setRenderTheme(IRenderTheme theme) {
+ }
+}
diff --git a/vtm-web-js/war/map.js b/vtm-web-js/war/map.js
index 3ab59c54..32ec8906 100644
--- a/vtm-web-js/war/map.js
+++ b/vtm-web-js/war/map.js
@@ -20,11 +20,11 @@ function createLayers() {
// map.addLayer(new vtm.BuildingLayer(m, l))
// map.addLayer(new vtm.LabelLayer(m, l))
- // t = map.loadTheme("TRONRENDER")
- // ts = new vtm.OsmLanduseJsonTileSource()
- // l = new vtm.VectorTileLayer(m, ts)
- // l.setRenderTheme(t)
- // map.addLayer(l)
+ t = map.loadTheme("TRONRENDER")
+ ts = new vtm.OsmLanduseJsonTileSource()
+ l = new vtm.VectorTileLayer(m, ts)
+ l.setRenderTheme(t)
+ map.addLayer(l)
}
function canvasResize() {
diff --git a/vtm-web/build.gradle b/vtm-web/build.gradle
index c3d2bf2f..24980f17 100644
--- a/vtm-web/build.gradle
+++ b/vtm-web/build.gradle
@@ -25,6 +25,7 @@ sourceSets {
dependencies {
compile project(':vtm-gdx')
+ compile project(':vtm-extras')
compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
@@ -36,6 +37,7 @@ dependencies {
evaluationDependsOn(':vtm')
evaluationDependsOn(':vtm-themes')
evaluationDependsOn(':vtm-gdx')
+evaluationDependsOn(':vtm-extras')
gwt {
gwtVersion='2.6.0'
diff --git a/vtm-web/src/org/oscim/gdx/emu/org/oscim/tiling/source/geojson/GeoJsonTileSource.java b/vtm-web/src/org/oscim/gdx/emu/org/oscim/tiling/source/geojson/GeoJsonTileSource.java
new file mode 100644
index 00000000..2e5c2c8b
--- /dev/null
+++ b/vtm-web/src/org/oscim/gdx/emu/org/oscim/tiling/source/geojson/GeoJsonTileSource.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source.geojson;
+
+import java.util.Map;
+
+import org.oscim.core.MapElement;
+import org.oscim.core.Tag;
+import org.oscim.tiling.ITileDataSource;
+import org.oscim.tiling.source.JsonTileDataSource;
+import org.oscim.tiling.source.UrlTileSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class GeoJsonTileSource extends UrlTileSource {
+ static final Logger log = LoggerFactory.getLogger(GeoJsonTileSource.class);
+
+ public GeoJsonTileSource(String url) {
+ super(url);
+ setExtension(".json");
+ }
+
+ @Override
+ public ITileDataSource getDataSource() {
+ return new JsonTileDataSource(this);
+ }
+
+ public Tag getFeatureTag() {
+ return null;
+ }
+
+ /** allow overriding tag handling */
+ public abstract void decodeTags(MapElement mapElement, Map properties);
+
+ public Tag rewriteTag(String key, Object value) {
+
+ if (value == null)
+ return null;
+
+ String val = (value instanceof String) ? (String) value : String.valueOf(value);
+
+ return new Tag(key, val);
+ }
+
+ /** modify mapElement before process() */
+ public void postGeomHook(MapElement mapElement) {
+
+ }
+}
diff --git a/vtm-web/src/org/oscim/tiling/source/JsonTileDataSource.java b/vtm-web/src/org/oscim/tiling/source/JsonTileDataSource.java
new file mode 100644
index 00000000..f4b257e0
--- /dev/null
+++ b/vtm-web/src/org/oscim/tiling/source/JsonTileDataSource.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source;
+
+import static org.oscim.tiling.ITileDataSink.QueryResult.FAILED;
+import static org.oscim.tiling.ITileDataSink.QueryResult.SUCCESS;
+
+import java.io.InputStream;
+
+import org.oscim.layers.tile.MapTile;
+import org.oscim.layers.tile.MapTile.State;
+import org.oscim.tiling.ITileDataSink;
+import org.oscim.tiling.ITileDataSource;
+import org.oscim.tiling.source.geojson.GeoJsonTileDecoder;
+import org.oscim.tiling.source.geojson.GeoJsonTileSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.jsonp.client.JsonpRequest;
+import com.google.gwt.jsonp.client.JsonpRequestBuilder;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+public class JsonTileDataSource implements ITileDataSource {
+ static final Logger log = LoggerFactory.getLogger(JsonTileDataSource.class);
+
+ protected final GeoJsonTileDecoder mTileDecoder;
+ protected final UrlTileSource mTileSource;
+
+ private final byte[] mRequestBuffer = new byte[1024];
+
+ public JsonTileDataSource(GeoJsonTileSource tileSource) {
+ mTileSource = tileSource;
+ mTileDecoder = new GeoJsonTileDecoder(tileSource);
+ }
+
+ UrlTileSource getTileSource() {
+ return mTileSource;
+ }
+
+ private ITileDataSink mSink;
+ private MapTile mTile;
+
+ @Override
+ public void query(MapTile tile, ITileDataSink sink) {
+ mTile = tile;
+ mSink = sink;
+
+ try {
+ int pos = mTileSource.formatTilePath(tile, mRequestBuffer, 0);
+
+ String url = mTileSource.getUrl()
+ + (new String(mRequestBuffer, 0, pos));
+
+ doGet(url);
+ } catch (Exception e) {
+ e.printStackTrace();
+ sink.completed(FAILED);
+ }
+ }
+
+ public void process(InputStream is) {
+ }
+
+ boolean mFinished;
+
+ @Override
+ public void destroy() {
+ mFinished = true;
+ }
+
+ JsonpRequest mRequestHandle;
+
+ void doGet(final String url) {
+ JsonpRequestBuilder builder = new JsonpRequestBuilder();
+ //builder.setCallbackParam("json_callback");
+
+ mRequestHandle = builder.requestObject(url, new AsyncCallback() {
+ public void onFailure(Throwable caught) {
+
+ mSink.completed(FAILED);
+ log.debug("fail! {} {}", mRequestHandle, caught.getMessage());
+ //mRequestHandle.cancel();
+ }
+
+ public void onSuccess(JavaScriptObject jso) {
+ if (mTile.state(State.NONE)) {
+ log.debug("tile cleared {}", url);
+ mSink.completed(FAILED);
+ return;
+ }
+
+ if (jso == null) {
+ log.debug("Couldn't retrieve JSON for {}", url);
+ mSink.completed(FAILED);
+ return;
+ }
+
+ try {
+ if (mTileDecoder.decode(mTile, mSink, jso)) {
+ mSink.completed(SUCCESS);
+ return;
+ }
+ } catch (Exception e) {
+ log.debug("Couldn't retrieve JSON for {} {}" + url, e);
+ // FIXME need to check where it might be thrown
+ mSink.completed(FAILED);
+ }
+ }
+ });
+ }
+}
diff --git a/vtm-web/src/org/oscim/tiling/source/geojson/Feature.java b/vtm-web/src/org/oscim/tiling/source/geojson/Feature.java
new file mode 100644
index 00000000..0773ce57
--- /dev/null
+++ b/vtm-web/src/org/oscim/tiling/source/geojson/Feature.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source.geojson;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Feature extends GeoJsonObject {
+
+ protected Feature() {
+
+ }
+
+ public final native Geometry> getGeometry() /*-{
+ return this.geometry;
+ }-*/;
+
+ public final native String getId() /*-{
+ return this.id;
+ }-*/;
+
+ public final native void setId(String id) /*-{
+ this.id = id;
+ }-*/;
+
+ public final Map getProperties(HashMap map) {
+ map.clear();
+ fromJavascriptObject(map);
+
+ return map;
+ }
+
+ public final native void fromJavascriptObject(HashMap s) /*-{
+ for(var key in this.properties) {
+ s.@java.util.HashMap::put(Ljava/lang/Object;Ljava/lang/Object;)(key, Object(this.properties[key]));
+ }
+ }-*/;
+}
diff --git a/vtm-web/src/org/oscim/tiling/source/geojson/FeatureCollection.java b/vtm-web/src/org/oscim/tiling/source/geojson/FeatureCollection.java
new file mode 100644
index 00000000..0ef10d4e
--- /dev/null
+++ b/vtm-web/src/org/oscim/tiling/source/geojson/FeatureCollection.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source.geojson;
+
+import java.util.Collection;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
+
+public class FeatureCollection extends JavaScriptObject {
+
+ protected FeatureCollection() {
+
+ }
+
+ public final Collection getFeatures() {
+ return new JsArrayCollection(getFeaturesInternal());
+ }
+
+ public final native JsArray getFeaturesInternal()/*-{
+ return this.features;
+ }-*/;
+
+}
diff --git a/vtm-web/src/org/oscim/tiling/source/geojson/GeoJsonObject.java b/vtm-web/src/org/oscim/tiling/source/geojson/GeoJsonObject.java
new file mode 100644
index 00000000..c8589256
--- /dev/null
+++ b/vtm-web/src/org/oscim/tiling/source/geojson/GeoJsonObject.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source.geojson;
+
+import com.google.gwt.core.client.JavaScriptObject;
+
+public abstract class GeoJsonObject extends JavaScriptObject {
+
+ protected GeoJsonObject() {
+
+ }
+
+ public final native double[] getBbox()/*-{
+ return bbox;
+ }-*/;
+
+ public final native void setBbox(double[] bbox) /*-{
+ this.bbox = bbox;
+ }-*/;
+}
diff --git a/vtm-web/src/org/oscim/tiling/source/geojson/GeoJsonTileDecoder.java b/vtm-web/src/org/oscim/tiling/source/geojson/GeoJsonTileDecoder.java
new file mode 100644
index 00000000..23e6ae0a
--- /dev/null
+++ b/vtm-web/src/org/oscim/tiling/source/geojson/GeoJsonTileDecoder.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source.geojson;
+
+import static org.oscim.core.MercatorProjection.latitudeToY;
+import static org.oscim.core.MercatorProjection.longitudeToX;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.LinkedHashMap;
+
+import org.oscim.core.GeometryBuffer.GeometryType;
+import org.oscim.core.MapElement;
+import org.oscim.core.Tile;
+import org.oscim.tiling.ITileDataSink;
+import org.oscim.tiling.source.ITileDecoder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gwt.core.client.JavaScriptObject;
+
+public class GeoJsonTileDecoder implements ITileDecoder {
+ static final Logger log = LoggerFactory.getLogger(GeoJsonTileDecoder.class);
+
+ private final MapElement mapElement;
+ private final GeoJsonTileSource mTileSource;
+
+ private ITileDataSink mTileDataSink;
+
+ public GeoJsonTileDecoder(GeoJsonTileSource tileSource) {
+ mTileSource = tileSource;
+ mapElement = new MapElement();
+ mapElement.layer = 5;
+ }
+
+ final static LinkedHashMap mProperties = new LinkedHashMap(10);
+
+ double mTileY, mTileX, mTileScale;
+
+ public boolean decode(Tile tile, ITileDataSink sink, JavaScriptObject jso) {
+ mTileDataSink = sink;
+
+ mTileScale = 1 << tile.zoomLevel;
+ mTileX = tile.tileX / mTileScale;
+ mTileY = tile.tileY / mTileScale;
+ mTileScale *= Tile.SIZE;
+
+ FeatureCollection c = (FeatureCollection) jso;
+
+ for (Feature f : c.getFeatures()) {
+ mapElement.clear();
+ mapElement.tags.clear();
+
+ /* add tag information */
+ mTileSource.decodeTags(mapElement, f.getProperties(mProperties));
+ if (mapElement.tags.numTags == 0)
+ continue;
+
+ /* add geometry information */
+ decodeGeometry(f.getGeometry());
+
+ if (mapElement.type == GeometryType.NONE)
+ continue;
+
+ mTileDataSink.process(mapElement);
+ }
+
+ return true;
+ }
+
+ private void decodeGeometry(Geometry> geometry) {
+ String type = geometry.type();
+
+ if ("Polygon".equals(type)) {
+ Polygon p = (Polygon) geometry.getCoordinates();
+ decodePolygon(p);
+ } else if ("MultiPolygon".equals(type)) {
+ MultiPolygon mp = (MultiPolygon) geometry.getCoordinates();
+ for (int k = 0, l = mp.getNumGeometries(); k < l; k++)
+ decodePolygon(mp.getGeometryN(k));
+
+ } else if ("LineString".equals(type)) {
+ LineString ls = (LineString) geometry.getCoordinates();
+ decodeLineString(ls);
+
+ } else if ("MultiLineString".equals(type)) {
+ MultiLineString ml = (MultiLineString) geometry.getCoordinates();
+ for (int k = 0, n = ml.getNumGeometries(); k < n; k++)
+ decodeLineString(ml.getGeometryN(k));
+ }
+ }
+
+ private void decodeLineString(LineString l) {
+ mapElement.startLine();
+ for (int j = 0, m = l.length(); j < m; j++) {
+ decodePoint(l.get(j));
+ }
+ }
+
+ private void decodePolygon(Polygon p) {
+ for (int i = 0, n = p.getNumRings(); i < n; i++) {
+ if (i > 0)
+ mapElement.startHole();
+ else
+ mapElement.startPolygon();
+
+ LineString ls = p.getRing(i);
+ for (int j = 0, m = ls.length() - 1; j < m; j++)
+ decodePoint(ls.get(j));
+ }
+ }
+
+ private void decodePoint(LngLat point) {
+
+ float x = (float) ((longitudeToX(point.getLongitude()) - mTileX) * mTileScale);
+ float y = (float) ((latitudeToY(point.getLatitude()) - mTileY) * mTileScale);
+
+ mapElement.addPoint(x, y);
+ }
+
+ @Override
+ public boolean decode(Tile tile, ITileDataSink sink, InputStream is) throws IOException {
+ return false;
+ }
+}
diff --git a/vtm-web/src/org/oscim/tiling/source/geojson/Geometry.java b/vtm-web/src/org/oscim/tiling/source/geojson/Geometry.java
new file mode 100644
index 00000000..c9a51d78
--- /dev/null
+++ b/vtm-web/src/org/oscim/tiling/source/geojson/Geometry.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source.geojson;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
+
+public abstract class Geometry extends JsArray {
+
+ protected Geometry() {
+
+ }
+
+ public final native String type()/*-{
+ return this.type
+ }-*/;
+
+ public final native JsArray getCoordinates() /*-{
+ return this.coordinates;
+ }-*/;
+}
diff --git a/vtm-web/src/org/oscim/tiling/source/geojson/JsArrayCollection.java b/vtm-web/src/org/oscim/tiling/source/geojson/JsArrayCollection.java
new file mode 100644
index 00000000..ed45484c
--- /dev/null
+++ b/vtm-web/src/org/oscim/tiling/source/geojson/JsArrayCollection.java
@@ -0,0 +1,100 @@
+package org.oscim.tiling.source.geojson;
+
+import java.util.AbstractCollection;
+import java.util.Iterator;
+
+import com.google.gwt.core.client.JavaScriptObject;
+
+/**
+ * a Java Friendly way of working with Js Arrays using the Java.util.Collection
+ * API
+ * https://groups.google.com/forum/#!topic/google-web-toolkit/_8X9WPL6qwM
+ *
+ * @author sg
+ *
+ * @param
+ */
+public class JsArrayCollection extends AbstractCollection {
+
+ private JsArr _data;
+
+ /**
+ * creates an empty array
+ */
+ public JsArrayCollection() {
+ _data = JsArr.create().cast();
+ }
+
+ /**
+ * creates JsArrayCollection wrapping an existing js array
+ */
+ public JsArrayCollection(JavaScriptObject data) {
+ this._data = data.cast();
+ }
+
+ public static JsArrayCollection create(JavaScriptObject data) {
+ return new JsArrayCollection(data);
+ }
+
+ @Override
+ public Iterator iterator() {
+ return new JsArrayIterator(this);
+ }
+
+ @Override
+ public int size() {
+ return _data.size();
+ }
+
+ public static class JsArrayIterator implements Iterator {
+
+ private JsArrayCollection arr;
+ int currentIndex;
+
+ public JsArrayIterator(JsArrayCollection arr) {
+ this.arr = arr;
+ currentIndex = 0;
+ }
+
+ @Override
+ public boolean hasNext() {
+ // System.out.println(currentIndex+" - "+arr.size());
+ return currentIndex < arr.size();
+ }
+
+ @Override
+ public T next() {
+ currentIndex++;
+ return arr._data.get(currentIndex - 1);
+ }
+
+ @Override
+ public void remove() {
+ arr._data.slice(currentIndex - 1, currentIndex);
+ }
+
+ }
+
+ /** untyped array */
+ private static class JsArr extends JavaScriptObject {
+ protected JsArr() {
+ }
+
+ public native final JsArr slice(int start, int end)/*-{
+ return this.slice(start, end);
+ }-*/;
+
+ public static final native JsArr create() /*-{
+ return [];
+ }-*/;
+
+ public final native int size() /*-{
+ return this.length;
+ }-*/;
+
+ public final native T get(int i) /*-{
+ return this[i];
+ }-*/;
+ }
+
+}
diff --git a/vtm-web/src/org/oscim/tiling/source/geojson/LineString.java b/vtm-web/src/org/oscim/tiling/source/geojson/LineString.java
new file mode 100644
index 00000000..490e1cf0
--- /dev/null
+++ b/vtm-web/src/org/oscim/tiling/source/geojson/LineString.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source.geojson;
+
+public class LineString extends Geometry {
+
+ protected LineString() {
+ }
+}
diff --git a/vtm-web/src/org/oscim/tiling/source/geojson/LngLat.java b/vtm-web/src/org/oscim/tiling/source/geojson/LngLat.java
new file mode 100644
index 00000000..0fdf879f
--- /dev/null
+++ b/vtm-web/src/org/oscim/tiling/source/geojson/LngLat.java
@@ -0,0 +1,18 @@
+package org.oscim.tiling.source.geojson;
+
+import com.google.gwt.core.client.JavaScriptObject;
+
+public class LngLat extends JavaScriptObject {
+
+ protected LngLat() {
+
+ }
+
+ public final native double getLongitude() /*-{
+ return this[0];
+ }-*/;
+
+ public final native double getLatitude() /*-{
+ return this[1];
+ }-*/;
+}
diff --git a/vtm-web/src/org/oscim/tiling/source/geojson/MultiLineString.java b/vtm-web/src/org/oscim/tiling/source/geojson/MultiLineString.java
new file mode 100644
index 00000000..422a3b44
--- /dev/null
+++ b/vtm-web/src/org/oscim/tiling/source/geojson/MultiLineString.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source.geojson;
+
+public class MultiLineString extends Geometry {
+
+ protected MultiLineString() {
+ }
+
+ public final native LineString getGeometryN(int i) /*-{
+ return this[i];
+ }-*/;
+
+ public final native int getNumGeometries() /*-{
+ return this.length;
+ }-*/;
+
+}
diff --git a/vtm-web/src/org/oscim/tiling/source/geojson/MultiPolygon.java b/vtm-web/src/org/oscim/tiling/source/geojson/MultiPolygon.java
new file mode 100644
index 00000000..c52b89a5
--- /dev/null
+++ b/vtm-web/src/org/oscim/tiling/source/geojson/MultiPolygon.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source.geojson;
+
+public class MultiPolygon extends Geometry {
+
+ protected MultiPolygon() {
+ }
+
+ public final native Polygon getGeometryN(int i) /*-{
+ return this[i];
+ }-*/;
+
+ public final native int getNumGeometries() /*-{
+ return this.length;
+ }-*/;
+
+}
diff --git a/vtm-web/src/org/oscim/tiling/source/geojson/Polygon.java b/vtm-web/src/org/oscim/tiling/source/geojson/Polygon.java
new file mode 100644
index 00000000..3ef0bc0b
--- /dev/null
+++ b/vtm-web/src/org/oscim/tiling/source/geojson/Polygon.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2014 Hannes Janetzek
+ *
+ * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.oscim.tiling.source.geojson;
+
+public class Polygon extends Geometry {
+
+ protected Polygon() {
+ }
+
+ public final native LineString getExteriorRing()/*-{
+ return this[0];
+ }-*/;
+
+ public final native LineString getRing(int i) /*-{
+ return this[i];
+ }-*/;
+
+ public final native int getNumRings() /*-{
+ return this.length;
+ }-*/;
+
+}
diff --git a/vtm/src/org/oscim/utils/ArrayUtils.java b/vtm/src/org/oscim/utils/ArrayUtils.java
index 73815698..112be334 100644
--- a/vtm/src/org/oscim/utils/ArrayUtils.java
+++ b/vtm/src/org/oscim/utils/ArrayUtils.java
@@ -61,4 +61,81 @@ public class ArrayUtils {
right--;
}
}
+
+ public static double parseNumber(char[] str, int pos, int end) {
+
+ boolean neg = false;
+ if (str[pos] == '-') {
+ neg = true;
+ pos++;
+ }
+
+ double val = 0;
+ int pre = 0;
+ char c = 0;
+
+ for (; pos < end; pos++, pre++) {
+ c = str[pos];
+ if (c < '0' || c > '9') {
+ if (pre == 0)
+ throw new NumberFormatException("s " + c);
+
+ break;
+ }
+ val = val * 10 + (int) (c - '0');
+ }
+
+ if (pre == 0)
+ throw new NumberFormatException();
+
+ if (c == '.') {
+ float div = 10;
+ for (pos++; pos < end; pos++) {
+ c = str[pos];
+ if (c < '0' || c > '9')
+ break;
+ val = val + ((int) (c - '0')) / div;
+ div *= 10;
+ }
+ }
+
+ if (c == 'e' || c == 'E') {
+ // advance 'e'
+ pos++;
+
+ // check direction
+ int dir = 1;
+ if (str[pos] == '-') {
+ dir = -1;
+ pos++;
+ }
+ // skip leading zeros
+ for (; pos < end; pos++)
+ if (str[pos] != '0')
+ break;
+
+ int shift = 0;
+ for (pre = 0; pos < end; pos++, pre++) {
+ c = str[pos];
+ if (c < '0' || c > '9') {
+ // nothing after 'e'
+ if (pre == 0)
+ throw new NumberFormatException("e " + c);
+ break;
+ }
+ shift = shift * 10 + (int) (c - '0');
+ }
+
+ // guess it's ok for sane values of E
+ if (dir > 0) {
+ while (shift-- > 0)
+ val *= 10;
+ } else {
+ while (shift-- > 0)
+ val /= 10;
+ }
+ }
+
+ return neg ? -val : val;
+ }
}