animate PathLayer example
This commit is contained in:
parent
3ef832efb8
commit
4dfbf1f088
@ -30,6 +30,7 @@ public class BitmapTileMapActivity extends MapActivity {
|
|||||||
|
|
||||||
private final static boolean USE_CACHE = true;
|
private final static boolean USE_CACHE = true;
|
||||||
private final TileSource mTileSource;
|
private final TileSource mTileSource;
|
||||||
|
protected BitmapTileLayer mBitmapLayer;
|
||||||
|
|
||||||
public BitmapTileMapActivity() {
|
public BitmapTileMapActivity() {
|
||||||
mTileSource = new DefaultSources.OpenStreetMap();
|
mTileSource = new DefaultSources.OpenStreetMap();
|
||||||
@ -59,7 +60,9 @@ public class BitmapTileMapActivity extends MapActivity {
|
|||||||
mCache.setCacheSize(512 * (1 << 10));
|
mCache.setCacheSize(512 * (1 << 10));
|
||||||
mTileSource.setCache(mCache);
|
mTileSource.setCache(mCache);
|
||||||
}
|
}
|
||||||
mMap.layers().add(new BitmapTileLayer(mMap, mTileSource));
|
|
||||||
|
mBitmapLayer = new BitmapTileLayer(mMap, mTileSource);
|
||||||
|
mMap.layers().add(mBitmapLayer);
|
||||||
|
|
||||||
mMap.setMapPosition(0, 0, 1 << 2);
|
mMap.setMapPosition(0, 0, 1 << 2);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import org.oscim.layers.PathLayer;
|
|||||||
import org.oscim.tiling.source.bitmap.DefaultSources;
|
import org.oscim.tiling.source.bitmap.DefaultSources;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.SystemClock;
|
||||||
|
|
||||||
public class PathOverlayActivity extends BitmapTileMapActivity {
|
public class PathOverlayActivity extends BitmapTileMapActivity {
|
||||||
|
|
||||||
@ -35,35 +36,71 @@ public class PathOverlayActivity extends BitmapTileMapActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
mBitmapLayer.getTileRenderer().setBitmapAlpha(0.5f);
|
||||||
|
|
||||||
for (double lon = -180; lon < 180; lon += 5) {
|
createLayers(1, true);
|
||||||
List<GeoPoint> pts = new ArrayList<GeoPoint>();
|
|
||||||
|
|
||||||
for (double lat = -90; lat <= 90; lat += 5)
|
mMap.setMapPosition(0, 0, 1 << 2);
|
||||||
//pts.add(new GeoPoint(lat, lon));
|
|
||||||
pts.add(new GeoPoint(lat, Math.sin((lat + 180) / 360 * Math.PI) * lon));
|
|
||||||
|
|
||||||
int c = Color.fade(Color.rainbow((float) (lon + 180) / 360), 0.8f);
|
looooop();
|
||||||
PathLayer pathLayer = new PathLayer(mMap, c, 3);
|
|
||||||
pathLayer.setPoints(pts);
|
|
||||||
|
|
||||||
mMap.layers().add(pathLayer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void looooop() {
|
||||||
|
mMap.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
long t = SystemClock.uptimeMillis();
|
||||||
|
float pos = t % 20000 / 10000f - 1f;
|
||||||
|
createLayers(pos, false);
|
||||||
|
//Samples.log.debug("update took" + (SystemClock.uptimeMillis() - t) + " " + pos);
|
||||||
|
looooop();
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
}, 50);
|
||||||
|
}
|
||||||
|
void redraw(){
|
||||||
|
mMap.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<PathLayer> mPathLayers = new ArrayList<PathLayer>();
|
||||||
|
|
||||||
|
void createLayers(float pos, boolean init) {
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
for (double lat = -90; lat <= 90; lat += 5) {
|
for (double lat = -90; lat <= 90; lat += 5) {
|
||||||
List<GeoPoint> pts = new ArrayList<GeoPoint>();
|
List<GeoPoint> pts = new ArrayList<GeoPoint>();
|
||||||
|
|
||||||
for (double lon = -180; lon <= 180; lon += 1)
|
for (double lon = -180; lon <= 180; lon += 2){
|
||||||
//pts.add(new GeoPoint(lat, lon));
|
//pts.add(new GeoPoint(lat, lon));
|
||||||
pts.add(new GeoPoint(Math.sin(lon / 6 * Math.PI) * 3 + lat, lon));
|
double longitude = lon + (pos * 180);
|
||||||
|
if (longitude < -180)
|
||||||
|
longitude += 360;
|
||||||
|
if (longitude > 180)
|
||||||
|
longitude -= 360;
|
||||||
|
|
||||||
int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.8f);
|
double latitude = lat + (pos * 90);
|
||||||
PathLayer pathLayer = new PathLayer(mMap, c, 3);
|
if (latitude< -90)
|
||||||
pathLayer.setPoints(pts);
|
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);
|
||||||
|
pathLayer = new PathLayer(mMap, c, 6);
|
||||||
mMap.layers().add(pathLayer);
|
mMap.layers().add(pathLayer);
|
||||||
|
mPathLayers.add(pathLayer);
|
||||||
|
} else {
|
||||||
|
pathLayer = mPathLayers.get(i++);
|
||||||
|
}
|
||||||
|
|
||||||
|
pathLayer.setPoints(pts);
|
||||||
}
|
}
|
||||||
|
|
||||||
mMap.setMapPosition(0, 0, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user