1. accept amenity as way
2. fix some TODO 3. show direction of travel git-svn-id: https://osmand.googlecode.com/svn/trunk@77 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
2d49463456
commit
891a38e697
6 changed files with 92 additions and 33 deletions
|
@ -5,10 +5,9 @@ import java.util.Map;
|
||||||
|
|
||||||
import com.osmand.Algoritms;
|
import com.osmand.Algoritms;
|
||||||
import com.osmand.osm.Entity;
|
import com.osmand.osm.Entity;
|
||||||
import com.osmand.osm.Node;
|
|
||||||
import com.osmand.osm.OSMSettings.OSMTagKey;
|
import com.osmand.osm.OSMSettings.OSMTagKey;
|
||||||
|
|
||||||
public class Amenity extends MapObject<Node> {
|
public class Amenity extends MapObject<Entity> {
|
||||||
// http://wiki.openstreetmap.org/wiki/Amenity
|
// http://wiki.openstreetmap.org/wiki/Amenity
|
||||||
public enum AmenityType {
|
public enum AmenityType {
|
||||||
SUSTENANCE, // restaurant, cafe ...
|
SUSTENANCE, // restaurant, cafe ...
|
||||||
|
@ -89,16 +88,16 @@ public class Amenity extends MapObject<Node> {
|
||||||
private String subType;
|
private String subType;
|
||||||
private AmenityType type;
|
private AmenityType type;
|
||||||
|
|
||||||
public Amenity(Node node){
|
public Amenity(Entity entity){
|
||||||
this.entity = node;
|
this.entity = entity;
|
||||||
this.type = getType(node);
|
this.type = getType(entity);
|
||||||
this.subType = getSubType(node);
|
this.subType = getSubType(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Amenity(){
|
public Amenity(){
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getSubType(Node node){
|
protected String getSubType(Entity node){
|
||||||
if(node.getTag(OSMTagKey.AMENITY) != null){
|
if(node.getTag(OSMTagKey.AMENITY) != null){
|
||||||
return node.getTag(OSMTagKey.AMENITY);
|
return node.getTag(OSMTagKey.AMENITY);
|
||||||
} else if(node.getTag(OSMTagKey.SHOP) != null){
|
} else if(node.getTag(OSMTagKey.SHOP) != null){
|
||||||
|
@ -111,7 +110,7 @@ public class Amenity extends MapObject<Node> {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AmenityType getType(Node node){
|
protected AmenityType getType(Entity node){
|
||||||
if(node.getTag(OSMTagKey.SHOP) != null){
|
if(node.getTag(OSMTagKey.SHOP) != null){
|
||||||
return AmenityType.SHOP;
|
return AmenityType.SHOP;
|
||||||
} else if(node.getTag(OSMTagKey.TOURISM) != null){
|
} else if(node.getTag(OSMTagKey.TOURISM) != null){
|
||||||
|
@ -141,10 +140,6 @@ public class Amenity extends MapObject<Node> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAmenity(Entity n){
|
public static boolean isAmenity(Entity n){
|
||||||
// TODO allow ways to be amenity!
|
|
||||||
if(!(n instanceof Node)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(n.getTag(OSMTagKey.AMENITY) != null){
|
if(n.getTag(OSMTagKey.AMENITY) != null){
|
||||||
return true;
|
return true;
|
||||||
} else if(n.getTag(OSMTagKey.SHOP) != null){
|
} else if(n.getTag(OSMTagKey.SHOP) != null){
|
||||||
|
|
|
@ -193,7 +193,7 @@ public class DataExtraction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (indexPOI && Amenity.isAmenity(e)) {
|
if (indexPOI && Amenity.isAmenity(e)) {
|
||||||
amenities.add(new Amenity((Node) e));
|
amenities.add(new Amenity(e));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (e instanceof Node && e.getTag(OSMTagKey.PLACE) != null) {
|
if (e instanceof Node && e.getTag(OSMTagKey.PLACE) != null) {
|
||||||
|
|
|
@ -104,6 +104,27 @@ public class MapUtils {
|
||||||
return new LatLon(latitude/count, longitude/count);
|
return new LatLon(latitude/count, longitude/count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double checkLongitude(double longitude) {
|
||||||
|
while (longitude < -180 || longitude > 180) {
|
||||||
|
if (longitude < 0) {
|
||||||
|
longitude += 360;
|
||||||
|
} else {
|
||||||
|
longitude -= 360;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double checkLatitude(double latitude) {
|
||||||
|
while (latitude < -90 || latitude > 90) {
|
||||||
|
if (latitude < 0) {
|
||||||
|
latitude += 180;
|
||||||
|
} else {
|
||||||
|
latitude -= 180;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return latitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,14 +134,15 @@ public class MapUtils {
|
||||||
// degree latitude measurements (90, -90) [53.9]
|
// degree latitude measurements (90, -90) [53.9]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO check boundaries
|
|
||||||
public static double getTileNumberX(int zoom, double longitude){
|
public static double getTileNumberX(int zoom, double longitude){
|
||||||
|
longitude = checkLongitude(longitude);
|
||||||
int n = 1 << zoom;
|
int n = 1 << zoom;
|
||||||
return (longitude + 180d)/360d * n;
|
return (longitude + 180d)/360d * n;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getTileNumberY(int zoom, double latitude){
|
public static double getTileNumberY(int zoom, double latitude){
|
||||||
int n = 1 << zoom;
|
int n = 1 << zoom;
|
||||||
|
latitude = checkLatitude(latitude);
|
||||||
double eval = Math.log( Math.tan(Math.toRadians(latitude)) + 1/Math.cos(Math.toRadians(latitude)) );
|
double eval = Math.log( Math.tan(Math.toRadians(latitude)) + 1/Math.cos(Math.toRadians(latitude)) );
|
||||||
return (1 - eval / Math.PI) / 2 * n;
|
return (1 - eval / Math.PI) / 2 * n;
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,6 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
private JCheckBox buildAddressIndex;
|
private JCheckBox buildAddressIndex;
|
||||||
private JCheckBox normalizingStreets;
|
private JCheckBox normalizingStreets;
|
||||||
private TreeModelListener treeModelListener;
|
private TreeModelListener treeModelListener;
|
||||||
private JCheckBox zipIndexFiles;
|
|
||||||
private JCheckBox loadingAllData;
|
private JCheckBox loadingAllData;
|
||||||
|
|
||||||
|
|
||||||
|
@ -300,9 +299,12 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
generateDataButton.setEnabled(region != null);
|
generateDataButton.setEnabled(region != null);
|
||||||
normalizingStreets.setVisible(region == null);
|
normalizingStreets.setVisible(region == null);
|
||||||
loadingAllData.setVisible(region == null);
|
loadingAllData.setVisible(region == null);
|
||||||
buildAddressIndex.setEnabled(region == null || region.getCitiesCount(null) > 0);
|
if(region == null && !buildAddressIndex.isEnabled()){
|
||||||
buildPoiIndex.setEnabled(region == null || !region.getAmenityManager().isEmpty());
|
buildAddressIndex.setEnabled(true);
|
||||||
zipIndexFiles.setVisible(region != null);
|
}
|
||||||
|
if(region == null && !buildPoiIndex.isEnabled()){
|
||||||
|
buildPoiIndex.setEnabled(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createButtonsBar(Container content){
|
public void createButtonsBar(Container content){
|
||||||
|
@ -341,11 +343,6 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
panel.add(loadingAllData);
|
panel.add(loadingAllData);
|
||||||
loadingAllData.setSelected(false);
|
loadingAllData.setSelected(false);
|
||||||
|
|
||||||
zipIndexFiles = new JCheckBox();
|
|
||||||
zipIndexFiles.setText("Zip index files");
|
|
||||||
panel.add(zipIndexFiles);
|
|
||||||
zipIndexFiles.setSelected(true);
|
|
||||||
|
|
||||||
updateButtonsBar();
|
updateButtonsBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,8 +357,7 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
DataIndexBuilder builder = new DataIndexBuilder(DataExtractionSettings.getSettings().getDefaultWorkingDir(), region);
|
DataIndexBuilder builder = new DataIndexBuilder(DataExtractionSettings.getSettings().getDefaultWorkingDir(), region);
|
||||||
StringBuilder msg = new StringBuilder();
|
StringBuilder msg = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
builder.setZipped(zipIndexFiles.isSelected());
|
msg.append("Indices for ").append(region.getName());
|
||||||
msg.append("Indices checked for ").append(region.getName());
|
|
||||||
if(buildPoiIndex.isEnabled()){
|
if(buildPoiIndex.isEnabled()){
|
||||||
dlg.startTask("Generating POI index...", -1);
|
dlg.startTask("Generating POI index...", -1);
|
||||||
builder.buildPOI();
|
builder.buildPOI();
|
||||||
|
@ -629,6 +625,12 @@ public class OsmExtractionUI implements IMapLocationListener {
|
||||||
try {
|
try {
|
||||||
DataExtraction dataExtraction = new DataExtraction(buildAddressIndex.isSelected(), buildPoiIndex.isSelected(),
|
DataExtraction dataExtraction = new DataExtraction(buildAddressIndex.isSelected(), buildPoiIndex.isSelected(),
|
||||||
normalizingStreets.isSelected(), loadingAllData.isSelected());
|
normalizingStreets.isSelected(), loadingAllData.isSelected());
|
||||||
|
if(!buildAddressIndex.isSelected()){
|
||||||
|
buildAddressIndex.setEnabled(false);
|
||||||
|
}
|
||||||
|
if(!buildPoiIndex.isSelected()){
|
||||||
|
buildPoiIndex.setEnabled(false);
|
||||||
|
}
|
||||||
res = dataExtraction.readCountry(f.getAbsolutePath(), dlg, filter);
|
res = dataExtraction.readCountry(f.getAbsolutePath(), dlg, filter);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
|
|
|
@ -56,7 +56,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
private List<OsmandMapLayer> layers = new ArrayList<OsmandMapLayer>();
|
private List<OsmandMapLayer> layers = new ArrayList<OsmandMapLayer>();
|
||||||
|
|
||||||
// UI Part
|
// UI Part
|
||||||
|
|
||||||
private AnimateDraggingMapThread animatedDraggingThread;
|
private AnimateDraggingMapThread animatedDraggingThread;
|
||||||
|
|
||||||
private PointF startDragging = null;
|
private PointF startDragging = null;
|
||||||
|
@ -248,6 +247,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
synchronized (holder) {
|
synchronized (holder) {
|
||||||
Canvas canvas = holder.lockCanvas();
|
Canvas canvas = holder.lockCanvas();
|
||||||
if (canvas != null) {
|
if (canvas != null) {
|
||||||
|
// canvas.rotate(45);
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i * tileSize + startingX < width; i++) {
|
for (int i = 0; i * tileSize + startingX < width; i++) {
|
||||||
for (int j = 0; j * tileSize + startingY < height; j++) {
|
for (int j = 0; j * tileSize + startingY < height; j++) {
|
||||||
|
@ -285,8 +285,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
||||||
(i + getTileSize() >= 0 && i < getWidth()) && (j + getTileSize() >= 0 && j < getHeight())) {
|
(i + getTileSize() >= 0 && i < getWidth()) && (j + getTileSize() >= 0 && j < getHeight())) {
|
||||||
SurfaceHolder holder = getHolder();
|
SurfaceHolder holder = getHolder();
|
||||||
synchronized (holder) {
|
synchronized (holder) {
|
||||||
|
// TODO
|
||||||
Canvas canvas = holder.lockCanvas(new Rect(i, j, getTileSize() + i, getTileSize() + j));
|
Canvas canvas = holder.lockCanvas(new Rect(i, j, getTileSize() + i, getTileSize() + j));
|
||||||
if (canvas != null) {
|
if (canvas != null) {
|
||||||
|
// canvas.rotate(45);
|
||||||
try {
|
try {
|
||||||
ResourceManager mgr = ResourceManager.getResourceManager();
|
ResourceManager mgr = ResourceManager.getResourceManager();
|
||||||
Bitmap bmp = mgr.getTileImageForMapSync(map, request.xTile, request.yTile, zoom, false);
|
Bitmap bmp = mgr.getTileImageForMapSync(map, request.xTile, request.yTile, zoom, false);
|
||||||
|
|
|
@ -2,7 +2,10 @@ package com.osmand.views;
|
||||||
|
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Matrix;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Path;
|
||||||
|
import android.graphics.Paint.Style;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
|
@ -10,11 +13,13 @@ import com.osmand.osm.MapUtils;
|
||||||
|
|
||||||
public class PointLocationLayer implements OsmandMapLayer {
|
public class PointLocationLayer implements OsmandMapLayer {
|
||||||
private Paint location;
|
private Paint location;
|
||||||
|
private Paint bearing;
|
||||||
private Paint area;
|
private Paint area;
|
||||||
|
|
||||||
protected Location lastKnownLocation = null;
|
protected Location lastKnownLocation = null;
|
||||||
protected final static int RADIUS = 7;
|
protected final static int RADIUS = 7;
|
||||||
private OsmandMapTileView view;
|
private OsmandMapTileView view;
|
||||||
|
private Path pathForDirection;
|
||||||
|
|
||||||
private void initUI() {
|
private void initUI() {
|
||||||
location = new Paint();
|
location = new Paint();
|
||||||
|
@ -25,6 +30,14 @@ public class PointLocationLayer implements OsmandMapLayer {
|
||||||
area = new Paint();
|
area = new Paint();
|
||||||
area.setColor(Color.BLUE);
|
area.setColor(Color.BLUE);
|
||||||
area.setAlpha(40);
|
area.setAlpha(40);
|
||||||
|
|
||||||
|
bearing = new Paint();
|
||||||
|
bearing.setColor(Color.BLUE);
|
||||||
|
bearing.setAlpha(150);
|
||||||
|
bearing.setAntiAlias(true);
|
||||||
|
bearing.setStyle(Style.FILL);
|
||||||
|
|
||||||
|
pathForDirection = new Path();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initLayer(OsmandMapTileView view) {
|
public void initLayer(OsmandMapTileView view) {
|
||||||
|
@ -42,13 +55,10 @@ public class PointLocationLayer implements OsmandMapLayer {
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(Canvas canvas) {
|
public void onDraw(Canvas canvas) {
|
||||||
if (isLocationVisible(lastKnownLocation)) {
|
if (isLocationVisible(lastKnownLocation)) {
|
||||||
int locationX = MapUtils.getPixelShiftX(view.getZoom(), lastKnownLocation.getLongitude(), view.getLongitude(), view
|
int locationX = MapUtils.getPixelShiftX(view.getZoom(), lastKnownLocation.getLongitude(), view.getLongitude(),
|
||||||
.getTileSize())
|
view.getTileSize()) + view.getWidth() / 2;
|
||||||
+ view.getWidth() / 2;
|
int locationY = MapUtils.getPixelShiftY(view.getZoom(),
|
||||||
int locationY = MapUtils
|
lastKnownLocation.getLatitude(), view.getLatitude(), view.getTileSize()) + view.getHeight() / 2;
|
||||||
.getPixelShiftY(view.getZoom(), lastKnownLocation.getLatitude(), view.getLatitude(), view.getTileSize())
|
|
||||||
+ view.getHeight() / 2;
|
|
||||||
// TODO specify bearing!
|
|
||||||
int radius = MapUtils.getLengthXFromMeters(view.getZoom(), view.getLatitude(), view.getLongitude(), lastKnownLocation
|
int radius = MapUtils.getLengthXFromMeters(view.getZoom(), view.getLatitude(), view.getLongitude(), lastKnownLocation
|
||||||
.getAccuracy(), view.getTileSize(), view.getWidth());
|
.getAccuracy(), view.getTileSize(), view.getWidth());
|
||||||
|
|
||||||
|
@ -58,6 +68,34 @@ public class PointLocationLayer implements OsmandMapLayer {
|
||||||
if (radius > RADIUS) {
|
if (radius > RADIUS) {
|
||||||
canvas.drawCircle(locationX, locationY, radius, area);
|
canvas.drawCircle(locationX, locationY, radius, area);
|
||||||
}
|
}
|
||||||
|
if(lastKnownLocation.hasBearing()){
|
||||||
|
float bearing = lastKnownLocation.getBearing();
|
||||||
|
int radiusBearing = 30;
|
||||||
|
if(lastKnownLocation.hasSpeed()){
|
||||||
|
radiusBearing =
|
||||||
|
Math.max(MapUtils.getLengthXFromMeters(view.getZoom(), view.getLatitude(), view.getLongitude(),
|
||||||
|
lastKnownLocation.getSpeed(), view.getTileSize(), view.getWidth()) * 2, radiusBearing);
|
||||||
|
}
|
||||||
|
radiusBearing += RADIUS /2;
|
||||||
|
|
||||||
|
pathForDirection.reset();
|
||||||
|
pathForDirection.moveTo(0, 0);
|
||||||
|
pathForDirection.lineTo((float) RADIUS, 1f);
|
||||||
|
pathForDirection.lineTo((float) -RADIUS, 1f);
|
||||||
|
pathForDirection.lineTo(0, 0);
|
||||||
|
Matrix m = new Matrix();
|
||||||
|
m.reset();
|
||||||
|
m.postScale(1, radiusBearing*0.5f);
|
||||||
|
m.postTranslate(0, -radiusBearing);
|
||||||
|
m.postTranslate(locationX, locationY);
|
||||||
|
m.postRotate(bearing, locationX, locationY);
|
||||||
|
|
||||||
|
pathForDirection.transform(m);
|
||||||
|
canvas.drawPath(pathForDirection, this.bearing);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue