From c6f44e7bbfb97e00695a2ea8ea39d0bae7360527 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Fri, 21 Mar 2014 01:21:30 +0100 Subject: [PATCH] gwt: use shader assets - add some url options for 'map' and 'theme' - use local asset folder - merge assets in local directory --- .gitignore | 1 + vtm-gdx-html/build.gradle | 24 ++++- .../src/org/oscim/gdx/GwtDefinition.gwt.xml | 2 +- .../src/org/oscim/gdx/client/GwtGdxMap.java | 101 ++++++++++++++---- .../gdx/backends/gwt/GwtGraphics.java | 8 +- 5 files changed, 115 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index b3636b46..29be210c 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ build/ /vtm-android-example/assets/ /vtm-gdx-desktop/assets/ /vtm-gdx-html/war/ +/vtm-gdx-html/assets/ /vtm-gdx-html/gwt-unitCache /vtm-spatialite/ /vtm-spatialite-android/ diff --git a/vtm-gdx-html/build.gradle b/vtm-gdx-html/build.gradle index 5a2a6120..1b5b68e5 100644 --- a/vtm-gdx-html/build.gradle +++ b/vtm-gdx-html/build.gradle @@ -43,7 +43,12 @@ gwt { superDev { noPrecompile=true } - + compiler { + enableClosureCompiler = false; // activates -XenableClosureCompiler + disableClassMetadata = true; // activates -XdisableClassMetadata + disableCastChecking = true; // activates -XdisableCastChecking + } + src += files(sourceSets.main.java.srcDirs) src += files(project(':vtm').sourceSets.main.allJava.srcDirs) src += files(project(':vtm-themes').sourceSets.main.allJava.srcDirs) @@ -58,6 +63,23 @@ task jettyDraftWar(type: JettyRunWar) { webApp=draftWar.archivePath } +task copyThemeAssets(type: Copy) { + from "$rootDir/vtm-themes/resources/assets" + into "assets" + include '**/*' +} + +task copyVtmAssets(type: Copy) { + from "$rootDir/vtm/resources/assets" + into "assets" + include '**/*' +} + +tasks.withType(JavaCompile) { compileTask -> + compileTask.dependsOn copyThemeAssets + compileTask.dependsOn copyVtmAssets +} + // Configuring Eclipse classpath eclipse.classpath { diff --git a/vtm-gdx-html/src/org/oscim/gdx/GwtDefinition.gwt.xml b/vtm-gdx-html/src/org/oscim/gdx/GwtDefinition.gwt.xml index c0e21f98..949bc9e6 100644 --- a/vtm-gdx-html/src/org/oscim/gdx/GwtDefinition.gwt.xml +++ b/vtm-gdx-html/src/org/oscim/gdx/GwtDefinition.gwt.xml @@ -21,7 +21,7 @@ - + diff --git a/vtm-gdx-html/src/org/oscim/gdx/client/GwtGdxMap.java b/vtm-gdx-html/src/org/oscim/gdx/client/GwtGdxMap.java index a68d33eb..6ff76635 100644 --- a/vtm-gdx-html/src/org/oscim/gdx/client/GwtGdxMap.java +++ b/vtm-gdx-html/src/org/oscim/gdx/client/GwtGdxMap.java @@ -16,6 +16,8 @@ */ package org.oscim.gdx.client; +import java.util.HashMap; + import org.oscim.backend.CanvasAdapter; import org.oscim.backend.GL20; import org.oscim.backend.GLAdapter; @@ -23,9 +25,14 @@ 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.vector.VectorTileLayer; +import org.oscim.layers.tile.vector.labeling.LabelLayer; import org.oscim.renderer.MapRenderer; +import org.oscim.theme.VtmThemes; import org.oscim.tiling.TileSource; -import org.oscim.tiling.source.bitmap.DefaultSources.NaturalEarth; +import org.oscim.tiling.source.bitmap.BitmapTileSource; +import org.oscim.tiling.source.bitmap.DefaultSources; +import org.oscim.tiling.source.bitmap.DefaultSources.StamenToner; import org.oscim.tiling.source.oscimap4.OSciMap4TileSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,14 +73,20 @@ class GwtGdxMap extends GdxMap { float tilt = 0; float rotation = 0; + String themeName = null; + String mapName = null; + final HashMap params = new HashMap(); + String addOpts = ""; if (Window.Location.getHash() != null) { String hash = Window.Location.getHash(); - hash = hash.substring(1); - String[] pairs = hash.split(","); + String[] urlParams = null; + urlParams = hash.split("&"); + if (urlParams.length == 1) + urlParams = hash.split(","); - for (String p : pairs) { + for (String p : urlParams) { try { if (p.startsWith("lat=")) lat = Double.parseDouble(p.substring(4)); @@ -85,33 +98,82 @@ class GwtGdxMap extends GdxMap { rotation = Float.parseFloat(p.substring(4)); else if (p.startsWith("tilt=")) tilt = Float.parseFloat(p.substring(5)); + else if (p.startsWith("theme=")) + themeName = p.substring(6); + else if (p.startsWith("map=")) + mapName = p.substring(4); + else { + String[] opt = p.split("="); + if (opt.length > 1) + params.put(opt[0], opt[1]); + else + params.put(opt[0], null); + + addOpts += p + "&"; + + } } catch (NumberFormatException e) { } } } + + final String addParam = + (themeName == null ? "" : ("theme=" + themeName + "&")) + + (mapName == null ? "" : ("map=" + mapName + "&")) + + addOpts; + MapPosition p = new MapPosition(); p.setZoomLevel(zoom); p.setPosition(lat, lon); - log.debug("map position: " + p.x + "/" + p.y + " " + lat + "/" + lon); - p.bearing = rotation; p.tilt = tilt; + mMap.setMapPosition(p); - //mMap.getViewport().setTilt(tilt); - //mMap.getViewport().setRotation(rotation); + VectorTileLayer l = null; - String url = c.getTileUrl(); - String sourceName = c.getTileSource(); + if (c.getBackgroundLayer() != null || mapName != null) { + BitmapTileSource ts; - TileSource tileSource; - tileSource = new OSciMap4TileSource(url); + if ("toner".equals(mapName)) + ts = new StamenToner(); + else if ("osm".equals(mapName)) + ts = new DefaultSources.OpenStreetMap(); + else if ("watercolor".equals(mapName)) + ts = new DefaultSources.StamenWatercolor(); + else if ("arcgis-shaded".equals(mapName)) + ts = new DefaultSources.ArcGISWorldShaded(); + else if ("imagico".equals(mapName)) + ts = new DefaultSources.ImagicoLandcover(); + else + ts = new StamenToner(); - initDefaultLayers(tileSource, false, true, true); + mMap.setBackgroundMap(new BitmapTileLayer(mMap, ts)); + } else { + String url = c.getTileUrl(); - if ("naturalearth".equals(c.getBackgroundLayer())) - mMap.setBackgroundMap(new BitmapTileLayer(mMap, new NaturalEarth())); + TileSource ts = new OSciMap4TileSource(url); + 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 (l != null) { + if (!params.containsKey("nolabel")) + mMap.layers().add(new LabelLayer(mMap, l)); + } mSearchBox = new SearchBox(mMap); @@ -139,9 +201,12 @@ class GwtGdxMap extends GdxMap { String newURL = Window.Location .createUrlBuilder() - .setHash("scale=" + pos.zoomLevel + ",rot=" + curRot - + ",tilt=" + curTilt + ",lat=" + (curLat / 1000f) - + ",lon=" + (curLon / 1000f)) + .setHash(addParam + + "scale=" + pos.zoomLevel + + "&rot=" + curRot + + "&tilt=" + curTilt + + "&lat=" + (curLat / 1000f) + + "&lon=" + (curLon / 1000f)) .buildString(); Window.Location.replace(newURL); } diff --git a/vtm-gdx-html/src/org/oscim/gdx/emu/com/badlogic/gdx/backends/gwt/GwtGraphics.java b/vtm-gdx-html/src/org/oscim/gdx/emu/com/badlogic/gdx/backends/gwt/GwtGraphics.java index 298b93fb..2827a169 100644 --- a/vtm-gdx-html/src/org/oscim/gdx/emu/com/badlogic/gdx/backends/gwt/GwtGraphics.java +++ b/vtm-gdx-html/src/org/oscim/gdx/emu/com/badlogic/gdx/backends/gwt/GwtGraphics.java @@ -73,7 +73,13 @@ public class GwtGraphics implements Graphics { context.viewport(0, 0, config.width, config.height); // this actually *enables* the option to use std derivatives in shader.. - context.getExtension("OES_standard_derivatives"); + if (context.getExtension("OES_standard_derivatives") == null) { + + } + + if (context.getExtension("WEBKIT_WEBGL_depth_texture") == null) { + + } this.gl = config.useDebugGL ? new GwtGL20Debug(context) : new GwtGLAdapter(context); canvas.setId("gdx-canvas");