Location texture renderer (#548)
- add LocationTextureLayer with accuracy - add Android sample for LocationTextureLayer
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright 2016-2018 devemux86
|
||||
* Copyright 2018 Longri
|
||||
*
|
||||
* 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.android.test;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.layers.LocationTextureLayer;
|
||||
import org.oscim.renderer.atlas.TextureAtlas;
|
||||
import org.oscim.renderer.atlas.TextureRegion;
|
||||
import org.oscim.renderer.bucket.TextureItem;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class LocationTextureActivity extends BitmapTileActivity implements LocationListener {
|
||||
private LocationTextureLayer locationLayer;
|
||||
private LocationManager locationManager;
|
||||
private final MapPosition mapPosition = new MapPosition();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//initial Android locationManager
|
||||
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
|
||||
//load a Bitmap/Svg from resources. (North/0° are on top
|
||||
InputStream is = getResources().openRawResource(R.raw.arrow);
|
||||
Bitmap bmp = null;
|
||||
try {
|
||||
bmp = CanvasAdapter.decodeSvgBitmap(is, 200, 200, 100);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//create TextureRegion from Bitmap
|
||||
TextureRegion textureRegion = new TextureRegion(new TextureItem(bmp), new TextureAtlas.Rect(0, 0, bmp.getWidth(), bmp.getHeight()));
|
||||
|
||||
//create LocationTexturLayer with created/loaded TextureRegion
|
||||
locationLayer = new LocationTextureLayer(mMap, textureRegion);
|
||||
|
||||
// you can set the Color of Accuracy circle (Color.BLUE is default)
|
||||
locationLayer.setAccuracyColor(Color.get(50, 50, 255));
|
||||
|
||||
// you can set the Color of Indicator circle (Color.RED is default)
|
||||
locationLayer.setIndicatorColor(Color.MAGENTA);
|
||||
|
||||
locationLayer.setEnabled(false);
|
||||
mMap.layers().add(locationLayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
enableAvailableProviders();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
locationManager.removeUpdates(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
locationLayer.setEnabled(true);
|
||||
locationLayer.setPosition(location.getLatitude(), location.getLongitude(), location.getBearing(), location.getAccuracy());
|
||||
|
||||
// Follow location
|
||||
mMap.getMapPosition(mapPosition);
|
||||
mapPosition.setPosition(location.getLatitude(), location.getLongitude());
|
||||
mMap.setMapPosition(mapPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderDisabled(String provider) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||
}
|
||||
|
||||
private void enableAvailableProviders() {
|
||||
locationManager.removeUpdates(this);
|
||||
|
||||
for (String provider : locationManager.getProviders(true)) {
|
||||
if (LocationManager.GPS_PROVIDER.equals(provider)
|
||||
|| LocationManager.NETWORK_PROVIDER.equals(provider)) {
|
||||
locationManager.requestLocationUpdates(provider, 0, 0, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016-2018 devemux86
|
||||
* Copyright 2017 Longri
|
||||
* Copyright 2017-2018 Longri
|
||||
* Copyright 2017 nebular
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
@@ -98,6 +98,7 @@ public class Samples extends Activity {
|
||||
}
|
||||
}));
|
||||
linearLayout.addView(createButton(LocationActivity.class));
|
||||
linearLayout.addView(createButton(LocationTextureActivity.class));
|
||||
linearLayout.addView(createButton(PoiSearchActivity.class));
|
||||
|
||||
linearLayout.addView(createLabel("Vector Features"));
|
||||
|
||||
Reference in New Issue
Block a user