From a9db7989c3c9dc0a90ecd1f4e1e5a2d26b3954b8 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Fri, 17 Jan 2014 03:23:40 +0100 Subject: [PATCH] add PathLayer example --- vtm-android-example/AndroidManifest.xml | 5 ++ .../oscim/android/test/BaseMapActivity.java | 18 +++-- .../android/test/PathOverlayActivity.java | 71 +++++++++++++++++++ .../src/org/oscim/android/test/Samples.java | 1 + 4 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 vtm-android-example/src/org/oscim/android/test/PathOverlayActivity.java diff --git a/vtm-android-example/AndroidManifest.xml b/vtm-android-example/AndroidManifest.xml index 0285e13c..4105ec68 100644 --- a/vtm-android-example/AndroidManifest.xml +++ b/vtm-android-example/AndroidManifest.xml @@ -33,6 +33,11 @@ android:label="@string/title_activity_map" > + + + \ No newline at end of file diff --git a/vtm-android-example/src/org/oscim/android/test/BaseMapActivity.java b/vtm-android-example/src/org/oscim/android/test/BaseMapActivity.java index 8c097a63..ccbce436 100644 --- a/vtm-android-example/src/org/oscim/android/test/BaseMapActivity.java +++ b/vtm-android-example/src/org/oscim/android/test/BaseMapActivity.java @@ -28,6 +28,8 @@ import android.view.Menu; public class BaseMapActivity extends MapActivity { + private final static boolean USE_CACHE = false; + MapView mMapView; VectorTileLayer mBaseLayer; TileSource mTileSource; @@ -44,18 +46,20 @@ public class BaseMapActivity extends MapActivity { mTileSource = new OSciMap4TileSource(); mTileSource.setOption("url", "http://opensciencemap.org/tiles/vtm"); - - mCache = new TileCache(this, "cachedir", "testdb"); - mCache.setCacheSize(512 * (1 << 10)); - mTileSource.setCache(mCache); - + if (USE_CACHE) { + mCache = new TileCache(this, "cachedir", "testdb"); + mCache.setCacheSize(512 * (1 << 10)); + mTileSource.setCache(mCache); + } mBaseLayer = mMap.setBaseMap(mTileSource); } @Override protected void onDestroy() { - super.onDestroy(); - mCache.dispose(); + super.onDestroy(); + + if (USE_CACHE) + mCache.dispose(); } @Override diff --git a/vtm-android-example/src/org/oscim/android/test/PathOverlayActivity.java b/vtm-android-example/src/org/oscim/android/test/PathOverlayActivity.java new file mode 100644 index 00000000..b60258a2 --- /dev/null +++ b/vtm-android-example/src/org/oscim/android/test/PathOverlayActivity.java @@ -0,0 +1,71 @@ +/* + * Copyright 2014 Hannes Janetzek + * + * 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 . + */ +package org.oscim.android.test; + +import java.util.ArrayList; +import java.util.List; + +import org.oscim.android.MapActivity; +import org.oscim.android.MapView; +import org.oscim.core.GeoPoint; +import org.oscim.layers.PathLayer; + +import android.graphics.Color; +import android.os.Bundle; + +public class PathOverlayActivity extends MapActivity { + + MapView mMapView; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_map); + + mMapView = (MapView) findViewById(R.id.mapView); + + + for (double lon = -180; lon <= 180; lon += 10) { + PathLayer pathLayer = new PathLayer(mMap, Color.CYAN); + pathLayer.addGreatCircle(new GeoPoint(-90, lon), new GeoPoint(90, lon)); + mMap.getLayers().add(pathLayer); + + } + + for (double lat = -90; lat <= 90; lat += 10) { + List pts = new ArrayList(); + + for (double lon = -180; lon <= 180; lon += 10) + pts.add(new GeoPoint(lat, lon)); + + PathLayer pathLayer = new PathLayer(mMap, Color.CYAN); + pathLayer.setPoints(pts); + + mMap.getLayers().add(pathLayer); + } + + + for (double lat = -90; lat <= 90; lat += 10) { + PathLayer pathLayer = new PathLayer(mMap, Color.LTGRAY, 4); + pathLayer.addGreatCircle(new GeoPoint(lat, -90), new GeoPoint(lat, 0)); + mMap.getLayers().add(pathLayer); + } + + for (double lat = -90; lat <= 90; lat += 10) { + PathLayer pathLayer = new PathLayer(mMap, Color.LTGRAY, 4); + mMap.getLayers().add(pathLayer); + } + } +} diff --git a/vtm-android-example/src/org/oscim/android/test/Samples.java b/vtm-android-example/src/org/oscim/android/test/Samples.java index 531e71c8..f8607950 100644 --- a/vtm-android-example/src/org/oscim/android/test/Samples.java +++ b/vtm-android-example/src/org/oscim/android/test/Samples.java @@ -36,6 +36,7 @@ public class Samples extends Activity { setContentView(R.layout.activity_samples); LinearLayout linearLayout = (LinearLayout) findViewById(R.id.samples); linearLayout.addView(createButton(SimpleMapActivity.class)); + linearLayout.addView(createButton(PathOverlayActivity.class)); } private Button createButton(final Class clazz) {