Improve code / xml formatting, closes #54
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<module rename-to="VtmWebApp">
|
||||
|
||||
<entry-point class="org.oscim.web.client.GwtLauncher" />
|
||||
<inherits name="org.oscim.gdx.VtmWeb" />
|
||||
|
||||
<set-property name='gwt.logging.enabled' value='TRUE' />
|
||||
<set-property name='gwt.logging.consoleHandler' value='ENABLED' />
|
||||
<set-property name='gwt.logging.firebugHandler' value='DISABLED' />
|
||||
<set-property name='gwt.logging.popupHandler' value='DISABLED' />
|
||||
<set-property name="gwt.logging.logLevel" value="FINE"/>
|
||||
|
||||
<!-- super dev mode -->
|
||||
<!-- <add-linker name="xsiframe"/>
|
||||
<set-configuration-property name='xsiframe.failIfScriptTag' value='FALSE'/>
|
||||
<set-configuration-property name="devModeRedirectEnabled" value="true"/>
|
||||
-->
|
||||
|
||||
<!-- <super-source path="emu" /> -->
|
||||
|
||||
<set-configuration-property name="gdx.assetpath" value="assets" />
|
||||
<!-- for gradle build, commend out for eclipse build/devmode -->
|
||||
<set-configuration-property name="gdx.assetoutputpath" value="build/gwt/draftOut" />
|
||||
<entry-point class="org.oscim.web.client.GwtLauncher" />
|
||||
<inherits name="org.oscim.gdx.VtmWeb" />
|
||||
|
||||
<set-property name="user.agent" value="safari"/>
|
||||
<set-property name='gwt.logging.enabled' value='TRUE' />
|
||||
<set-property name='gwt.logging.consoleHandler' value='ENABLED' />
|
||||
<set-property name='gwt.logging.firebugHandler' value='DISABLED' />
|
||||
<set-property name='gwt.logging.popupHandler' value='DISABLED' />
|
||||
<set-property name="gwt.logging.logLevel" value="FINE" />
|
||||
|
||||
<!-- super dev mode -->
|
||||
<!-- <add-linker name="xsiframe"/>
|
||||
<set-configuration-property name='xsiframe.failIfScriptTag' value='FALSE'/>
|
||||
<set-configuration-property name="devModeRedirectEnabled" value="true"/>
|
||||
-->
|
||||
|
||||
<!-- <super-source path="emu" /> -->
|
||||
|
||||
<set-configuration-property name="gdx.assetpath" value="assets" />
|
||||
<!-- for gradle build, commend out for eclipse build/devmode -->
|
||||
<set-configuration-property name="gdx.assetoutputpath" value="build/gwt/draftOut" />
|
||||
|
||||
<set-property name="user.agent" value="safari" />
|
||||
</module>
|
||||
|
||||
@@ -16,59 +16,59 @@
|
||||
*/
|
||||
package org.oscim.web.client;
|
||||
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.gdx.client.MapConfig;
|
||||
|
||||
import com.badlogic.gdx.ApplicationListener;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplication;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
|
||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback;
|
||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState;
|
||||
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.gdx.client.MapConfig;
|
||||
|
||||
public class GwtLauncher extends GwtApplication {
|
||||
|
||||
@Override
|
||||
public GwtApplicationConfiguration getConfig() {
|
||||
@Override
|
||||
public GwtApplicationConfiguration getConfig() {
|
||||
|
||||
GwtApplicationConfiguration cfg =
|
||||
new GwtApplicationConfiguration(getWindowWidth(),
|
||||
getWindowHeight());
|
||||
GwtApplicationConfiguration cfg =
|
||||
new GwtApplicationConfiguration(getWindowWidth(),
|
||||
getWindowHeight());
|
||||
|
||||
cfg.canvasId = "map-canvas";
|
||||
cfg.stencil = true;
|
||||
cfg.fps = 120;
|
||||
cfg.canvasId = "map-canvas";
|
||||
cfg.stencil = true;
|
||||
cfg.fps = 120;
|
||||
|
||||
return cfg;
|
||||
}
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationListener getApplicationListener() {
|
||||
Tile.SIZE = MapConfig.get().getTileSize();
|
||||
@Override
|
||||
public ApplicationListener getApplicationListener() {
|
||||
Tile.SIZE = MapConfig.get().getTileSize();
|
||||
|
||||
return new GwtMap();
|
||||
}
|
||||
return new GwtMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreloaderCallback getPreloaderCallback() {
|
||||
return new PreloaderCallback() {
|
||||
@Override
|
||||
public PreloaderCallback getPreloaderCallback() {
|
||||
return new PreloaderCallback() {
|
||||
|
||||
@Override
|
||||
public void update(PreloaderState state) {
|
||||
}
|
||||
@Override
|
||||
public void update(PreloaderState state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String file) {
|
||||
//log.debug("error loading " + file);
|
||||
}
|
||||
};
|
||||
}
|
||||
@Override
|
||||
public void error(String file) {
|
||||
//log.debug("error loading " + file);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static native int getWindowWidth() /*-{
|
||||
return $wnd.innerWidth;
|
||||
private static native int getWindowWidth() /*-{
|
||||
return $wnd.innerWidth;
|
||||
}-*/;
|
||||
|
||||
private static native int getWindowHeight() /*-{
|
||||
return $wnd.innerHeight;
|
||||
private static native int getWindowHeight() /*-{
|
||||
return $wnd.innerHeight;
|
||||
}-*/;
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
*/
|
||||
package org.oscim.web.client;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplication;
|
||||
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.GL;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
@@ -39,112 +42,109 @@ import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplication;
|
||||
|
||||
class GwtMap extends GdxMap {
|
||||
static final Logger log = LoggerFactory.getLogger(GwtMap.class);
|
||||
static final Logger log = LoggerFactory.getLogger(GwtMap.class);
|
||||
|
||||
SearchBox mSearchBox;
|
||||
SearchBox mSearchBox;
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
MapConfig c = MapConfig.get();
|
||||
@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())
|
||||
GwtGdxGraphics.NO_STROKE_TEXT = true;
|
||||
// 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())
|
||||
GwtGdxGraphics.NO_STROKE_TEXT = true;
|
||||
|
||||
GwtGdxGraphics.init();
|
||||
GdxAssets.init("");
|
||||
CanvasAdapter.textScale = 0.7f;
|
||||
GwtGdxGraphics.init();
|
||||
GdxAssets.init("");
|
||||
CanvasAdapter.textScale = 0.7f;
|
||||
|
||||
GLAdapter.init((GL) Gdx.graphics.getGL20());
|
||||
GLAdapter.GDX_WEBGL_QUIRKS = true;
|
||||
MapRenderer.setBackgroundColor(0xffffff);
|
||||
//Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
||||
GLAdapter.init((GL) Gdx.graphics.getGL20());
|
||||
GLAdapter.GDX_WEBGL_QUIRKS = true;
|
||||
MapRenderer.setBackgroundColor(0xffffff);
|
||||
//Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
||||
|
||||
super.create();
|
||||
super.create();
|
||||
|
||||
MapPosition p = new MapPosition();
|
||||
p.setZoomLevel(c.getZoom());
|
||||
p.setPosition(c.getLatitude(), c.getLongitude());
|
||||
MapPosition p = new MapPosition();
|
||||
p.setZoomLevel(c.getZoom());
|
||||
p.setPosition(c.getLatitude(), c.getLongitude());
|
||||
|
||||
MapUrl mapUrl = new MapUrl(mMap);
|
||||
mapUrl.parseUrl(p);
|
||||
mapUrl.scheduleRepeating(5000);
|
||||
MapUrl mapUrl = new MapUrl(mMap);
|
||||
mapUrl.parseUrl(p);
|
||||
mapUrl.scheduleRepeating(5000);
|
||||
|
||||
mMap.setMapPosition(p);
|
||||
mMap.setMapPosition(p);
|
||||
|
||||
String mapName = mapUrl.getParam("map");
|
||||
String themeName = mapUrl.getParam("theme");
|
||||
String mapName = mapUrl.getParam("map");
|
||||
String themeName = mapUrl.getParam("theme");
|
||||
|
||||
VectorTileLayer l = null;
|
||||
VectorTileLayer l = null;
|
||||
|
||||
if (mapName != null) {
|
||||
BitmapTileSource ts;
|
||||
if (mapName != null) {
|
||||
BitmapTileSource ts;
|
||||
|
||||
if ("toner".equals(mapName))
|
||||
ts = DefaultSources.STAMEN_TONER.build();
|
||||
else if ("osm".equals(mapName))
|
||||
ts = DefaultSources.OPENSTREETMAP.build();
|
||||
else if ("watercolor".equals(mapName))
|
||||
ts = DefaultSources.STAMEN_WATERCOLOR.build();
|
||||
else if ("arcgis-shaded".equals(mapName))
|
||||
ts = DefaultSources.ARCGIS_RELIEF.build();
|
||||
else if ("imagico".equals(mapName))
|
||||
ts = DefaultSources.IMAGICO_LANDCOVER.build();
|
||||
else
|
||||
ts = DefaultSources.STAMEN_TONER.build();
|
||||
if ("toner".equals(mapName))
|
||||
ts = DefaultSources.STAMEN_TONER.build();
|
||||
else if ("osm".equals(mapName))
|
||||
ts = DefaultSources.OPENSTREETMAP.build();
|
||||
else if ("watercolor".equals(mapName))
|
||||
ts = DefaultSources.STAMEN_WATERCOLOR.build();
|
||||
else if ("arcgis-shaded".equals(mapName))
|
||||
ts = DefaultSources.ARCGIS_RELIEF.build();
|
||||
else if ("imagico".equals(mapName))
|
||||
ts = DefaultSources.IMAGICO_LANDCOVER.build();
|
||||
else
|
||||
ts = DefaultSources.STAMEN_TONER.build();
|
||||
|
||||
mMap.setBaseMap(new BitmapTileLayer(mMap, ts));
|
||||
} else {
|
||||
TileSource ts = new OSciMap4TileSource();
|
||||
l = mMap.setBaseMap(ts);
|
||||
mMap.setBaseMap(new BitmapTileLayer(mMap, ts));
|
||||
} else {
|
||||
TileSource ts = new OSciMap4TileSource();
|
||||
l = mMap.setBaseMap(ts);
|
||||
|
||||
if (themeName == null) {
|
||||
mMap.setTheme(VtmThemes.DEFAULT);
|
||||
} else {
|
||||
if ("osmarender".equals(themeName))
|
||||
mMap.setTheme(VtmThemes.OSMARENDER);
|
||||
else if ("tron".equals(themeName))
|
||||
mMap.setTheme(VtmThemes.TRONRENDER);
|
||||
else if ("newtron".equals(themeName))
|
||||
mMap.setTheme(VtmThemes.NEWTRON);
|
||||
else
|
||||
mMap.setTheme(VtmThemes.DEFAULT);
|
||||
}
|
||||
}
|
||||
if (themeName == null) {
|
||||
mMap.setTheme(VtmThemes.DEFAULT);
|
||||
} else {
|
||||
if ("osmarender".equals(themeName))
|
||||
mMap.setTheme(VtmThemes.OSMARENDER);
|
||||
else if ("tron".equals(themeName))
|
||||
mMap.setTheme(VtmThemes.TRONRENDER);
|
||||
else if ("newtron".equals(themeName))
|
||||
mMap.setTheme(VtmThemes.NEWTRON);
|
||||
else
|
||||
mMap.setTheme(VtmThemes.DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
boolean s3db = mapUrl.params.containsKey("s3db");
|
||||
if (s3db) {
|
||||
TileSource ts = OSciMap4TileSource.builder()
|
||||
.url("http://opensciencemap.org/tiles/s3db")
|
||||
.zoomMin(16)
|
||||
.zoomMax(16)
|
||||
.build();
|
||||
mMap.layers().add(new S3DBLayer(mMap, ts));
|
||||
}
|
||||
if (l != null) {
|
||||
boolean nolabels = mapUrl.params.containsKey("nolabels");
|
||||
boolean nobuildings = mapUrl.params.containsKey("nobuildings");
|
||||
boolean s3db = mapUrl.params.containsKey("s3db");
|
||||
if (s3db) {
|
||||
TileSource ts = OSciMap4TileSource.builder()
|
||||
.url("http://opensciencemap.org/tiles/s3db")
|
||||
.zoomMin(16)
|
||||
.zoomMax(16)
|
||||
.build();
|
||||
mMap.layers().add(new S3DBLayer(mMap, ts));
|
||||
}
|
||||
if (l != null) {
|
||||
boolean nolabels = mapUrl.params.containsKey("nolabels");
|
||||
boolean nobuildings = mapUrl.params.containsKey("nobuildings");
|
||||
|
||||
if (!nobuildings && !s3db)
|
||||
mMap.layers().add(new BuildingLayer(mMap, l));
|
||||
if (!nobuildings && !s3db)
|
||||
mMap.layers().add(new BuildingLayer(mMap, l));
|
||||
|
||||
if (!nolabels)
|
||||
mMap.layers().add(new LabelLayer(mMap, l));
|
||||
}
|
||||
if (!nolabels)
|
||||
mMap.layers().add(new LabelLayer(mMap, l));
|
||||
}
|
||||
|
||||
mSearchBox = new SearchBox(mMap);
|
||||
mSearchBox = new SearchBox(mMap);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createLayers() {
|
||||
}
|
||||
@Override
|
||||
protected void createLayers() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,17 +16,6 @@
|
||||
*/
|
||||
package org.oscim.web.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.oscim.core.BoundingBox;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.layers.PathLayer;
|
||||
import org.oscim.map.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gwt.cell.client.AbstractCell;
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.core.client.JsArray;
|
||||
@@ -52,315 +41,326 @@ import com.google.gwt.view.client.ProvidesKey;
|
||||
import com.google.gwt.view.client.SelectionChangeEvent;
|
||||
import com.google.gwt.view.client.SingleSelectionModel;
|
||||
|
||||
import org.oscim.core.BoundingBox;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.layers.PathLayer;
|
||||
import org.oscim.map.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Entry point classes define <code>onModuleLoad()</code>.
|
||||
*/
|
||||
public class SearchBox {
|
||||
|
||||
protected static final Logger log = LoggerFactory.getLogger(SearchBox.class);
|
||||
protected static final Logger log = LoggerFactory.getLogger(SearchBox.class);
|
||||
|
||||
private static final String NOMINATIM_GLOBAL = "http://nominatim.openstreetmap.org/search?polygon_text=1&addressdetails=0&format=json&limit=25&q=";
|
||||
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();
|
||||
}
|
||||
};
|
||||
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 getId();
|
||||
|
||||
String getName();
|
||||
String getName();
|
||||
|
||||
double getLatitude();
|
||||
double getLatitude();
|
||||
|
||||
double getLongitude();
|
||||
double getLongitude();
|
||||
|
||||
String getIcon();
|
||||
String getIcon();
|
||||
|
||||
BoundingBox getBoundingBox();
|
||||
}
|
||||
BoundingBox getBoundingBox();
|
||||
}
|
||||
|
||||
final static class NominatimData extends JavaScriptObject implements
|
||||
PoiData {
|
||||
final static class NominatimData extends JavaScriptObject implements
|
||||
PoiData {
|
||||
|
||||
protected NominatimData() {
|
||||
}
|
||||
protected NominatimData() {
|
||||
}
|
||||
|
||||
final static class BBox extends JsArrayNumber {
|
||||
protected BBox() {
|
||||
}
|
||||
}
|
||||
final static class BBox extends JsArrayNumber {
|
||||
protected BBox() {
|
||||
}
|
||||
}
|
||||
|
||||
final static class Polygon extends JsArray<JsArrayNumber> {
|
||||
protected Polygon() {
|
||||
}
|
||||
final static class Polygon extends JsArray<JsArrayNumber> {
|
||||
protected Polygon() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final native String getId()
|
||||
/*-{
|
||||
return this.osm_id;
|
||||
@Override
|
||||
public final native String getId()
|
||||
/*-{
|
||||
return this.osm_id;
|
||||
}-*/;
|
||||
|
||||
public final native String name() /*-{
|
||||
public final native String name() /*-{
|
||||
return this.display_name;
|
||||
}-*/;
|
||||
|
||||
public final native BBox getBBox() /*-{
|
||||
public final native BBox getBBox() /*-{
|
||||
return this.boundingbox
|
||||
}-*/;
|
||||
|
||||
public final native String getWkt() /*-{
|
||||
public final native String getWkt() /*-{
|
||||
return this.geotext;
|
||||
}-*/;
|
||||
|
||||
private final native String latitude() /*-{
|
||||
private final native String latitude() /*-{
|
||||
return this.lat;
|
||||
}-*/;
|
||||
|
||||
private final native String longitude() /*-{
|
||||
private final native String longitude() /*-{
|
||||
return this.lon;
|
||||
}-*/;
|
||||
|
||||
public final native String getIcon() /*-{
|
||||
public final native String getIcon() /*-{
|
||||
return this.icon;
|
||||
}-*/;
|
||||
|
||||
@Override
|
||||
public double getLatitude() {
|
||||
try {
|
||||
return Double.parseDouble(latitude());
|
||||
} catch (Exception e) {
|
||||
@Override
|
||||
public double getLatitude() {
|
||||
try {
|
||||
return Double.parseDouble(latitude());
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLongitude() {
|
||||
try {
|
||||
return Double.parseDouble(longitude());
|
||||
} 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 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];
|
||||
@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();
|
||||
}
|
||||
}
|
||||
return name();
|
||||
}
|
||||
}
|
||||
|
||||
class PoiCell extends AbstractCell<PoiData> {
|
||||
class PoiCell extends AbstractCell<PoiData> {
|
||||
|
||||
@Override
|
||||
public void render(com.google.gwt.cell.client.Cell.Context context,
|
||||
PoiData value, SafeHtmlBuilder sb) {
|
||||
@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;
|
||||
}
|
||||
// Value can be null, so do a null check..
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
sb.appendHtmlConstant("<table>");
|
||||
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>");
|
||||
}
|
||||
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>");
|
||||
}
|
||||
}
|
||||
// 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 Map map) {
|
||||
final Button searchButton = new Button("Search");
|
||||
final TextBox searchField = new TextBox();
|
||||
//searchField.setText("Bremen");
|
||||
final PathLayer mOverlay = new PathLayer(map, 0xCC0000FF);
|
||||
map.layers().add(mOverlay);
|
||||
public SearchBox(final Map map) {
|
||||
final Button searchButton = new Button("Search");
|
||||
final TextBox searchField = new TextBox();
|
||||
//searchField.setText("Bremen");
|
||||
final PathLayer mOverlay = new PathLayer(map, 0xCC0000FF);
|
||||
map.layers().add(mOverlay);
|
||||
|
||||
// We can add style names to widgets
|
||||
searchButton.addStyleName("sendButton");
|
||||
// We can add style names to widgets
|
||||
searchButton.addStyleName("sendButton");
|
||||
|
||||
RootPanel.get("nameFieldContainer").add(searchField);
|
||||
RootPanel.get("sendButtonContainer").add(searchButton);
|
||||
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();
|
||||
// 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 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);
|
||||
// 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 SingleSelectionModel<PoiData> selectionModel = new SingleSelectionModel<PoiData>(
|
||||
PoiData.KEY_PROVIDER);
|
||||
cellList.setSelectionModel(selectionModel);
|
||||
|
||||
final ScrollPanel scroller = new ScrollPanel(cellList);
|
||||
RootPanel.get("listContainer").add(scroller);
|
||||
final ScrollPanel scroller = new ScrollPanel(cellList);
|
||||
RootPanel.get("listContainer").add(scroller);
|
||||
|
||||
scroller.setSize("350px", "300px");
|
||||
scroller.setSize("350px", "300px");
|
||||
|
||||
RootPanel.get("search").getElement().getStyle().setVisibility(Visibility.VISIBLE);
|
||||
scroller.setVisible(false);
|
||||
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();
|
||||
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();
|
||||
mOverlay.clearPath();
|
||||
|
||||
//log.debug("selected " + d.getName() + " " + d.getLatitude() + " "
|
||||
// + d.getLongitude());
|
||||
//log.debug("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
|
||||
map.animator().animateTo(500, b.getCenterPoint(), 1 << 16, false);
|
||||
else
|
||||
map.animator().animateTo(b);
|
||||
if (d instanceof NominatimData && ((NominatimData) d).getWkt() != null) {
|
||||
String wkt = ((NominatimData) d).getWkt();
|
||||
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
|
||||
map.animator().animateTo(500, b.getCenterPoint(), 1 << 16, false);
|
||||
else
|
||||
map.animator().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.debug(wkt);
|
||||
}
|
||||
//FIXME mOverlay.setGeom(g);
|
||||
WKTReader r = new WKTReader();
|
||||
GeometryBuffer g = new GeometryBuffer(1024, 10);
|
||||
try {
|
||||
r.parse(wkt, g);
|
||||
} catch (Exception e) {
|
||||
log.debug(wkt);
|
||||
}
|
||||
//FIXME mOverlay.setGeom(g);
|
||||
|
||||
//log.debug("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
|
||||
map.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mOverlay.clearPath();
|
||||
}
|
||||
}, 5000);
|
||||
} else {
|
||||
MapPosition pos = new MapPosition();
|
||||
//log.debug("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
|
||||
map.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mOverlay.clearPath();
|
||||
}
|
||||
}, 5000);
|
||||
} else {
|
||||
MapPosition pos = new MapPosition();
|
||||
|
||||
map.viewport().setTilt(0);
|
||||
map.viewport().setRotation(0);
|
||||
map.viewport().setTilt(0);
|
||||
map.viewport().setRotation(0);
|
||||
|
||||
pos.setZoomLevel(13);
|
||||
pos.setPosition(d.getLatitude(), d.getLongitude());
|
||||
map.setMapPosition(pos);
|
||||
}
|
||||
pos.setZoomLevel(13);
|
||||
pos.setPosition(d.getLatitude(), d.getLongitude());
|
||||
map.setMapPosition(pos);
|
||||
}
|
||||
|
||||
scroller.setVisible(false);
|
||||
}
|
||||
scroller.setVisible(false);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
// Create a handler for the sendButton and nameField
|
||||
class MyHandler implements ClickHandler, KeyUpHandler {
|
||||
// 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 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();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
/**
|
||||
* 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);
|
||||
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.debug("request failed");
|
||||
searchButton.setEnabled(true);
|
||||
}
|
||||
JsonpRequestBuilder builder = new JsonpRequestBuilder();
|
||||
builder.setCallbackParam("json_callback");
|
||||
builder.requestObject(url, new AsyncCallback<JsArray<NominatimData>>() {
|
||||
public void onFailure(Throwable caught) {
|
||||
log.debug("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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
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);
|
||||
// Add a handler to send the name to the server
|
||||
MyHandler handler = new MyHandler();
|
||||
searchButton.addClickHandler(handler);
|
||||
searchField.addKeyUpHandler(handler);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,222 +19,222 @@ package org.oscim.web.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 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();
|
||||
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 };
|
||||
public void parse(String wkt, GeometryBuffer geom) throws Exception {
|
||||
// return position.
|
||||
int[] pos = new int[]{0};
|
||||
|
||||
int len = wkt.length();
|
||||
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();
|
||||
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);
|
||||
parseLine(geom, wkt, len, pos);
|
||||
|
||||
} else if (wkt.startsWith(POLY, pos[0])) {
|
||||
pos[0] += SKIP_POLY;
|
||||
geom.startPolygon();
|
||||
} else if (wkt.startsWith(POLY, pos[0])) {
|
||||
pos[0] += SKIP_POLY;
|
||||
geom.startPolygon();
|
||||
|
||||
parsePoly(geom, wkt, len, pos);
|
||||
parsePoly(geom, wkt, len, pos);
|
||||
|
||||
} else if (wkt.startsWith(MULTI, pos[0])) {
|
||||
pos[0] += SKIP_MULTI;
|
||||
} 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, ')');
|
||||
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(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 ");
|
||||
}
|
||||
} 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();
|
||||
private static void ensure(String wkt, int[] pos, char c) throws Exception {
|
||||
if (wkt.charAt(pos[0]) != c)
|
||||
throw new Exception();
|
||||
|
||||
pos[0]++;
|
||||
}
|
||||
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);
|
||||
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, ')');
|
||||
}
|
||||
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, '(');
|
||||
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, ')');
|
||||
}
|
||||
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);
|
||||
private static void parsePoint(GeometryBuffer geom, String wkt, int len, int[] adv) {
|
||||
float x = parseNumber(wkt, len, adv);
|
||||
|
||||
// skip ' '
|
||||
adv[0]++;
|
||||
// skip ' '
|
||||
adv[0]++;
|
||||
|
||||
float y = parseNumber(wkt, len, adv);
|
||||
float y = parseNumber(wkt, len, adv);
|
||||
|
||||
geom.addPoint(x, y);
|
||||
}
|
||||
geom.addPoint(x, y);
|
||||
}
|
||||
|
||||
static float parseNumber(String wkt, int len, int[] adv) {
|
||||
int pos = adv[0];
|
||||
static float parseNumber(String wkt, int len, int[] adv) {
|
||||
int pos = adv[0];
|
||||
|
||||
boolean neg = false;
|
||||
if (wkt.charAt(pos) == '-') {
|
||||
neg = true;
|
||||
pos++;
|
||||
}
|
||||
boolean neg = false;
|
||||
if (wkt.charAt(pos) == '-') {
|
||||
neg = true;
|
||||
pos++;
|
||||
}
|
||||
|
||||
float val = 0;
|
||||
int pre = 0;
|
||||
char c = 0;
|
||||
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);
|
||||
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');
|
||||
}
|
||||
break;
|
||||
}
|
||||
val = val * 10 + (int) (c - '0');
|
||||
}
|
||||
|
||||
if (pre == 0)
|
||||
throw new NumberFormatException();
|
||||
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 == '.') {
|
||||
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++;
|
||||
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;
|
||||
// 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');
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
adv[0] = pos;
|
||||
|
||||
return neg ? -val : val;
|
||||
}
|
||||
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();
|
||||
// }
|
||||
// }
|
||||
// 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();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user