gwt: add vtm-web-js project

This commit is contained in:
Hannes Janetzek
2014-03-22 03:23:19 +01:00
parent e6eab7f773
commit c7508d330d
16 changed files with 885 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
<?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" />
<inherits name='org.timepedia.exporter.Exporter' />
<set-property name="export" value="yes" />
<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" />
<set-configuration-property name="gdx.assetpath" value="assets" />
<!-- for gradle build, commend out for eclipse build -->
<set-configuration-property name="gdx.assetoutputpath" value="build/gwt/draftOut" />
<set-property name="user.agent" value="safari" />
</module>

View File

@@ -0,0 +1,83 @@
/*
* Copyright 2013 Hannes Janetzek
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.web.client;
import org.oscim.core.Tile;
import org.timepedia.exporter.client.ExporterUtil;
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;
public class GwtLauncher extends GwtApplication {
@Override
public void onModuleLoad() {
//GWT.create(GwtGdxMap.class);
//JsOverlays.init();
ExporterUtil.exportAll();
super.onModuleLoad();
}
@Override
public GwtApplicationConfiguration getConfig() {
GwtApplicationConfiguration cfg =
new GwtApplicationConfiguration(getWindowWidth(),
getWindowHeight());
cfg.canvasId = "map-canvas";
cfg.stencil = true;
cfg.fps = 120;
return cfg;
}
@Override
public ApplicationListener getApplicationListener() {
Tile.SIZE = MapConfig.get().getTileSize();
return new GwtMap();
}
@Override
public PreloaderCallback getPreloaderCallback() {
return new PreloaderCallback() {
@Override
public void update(PreloaderState state) {
}
@Override
public void error(String file) {
//log.debug("error loading " + file);
}
};
}
private static native int getWindowWidth() /*-{
return $wnd.innerWidth;
}-*/;
private static native int getWindowHeight() /*-{
return $wnd.innerHeight;
}-*/;
}

View File

@@ -0,0 +1,112 @@
/*
* Copyright 2013 Hannes Janetzek
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.web.client;
import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.GL20;
import org.oscim.backend.GLAdapter;
import org.oscim.core.MapPosition;
import org.oscim.gdx.GdxAssets;
import org.oscim.gdx.GdxMap;
import org.oscim.gdx.client.GwtGdxGraphics;
import org.oscim.gdx.client.UrlUpdater;
import org.oscim.renderer.MapRenderer;
import org.oscim.web.js.JsMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.gwt.GwtApplication;
import com.google.gwt.user.client.Window;
public class GwtMap extends GdxMap {
static final Logger log = LoggerFactory.getLogger(GwtMap.class);
@Override
public void create() {
GwtGdxGraphics.init();
GdxAssets.init("");
CanvasAdapter.textScale = 0.7f;
GLAdapter.init((GL20) Gdx.graphics.getGL20());
GLAdapter.GDX_WEBGL_QUIRKS = true;
MapRenderer.setBackgroundColor(0xffffff);
JsMap.init(mMap);
// 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;
MapConfig c = MapConfig.get();
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);
p.bearing = rotation;
p.tilt = tilt;
mMap.setMapPosition(p);
UrlUpdater urlUpdater = new UrlUpdater(mMap);
urlUpdater.scheduleRepeating(4000);
}
private final native void createLayersN()/*-{
$wnd.createLayers();
}-*/;
@Override
protected void createLayers() {
log.debug("<<< create layers >>>");
createLayersN();
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright 2013 Hannes Janetzek
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.web.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;
}-*/;
public final native int getTileSize() /*-{
return this.tileSize || 256;
}-*/;
}

View File

@@ -0,0 +1,22 @@
package org.oscim.web.js;
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
import org.oscim.map.Map;
import org.oscim.tiling.TileSource;
import org.timepedia.exporter.client.Export;
import org.timepedia.exporter.client.ExportOverlay;
import org.timepedia.exporter.client.ExportPackage;
@ExportPackage("vtm")
@Export("BitmapTileLayer")
public class JsBitmapTileLayer extends BitmapTileLayer implements ExportOverlay<BitmapTileLayer> {
public JsBitmapTileLayer(Map map, TileSource tileSource) {
super(map, tileSource);
}
// @ExportConstructor
// public static BitmapTileLayer constructor(Map map, TileSource tileSource) {
// return new JsBitmapTileLayer(map, tileSource);
// }
}

View File

@@ -0,0 +1,27 @@
package org.oscim.web.js;
import org.oscim.tiling.ITileDataSource;
import org.oscim.tiling.source.bitmap.BitmapTileSource;
import org.timepedia.exporter.client.Export;
import org.timepedia.exporter.client.ExportOverlay;
import org.timepedia.exporter.client.ExportPackage;
@ExportPackage("vtm")
@Export("BitmapTileSource")
public class JsBitmapTileSource extends BitmapTileSource implements
ExportOverlay<BitmapTileSource> {
public JsBitmapTileSource(String url, int zoomMin, int zoomMax) {
super(url, zoomMin, zoomMax);
}
@Override
public ITileDataSource getDataSource() {
return null;
}
// @ExportConstructor
// public static BitmapTileSource constructor(String url, int zoomMin, int zoomMax) {
// return new JsBitmapTileSource(url, zoomMin, zoomMax);
// }
}

View File

@@ -0,0 +1,60 @@
package org.oscim.web.js;
import org.oscim.core.MapPosition;
import org.oscim.layers.Layer;
import org.oscim.map.Layers;
import org.oscim.map.Map;
import org.oscim.theme.IRenderTheme;
import org.oscim.theme.ThemeLoader;
import org.oscim.theme.VtmThemes;
import org.timepedia.exporter.client.Export;
import org.timepedia.exporter.client.ExportPackage;
import org.timepedia.exporter.client.Exportable;
import org.timepedia.exporter.client.NoExport;
@ExportPackage("")
@Export("map")
public class JsMap implements Exportable {
static Map mMap;
@Export
public static Map map() {
return mMap;
}
@Export
public static Layers layers() {
return mMap.layers();
}
@Export
public static boolean addLayer(Layer l) {
return mMap.layers().add(l);
}
@Export
public static boolean getPosition(MapPosition pos) {
return mMap.getMapPosition(pos);
}
@Export
public static void setPosition(MapPosition pos) {
mMap.setMapPosition(pos);
}
@Export
public static IRenderTheme loadTheme(String theme) {
return ThemeLoader.load(VtmThemes.valueOf(theme));
}
@NoExport
public static void init(Map map) {
mMap = map;
}
// @ExportInstanceMethod("foo")
// public static String instanceMethod(Map instance, String surname) {
// return instance.getName() + "-" + surname;
// }
}

View File

@@ -0,0 +1,144 @@
package org.oscim.web.js;
import org.oscim.core.MapPosition;
import org.oscim.layers.GenericLayer;
import org.oscim.layers.Layer;
import org.oscim.layers.TileGridLayer;
import org.oscim.layers.tile.vector.BuildingLayer;
import org.oscim.layers.tile.vector.OsmTileLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.map.Layers;
import org.oscim.map.Map;
import org.oscim.renderer.LayerRenderer;
import org.oscim.theme.IRenderTheme;
import org.oscim.tiling.TileSource;
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
import org.timepedia.exporter.client.Export;
import org.timepedia.exporter.client.ExportOverlay;
import org.timepedia.exporter.client.ExportPackage;
public final class JsOverlays {
@ExportPackage("vtm")
@Export("Layers")
public interface XLayers extends ExportOverlay<Layers> {
void add(Layer layer);
}
@ExportPackage("vtm")
@Export("Map")
public interface XMap extends ExportOverlay<Map> {
public abstract Layers layers();
public abstract void setMapPosition(MapPosition pos);
public abstract MapPosition getMapPosition();
}
@ExportPackage("vtm")
@Export("MapPosition")
public static class XMapPosition implements ExportOverlay<MapPosition> {
public XMapPosition(double latitude, double longitude, double scale) {
};
public XMapPosition() {
};
public void setPosition(double latitude, double longitude) {
}
public void setScale(double scale) {
}
}
@ExportPackage("vtm")
@Export("GenericLayer")
public abstract class XGenericLayer implements ExportOverlay<GenericLayer> {
public XGenericLayer(Map map, LayerRenderer renderer) {
}
}
@ExportPackage("vtm")
@Export("TileGridLayer")
public static class XTileGridLayer implements ExportOverlay<TileGridLayer> {
public XTileGridLayer(Map map) {
}
}
@ExportPackage("vtm")
@Export("VectorTileLayer")
public static class XVectorTileLayer implements ExportOverlay<VectorTileLayer> {
public XVectorTileLayer(Map map, TileSource tileSource) {
}
public boolean setTileSource(TileSource tileSource) {
return false;
}
public void setRenderTheme(IRenderTheme theme) {
}
}
@ExportPackage("vtm")
@Export("OsmTileLayer")
public static class XOsmTileLayer implements ExportOverlay<OsmTileLayer> {
public XOsmTileLayer(Map map) {
}
public boolean setTileSource(TileSource tileSource) {
return false;
}
public void setRenderTheme(IRenderTheme theme) {
}
}
// @ExportPackage("vtm")
// @Export("OsmLanduseJsonTileSource")
// public static class XOsmLanduseJsonTileSource implements
// ExportOverlay<OsmLanduseJsonTileSource> {
// public XOsmLanduseJsonTileSource() {
// }
// }
//
// @ExportPackage("vtm")
// @Export("HighroadJsonTileSource")
// public static class XHighroadJsonTileSource implements
// ExportOverlay<HighroadJsonTileSource> {
// public XHighroadJsonTileSource() {
// }
// }
@ExportPackage("vtm")
@Export("OSciMap4TileSource")
public static class XOSciMap4TileSource implements
ExportOverlay<OSciMap4TileSource> {
public XOSciMap4TileSource(String url) {
}
public XOSciMap4TileSource() {
}
}
@ExportPackage("vtm")
@Export("LabelLayer")
public static class XLabelLayer implements
ExportOverlay<LabelLayer> {
public XLabelLayer(Map map, VectorTileLayer l) {
}
}
@ExportPackage("vtm")
@Export("BuildingLayer")
public static class XBuildingLayer implements
ExportOverlay<BuildingLayer> {
public XBuildingLayer(Map map, VectorTileLayer l) {
}
}
// @ExportPackage("vtm")
// @Export("Viewport")
// public interface XViewport extends ExportOverlay
//
}