Add location layer and Samples example #171

This commit is contained in:
Emux
2016-10-14 11:36:34 +03:00
parent e5c62c9bc4
commit e53523b82a
7 changed files with 153 additions and 32 deletions

View File

@@ -2,6 +2,7 @@
* Copyright 2010, 2011, 2012 mapsforge.org
* Copyright 2013 Hannes Janetzek
* Copyright 2013 Ahmad Al-saleem
* Copyright 2016 devemux86
*
* 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
@@ -31,7 +32,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LocationHandler implements LocationListener {
final static Logger log = LoggerFactory.getLogger(LocationHandler.class);
private final static Logger log = LoggerFactory.getLogger(LocationHandler.class);
public enum Mode {
OFF,
@@ -43,7 +44,7 @@ public class LocationHandler implements LocationListener {
private final static int SHOW_LOCATION_ZOOM = 14;
private final LocationManager mLocationManager;
private final LocationOverlay mLocationOverlay;
private final LocationLayerImpl mLocationLayer;
private Mode mMode = Mode.OFF;
@@ -54,7 +55,7 @@ public class LocationHandler implements LocationListener {
mLocationManager = (LocationManager) tileMap
.getSystemService(Context.LOCATION_SERVICE);
mLocationOverlay = new LocationOverlay(App.map, compass);
mLocationLayer = new LocationLayerImpl(App.map, compass);
mMapPosition = new MapPosition();
}
@@ -115,13 +116,13 @@ public class LocationHandler implements LocationListener {
if (location == null)
return false;
mLocationOverlay.setEnabled(true);
mLocationOverlay.setPosition(location.getLatitude(),
mLocationLayer.setEnabled(true);
mLocationLayer.setPosition(location.getLatitude(),
location.getLongitude(),
location.getAccuracy());
// FIXME -> implement LayerGroup
App.map.layers().add(4, mLocationOverlay);
App.map.layers().add(4, mLocationLayer);
App.map.updateMap(true);
return true;
@@ -133,9 +134,9 @@ public class LocationHandler implements LocationListener {
private boolean disableShowMyLocation() {
mLocationManager.removeUpdates(this);
mLocationOverlay.setEnabled(false);
mLocationLayer.setEnabled(false);
App.map.layers().remove(mLocationOverlay);
App.map.layers().remove(mLocationLayer);
App.map.updateMap(true);
return true;
@@ -199,7 +200,7 @@ public class LocationHandler implements LocationListener {
App.map.setMapPosition(mMapPosition);
}
mLocationOverlay.setPosition(lat, lon, location.getAccuracy());
mLocationLayer.setPosition(lat, lon, location.getAccuracy());
}
@Override

View File

@@ -16,41 +16,23 @@
*/
package org.oscim.app.location;
import org.oscim.core.MercatorProjection;
import org.oscim.layers.Layer;
import org.oscim.layers.LocationLayer;
import org.oscim.map.Map;
import org.oscim.renderer.LocationRenderer;
public class LocationOverlay extends Layer {
class LocationLayerImpl extends LocationLayer {
private final Compass mCompass;
private final LocationRenderer mLocationRenderer;
public LocationOverlay(Map map, Compass compass) {
LocationLayerImpl(Map map, Compass compass) {
super(map);
mCompass = compass;
mRenderer = mLocationRenderer = new LocationRenderer(mMap, this);
mLocationRenderer.setCallback(compass);
}
public void setPosition(double latitude, double longitude, double accuracy) {
double x = MercatorProjection.longitudeToX(longitude);
double y = MercatorProjection.latitudeToY(latitude);
double radius = accuracy / MercatorProjection.groundResolution(latitude, 1);
mLocationRenderer.setLocation(x, y, radius);
mLocationRenderer.animate(true);
locationRenderer.setCallback(compass);
}
@Override
public void setEnabled(boolean enabled) {
if (enabled == isEnabled())
return;
super.setEnabled(enabled);
if (!enabled)
mLocationRenderer.animate(false);
mCompass.setEnabled(enabled);
}
}