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.osm.Entity;
|
||||
import com.osmand.osm.Node;
|
||||
import com.osmand.osm.OSMSettings.OSMTagKey;
|
||||
|
||||
public class Amenity extends MapObject<Node> {
|
||||
public class Amenity extends MapObject<Entity> {
|
||||
// http://wiki.openstreetmap.org/wiki/Amenity
|
||||
public enum AmenityType {
|
||||
SUSTENANCE, // restaurant, cafe ...
|
||||
|
@ -89,16 +88,16 @@ public class Amenity extends MapObject<Node> {
|
|||
private String subType;
|
||||
private AmenityType type;
|
||||
|
||||
public Amenity(Node node){
|
||||
this.entity = node;
|
||||
this.type = getType(node);
|
||||
this.subType = getSubType(node);
|
||||
public Amenity(Entity entity){
|
||||
this.entity = entity;
|
||||
this.type = getType(entity);
|
||||
this.subType = getSubType(entity);
|
||||
}
|
||||
|
||||
public Amenity(){
|
||||
}
|
||||
|
||||
protected String getSubType(Node node){
|
||||
protected String getSubType(Entity node){
|
||||
if(node.getTag(OSMTagKey.AMENITY) != null){
|
||||
return node.getTag(OSMTagKey.AMENITY);
|
||||
} else if(node.getTag(OSMTagKey.SHOP) != null){
|
||||
|
@ -111,7 +110,7 @@ public class Amenity extends MapObject<Node> {
|
|||
return "";
|
||||
}
|
||||
|
||||
protected AmenityType getType(Node node){
|
||||
protected AmenityType getType(Entity node){
|
||||
if(node.getTag(OSMTagKey.SHOP) != null){
|
||||
return AmenityType.SHOP;
|
||||
} else if(node.getTag(OSMTagKey.TOURISM) != null){
|
||||
|
@ -141,10 +140,6 @@ public class Amenity extends MapObject<Node> {
|
|||
}
|
||||
|
||||
public static boolean isAmenity(Entity n){
|
||||
// TODO allow ways to be amenity!
|
||||
if(!(n instanceof Node)){
|
||||
return false;
|
||||
}
|
||||
if(n.getTag(OSMTagKey.AMENITY) != null){
|
||||
return true;
|
||||
} else if(n.getTag(OSMTagKey.SHOP) != null){
|
||||
|
|
|
@ -193,7 +193,7 @@ public class DataExtraction {
|
|||
}
|
||||
}
|
||||
if (indexPOI && Amenity.isAmenity(e)) {
|
||||
amenities.add(new Amenity((Node) e));
|
||||
amenities.add(new Amenity(e));
|
||||
return true;
|
||||
}
|
||||
if (e instanceof Node && e.getTag(OSMTagKey.PLACE) != null) {
|
||||
|
|
|
@ -104,6 +104,27 @@ public class MapUtils {
|
|||
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]
|
||||
*/
|
||||
|
||||
// TODO check boundaries
|
||||
public static double getTileNumberX(int zoom, double longitude){
|
||||
longitude = checkLongitude(longitude);
|
||||
int n = 1 << zoom;
|
||||
return (longitude + 180d)/360d * n;
|
||||
}
|
||||
|
||||
public static double getTileNumberY(int zoom, double latitude){
|
||||
int n = 1 << zoom;
|
||||
latitude = checkLatitude(latitude);
|
||||
double eval = Math.log( Math.tan(Math.toRadians(latitude)) + 1/Math.cos(Math.toRadians(latitude)) );
|
||||
return (1 - eval / Math.PI) / 2 * n;
|
||||
}
|
||||
|
|
|
@ -112,7 +112,6 @@ public class OsmExtractionUI implements IMapLocationListener {
|
|||
private JCheckBox buildAddressIndex;
|
||||
private JCheckBox normalizingStreets;
|
||||
private TreeModelListener treeModelListener;
|
||||
private JCheckBox zipIndexFiles;
|
||||
private JCheckBox loadingAllData;
|
||||
|
||||
|
||||
|
@ -300,9 +299,12 @@ public class OsmExtractionUI implements IMapLocationListener {
|
|||
generateDataButton.setEnabled(region != null);
|
||||
normalizingStreets.setVisible(region == null);
|
||||
loadingAllData.setVisible(region == null);
|
||||
buildAddressIndex.setEnabled(region == null || region.getCitiesCount(null) > 0);
|
||||
buildPoiIndex.setEnabled(region == null || !region.getAmenityManager().isEmpty());
|
||||
zipIndexFiles.setVisible(region != null);
|
||||
if(region == null && !buildAddressIndex.isEnabled()){
|
||||
buildAddressIndex.setEnabled(true);
|
||||
}
|
||||
if(region == null && !buildPoiIndex.isEnabled()){
|
||||
buildPoiIndex.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void createButtonsBar(Container content){
|
||||
|
@ -341,11 +343,6 @@ public class OsmExtractionUI implements IMapLocationListener {
|
|||
panel.add(loadingAllData);
|
||||
loadingAllData.setSelected(false);
|
||||
|
||||
zipIndexFiles = new JCheckBox();
|
||||
zipIndexFiles.setText("Zip index files");
|
||||
panel.add(zipIndexFiles);
|
||||
zipIndexFiles.setSelected(true);
|
||||
|
||||
updateButtonsBar();
|
||||
}
|
||||
|
||||
|
@ -360,8 +357,7 @@ public class OsmExtractionUI implements IMapLocationListener {
|
|||
DataIndexBuilder builder = new DataIndexBuilder(DataExtractionSettings.getSettings().getDefaultWorkingDir(), region);
|
||||
StringBuilder msg = new StringBuilder();
|
||||
try {
|
||||
builder.setZipped(zipIndexFiles.isSelected());
|
||||
msg.append("Indices checked for ").append(region.getName());
|
||||
msg.append("Indices for ").append(region.getName());
|
||||
if(buildPoiIndex.isEnabled()){
|
||||
dlg.startTask("Generating POI index...", -1);
|
||||
builder.buildPOI();
|
||||
|
@ -629,6 +625,12 @@ public class OsmExtractionUI implements IMapLocationListener {
|
|||
try {
|
||||
DataExtraction dataExtraction = new DataExtraction(buildAddressIndex.isSelected(), buildPoiIndex.isSelected(),
|
||||
normalizingStreets.isSelected(), loadingAllData.isSelected());
|
||||
if(!buildAddressIndex.isSelected()){
|
||||
buildAddressIndex.setEnabled(false);
|
||||
}
|
||||
if(!buildPoiIndex.isSelected()){
|
||||
buildPoiIndex.setEnabled(false);
|
||||
}
|
||||
res = dataExtraction.readCountry(f.getAbsolutePath(), dlg, filter);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
|
|
|
@ -56,7 +56,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
private List<OsmandMapLayer> layers = new ArrayList<OsmandMapLayer>();
|
||||
|
||||
// UI Part
|
||||
|
||||
private AnimateDraggingMapThread animatedDraggingThread;
|
||||
|
||||
private PointF startDragging = null;
|
||||
|
@ -248,6 +247,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
|
|||
synchronized (holder) {
|
||||
Canvas canvas = holder.lockCanvas();
|
||||
if (canvas != null) {
|
||||
// canvas.rotate(45);
|
||||
try {
|
||||
for (int i = 0; i * tileSize + startingX < width; i++) {
|
||||
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())) {
|
||||
SurfaceHolder holder = getHolder();
|
||||
synchronized (holder) {
|
||||
// TODO
|
||||
Canvas canvas = holder.lockCanvas(new Rect(i, j, getTileSize() + i, getTileSize() + j));
|
||||
if (canvas != null) {
|
||||
// canvas.rotate(45);
|
||||
try {
|
||||
ResourceManager mgr = ResourceManager.getResourceManager();
|
||||
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.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.location.Location;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
|
@ -10,11 +13,13 @@ import com.osmand.osm.MapUtils;
|
|||
|
||||
public class PointLocationLayer implements OsmandMapLayer {
|
||||
private Paint location;
|
||||
private Paint bearing;
|
||||
private Paint area;
|
||||
|
||||
protected Location lastKnownLocation = null;
|
||||
protected final static int RADIUS = 7;
|
||||
private OsmandMapTileView view;
|
||||
private Path pathForDirection;
|
||||
|
||||
private void initUI() {
|
||||
location = new Paint();
|
||||
|
@ -25,6 +30,14 @@ public class PointLocationLayer implements OsmandMapLayer {
|
|||
area = new Paint();
|
||||
area.setColor(Color.BLUE);
|
||||
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) {
|
||||
|
@ -42,13 +55,10 @@ public class PointLocationLayer implements OsmandMapLayer {
|
|||
@Override
|
||||
public void onDraw(Canvas canvas) {
|
||||
if (isLocationVisible(lastKnownLocation)) {
|
||||
int locationX = MapUtils.getPixelShiftX(view.getZoom(), lastKnownLocation.getLongitude(), view.getLongitude(), view
|
||||
.getTileSize())
|
||||
+ view.getWidth() / 2;
|
||||
int locationY = MapUtils
|
||||
.getPixelShiftY(view.getZoom(), lastKnownLocation.getLatitude(), view.getLatitude(), view.getTileSize())
|
||||
+ view.getHeight() / 2;
|
||||
// TODO specify bearing!
|
||||
int locationX = MapUtils.getPixelShiftX(view.getZoom(), lastKnownLocation.getLongitude(), view.getLongitude(),
|
||||
view.getTileSize()) + view.getWidth() / 2;
|
||||
int locationY = MapUtils.getPixelShiftY(view.getZoom(),
|
||||
lastKnownLocation.getLatitude(), view.getLatitude(), view.getTileSize()) + view.getHeight() / 2;
|
||||
int radius = MapUtils.getLengthXFromMeters(view.getZoom(), view.getLatitude(), view.getLongitude(), lastKnownLocation
|
||||
.getAccuracy(), view.getTileSize(), view.getWidth());
|
||||
|
||||
|
@ -58,6 +68,34 @@ public class PointLocationLayer implements OsmandMapLayer {
|
|||
if (radius > RADIUS) {
|
||||
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