Location texture renderer (#548)
- add LocationTextureLayer with accuracy - add Android sample for LocationTextureLayer
This commit is contained in:
@@ -57,6 +57,9 @@
|
||||
<activity
|
||||
android:name=".LocationActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize" />
|
||||
<activity
|
||||
android:name=".LocationTextureActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize" />
|
||||
<activity
|
||||
android:name=".MapEventLayer2Activity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize" />
|
||||
|
||||
19
vtm-android-example/res/raw/arrow.svg
Normal file
19
vtm-android-example/res/raw/arrow.svg
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" width="249.667" height="254.667" viewBox="0 0 249.67 254.67" enable-background="new 0 0 249.67 254.67" xml:space="preserve">
|
||||
<linearGradient id="SVGID_Fill1_" gradientUnits="objectBoundingBox" x1="-0.0161654" y1="0.500001" x2="1.01616" y2="0.500001">
|
||||
<stop offset="0.0344828" stop-color="#FF0000" stop-opacity="1"/>
|
||||
<stop offset="0.5" stop-color="#FF0000" stop-opacity="1"/>
|
||||
<stop offset="1" stop-color="#F8E6E6" stop-opacity="1"/>
|
||||
</linearGradient>
|
||||
<path fill="url(#SVGID_Fill1_)" stroke-width="5" stroke-linejoin="round" stroke="#000000" stroke-opacity="1" d="M 47.5002,250.834L 124.833,2.50006L 202.167,252.167L 124.167,199.167L 47.5002,250.834 Z "/>
|
||||
<linearGradient id="SVGID_Fill2_" gradientUnits="objectBoundingBox" x1="0.0255055" y1="0.518124" x2="0.986547" y2="0.518124" gradientTransform="rotate(42.130627 0.025506 0.518124)">
|
||||
<stop offset="0.301724" stop-color="#ECECEC" stop-opacity="0.345098"/>
|
||||
<stop offset="0.62931" stop-color="#1C1C1C" stop-opacity="0.776471"/>
|
||||
<stop offset="0.689655" stop-color="#000000" stop-opacity="0.423529"/>
|
||||
<stop offset="1" stop-color="#000000" stop-opacity="0.286275"/>
|
||||
</linearGradient>
|
||||
<filter id="Filter_GaussianBlur1_" filterUnits="userSpaceOnUse">
|
||||
<feGaussianBlur stdDeviation="1.88976"/>
|
||||
</filter>
|
||||
<path fill="url(#SVGID_Fill2_)" stroke-width="0.2" stroke-linejoin="round" filter="url(#Filter_GaussianBlur1_)" d="M 56.8333,241.5L 124.833,31.0001L 123.5,195.167L 56.8333,241.5 Z "/>
|
||||
</svg>
|
||||
@@ -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