Improve code / xml formatting, closes #54

This commit is contained in:
Emux
2016-07-09 19:45:22 +03:00
parent 7919d0ab9c
commit e793e8851b
458 changed files with 58405 additions and 63062 deletions

View File

@@ -16,10 +16,10 @@
*/
package org.oscim.tiling.source;
import static org.oscim.tiling.QueryResult.FAILED;
import static org.oscim.tiling.QueryResult.SUCCESS;
import java.io.InputStream;
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;
import org.oscim.layers.tile.MapTile;
import org.oscim.layers.tile.MapTile.State;
@@ -30,95 +30,95 @@ 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;
import java.io.InputStream;
import static org.oscim.tiling.QueryResult.FAILED;
import static org.oscim.tiling.QueryResult.SUCCESS;
public class JsonTileDataSource implements ITileDataSource {
static final Logger log = LoggerFactory.getLogger(JsonTileDataSource.class);
static final Logger log = LoggerFactory.getLogger(JsonTileDataSource.class);
protected final GeoJsonTileDecoder mTileDecoder;
protected final UrlTileSource mTileSource;
protected final GeoJsonTileDecoder mTileDecoder;
protected final UrlTileSource mTileSource;
public JsonTileDataSource(GeoJsonTileSource tileSource) {
mTileSource = tileSource;
mTileDecoder = new GeoJsonTileDecoder(tileSource);
}
public JsonTileDataSource(GeoJsonTileSource tileSource) {
mTileSource = tileSource;
mTileDecoder = new GeoJsonTileDecoder(tileSource);
}
UrlTileSource getTileSource() {
return mTileSource;
}
UrlTileSource getTileSource() {
return mTileSource;
}
private ITileDataSink mSink;
private MapTile mTile;
private ITileDataSink mSink;
private MapTile mTile;
@Override
public void query(MapTile tile, ITileDataSink sink) {
mTile = tile;
mSink = sink;
@Override
public void query(MapTile tile, ITileDataSink sink) {
mTile = tile;
mSink = sink;
try {
doGet(mTileSource.getTileUrl(tile));
} catch (Exception e) {
e.printStackTrace();
sink.completed(FAILED);
}
}
try {
doGet(mTileSource.getTileUrl(tile));
} catch (Exception e) {
e.printStackTrace();
sink.completed(FAILED);
}
}
public void process(InputStream is) {
}
public void process(InputStream is) {
}
boolean mFinished;
boolean mFinished;
@Override
public void dispose() {
mFinished = true;
}
@Override
public void dispose() {
mFinished = true;
}
@Override
public void cancel() {
mFinished = true;
}
@Override
public void cancel() {
mFinished = true;
}
JsonpRequest<JavaScriptObject> mRequestHandle;
JsonpRequest<JavaScriptObject> mRequestHandle;
void doGet(final String url) {
JsonpRequestBuilder builder = new JsonpRequestBuilder();
//builder.setCallbackParam("json_callback");
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) {
mRequestHandle = builder.requestObject(url, new AsyncCallback<JavaScriptObject>() {
public void onFailure(Throwable caught) {
mSink.completed(FAILED);
log.debug("fail! {} {}", mRequestHandle, caught.getMessage());
//mRequestHandle.cancel();
}
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;
}
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;
}
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);
}
}
});
}
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

@@ -21,30 +21,30 @@ import java.util.Map;
public class Feature extends GeoJsonObject {
protected Feature() {
protected Feature() {
}
}
public final native Geometry<?> getGeometry() /*-{
return this.geometry;
public final native Geometry<?> getGeometry() /*-{
return this.geometry;
}-*/;
public final native String getId() /*-{
return this.id;
public final native String getId() /*-{
return this.id;
}-*/;
public final native void setId(String 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);
public final Map<String, Object> getProperties(HashMap<String, Object> map) {
map.clear();
fromJavascriptObject(map);
return map;
}
return map;
}
public final native void fromJavascriptObject(HashMap<String, Object> s) /*-{
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

@@ -16,23 +16,23 @@
*/
package org.oscim.tiling.source.geojson;
import java.util.Collection;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import java.util.Collection;
public class FeatureCollection extends JavaScriptObject {
protected FeatureCollection() {
protected FeatureCollection() {
}
}
public final Collection<Feature> getFeatures() {
return new JsArrayCollection<Feature>(getFeaturesInternal());
}
public final Collection<Feature> getFeatures() {
return new JsArrayCollection<Feature>(getFeaturesInternal());
}
public final native JsArray<Feature> getFeaturesInternal()/*-{
return this.features;
public final native JsArray<Feature> getFeaturesInternal()/*-{
return this.features;
}-*/;
}

View File

@@ -20,15 +20,15 @@ import com.google.gwt.core.client.JavaScriptObject;
public abstract class GeoJsonObject extends JavaScriptObject {
protected GeoJsonObject() {
protected GeoJsonObject() {
}
}
public final native double[] getBbox()/*-{
return bbox;
public final native double[] getBbox()/*-{
return bbox;
}-*/;
public final native void setBbox(double[] bbox) /*-{
this.bbox = bbox;
public final native void setBbox(double[] bbox) /*-{
this.bbox = bbox;
}-*/;
}

View File

@@ -16,12 +16,7 @@
*/
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 com.google.gwt.core.client.JavaScriptObject;
import org.oscim.core.GeometryBuffer.GeometryType;
import org.oscim.core.MapElement;
@@ -31,109 +26,114 @@ import org.oscim.tiling.source.ITileDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gwt.core.client.JavaScriptObject;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedHashMap;
import static org.oscim.core.MercatorProjection.latitudeToY;
import static org.oscim.core.MercatorProjection.longitudeToX;
public class GeoJsonTileDecoder implements ITileDecoder {
static final Logger log = LoggerFactory.getLogger(GeoJsonTileDecoder.class);
static final Logger log = LoggerFactory.getLogger(GeoJsonTileDecoder.class);
private final MapElement mapElement;
private final GeoJsonTileSource mTileSource;
private final MapElement mapElement;
private final GeoJsonTileSource mTileSource;
private ITileDataSink mTileDataSink;
private ITileDataSink mTileDataSink;
public GeoJsonTileDecoder(GeoJsonTileSource tileSource) {
mTileSource = tileSource;
mapElement = new MapElement();
mapElement.layer = 5;
}
public GeoJsonTileDecoder(GeoJsonTileSource tileSource) {
mTileSource = tileSource;
mapElement = new MapElement();
mapElement.layer = 5;
}
final static LinkedHashMap<String, Object> mProperties = new LinkedHashMap<String, Object>(10);
final static LinkedHashMap<String, Object> mProperties = new LinkedHashMap<String, Object>(10);
double mTileY, mTileX, mTileScale;
double mTileY, mTileX, mTileScale;
public boolean decode(Tile tile, ITileDataSink sink, JavaScriptObject jso) {
mTileDataSink = sink;
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;
mTileScale = 1 << tile.zoomLevel;
mTileX = tile.tileX / mTileScale;
mTileY = tile.tileY / mTileScale;
mTileScale *= Tile.SIZE;
FeatureCollection c = (FeatureCollection) jso;
FeatureCollection c = (FeatureCollection) jso;
for (Feature f : c.getFeatures()) {
mapElement.clear();
mapElement.tags.clear();
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;
mTileSource.decodeTags(mapElement, f.getProperties(mProperties));
if (mapElement.tags.numTags == 0)
continue;
/* add geometry information */
decodeGeometry(f.getGeometry());
decodeGeometry(f.getGeometry());
if (mapElement.type == GeometryType.NONE)
continue;
if (mapElement.type == GeometryType.NONE)
continue;
mTileDataSink.process(mapElement);
}
mTileDataSink.process(mapElement);
}
return true;
}
return true;
}
private void decodeGeometry(Geometry<?> geometry) {
String type = geometry.type();
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));
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 ("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));
}
}
} 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 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();
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));
}
}
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) {
private void decodePoint(LngLat point) {
float x = (float) ((longitudeToX(point.getLongitude()) - mTileX) * mTileScale);
float y = (float) ((latitudeToY(point.getLatitude()) - mTileY) * mTileScale);
float x = (float) ((longitudeToX(point.getLongitude()) - mTileX) * mTileScale);
float y = (float) ((latitudeToY(point.getLatitude()) - mTileY) * mTileScale);
mapElement.addPoint(x, y);
}
mapElement.addPoint(x, y);
}
@Override
public boolean decode(Tile tile, ITileDataSink sink, InputStream is) throws IOException {
return false;
}
@Override
public boolean decode(Tile tile, ITileDataSink sink, InputStream is) throws IOException {
return false;
}
}

View File

@@ -21,15 +21,15 @@ import com.google.gwt.core.client.JsArray;
public abstract class Geometry<T extends JavaScriptObject> extends JsArray<T> {
protected Geometry() {
protected Geometry() {
}
}
public final native String type()/*-{
return this.type
public final native String type()/*-{
return this.type
}-*/;
public final native JsArray<T> getCoordinates() /*-{
return this.coordinates;
public final native JsArray<T> getCoordinates() /*-{
return this.coordinates;
}-*/;
}

View File

@@ -1,100 +1,101 @@
package org.oscim.tiling.source.geojson;
import com.google.gwt.core.client.JavaScriptObject;
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>
* @author sg
*/
public class JsArrayCollection<T> extends AbstractCollection<T> {
private JsArr<T> _data;
private JsArr<T> _data;
/**
* creates an empty array
*/
public JsArrayCollection() {
_data = JsArr.create().cast();
}
/**
* 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();
}
/**
* 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);
}
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 Iterator<T> iterator() {
return new JsArrayIterator<T>(this);
}
@Override
public int size() {
return _data.size();
}
@Override
public int size() {
return _data.size();
}
public static class JsArrayIterator<T> implements Iterator<T> {
public static class JsArrayIterator<T> implements Iterator<T> {
private JsArrayCollection<T> arr;
int currentIndex;
private JsArrayCollection<T> arr;
int currentIndex;
public JsArrayIterator(JsArrayCollection<T> arr) {
this.arr = arr;
currentIndex = 0;
}
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 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 T next() {
currentIndex++;
return arr._data.get(currentIndex - 1);
}
@Override
public void remove() {
arr._data.slice(currentIndex - 1, currentIndex);
}
@Override
public void remove() {
arr._data.slice(currentIndex - 1, currentIndex);
}
}
}
/** untyped array */
private static class JsArr<T> extends JavaScriptObject {
protected JsArr() {
}
/**
* 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 native final JsArr<T> slice(int start, int end)/*-{
return this.slice(start, end);
}-*/;
public static final native <T> JsArr<T> create() /*-{
return [];
public static final native <T> JsArr<T> create() /*-{
return [];
}-*/;
public final native int size() /*-{
public final native int size() /*-{
return this.length;
}-*/;
public final native T get(int i) /*-{
public final native T get(int i) /*-{
return this[i];
}-*/;
}
}
}

View File

@@ -18,6 +18,6 @@ package org.oscim.tiling.source.geojson;
public class LineString extends Geometry<LngLat> {
protected LineString() {
}
protected LineString() {
}
}

View File

@@ -4,15 +4,15 @@ import com.google.gwt.core.client.JavaScriptObject;
public class LngLat extends JavaScriptObject {
protected LngLat() {
protected LngLat() {
}
}
public final native double getLongitude() /*-{
return this[0];
public final native double getLongitude() /*-{
return this[0];
}-*/;
public final native double getLatitude() /*-{
return this[1];
public final native double getLatitude() /*-{
return this[1];
}-*/;
}

View File

@@ -18,15 +18,15 @@ package org.oscim.tiling.source.geojson;
public class MultiLineString extends Geometry<LineString> {
protected MultiLineString() {
}
protected MultiLineString() {
}
public final native LineString getGeometryN(int i) /*-{
return this[i];
public final native LineString getGeometryN(int i) /*-{
return this[i];
}-*/;
public final native int getNumGeometries() /*-{
return this.length;
public final native int getNumGeometries() /*-{
return this.length;
}-*/;
}

View File

@@ -18,15 +18,15 @@ package org.oscim.tiling.source.geojson;
public class MultiPolygon extends Geometry<Polygon> {
protected MultiPolygon() {
}
protected MultiPolygon() {
}
public final native Polygon getGeometryN(int i) /*-{
return this[i];
public final native Polygon getGeometryN(int i) /*-{
return this[i];
}-*/;
public final native int getNumGeometries() /*-{
return this.length;
public final native int getNumGeometries() /*-{
return this.length;
}-*/;
}

View File

@@ -18,18 +18,18 @@ package org.oscim.tiling.source.geojson;
public class Polygon extends Geometry<LineString> {
protected Polygon() {
}
protected Polygon() {
}
public final native LineString getExteriorRing()/*-{
return this[0];
public final native LineString getExteriorRing()/*-{
return this[0];
}-*/;
public final native LineString getRing(int i) /*-{
return this[i];
public final native LineString getRing(int i) /*-{
return this[i];
}-*/;
public final native int getNumRings() /*-{
public final native int getNumRings() /*-{
return this.length;
}-*/;