vtm-ios-example module (#326)

This commit is contained in:
Longri
2017-03-03 09:48:05 +01:00
committed by Emux
parent 808671c1fb
commit 7500ca1711
17 changed files with 374 additions and 6 deletions

View File

@@ -0,0 +1,63 @@
/*
* Copyright 2016 Longri
* Copyright 2016 devemux86
*
* 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.ios.test;
import com.badlogic.gdx.backends.iosrobovm.IOSApplication;
import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration;
import org.oscim.backend.CanvasAdapter;
import org.robovm.apple.foundation.NSAutoreleasePool;
import org.robovm.apple.glkit.GLKViewDrawableStencilFormat;
import org.robovm.apple.uikit.UIApplication;
import org.robovm.apple.uikit.UIDevice;
import org.robovm.apple.uikit.UIScreen;
public class ExampleLauncher extends IOSApplication.Delegate {
@Override
protected IOSApplication createApplication() {
IOSApplicationConfiguration config = new IOSApplicationConfiguration();
config.orientationLandscape = true;
config.orientationPortrait = true;
config.stencilFormat = GLKViewDrawableStencilFormat._8;
float scale = (float) (getIosVersion() >= 8 ? UIScreen.getMainScreen().getNativeScale() : UIScreen.getMainScreen().getScale());
CanvasAdapter.dpi *= scale;
// IOSMapApp iosMapApp = new IOSMapApp();
// IOSMapAppCluster iosMapApp = new IOSMapAppCluster();
IOSLineTexTest iosMapApp = new IOSLineTexTest();
iosMapApp.init();
return new IOSApplication(iosMapApp, config);
}
private int getIosVersion() {
String systemVersion = UIDevice.getCurrentDevice().getSystemVersion();
return Integer.parseInt(systemVersion.split("\\.")[0]);
}
public static void main(String[] argv) {
NSAutoreleasePool pool = new NSAutoreleasePool();
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE");
UIApplication.main(argv, null, ExampleLauncher.class);
pool.drain();
}
}

View File

@@ -0,0 +1,135 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016 Longri
*
* 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.ios.test;
import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.GLAdapter;
import org.oscim.backend.canvas.Color;
import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition;
import org.oscim.event.Event;
import org.oscim.gdx.GdxAssets;
import org.oscim.gdx.GdxMap;
import org.oscim.ios.backend.IosGL;
import org.oscim.ios.backend.IosGraphics;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.layers.vector.PathLayer;
import org.oscim.layers.vector.geometries.Style;
import org.oscim.map.Map;
import org.oscim.renderer.bucket.TextureItem;
import org.oscim.theme.VtmThemes;
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
import java.util.ArrayList;
import java.util.List;
public class IOSLineTexTest extends GdxMap {
public static void init() {
// init globals
IosGraphics.init();
GdxAssets.init("assets/");
GLAdapter.init(new IosGL());
}
private static final boolean ANIMATION = false;
private List<PathLayer> mPathLayers = new ArrayList<>();
private TextureItem tex;
@Override
public void createLayers() {
VectorTileLayer l = mMap.setBaseMap(new OSciMap4TileSource());
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
mMap.setTheme(VtmThemes.DEFAULT);
mMap.setMapPosition(0, 0, 1 << 2);
tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/pike.png"));
tex.mipmap = true;
createLayers(1, true);
if (ANIMATION)
mMap.events.bind(new Map.UpdateListener() {
@Override
public void onMapEvent(Event e, MapPosition mapPosition) {
//if (e == Map.UPDATE_EVENT) {
long t = System.currentTimeMillis();
float pos = t % 20000 / 10000f - 1f;
createLayers(pos, false);
mMap.updateMap(true);
//}
}
});
}
void createLayers(float pos, boolean init) {
int i = 0;
for (double lat = -90; lat <= 90; lat += 5) {
List<GeoPoint> pts = new ArrayList<>();
for (double lon = -180; lon <= 180; lon += 2) {
//pts.add(new GeoPoint(lat, lon));
// double longitude = lon + (pos * 180);
// if (longitude < -180)
// longitude += 360;
// if (longitude > 180)
// longitude -= 360;
double longitude = lon;
double latitude = lat + (pos * 90);
if (latitude < -90)
latitude += 180;
if (latitude > 90)
latitude -= 180;
latitude += Math.sin((Math.abs(pos) * (lon / Math.PI)));
pts.add(new GeoPoint(latitude, longitude));
}
PathLayer pathLayer;
if (init) {
int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.5f);
Style style = Style.builder()
.stippleColor(c)
.stipple(24)
.stippleWidth(1)
.strokeWidth(12)
.strokeColor(c)
.fixed(true)
.texture(tex)
.randomOffset(false)
.build();
pathLayer = new PathLayer(mMap, style);
mMap.layers().add(pathLayer);
mPathLayers.add(pathLayer);
} else {
pathLayer = mPathLayers.get(i++);
}
pathLayer.setPoints(pts);
}
}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016 Longri
*
* 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.ios.test;
import org.oscim.backend.GLAdapter;
import org.oscim.gdx.GdxAssets;
import org.oscim.gdx.GdxMap;
import org.oscim.ios.backend.IosGL;
import org.oscim.ios.backend.IosGraphics;
import org.oscim.layers.GroupLayer;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.map.Map;
import org.oscim.renderer.BitmapRenderer;
import org.oscim.renderer.GLViewport;
import org.oscim.scalebar.DefaultMapScaleBar;
import org.oscim.scalebar.ImperialUnitAdapter;
import org.oscim.scalebar.MapScaleBar;
import org.oscim.scalebar.MapScaleBarLayer;
import org.oscim.scalebar.MetricUnitAdapter;
import org.oscim.theme.VtmThemes;
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
public class IOSMapApp extends GdxMap {
public static void init() {
// init globals
IosGraphics.init();
GdxAssets.init("assets/");
GLAdapter.init(new IosGL());
}
@Override
public void createLayers() {
Map map = getMap();
VectorTileLayer l = map.setBaseMap(new OSciMap4TileSource());
GroupLayer groupLayer = new GroupLayer(mMap);
groupLayer.layers.add(new BuildingLayer(map, l));
groupLayer.layers.add(new LabelLayer(map, l));
map.layers().add(groupLayer);
DefaultMapScaleBar mapScaleBar = new DefaultMapScaleBar(mMap);
mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
mapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
mapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);
mapScaleBar.setScaleBarPosition(MapScaleBar.ScaleBarPosition.BOTTOM_LEFT);
MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mMap, mapScaleBar);
BitmapRenderer renderer = mapScaleBarLayer.getRenderer();
renderer.setPosition(GLViewport.Position.BOTTOM_LEFT);
renderer.setOffset(5, 0);
map.layers().add(mapScaleBarLayer);
map.setTheme(VtmThemes.DEFAULT);
map.setMapPosition(53.075, 8.808, 1 << 17);
}
}