MapPosition animation sample improvements #252
This commit is contained in:
parent
2573e458d5
commit
38a9c71bc2
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016 Mathieu De Brito
|
* Copyright 2016 Mathieu De Brito
|
||||||
|
* Copyright 2016 devemux86
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the
|
* 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
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
@ -15,13 +16,19 @@
|
|||||||
package org.oscim.android.test;
|
package org.oscim.android.test;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.oscim.core.MapPosition;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.core.MercatorProjection;
|
import org.oscim.core.MercatorProjection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test consecutive map position animations.
|
||||||
|
*/
|
||||||
public class MapPositionActivity extends SimpleMapActivity {
|
public class MapPositionActivity extends SimpleMapActivity {
|
||||||
|
|
||||||
|
// Avoid object creation
|
||||||
|
private final MapPosition mapPosition = new MapPosition();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -29,52 +36,52 @@ public class MapPositionActivity extends SimpleMapActivity {
|
|||||||
runTest();
|
runTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
void runTest() {
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
// 1 - ask for a bearing
|
/* ignore saved position */
|
||||||
int bearing = 180;
|
mMap.setMapPosition(0, 0, 1 << 2);
|
||||||
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) {
|
private void animateToBearing(final float bearing) {
|
||||||
mMapView.postDelayed(new Runnable() {
|
mMap.postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MapPosition p = mMapView.map().getMapPosition();
|
mMap.getMapPosition(mapPosition);
|
||||||
p.setX(MercatorProjection.longitudeToX(longitude));
|
mapPosition.setBearing(bearing);
|
||||||
p.setY(MercatorProjection.latitudeToY(latitude));
|
mMap.animator().animateTo(1000, mapPosition);
|
||||||
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);
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkThatAnimationsHaveMerged(final int bearing) {
|
private void animateToLocation(final double latitude, final double longitude) {
|
||||||
mMapView.postDelayed(new Runnable() {
|
mMap.postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MapPosition p = mMapView.map().getMapPosition();
|
mMap.getMapPosition(mapPosition);
|
||||||
if (p.getBearing() != bearing) {
|
mapPosition.setPosition(latitude, longitude);
|
||||||
Log.e(MapPositionActivity.class.getName(), "Bearing is not correct (expected:" + bearing + ", actual:" + p.getBearing() + ")");
|
mMap.animator().animateTo(1000, mapPosition);
|
||||||
}
|
}
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runTest() {
|
||||||
|
// 1 - ask for a bearing
|
||||||
|
final float bearing = 180;
|
||||||
|
animateToBearing(bearing);
|
||||||
|
|
||||||
|
// 2 - ask for a new location
|
||||||
|
double latitude = Math.random() * MercatorProjection.LATITUDE_MAX;
|
||||||
|
double longitude = Math.random() * MercatorProjection.LONGITUDE_MAX;
|
||||||
|
animateToLocation(latitude, longitude);
|
||||||
|
|
||||||
|
// If animations were merged, final bearing should be 180°
|
||||||
|
mMap.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mMap.getMapPosition(mapPosition);
|
||||||
|
Toast.makeText(MapPositionActivity.this, "Bearing expected: " + bearing + ", got: " + mapPosition.getBearing(), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
|
@ -56,13 +56,13 @@ public class Samples extends Activity {
|
|||||||
|
|
||||||
linearLayout.addView(createLabel("User Interaction"));
|
linearLayout.addView(createLabel("User Interaction"));
|
||||||
linearLayout.addView(createButton(NewGesturesActivity.class));
|
linearLayout.addView(createButton(NewGesturesActivity.class));
|
||||||
|
linearLayout.addView(createButton(LayerGroupActivity.class));
|
||||||
linearLayout.addView(createButton(MapFragmentActivity.class));
|
linearLayout.addView(createButton(MapFragmentActivity.class));
|
||||||
|
|
||||||
linearLayout.addView(createLabel("Dual Map Views"));
|
linearLayout.addView(createLabel("Dual Map Views"));
|
||||||
linearLayout.addView(createButton(MultiMapActivity.class));
|
linearLayout.addView(createButton(MultiMapActivity.class));
|
||||||
|
|
||||||
linearLayout.addView(createLabel("Experiments"));
|
linearLayout.addView(createLabel("Experiments"));
|
||||||
linearLayout.addView(createButton(LayerGroupActivity.class));
|
|
||||||
linearLayout.addView(createButton(MapPositionActivity.class));
|
linearLayout.addView(createButton(MapPositionActivity.class));
|
||||||
linearLayout.addView(createButton(S3DBMapActivity.class));
|
linearLayout.addView(createButton(S3DBMapActivity.class));
|
||||||
linearLayout.addView(createButton(ThemeStylerActivity.class));
|
linearLayout.addView(createButton(ThemeStylerActivity.class));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user