Merge branch 'geojson'

This commit is contained in:
Hannes Janetzek 2014-03-30 20:27:47 +02:00
commit 92d9bba0e1
32 changed files with 1703 additions and 40 deletions

View File

@ -67,6 +67,11 @@
android:name="org.oscim.android.test.JeoIndoorMapActivity" android:name="org.oscim.android.test.JeoIndoorMapActivity"
android:label="@string/title_activity_map" > android:label="@string/title_activity_map" >
</activity> </activity>
<activity
android:name="org.oscim.android.test.OsmJsonMapActivity"
android:label="@string/title_activity_map" >
</activity>
</application> </application>
</manifest> </manifest>

View File

@ -12,6 +12,7 @@ apply plugin: 'android'
dependencies { dependencies {
compile project(':vtm-android') compile project(':vtm-android')
compile project(':vtm-jeo') compile project(':vtm-jeo')
compile project(':vtm-extras')
compile project(':vtm-themes') compile project(':vtm-themes')
} }
@ -31,9 +32,15 @@ android {
debug.setRoot('build-types/debug') debug.setRoot('build-types/debug')
release.setRoot('build-types/release') release.setRoot('build-types/release')
} }
packagingOptions { // remove duplicates
exclude 'META-INF/services/org.jeo.data.Driver' 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 // Including configurations into Eclipse

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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));
}
}

View File

@ -48,6 +48,7 @@ public class Samples extends Activity {
linearLayout.addView(createButton(ThemeStylerActivity.class)); linearLayout.addView(createButton(ThemeStylerActivity.class));
linearLayout.addView(createButton(S3DBMapActivity.class)); linearLayout.addView(createButton(S3DBMapActivity.class));
linearLayout.addView(createButton(JeoIndoorMapActivity.class)); linearLayout.addView(createButton(JeoIndoorMapActivity.class));
linearLayout.addView(createButton(OsmJsonMapActivity.class));
} }
private Button createButton(final Class<?> clazz) { private Button createButton(final Class<?> clazz) {

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<String, Object> 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<String, Object>();
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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<String, String> opt = new HashMap<String, String>();
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<String, Object> 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) {
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<String, Object> properties) {
String highway = null;
boolean isLink = false;
mapElement.layer = 5;
for (Map.Entry<String, Object> 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);
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<String, Object> properties) {
mapElement.tags.add(mTagBuilding);
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<String, Tag> mappings =
new LinkedHashMap<String, Tag>();
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<String, Object> properties) {
for (Map.Entry<String, Object> 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);
//}
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<String, Object> properties) {
mapElement.tags.add(mTagWater);
}
}

View File

@ -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<String, Object> properties) {
mapElement.tags.add(mTagWater);
}
}

View File

@ -275,10 +275,13 @@
<m v="stream"> <m v="stream">
<line stroke="#b5d6f1" width="0.275" /> <line stroke="#b5d6f1" width="0.275" />
</m> </m>
<m v="river"> <m v="river" zoom-min="12" >
<line stroke="#b5d6f1" width="1.0" /> <line stroke="#a5b6e1" width="1.5" />
</m> </m>
<m v="river" zoom-max="11" >
<line stroke="#a5b6e1" width="1.5" fix="true"/>
</m>
<m v="dock"> <m v="dock">
<area fill="#b5d6f1" /> <area fill="#b5d6f1" />
</m> </m>

View File

@ -24,6 +24,7 @@ sourceSets {
dependencies { dependencies {
providedCompile project(':vtm-web') providedCompile project(':vtm-web')
providedCompile project(':vtm-extras')
providedCompile "com.badlogicgames.gdx:gdx:$gdxVersion:sources" providedCompile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
providedCompile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources" providedCompile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
providedCompile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion" providedCompile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"

View File

@ -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<OsmLanduseJsonTileSource> {
public JsOsmLanduseJsonTileSource() {
}
}

View File

@ -13,12 +13,15 @@ import org.oscim.map.Map;
import org.oscim.renderer.LayerRenderer; import org.oscim.renderer.LayerRenderer;
import org.oscim.theme.IRenderTheme; import org.oscim.theme.IRenderTheme;
import org.oscim.tiling.TileSource; import org.oscim.tiling.TileSource;
import org.oscim.tiling.source.geojson.HighroadJsonTileSource;
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource; import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
import org.timepedia.exporter.client.Export; import org.timepedia.exporter.client.Export;
import org.timepedia.exporter.client.ExportOverlay; import org.timepedia.exporter.client.ExportOverlay;
import org.timepedia.exporter.client.ExportPackage; import org.timepedia.exporter.client.ExportPackage;
import org.timepedia.exporter.client.Exportable;
public final class JsOverlays { @ExportPackage("")
public class JsOverlays implements Exportable {
@ExportPackage("vtm") @ExportPackage("vtm")
@Export("Layers") @Export("Layers")
public interface XLayers extends ExportOverlay<Layers> { public interface XLayers extends ExportOverlay<Layers> {
@ -66,20 +69,6 @@ public final class JsOverlays {
} }
} }
@ExportPackage("vtm")
@Export("VectorTileLayer")
public static class XVectorTileLayer implements ExportOverlay<VectorTileLayer> {
public XVectorTileLayer(Map map, TileSource tileSource) {
}
public boolean setTileSource(TileSource tileSource) {
return false;
}
public void setRenderTheme(IRenderTheme theme) {
}
}
@ExportPackage("vtm") @ExportPackage("vtm")
@Export("OsmTileLayer") @Export("OsmTileLayer")
public static class XOsmTileLayer implements ExportOverlay<OsmTileLayer> { public static class XOsmTileLayer implements ExportOverlay<OsmTileLayer> {
@ -94,21 +83,13 @@ public final class JsOverlays {
} }
} }
// @ExportPackage("vtm") @ExportPackage("vtm")
// @Export("OsmLanduseJsonTileSource") @Export("HighroadJsonTileSource")
// public static class XOsmLanduseJsonTileSource implements public static class XHighroadJsonTileSource implements
// ExportOverlay<OsmLanduseJsonTileSource> { ExportOverlay<HighroadJsonTileSource> {
// public XOsmLanduseJsonTileSource() { public XHighroadJsonTileSource() {
// } }
// } }
//
// @ExportPackage("vtm")
// @Export("HighroadJsonTileSource")
// public static class XHighroadJsonTileSource implements
// ExportOverlay<HighroadJsonTileSource> {
// public XHighroadJsonTileSource() {
// }
// }
@ExportPackage("vtm") @ExportPackage("vtm")
@Export("OSciMap4TileSource") @Export("OSciMap4TileSource")

View File

@ -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<VectorTileLayer> {
public JsVectorTileLayer(Map map, TileSource tileSource) {
}
public boolean setTileSource(TileSource tileSource) {
return false;
}
public void setRenderTheme(IRenderTheme theme) {
}
}

View File

@ -20,11 +20,11 @@ function createLayers() {
// map.addLayer(new vtm.BuildingLayer(m, l)) // map.addLayer(new vtm.BuildingLayer(m, l))
// map.addLayer(new vtm.LabelLayer(m, l)) // map.addLayer(new vtm.LabelLayer(m, l))
// t = map.loadTheme("TRONRENDER") t = map.loadTheme("TRONRENDER")
// ts = new vtm.OsmLanduseJsonTileSource() ts = new vtm.OsmLanduseJsonTileSource()
// l = new vtm.VectorTileLayer(m, ts) l = new vtm.VectorTileLayer(m, ts)
// l.setRenderTheme(t) l.setRenderTheme(t)
// map.addLayer(l) map.addLayer(l)
} }
function canvasResize() { function canvasResize() {

View File

@ -25,6 +25,7 @@ sourceSets {
dependencies { dependencies {
compile project(':vtm-gdx') compile project(':vtm-gdx')
compile project(':vtm-extras')
compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources" compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources" compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion" compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
@ -36,6 +37,7 @@ dependencies {
evaluationDependsOn(':vtm') evaluationDependsOn(':vtm')
evaluationDependsOn(':vtm-themes') evaluationDependsOn(':vtm-themes')
evaluationDependsOn(':vtm-gdx') evaluationDependsOn(':vtm-gdx')
evaluationDependsOn(':vtm-extras')
gwt { gwt {
gwtVersion='2.6.0' gwtVersion='2.6.0'

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<String, Object> 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) {
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<JavaScriptObject> mRequestHandle;
void doGet(final String url) {
JsonpRequestBuilder builder = new JsonpRequestBuilder();
//builder.setCallbackParam("json_callback");
mRequestHandle = builder.requestObject(url, new AsyncCallback<JavaScriptObject>() {
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);
}
}
});
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<String, Object> getProperties(HashMap<String, Object> map) {
map.clear();
fromJavascriptObject(map);
return map;
}
public final native void fromJavascriptObject(HashMap<String, Object> s) /*-{
for(var key in this.properties) {
s.@java.util.HashMap::put(Ljava/lang/Object;Ljava/lang/Object;)(key, Object(this.properties[key]));
}
}-*/;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<Feature> getFeatures() {
return new JsArrayCollection<Feature>(getFeaturesInternal());
}
public final native JsArray<Feature> getFeaturesInternal()/*-{
return this.features;
}-*/;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}-*/;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<String, Object> mProperties = new LinkedHashMap<String, Object>(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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.tiling.source.geojson;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
public abstract class Geometry<T extends JavaScriptObject> extends JsArray<T> {
protected Geometry() {
}
public final native String type()/*-{
return this.type
}-*/;
public final native JsArray<T> getCoordinates() /*-{
return this.coordinates;
}-*/;
}

View File

@ -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 <T>
*/
public class JsArrayCollection<T> extends AbstractCollection<T> {
private JsArr<T> _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 <T> JsArrayCollection<T> create(JavaScriptObject data) {
return new JsArrayCollection<T>(data);
}
@Override
public Iterator<T> iterator() {
return new JsArrayIterator<T>(this);
}
@Override
public int size() {
return _data.size();
}
public static class JsArrayIterator<T> implements Iterator<T> {
private JsArrayCollection<T> arr;
int currentIndex;
public JsArrayIterator(JsArrayCollection<T> 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<T> extends JavaScriptObject {
protected JsArr() {
}
public native final JsArr<T> slice(int start, int end)/*-{
return this.slice(start, end);
}-*/;
public static final native <T> JsArr<T> create() /*-{
return [];
}-*/;
public final native int size() /*-{
return this.length;
}-*/;
public final native T get(int i) /*-{
return this[i];
}-*/;
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.tiling.source.geojson;
public class LineString extends Geometry<LngLat> {
protected LineString() {
}
}

View File

@ -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];
}-*/;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.tiling.source.geojson;
public class MultiLineString extends Geometry<LineString> {
protected MultiLineString() {
}
public final native LineString getGeometryN(int i) /*-{
return this[i];
}-*/;
public final native int getNumGeometries() /*-{
return this.length;
}-*/;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.tiling.source.geojson;
public class MultiPolygon extends Geometry<Polygon> {
protected MultiPolygon() {
}
public final native Polygon getGeometryN(int i) /*-{
return this[i];
}-*/;
public final native int getNumGeometries() /*-{
return this.length;
}-*/;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.tiling.source.geojson;
public class Polygon extends Geometry<LineString> {
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;
}-*/;
}

View File

@ -61,4 +61,81 @@ public class ArrayUtils {
right--; 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;
}
} }