html: add SearchBox for nominatim
- add simple WKT parser - extract GwtLaucher inner classes
This commit is contained in:
parent
8c9eaaea96
commit
6dfd180cb9
142
vtm-gdx-html/src/org/oscim/gdx/client/GwtGdxMap.java
Normal file
142
vtm-gdx-html/src/org/oscim/gdx/client/GwtGdxMap.java
Normal file
@ -0,0 +1,142 @@
|
||||
package org.oscim.gdx.client;
|
||||
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.MercatorProjection;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
||||
import org.oscim.layers.tile.bitmap.NaturalEarth;
|
||||
import org.oscim.renderer.GLRenderer;
|
||||
import org.oscim.tilesource.TileSource;
|
||||
import org.oscim.tilesource.oscimap2.OSciMap2TileSource;
|
||||
import org.oscim.tilesource.oscimap4.OSciMap4TileSource;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplication;
|
||||
import com.google.gwt.user.client.Timer;
|
||||
import com.google.gwt.user.client.Window;
|
||||
|
||||
class GwtGdxMap extends GdxMap {
|
||||
private static final String TAG = GwtGdxMap.class.getName();
|
||||
|
||||
SearchBox mSearchBox;
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
MapConfig c = MapConfig.get();
|
||||
|
||||
// stroke text takes about 70% cpu time in firefox:
|
||||
// https://bug568526.bugzilla.mozilla.org/attachment.cgi?id=447932
|
||||
// <- circle/stroke test 800ms firefox, 80ms chromium..
|
||||
// TODO use texture atlas to avoid drawing text-textures
|
||||
if (GwtApplication.agentInfo().isLinux() && GwtApplication.agentInfo().isFirefox())
|
||||
GwtCanvasAdapter.NO_STROKE_TEXT = true;
|
||||
|
||||
CanvasAdapter.g = GwtCanvasAdapter.INSTANCE;
|
||||
CanvasAdapter.textScale = 0.7f;
|
||||
GLAdapter.g = (GL20) Gdx.graphics.getGL20();
|
||||
GLAdapter.GDX_WEBGL_QUIRKS = true;
|
||||
GLRenderer.setBackgroundColor(0xffffff);
|
||||
//Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
||||
|
||||
super.create();
|
||||
|
||||
double lat = c.getLatitude();
|
||||
double lon = c.getLongitude();
|
||||
int zoom = c.getZoom();
|
||||
|
||||
float tilt = 0;
|
||||
float rotation = 0;
|
||||
|
||||
if (Window.Location.getHash() != null) {
|
||||
String hash = Window.Location.getHash();
|
||||
|
||||
hash = hash.substring(1);
|
||||
String[] pairs = hash.split(",");
|
||||
|
||||
for (String p : pairs) {
|
||||
try {
|
||||
if (p.startsWith("lat="))
|
||||
lat = Double.parseDouble(p.substring(4));
|
||||
else if (p.startsWith("lon="))
|
||||
lon = Double.parseDouble(p.substring(4));
|
||||
else if (p.startsWith("scale="))
|
||||
zoom = Integer.parseInt(p.substring(6));
|
||||
else if (p.startsWith("rot="))
|
||||
rotation = Float.parseFloat(p.substring(4));
|
||||
else if (p.startsWith("tilt="))
|
||||
tilt = Float.parseFloat(p.substring(5));
|
||||
} catch (NumberFormatException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
MapPosition p = new MapPosition();
|
||||
p.setZoomLevel(zoom);
|
||||
p.setPosition(lat, lon);
|
||||
Log.d(TAG, "map position: " + p.x + "/" + p.y + " " + lat + "/" + lon);
|
||||
|
||||
p.angle = rotation;
|
||||
p.tilt = tilt;
|
||||
mMapView.setMapPosition(p);
|
||||
|
||||
//mMapView.getMapViewPosition().setTilt(tilt);
|
||||
//mMapView.getMapViewPosition().setRotation(rotation);
|
||||
|
||||
String url = c.getTileUrl();
|
||||
String sourceName = c.getTileSource();
|
||||
|
||||
TileSource tileSource;
|
||||
if ("oscimap4".equals(sourceName))
|
||||
tileSource = new OSciMap4TileSource();
|
||||
else
|
||||
//if ("oscimap2".equals(source))
|
||||
tileSource = new OSciMap2TileSource();
|
||||
|
||||
tileSource.setOption("url", url);
|
||||
|
||||
initDefaultMap(tileSource, false, true, true);
|
||||
|
||||
if ("naturalearth".equals(c.getBackgroundLayer()))
|
||||
mMapView.setBackgroundMap(new BitmapTileLayer(mMapView, NaturalEarth.INSTANCE));
|
||||
|
||||
mSearchBox = new SearchBox(mMapView);
|
||||
|
||||
// update URL hash to current position, every 5 seconds
|
||||
Timer timer = new Timer() {
|
||||
private int curLon, curLat, curZoom, curTilt, curRot;
|
||||
private MapPosition pos = new MapPosition();
|
||||
|
||||
public void run() {
|
||||
mMapView.getMapViewPosition().getMapPosition(pos);
|
||||
int lat = (int) (MercatorProjection.toLatitude(pos.y) * 1000);
|
||||
int lon = (int) (MercatorProjection.toLongitude(pos.x) * 1000);
|
||||
int rot = (int) (pos.angle);
|
||||
rot = (int) (pos.angle) % 360;
|
||||
//rot = rot < 0 ? -rot : rot;
|
||||
|
||||
if (curZoom != pos.zoomLevel || curLat != lat || curLon != lon
|
||||
|| curTilt != rot || curRot != (int) (pos.angle)) {
|
||||
|
||||
curLat = lat;
|
||||
curLon = lon;
|
||||
curZoom = pos.zoomLevel;
|
||||
curTilt = (int) pos.tilt;
|
||||
curRot = rot;
|
||||
|
||||
String newURL = Window.Location
|
||||
.createUrlBuilder()
|
||||
.setHash("scale=" + pos.zoomLevel + ",rot=" + curRot
|
||||
+ ",tilt=" + curTilt + ",lat=" + (curLat / 1000f)
|
||||
+ ",lon=" + (curLon / 1000f))
|
||||
.buildString();
|
||||
Window.Location.replace(newURL);
|
||||
}
|
||||
}
|
||||
};
|
||||
timer.scheduleRepeating(5000);
|
||||
}
|
||||
}
|
@ -1,32 +1,16 @@
|
||||
package org.oscim.gdx.client;
|
||||
|
||||
// -draftCompile -localWorkers 2
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.MercatorProjection;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.layers.Layer;
|
||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
||||
import org.oscim.layers.tile.bitmap.NaturalEarth;
|
||||
import org.oscim.renderer.GLRenderer;
|
||||
import org.oscim.tilesource.TileSource;
|
||||
import org.oscim.tilesource.oscimap2.OSciMap2TileSource;
|
||||
import org.oscim.tilesource.oscimap4.OSciMap4TileSource;
|
||||
import org.oscim.view.MapView;
|
||||
|
||||
import com.badlogic.gdx.ApplicationListener;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplication;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
|
||||
import com.badlogic.gdx.backends.gwt.GwtGraphics;
|
||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback;
|
||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState;
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.ui.DockLayoutPanel;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.RootPanel;
|
||||
@ -86,121 +70,4 @@ public class GwtLauncher extends GwtApplication {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static native String getMapConfig(String key)/*-{
|
||||
return $wnd.mapconfig && $wnd.mapconfig[key] || null;
|
||||
}-*/;
|
||||
|
||||
class GwtGdxMap extends GdxMap {
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
// stroke text takes about 70% cpu time in firefox:
|
||||
// https://bug568526.bugzilla.mozilla.org/attachment.cgi?id=447932
|
||||
// <- circle/stroke test 800ms firefox, 80ms chromium..
|
||||
// TODO use texture atlas to avoid drawing text-textures
|
||||
if (GwtApplication.agentInfo().isLinux() && GwtApplication.agentInfo().isFirefox())
|
||||
GwtCanvasAdapter.NO_STROKE_TEXT = true;
|
||||
|
||||
CanvasAdapter.g = GwtCanvasAdapter.INSTANCE;
|
||||
GLAdapter.g = (GL20) Gdx.graphics.getGL20();
|
||||
GLAdapter.GDX_WEBGL_QUIRKS = true;
|
||||
GLRenderer.setBackgroundColor(0xffffff);
|
||||
//Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
||||
|
||||
super.create();
|
||||
|
||||
double lat = Double.parseDouble(getMapConfig("latitude"));
|
||||
double lon = Double.parseDouble(getMapConfig("longitude"));
|
||||
int zoom = Integer.parseInt(getMapConfig("zoom"));
|
||||
float tilt = 0;
|
||||
float rotation = 0;
|
||||
|
||||
if (Window.Location.getHash() != null) {
|
||||
String hash = Window.Location.getHash();
|
||||
//Log.d("...", "hash: " + hash);
|
||||
hash = hash.substring(1);
|
||||
String[] pairs = hash.split(",");
|
||||
|
||||
for (String p : pairs) {
|
||||
try {
|
||||
if (p.startsWith("lat="))
|
||||
lat = Double.parseDouble(p.substring(4));
|
||||
else if (p.startsWith("lon="))
|
||||
lon = Double.parseDouble(p.substring(4));
|
||||
else if (p.startsWith("scale="))
|
||||
zoom = Integer.parseInt(p.substring(6));
|
||||
else if (p.startsWith("rot="))
|
||||
rotation = Float.parseFloat(p.substring(4));
|
||||
else if (p.startsWith("tilt="))
|
||||
tilt = Float.parseFloat(p.substring(5));
|
||||
} catch (NumberFormatException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
MapPosition p = new MapPosition();
|
||||
p.setZoomLevel(zoom);
|
||||
p.setPosition(lat, lon);
|
||||
mMapView.setMapPosition(p);
|
||||
|
||||
mMapView.getMapViewPosition().setTilt(tilt);
|
||||
mMapView.getMapViewPosition().setRotation(rotation);
|
||||
|
||||
String url = getMapConfig("tileurl");
|
||||
|
||||
TileSource tileSource;
|
||||
if ("oscimap4".equals(getMapConfig("tilesource")))
|
||||
tileSource = new OSciMap4TileSource();
|
||||
else
|
||||
tileSource = new OSciMap2TileSource();
|
||||
tileSource.setOption("url", url);
|
||||
|
||||
initDefaultMap(tileSource, false, true, true);
|
||||
|
||||
mMapView.getLayerManager().add(new UrlPositionUpdate(mMapView));
|
||||
mMapView.setBackgroundMap(new BitmapTileLayer(mMapView, NaturalEarth.INSTANCE));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class UrlPositionUpdate extends Layer {
|
||||
|
||||
public UrlPositionUpdate(MapView mapView) {
|
||||
super(mapView);
|
||||
}
|
||||
|
||||
private int curLon, curLat, curZoom, curTilt, curRot;
|
||||
|
||||
@Override
|
||||
public void onUpdate(MapPosition pos, boolean changed, boolean clear) {
|
||||
if (!changed)
|
||||
return;
|
||||
int lat = (int) (MercatorProjection.toLatitude(pos.y) * 1000);
|
||||
int lon = (int) (MercatorProjection.toLongitude(pos.x) * 1000);
|
||||
int rot = (int) (pos.angle);
|
||||
rot = (int) (pos.angle) % 360;
|
||||
rot = rot < 0 ? -rot : rot;
|
||||
|
||||
if (curZoom != pos.zoomLevel
|
||||
|| curLat != lat
|
||||
|| curLon != lon
|
||||
|| curTilt != rot
|
||||
|| curRot != (int) (pos.angle)) {
|
||||
|
||||
curLat = lat;
|
||||
curLon = lon;
|
||||
curZoom = pos.zoomLevel;
|
||||
curTilt = (int) pos.tilt;
|
||||
curRot = rot;
|
||||
|
||||
//String newURL = Window.Location.createUrlBuilder()
|
||||
// .setHash("scale=" + pos.zoomLevel + ",rot=" + curRot + ",tilt=" +
|
||||
// curTilt + ",lat=" + (curLat / 1000f) + ",lon=" + (curLon / 1000f))
|
||||
// .buildString();
|
||||
//Window.Location.replace(newURL);
|
||||
//Window.Location.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
37
vtm-gdx-html/src/org/oscim/gdx/client/MapConfig.java
Normal file
37
vtm-gdx-html/src/org/oscim/gdx/client/MapConfig.java
Normal file
@ -0,0 +1,37 @@
|
||||
package org.oscim.gdx.client;
|
||||
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
|
||||
class MapConfig extends JavaScriptObject {
|
||||
protected MapConfig() {
|
||||
}
|
||||
|
||||
public static native MapConfig get()/*-{
|
||||
return $wnd.mapconfig;
|
||||
}-*/;
|
||||
|
||||
public final native double getLatitude() /*-{
|
||||
return this.latitude;
|
||||
}-*/;
|
||||
|
||||
public final native double getLongitude() /*-{
|
||||
return this.longitude;
|
||||
}-*/;
|
||||
|
||||
public final native int getZoom() /*-{
|
||||
return this.zoom;
|
||||
}-*/;
|
||||
|
||||
public final native String getTileSource() /*-{
|
||||
return this.tilesource;
|
||||
}-*/;
|
||||
|
||||
public final native String getTileUrl() /*-{
|
||||
return this.tileurl;
|
||||
}-*/;
|
||||
|
||||
public final native String getBackgroundLayer() /*-{
|
||||
return this.background;
|
||||
}-*/;
|
||||
}
|
||||
|
349
vtm-gdx-html/src/org/oscim/gdx/client/SearchBox.java
Normal file
349
vtm-gdx-html/src/org/oscim/gdx/client/SearchBox.java
Normal file
@ -0,0 +1,349 @@
|
||||
package org.oscim.gdx.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.oscim.backend.Log;
|
||||
import org.oscim.core.BoundingBox;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.layers.overlay.PathOverlay;
|
||||
import org.oscim.view.MapView;
|
||||
|
||||
import com.google.gwt.cell.client.AbstractCell;
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.core.client.JsArray;
|
||||
import com.google.gwt.core.client.JsArrayNumber;
|
||||
import com.google.gwt.dom.client.Style.Visibility;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.dom.client.FocusEvent;
|
||||
import com.google.gwt.event.dom.client.FocusHandler;
|
||||
import com.google.gwt.event.dom.client.KeyCodes;
|
||||
import com.google.gwt.event.dom.client.KeyUpEvent;
|
||||
import com.google.gwt.event.dom.client.KeyUpHandler;
|
||||
import com.google.gwt.http.client.URL;
|
||||
import com.google.gwt.jsonp.client.JsonpRequestBuilder;
|
||||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||||
import com.google.gwt.user.cellview.client.CellList;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.RootPanel;
|
||||
import com.google.gwt.user.client.ui.ScrollPanel;
|
||||
import com.google.gwt.user.client.ui.TextBox;
|
||||
import com.google.gwt.view.client.ProvidesKey;
|
||||
import com.google.gwt.view.client.SelectionChangeEvent;
|
||||
import com.google.gwt.view.client.SingleSelectionModel;
|
||||
|
||||
/**
|
||||
* Entry point classes define <code>onModuleLoad()</code>.
|
||||
*/
|
||||
public class SearchBox {
|
||||
|
||||
protected static final String TAG = SearchBox.class.getName();
|
||||
|
||||
private static final String NOMINATIM_GLOBAL = "http://nominatim.openstreetmap.org/search?polygon_text=1&addressdetails=0&format=json&limit=25&q=";
|
||||
|
||||
interface PoiData {
|
||||
public static final ProvidesKey<PoiData> KEY_PROVIDER = new ProvidesKey<PoiData>() {
|
||||
@Override
|
||||
public Object getKey(PoiData item) {
|
||||
return item == null ? null : item.getId();
|
||||
}
|
||||
};
|
||||
|
||||
String getId();
|
||||
|
||||
String getName();
|
||||
|
||||
double getLatitude();
|
||||
|
||||
double getLongitude();
|
||||
|
||||
String getIcon();
|
||||
|
||||
BoundingBox getBoundingBox();
|
||||
}
|
||||
|
||||
final static class NominatimData extends JavaScriptObject implements
|
||||
PoiData {
|
||||
|
||||
protected NominatimData() {
|
||||
}
|
||||
|
||||
final static class BBox extends JsArrayNumber {
|
||||
protected BBox() {
|
||||
}
|
||||
}
|
||||
|
||||
final static class Polygon extends JsArray<JsArrayNumber> {
|
||||
protected Polygon() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public final native String getId() /*-{
|
||||
return this.osm_id;
|
||||
}-*/;
|
||||
|
||||
public final native String name() /*-{
|
||||
return this.display_name;
|
||||
}-*/;
|
||||
|
||||
public final native BBox getBBox() /*-{
|
||||
return this.boundingbox
|
||||
}-*/;
|
||||
|
||||
public final native String getWkt() /*-{
|
||||
return this.geotext;
|
||||
}-*/;
|
||||
|
||||
private final native String latitude() /*-{
|
||||
return this.lat;
|
||||
}-*/;
|
||||
|
||||
private final native String longitude() /*-{
|
||||
return this.lon;
|
||||
}-*/;
|
||||
|
||||
public final native String getIcon() /*-{
|
||||
return this.icon;
|
||||
}-*/;
|
||||
|
||||
@Override
|
||||
public double getLatitude() {
|
||||
try {
|
||||
return Double.parseDouble(latitude());
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLongitude() {
|
||||
try {
|
||||
return Double.parseDouble(longitude());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BoundingBox getBoundingBox() {
|
||||
if (getBBox() != null) {
|
||||
BBox b = getBBox();
|
||||
return new BoundingBox(b.get(0), b.get(2), b.get(1), b.get(3));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
String[] n = name().split(", ");
|
||||
if (n != null && n.length > 2)
|
||||
return n[0] + ", " + n[1] + " " + n[2];
|
||||
else if (n != null && n.length > 1)
|
||||
return n[0] + ", " + n[1];
|
||||
|
||||
return name();
|
||||
}
|
||||
}
|
||||
|
||||
class PoiCell extends AbstractCell<PoiData> {
|
||||
|
||||
@Override
|
||||
public void render(com.google.gwt.cell.client.Cell.Context context,
|
||||
PoiData value, SafeHtmlBuilder sb) {
|
||||
|
||||
// Value can be null, so do a null check..
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
sb.appendHtmlConstant("<table>");
|
||||
|
||||
if (value.getIcon() != null) {
|
||||
// Add the contact image.
|
||||
sb.appendHtmlConstant("<tr><td rowspan='3'>");
|
||||
sb.appendHtmlConstant("<img border=0 src=" + value.getIcon() + ">");
|
||||
sb.appendHtmlConstant("</td>");
|
||||
}
|
||||
|
||||
// Add the name and address.
|
||||
sb.appendHtmlConstant("<td style='font-size:95%;'>");
|
||||
sb.appendEscaped(value.getName());
|
||||
sb.appendHtmlConstant("</td></tr>");
|
||||
//sb.appendEscaped("<tr><td>" + value.getId()+ "</td></tr>");
|
||||
sb.appendHtmlConstant("</table>");
|
||||
sb.appendHtmlConstant("<hline>");
|
||||
}
|
||||
}
|
||||
|
||||
public SearchBox(final MapView mapView) {
|
||||
final Button searchButton = new Button("Search");
|
||||
final TextBox searchField = new TextBox();
|
||||
//searchField.setText("Bremen");
|
||||
final PathOverlay mOverlay = new PathOverlay(mapView, 0xCC0000FF);
|
||||
mapView.getLayerManager().add(mOverlay);
|
||||
|
||||
// We can add style names to widgets
|
||||
searchButton.addStyleName("sendButton");
|
||||
|
||||
RootPanel.get("nameFieldContainer").add(searchField);
|
||||
RootPanel.get("sendButtonContainer").add(searchButton);
|
||||
|
||||
// Focus the cursor on the name field when the app loads
|
||||
searchField.setFocus(true);
|
||||
searchField.selectAll();
|
||||
|
||||
// Create a cell to render each value in the list.
|
||||
PoiCell poiCell = new PoiCell();
|
||||
|
||||
// Create a CellList that uses the cell.
|
||||
final CellList<PoiData> cellList = new CellList<PoiData>(poiCell,
|
||||
PoiData.KEY_PROVIDER);
|
||||
|
||||
final SingleSelectionModel<PoiData> selectionModel = new SingleSelectionModel<PoiData>(
|
||||
PoiData.KEY_PROVIDER);
|
||||
cellList.setSelectionModel(selectionModel);
|
||||
|
||||
final ScrollPanel scroller = new ScrollPanel(cellList);
|
||||
RootPanel.get("listContainer").add(scroller);
|
||||
|
||||
scroller.setSize("350px", "300px");
|
||||
|
||||
RootPanel.get("search").getElement().getStyle().setVisibility(Visibility.VISIBLE);
|
||||
scroller.setVisible(false);
|
||||
|
||||
searchField.addFocusHandler(new FocusHandler() {
|
||||
@Override
|
||||
public void onFocus(FocusEvent event) {
|
||||
scroller.setVisible(true);
|
||||
}
|
||||
});
|
||||
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
|
||||
public void onSelectionChange(SelectionChangeEvent event) {
|
||||
final PoiData d = selectionModel.getSelectedObject();
|
||||
|
||||
mOverlay.clearPath();
|
||||
|
||||
//Log.d(TAG, "selected " + d.getName() + " " + d.getLatitude() + " "
|
||||
// + d.getLongitude());
|
||||
|
||||
BoundingBox b = d.getBoundingBox();
|
||||
if (b != null) {
|
||||
if (b.maxLatitudeE6 - b.minLatitudeE6 < 100 &&
|
||||
b.maxLongitudeE6 - b.minLongitudeE6 < 100)
|
||||
// for small bbox use zoom=16 to get an overview
|
||||
mapView.getMapViewPosition().animateTo(500, b.getCenterPoint(), 1 << 16, false);
|
||||
else
|
||||
mapView.getMapViewPosition().animateTo(b);
|
||||
if (d instanceof NominatimData && ((NominatimData) d).getWkt() != null) {
|
||||
String wkt = ((NominatimData) d).getWkt();
|
||||
|
||||
WKTReader r = new WKTReader();
|
||||
GeometryBuffer g = new GeometryBuffer(1024, 10);
|
||||
try {
|
||||
r.parse(wkt, g);
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, wkt);
|
||||
}
|
||||
mOverlay.setGeom(g);
|
||||
|
||||
//Log.d(TAG, "add polygon " + p.length());
|
||||
} else {
|
||||
mOverlay.addPoint(b.maxLatitudeE6, b.minLongitudeE6);
|
||||
mOverlay.addPoint(b.maxLatitudeE6, b.maxLongitudeE6);
|
||||
mOverlay.addPoint(b.minLatitudeE6, b.maxLongitudeE6);
|
||||
mOverlay.addPoint(b.minLatitudeE6, b.minLongitudeE6);
|
||||
mOverlay.addPoint(b.maxLatitudeE6, b.minLongitudeE6);
|
||||
}
|
||||
// hide overlay after 5 seconds
|
||||
mapView.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mOverlay.clearPath();
|
||||
}
|
||||
}, 5000);
|
||||
} else {
|
||||
MapPosition pos = new MapPosition();
|
||||
|
||||
mapView.getMapViewPosition().setTilt(0);
|
||||
mapView.getMapViewPosition().setRotation(0);
|
||||
|
||||
pos.setZoomLevel(13);
|
||||
pos.setPosition(d.getLatitude(), d.getLongitude());
|
||||
mapView.setMapPosition(pos);
|
||||
mapView.updateMap(true);
|
||||
}
|
||||
|
||||
scroller.setVisible(false);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Create a handler for the sendButton and nameField
|
||||
class MyHandler implements ClickHandler, KeyUpHandler {
|
||||
|
||||
/**
|
||||
* Fired when the user clicks on the sendButton.
|
||||
*/
|
||||
public void onClick(ClickEvent event) {
|
||||
sendRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when the user types in the nameField.
|
||||
*/
|
||||
public void onKeyUp(KeyUpEvent event) {
|
||||
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
|
||||
sendRequest();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the name from the nameField to the server and wait for a
|
||||
* response.
|
||||
*/
|
||||
private void sendRequest() {
|
||||
String textToServer = searchField.getText();
|
||||
searchButton.setEnabled(false);
|
||||
|
||||
String url = URL
|
||||
.encode(NOMINATIM_GLOBAL
|
||||
+ textToServer);
|
||||
|
||||
JsonpRequestBuilder builder = new JsonpRequestBuilder();
|
||||
builder.setCallbackParam("json_callback");
|
||||
builder.requestObject(url, new AsyncCallback<JsArray<NominatimData>>() {
|
||||
public void onFailure(Throwable caught) {
|
||||
Log.d(TAG, "request failed");
|
||||
searchButton.setEnabled(true);
|
||||
}
|
||||
|
||||
public void onSuccess(JsArray<NominatimData> data) {
|
||||
List<PoiData> items = new ArrayList<PoiData>();
|
||||
for (int i = 0, n = data.length(); i < n; i++) {
|
||||
NominatimData d = data.get(i);
|
||||
items.add(d);
|
||||
}
|
||||
|
||||
cellList.setRowCount(items.size(), true);
|
||||
cellList.setRowData(0, items);
|
||||
scroller.setVisible(true);
|
||||
searchButton.setEnabled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Add a handler to send the name to the server
|
||||
MyHandler handler = new MyHandler();
|
||||
searchButton.addClickHandler(handler);
|
||||
searchField.addKeyUpHandler(handler);
|
||||
|
||||
}
|
||||
|
||||
}
|
224
vtm-gdx-html/src/org/oscim/gdx/client/WKTReader.java
Normal file
224
vtm-gdx-html/src/org/oscim/gdx/client/WKTReader.java
Normal file
@ -0,0 +1,224 @@
|
||||
package org.oscim.gdx.client;
|
||||
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
|
||||
public class WKTReader {
|
||||
private final static String POINT = "POINT";
|
||||
private final static String LINE = "LINESTRING";
|
||||
private final static String POLY = "POLYGON";
|
||||
private final static String MULTI = "MULTI";
|
||||
|
||||
private final static int SKIP_POINT = POINT.length();
|
||||
private final static int SKIP_LINE = LINE.length();
|
||||
private final static int SKIP_POLY = POLY.length();
|
||||
private final static int SKIP_MULTI = MULTI.length();
|
||||
|
||||
public void parse(String wkt, GeometryBuffer geom) throws Exception {
|
||||
// return position.
|
||||
int[] pos = new int[] { 0 };
|
||||
|
||||
int len = wkt.length();
|
||||
|
||||
if (wkt.startsWith(POINT, pos[0])) {
|
||||
pos[0] += SKIP_POINT;
|
||||
geom.startPoints();
|
||||
ensure(wkt, pos, '(');
|
||||
parsePoint(geom, wkt, len, pos);
|
||||
ensure(wkt, pos, ')');
|
||||
} else if (wkt.startsWith(LINE, pos[0])) {
|
||||
pos[0] += SKIP_LINE;
|
||||
geom.startLine();
|
||||
|
||||
parseLine(geom, wkt, len, pos);
|
||||
|
||||
} else if (wkt.startsWith(POLY, pos[0])) {
|
||||
pos[0] += SKIP_POLY;
|
||||
geom.startPolygon();
|
||||
|
||||
parsePoly(geom, wkt, len, pos);
|
||||
|
||||
} else if (wkt.startsWith(MULTI, pos[0])) {
|
||||
pos[0] += SKIP_MULTI;
|
||||
|
||||
if (wkt.startsWith(POINT, pos[0])) {
|
||||
pos[0] += SKIP_POINT;
|
||||
geom.startPoints();
|
||||
ensure(wkt, pos, '(');
|
||||
parsePoint(geom, wkt, len, pos);
|
||||
while (wkt.charAt(pos[0]) == ',') {
|
||||
pos[0]++;
|
||||
parsePoint(geom, wkt, len, pos);
|
||||
}
|
||||
ensure(wkt, pos, ')');
|
||||
|
||||
} else if (wkt.startsWith(LINE, pos[0])) {
|
||||
pos[0] += SKIP_LINE;
|
||||
geom.startLine();
|
||||
ensure(wkt, pos, '(');
|
||||
parseLine(geom, wkt, len, pos);
|
||||
while (wkt.charAt(pos[0]) == ',') {
|
||||
pos[0]++;
|
||||
geom.startLine();
|
||||
parseLine(geom, wkt, len, pos);
|
||||
}
|
||||
ensure(wkt, pos, ')');
|
||||
|
||||
} else if (wkt.startsWith(POLY, pos[0])) {
|
||||
pos[0] += SKIP_POLY;
|
||||
geom.startPolygon();
|
||||
ensure(wkt, pos, '(');
|
||||
parsePoly(geom, wkt, len, pos);
|
||||
while (wkt.charAt(pos[0]) == ',') {
|
||||
pos[0]++;
|
||||
geom.startPolygon();
|
||||
parsePoly(geom, wkt, len, pos);
|
||||
}
|
||||
ensure(wkt, pos, ')');
|
||||
} else
|
||||
throw new Exception("usupported geometry ");
|
||||
} else
|
||||
throw new Exception("usupported geometry ");
|
||||
}
|
||||
|
||||
private static void ensure(String wkt, int[] pos, char c) throws Exception {
|
||||
if (wkt.charAt(pos[0]) != c)
|
||||
throw new Exception();
|
||||
|
||||
pos[0]++;
|
||||
}
|
||||
|
||||
private static void parsePoly(GeometryBuffer geom, String wkt, int len, int[] adv)
|
||||
throws Exception {
|
||||
// outer ring
|
||||
ensure(wkt, adv, '(');
|
||||
parseLine(geom, wkt, len, adv);
|
||||
|
||||
while (wkt.charAt(adv[0]) == ',') {
|
||||
adv[0]++;
|
||||
geom.startHole();
|
||||
parseLine(geom, wkt, len, adv);
|
||||
}
|
||||
ensure(wkt, adv, ')');
|
||||
}
|
||||
|
||||
private static void parseLine(GeometryBuffer geom, String wkt, int len, int[] adv)
|
||||
throws Exception {
|
||||
ensure(wkt, adv, '(');
|
||||
|
||||
parsePoint(geom, wkt, len, adv);
|
||||
while (wkt.charAt(adv[0]) == ',') {
|
||||
adv[0]++;
|
||||
parsePoint(geom, wkt, len, adv);
|
||||
}
|
||||
ensure(wkt, adv, ')');
|
||||
}
|
||||
|
||||
private static void parsePoint(GeometryBuffer geom, String wkt, int len, int[] adv) {
|
||||
float x = parseNumber(wkt, len, adv);
|
||||
|
||||
// skip ' '
|
||||
adv[0]++;
|
||||
|
||||
float y = parseNumber(wkt, len, adv);
|
||||
|
||||
geom.addPoint(x, y);
|
||||
}
|
||||
|
||||
static float parseNumber(String wkt, int len, int[] adv) {
|
||||
int pos = adv[0];
|
||||
|
||||
boolean neg = false;
|
||||
if (wkt.charAt(pos) == '-') {
|
||||
neg = true;
|
||||
pos++;
|
||||
}
|
||||
|
||||
float val = 0;
|
||||
int pre = 0;
|
||||
char c = 0;
|
||||
|
||||
for (; pos < len; pos++, pre++) {
|
||||
c = wkt.charAt(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 < len; pos++) {
|
||||
c = wkt.charAt(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 (wkt.charAt(pos) == '-') {
|
||||
dir = -1;
|
||||
pos++;
|
||||
}
|
||||
// skip leading zeros
|
||||
for (; pos < len; pos++)
|
||||
if (wkt.charAt(pos) != '0')
|
||||
break;
|
||||
|
||||
int shift = 0;
|
||||
for (pre = 0; pos < len; pos++, pre++) {
|
||||
c = wkt.charAt(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;
|
||||
}
|
||||
}
|
||||
|
||||
adv[0] = pos;
|
||||
|
||||
return neg ? -val : val;
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// WKTReader r = new WKTReader();
|
||||
// GeometryBuffer geom = new GeometryBuffer(10, 10);
|
||||
// try {
|
||||
// String wkt = "MULTIPOINT(0 0,1 0)";
|
||||
// r.parse(wkt, geom);
|
||||
// for (int i = 0; i < geom.index.length; i++) {
|
||||
// int len = geom.index[i];
|
||||
// if (len < 0)
|
||||
// break;
|
||||
// for (int p = 0; p < len; p += 2)
|
||||
// System.out.println(len + ": " + geom.points[p] + "," + geom.points[p + 1]);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
}
|
@ -17,7 +17,15 @@
|
||||
background-color: #ddd;
|
||||
text-align: center;
|
||||
}
|
||||
gdx-canvas {
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
margin: 0 0 0 0;
|
||||
font-family: Arial, "MS Trebuchet", sans-serif;
|
||||
}
|
||||
|
||||
#gdx-canvas {
|
||||
cursor: default;
|
||||
outline: none;
|
||||
position: fixed;
|
||||
@ -25,11 +33,7 @@
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
html, body {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
margin: 0 0 0 0;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
#credits {
|
||||
@ -45,23 +49,89 @@
|
||||
-webkit-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
font-size: 11px;
|
||||
font-family: Arial, "MS Trebuchet", sans-serif;
|
||||
}
|
||||
#credits a {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
font-variant: small-caps;
|
||||
}
|
||||
#search {
|
||||
z-index: 20000;
|
||||
position: absolute;
|
||||
top: 0.5em;
|
||||
left: 0.5em;
|
||||
background-color: rgba(0,0,0,0.8);
|
||||
-moz-border-radius: 3px;
|
||||
-webkit-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
visibility: hidden;
|
||||
}
|
||||
#listContainer{
|
||||
color: #FFFFFF;
|
||||
}
|
||||
#nameFieldContainer, .gwt-TextBox {
|
||||
width: 250px;
|
||||
}
|
||||
|
||||
/* Turn on a 16x16 scrollbar */
|
||||
::-webkit-scrollbar {
|
||||
width: 10px;
|
||||
height: 0px;
|
||||
}
|
||||
|
||||
/* Turn on single button up on top, and down on bottom */
|
||||
::-webkit-scrollbar-button:start:decrement, ::-webkit-scrollbar-button:end:increment {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Turn off the down area up on top, and up area on bottom */
|
||||
::-webkit-scrollbar-button:vertical:start:increment, ::-webkit-scrollbar-button:vertical:end:decrement {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Place The scroll down button at the bottom */
|
||||
::-webkit-scrollbar-button:end:increment {
|
||||
/*background-image: url(images/scroll_cntrl_dwn.png);*/
|
||||
}
|
||||
|
||||
/* Place The scroll up button at the up */
|
||||
::-webkit-scrollbar-button:start:decrement {
|
||||
/*background-image: url(images/scroll_cntrl_up.png);*/
|
||||
}
|
||||
|
||||
/* Top area above thumb and below up button */
|
||||
::-webkit-scrollbar-track-piece:vertical:start {
|
||||
/*background-image: url(images/scroll_gutter_top.png), url(images/scroll_gutter_mid.png);
|
||||
background-repeat: no-repeat, repeat-y;*/
|
||||
}
|
||||
|
||||
/* Bottom area below thumb and down button */
|
||||
::-webkit-scrollbar-track-piece:vertical:end {
|
||||
/*background-image: url(images/scroll_gutter_btm.png), url(images/scroll_gutter_mid.png);
|
||||
background-repeat: no-repeat, repeat-y;
|
||||
background-position: bottom left, 0 0;*/
|
||||
}
|
||||
|
||||
/* The thumb itself */
|
||||
::-webkit-scrollbar-thumb:vertical {
|
||||
height: 56px;
|
||||
width: 12px;
|
||||
/* -webkit-border-image: url(images/scroll_thumb.png) 8 0 8 0 stretch stretch;*/
|
||||
background-color: #DDDDDD;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<script type="text/javascript">
|
||||
var mapconfig = {
|
||||
tilesource : "oscimap4",
|
||||
tileurl : "/tiles/vtm",
|
||||
zoom : "2",
|
||||
latitude : "0.0",
|
||||
longitude : "0.0"
|
||||
zoom : 2,
|
||||
latitude : 0.0,
|
||||
longitude : 0.0
|
||||
}
|
||||
//background : "naturalearth"
|
||||
</script>
|
||||
|
||||
</head>
|
||||
@ -78,6 +148,17 @@
|
||||
| map data © <a href="http://www.openstreemap.org">OpenStreetMap</a> contributors
|
||||
| <a href="http://www.opensciencemap.org">OpenScienceMap</a>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<div id="search">
|
||||
<table align="center">
|
||||
<tr>
|
||||
<td id="nameFieldContainer">
|
||||
<td id="sendButtonContainer">
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" id="listContainer">
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user