diff --git a/vtm-android-example/AndroidManifest.xml b/vtm-android-example/AndroidManifest.xml index 6f941254..edab890c 100644 --- a/vtm-android-example/AndroidManifest.xml +++ b/vtm-android-example/AndroidManifest.xml @@ -47,6 +47,9 @@ + diff --git a/vtm-android-example/src/org/oscim/android/test/MapPositionActivity.java b/vtm-android-example/src/org/oscim/android/test/MapPositionActivity.java new file mode 100644 index 00000000..f8d807d5 --- /dev/null +++ b/vtm-android-example/src/org/oscim/android/test/MapPositionActivity.java @@ -0,0 +1,81 @@ +/* + * Copyright 2016 Mathieu De Brito + * + * 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 android.os.Bundle; +import android.util.Log; + +import org.oscim.core.MapPosition; +import org.oscim.core.MercatorProjection; + +public class MapPositionActivity extends SimpleMapActivity { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + runTest(); + } + + void runTest() { + + // 1 - ask for a bearing + int bearing = 180; + animateToBearing(bearing); + + // 2 - ask for a new location + double latitude = Math.random() * 60; + double longitude = Math.random() * 180; + animateToLocation(latitude, longitude); + + // If animations have merged, final bearing should 180 + checkThatAnimationsHaveMerged(bearing); + } + + void animateToLocation(final double latitude, final double longitude) { + mMapView.postDelayed(new Runnable() { + @Override + public void run() { + MapPosition p = mMapView.map().getMapPosition(); + p.setX(MercatorProjection.longitudeToX(longitude)); + p.setY(MercatorProjection.latitudeToY(latitude)); + mMapView.map().animator().animateTo(1000, p); + } + }, 1000); + } + + void animateToBearing(final int bearing) { + mMapView.postDelayed(new Runnable() { + @Override + public void run() { + MapPosition p = mMapView.map().getMapPosition(); + p.setBearing(bearing); + mMapView.map().animator().animateTo(1000, p); + } + }, 500); + } + + void checkThatAnimationsHaveMerged(final int bearing) { + mMapView.postDelayed(new Runnable() { + @Override + public void run() { + MapPosition p = mMapView.map().getMapPosition(); + if (p.getBearing() != bearing) { + Log.e(MapPositionActivity.class.getName(), "Bearing is not correct (expected:" + bearing + ", actual:" + p.getBearing() + ")"); + } + } + }, 3000); + } +} 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 a9640b5b..8c9afb4f 100644 --- a/vtm-android-example/src/org/oscim/android/test/Samples.java +++ b/vtm-android-example/src/org/oscim/android/test/Samples.java @@ -63,6 +63,7 @@ public class Samples extends Activity { linearLayout.addView(createLabel("Experiments")); linearLayout.addView(createButton(LayerGroupActivity.class)); + linearLayout.addView(createButton(MapPositionActivity.class)); linearLayout.addView(createButton(S3DBMapActivity.class)); linearLayout.addView(createButton(ThemeStylerActivity.class)); linearLayout.addView(createButton(JeoIndoorMapActivity.class));