refactor data structure

git-svn-id: https://osmand.googlecode.com/svn/trunk@57 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-05-14 21:05:18 +00:00
parent 5322550b13
commit 6af7969c8a
19 changed files with 353 additions and 135 deletions

View file

@ -40,9 +40,11 @@ public class ToDoConstants {
/// SWING version :
// TODO :
// 1. save preferences ? where?
// 1. save preferences ? where? (use internet, default dir save and other...)
// 2. specify area to download tiles ()
// 3. download tiles without using dir tiles
// 4. Config file log & see log from file
// 5. specify area to load map (filter for osm loading)
// 6. Predefine what should be extracted from osm (building, poi or roads)
}

View file

@ -7,7 +7,7 @@ import com.osmand.Algoritms;
import com.osmand.osm.Node;
import com.osmand.osm.OSMSettings.OSMTagKey;
public class Amenity {
public class Amenity extends MapObject<Node> {
// http://wiki.openstreetmap.org/wiki/Amenity
public enum AmenityType {
SUSTENANCE, // restaurant, cafe ...
@ -76,17 +76,12 @@ public class Amenity {
}
private final Node node;
public Amenity(Node node){
this.node = node;
}
public Node getNode() {
return node;
}
public String getSubType(){
if(node.getTag(OSMTagKey.AMENITY) != null){
return node.getTag(OSMTagKey.AMENITY);
@ -126,6 +121,11 @@ public class Amenity {
return false;
}
@Override
public Node getEntity() {
return node;
}
public String getSimpleFormat(){
String name = node.getTag(OSMTagKey.NAME);
return Algoritms.capitalizeFirstLetterAndLowercase(getType().toString()) +

View file

@ -0,0 +1,18 @@
package com.osmand.data;
import com.osmand.osm.Entity;
public class Building extends MapObject<Entity> {
private final Entity e;
public Building(Entity e){
this.e = e;
}
@Override
public Entity getEntity() {
return e;
}
}

View file

@ -5,11 +5,10 @@ import java.util.Map;
import java.util.TreeMap;
import com.osmand.osm.Entity;
import com.osmand.osm.LatLon;
import com.osmand.osm.Node;
import com.osmand.osm.OSMSettings.OSMTagKey;
public class City {
public class City extends MapObject<Node> {
public enum CityType {
CITY(10000), TOWN(5000), VILLAGE(1000), HAMLET(300), SUBURB(300);
@ -46,36 +45,39 @@ public class City {
return streets.get(street);
}
public Street registerBuilding(LatLon point, Entity e){
public Street registerBuilding(Entity e){
String number = e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER);
String street = e.getTag(OSMTagKey.ADDR_STREET);
if( street != null && number != null){
registerStreet(street).registerBuilding(point, e);
registerStreet(street).registerBuilding(e);
return streets.get(street);
}
return null;
}
public String getName(){
return el.getTag(OSMTagKey.NAME);
}
public CityType getType(){
return type;
}
public Node getNode(){
return el;
}
public Collection<Street> getStreets(){
return streets.values();
}
@Override
public Node getEntity() {
return el;
}
@Override
public String toString() {
return "City [" +type+"] " + getName();
}
public void doDataPreparation(){
for(Street s : getStreets()){
s.doDataPreparation();
}
}
}

View file

@ -1,6 +1,7 @@
package com.osmand.data;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -26,12 +27,30 @@ public class DataTileManager<T> {
public void setZoom(int zoom) {
// TODO !!! it is required to reindex all stored objects
if(!objects.isEmpty()){
if(!isEmpty()){
throw new UnsupportedOperationException();
}
this.zoom = zoom;
}
public boolean isEmpty(){
for(String s : objects.keySet()){
if(!objects.get(s).isEmpty()){
return false;
}
}
return true;
}
public int getObjectsCount(){
int x = 0;
for(String s : objects.keySet()){
x += objects.get(s).size();
}
return x;
}
private void putObjects(int tx, int ty, List<T> r){
if(objects.containsKey(evTile(tx, ty))){
r.addAll(objects.get(evTile(tx, ty)));
@ -65,7 +84,24 @@ public class DataTileManager<T> {
* returns not exactly sorted list,
* however the first objects are from closer tile than last
*/
public List<T> getClosestObjects(double latitude, double longitude, int depth){
public List<T> getClosestObjects(double latitude, double longitude, int defaultStep){
if(isEmpty()){
return Collections.emptyList();
}
int dp = 1;
List<T> l = null;
while (l == null || l.isEmpty()) {
l = getClosestObjects(latitude, longitude, dp, dp + defaultStep);
dp += defaultStep;
}
return l;
}
public List<T> getClosestObjects(double latitude, double longitude){
return getClosestObjects(latitude, longitude, 3);
}
public List<T> getClosestObjects(double latitude, double longitude, int startDepth, int depth){
int tileX = (int) MapUtils.getTileNumberX(zoom, longitude);
int tileY = (int) MapUtils.getTileNumberY(zoom, latitude);
List<T> result = new ArrayList<T>();
@ -78,9 +114,9 @@ public class DataTileManager<T> {
// however the simplest way could be to visit row by row & after sort tiles by distance (that's less efficient)
// go through circle
for (int i = 1; i <= depth; i++) {
for (int i = startDepth; i <= depth; i++) {
// goes <EFBFBD>
// goes
for (int j = 0; j <= i; j++) {
// left & right
int dx = j == 0 ? 0 : -1;
@ -119,10 +155,6 @@ public class DataTileManager<T> {
return tile;
}
public boolean isEmpty(){
return objects.isEmpty();
}
}

View file

@ -0,0 +1,51 @@
package com.osmand.data;
import com.osmand.osm.Entity;
import com.osmand.osm.LatLon;
import com.osmand.osm.MapUtils;
import com.osmand.osm.OSMSettings.OSMTagKey;
public abstract class MapObject<T extends Entity> implements Comparable<MapObject<T>> {
protected String name = null;
protected LatLon location = null;
public abstract T getEntity();
public String getName() {
if (this.name != null) {
return this.name;
}
Entity e = getEntity();
if (e != null) {
String name = getEntity().getTag(OSMTagKey.NAME);
if (name != null) {
return name;
}
return e.getId() + "";
} else {
return "";
}
}
public void setName(String name) {
this.name = name;
}
public LatLon getLocation(){
if(location != null){
return location;
}
return MapUtils.getCenter(getEntity());
}
public void setLocation(double latitude, double longitude){
location = new LatLon(latitude, longitude);
}
@Override
public int compareTo(MapObject<T> o) {
return getName().compareTo(o.getName());
}
}

View file

@ -33,8 +33,10 @@ public class Region {
}
}
private DataTileManager<City> cityManager = new DataTileManager<City>();
private Map<CityType, List<City>> cities = new HashMap<CityType, List<City>>();
{
cityManager.setZoom(10);
for(CityType type : CityType.values()){
cities.put(type, new ArrayList<City>());
}
@ -116,15 +118,13 @@ public class Region {
public City getClosestCity(LatLon point) {
City closest = null;
double relDist = Double.POSITIVE_INFINITY;
for(CityType t : CityType.values()){
for(City c : cities.get(t)){
double rel = MapUtils.getDistance(c.getNode(), point) / t.getRadius();
if(rel < 1) {
return c; // we are in that city
}
for (City c : cityManager.getClosestObjects(point.getLatitude(), point.getLongitude())) {
double rel = MapUtils.getDistance(c.getEntity(), point) / c.getType().getRadius();
if (rel < relDist) {
closest = c;
relDist = rel;
if(relDist < 0.2d){
break;
}
}
}
@ -132,7 +132,7 @@ public class Region {
}
public List<Amenity> getClosestAmenities(double latitude, double longitude){
return amenities.getClosestObjects(latitude, longitude, 2);
return amenities.getClosestObjects(latitude, longitude);
}
public DataTileManager<Amenity> getAmenityManager(){
@ -140,13 +140,15 @@ public class Region {
}
public void registerAmenity(Amenity a){
amenities.registerObject(a.getNode().getLatitude(), a.getNode().getLongitude(), a);
LatLon location = a.getLocation();
amenities.registerObject(location.getLatitude(), location.getLongitude(), a);
}
public City registerCity(Node c){
City city = new City(c);
if(city.getType() != null && !Algoritms.isEmpty(city.getName())){
cityManager.registerObject(c.getLatitude(), c.getLongitude(), city);
cities.get(city.getType()).add(city);
return city;
}
@ -158,7 +160,11 @@ public class Region {
CityComparator comp = new CityComparator();
for(CityType t : cities.keySet()){
Collections.sort(cities.get(t), comp);
for(City c : cities.get(t)){
c.doDataPreparation();
}
}
}

View file

@ -1,43 +1,77 @@
package com.osmand.data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.osmand.osm.Entity;
import com.osmand.osm.LatLon;
import com.osmand.osm.MapUtils;
import com.osmand.osm.Node;
import com.osmand.osm.OSMSettings.OSMTagKey;
public class Street {
public class Street extends MapObject<Entity> {
private final String name;
private Map<Entity, LatLon> buildings = new HashMap<Entity, LatLon>();
private List<Building> buildings = new ArrayList<Building>();
private List<Node> wayNodes = new ArrayList<Node>();
private Node center = null;
public Street(String name){
this.name = name;
}
public void registerBuilding(LatLon point, Entity e){
buildings.put(e, point);
public void registerBuilding(Entity e){
Building building = new Building(e);
building.setName(e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER));
buildings.add(building);
}
public Set<Entity> getBuildings() {
return buildings.keySet();
}
public LatLon getLocationBuilding(Entity e){
return buildings.get(e);
public List<Building> getBuildings() {
return buildings;
}
public String getName() {
return name;
}
public LatLon getLocation(){
if(center == null){
calculateCenter();
}
return center.getLatLon();
}
protected void calculateCenter(){
if(wayNodes.size() == 1){
center = wayNodes.get(0);
return;
}
LatLon c = MapUtils.getWeightCenterForNodes(wayNodes);
double dist = Double.POSITIVE_INFINITY;
for(Node n : wayNodes){
double nd = MapUtils.getDistance(n, c);
if(nd < dist){
center = n;
dist = nd;
}
}
}
public List<Node> getWayNodes() {
return wayNodes;
}
public void doDataPreparation() {
calculateCenter();
Collections.sort(buildings);
}
@Override
public Entity getEntity() {
return center;
}
}

View file

@ -214,35 +214,20 @@ public class DataExtraction {
if("country".equals(place)){
country.setEntity(s);
} else {
City registerCity = country.registerCity(s);
if(registerCity == null){
System.out.println(place + " - " + s.getTag(OSMTagKey.NAME));
}
country.registerCity(s);
}
}
// 2. found buildings (index addresses)
for(Entity b : buildings){
LatLon center = b.getLatLon();
// TODO first of all tag could be checked NodeUtil.getTag(e, "addr:city")
if(center == null){
// no nodes where loaded for this way
} else {
City city = country.getClosestCity(center);
if (city != null) {
city.registerBuilding(center, b);
}
}
}
for(Amenity a: amenities){
country.registerAmenity(a);
}
progress.startTask("Indexing streets...", ways.size());
waysManager = new DataTileManager<Way>();
for (Way w : ways) {
progress.progress(1);
if (w.getTag(OSMTagKey.NAME) != null) {
String street = w.getTag(OSMTagKey.NAME);
LatLon center = MapUtils.getWeightCenterForNodes(w.getNodes());
@ -256,8 +241,27 @@ public class DataExtraction {
waysManager.registerObject(center.getLatitude(), center.getLongitude(), w);
}
}
progress.finishTask();
/// way with name : МЗОР, ул. ...,
// found buildings (index addresses)
progress.startTask("Indexing buildings...", buildings.size());
for(Entity b : buildings){
LatLon center = b.getLatLon();
progress.progress(1);
// TODO first of all tag could be checked NodeUtil.getTag(e, "addr:city")
if(center == null){
// no nodes where loaded for this way
} else {
City city = country.getClosestCity(center);
if (city != null) {
city.registerBuilding(b);
}
}
}
progress.finishTask();
country.doDataPreparation();
return country;
}

View file

@ -61,7 +61,7 @@ public class DataIndexBuilder {
List<Amenity> list = region.getAmenityManager().getAllObjects();
List<Long> interestedObjects = new ArrayList<Long>(list.size());
for(Amenity a : list) {
interestedObjects.add(a.getNode().getId());
interestedObjects.add(a.getEntity().getId());
}
OutputStream output = checkFile("POI/"+region.getName()+".osm");
try {

View file

@ -1,5 +1,6 @@
package com.osmand.osm;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@ -16,6 +17,10 @@ public class MapUtils {
return getDistance(e1.getLatitude(), e1.getLongitude(), e2.getLatitude(), e2.getLongitude());
}
public static double getDistance(LatLon l, double latitude, double longitude){
return getDistance(l.getLatitude(), l.getLongitude(), latitude, longitude);
}
public static double getDistance(Node e1, double latitude, double longitude){
return getDistance(e1.getLatitude(), e1.getLongitude(), latitude, longitude);
}
@ -47,6 +52,20 @@ public class MapUtils {
return getDistance(l1, l2);
}
public static LatLon getCenter(Entity e){
if(e instanceof Node){
return ((Node) e).getLatLon();
} else if(e instanceof Way){
return getWeightCenterForNodes(((Way) e).getNodes());
} else if(e instanceof Relation){
List<LatLon> list = new ArrayList<LatLon>();
for(Entity fe : ((Relation) e).getMembers(null)){
list.add(getCenter(fe));
}
return getWeightCenter(list);
}
return null;
}
public static LatLon getWeightCenter(Collection<LatLon> nodes){
if(nodes.isEmpty()){

View file

@ -67,13 +67,7 @@ public class Way extends Entity {
if(nodes == null){
return null;
}
List<LatLon> list = new ArrayList<LatLon>(nodes.size());
for(Node n : nodes){
if(n != null){
list.add(n.getLatLon());
}
}
return MapUtils.getWeightCenter(list);
return MapUtils.getWeightCenterForNodes(nodes);
}

View file

@ -0,0 +1,52 @@
package com.osmand.osm.io;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.osmand.data.Region;
public class OSMIndexStorage extends OsmBaseStorage {
protected static final String ELEM_OSMAND = "osmand";
protected static final String ELEM_INDEX = "index";
protected static final String ELEM_CITY = "city";
protected static final String ELEM_STREET = "street";
protected static final String ELEM_BUILDING = "building";
public static final String OSMAND_VERSION = "0.1";
protected Region region;
public OSMIndexStorage(Region region){
this.region = region;
}
@Override
protected void initRootElement(String uri, String localName, String name, Attributes attributes) throws OsmVersionNotSupported {
if(ELEM_OSM.equals(name)){
if(!supportedVersions.contains(attributes.getValue(ATTR_VERSION))){
throw new OsmVersionNotSupported();
}
} else if(ELEM_OSMAND.equals(name)){
if(!OSMAND_VERSION.equals(attributes.getValue(ATTR_VERSION))){
throw new OsmVersionNotSupported();
}
} else {
throw new OsmVersionNotSupported();
}
parseStarted = true;
}
@Override
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
name = saxParser.isNamespaceAware() ? localName : name;
if(!parseStarted){
initRootElement(uri, localName, name, attributes);
} else if(ELEM_INDEX.equals(name)){
} else if(ELEM_CITY.equals(name)){
} else {
super.startElement(uri, localName, name, attributes);
}
}
}

View file

@ -1,5 +1,22 @@
package com.osmand.osm.io;
import static com.osmand.osm.io.OsmBaseStorage.ATTR_ID;
import static com.osmand.osm.io.OsmBaseStorage.ATTR_K;
import static com.osmand.osm.io.OsmBaseStorage.ATTR_LAT;
import static com.osmand.osm.io.OsmBaseStorage.ATTR_LON;
import static com.osmand.osm.io.OsmBaseStorage.ATTR_REF;
import static com.osmand.osm.io.OsmBaseStorage.ATTR_ROLE;
import static com.osmand.osm.io.OsmBaseStorage.ATTR_TYPE;
import static com.osmand.osm.io.OsmBaseStorage.ATTR_V;
import static com.osmand.osm.io.OsmBaseStorage.ATTR_VERSION;
import static com.osmand.osm.io.OsmBaseStorage.ELEM_MEMBER;
import static com.osmand.osm.io.OsmBaseStorage.ELEM_ND;
import static com.osmand.osm.io.OsmBaseStorage.ELEM_NODE;
import static com.osmand.osm.io.OsmBaseStorage.ELEM_OSM;
import static com.osmand.osm.io.OsmBaseStorage.ELEM_RELATION;
import static com.osmand.osm.io.OsmBaseStorage.ELEM_TAG;
import static com.osmand.osm.io.OsmBaseStorage.ELEM_WAY;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@ -19,8 +36,6 @@ import com.osmand.osm.Way;
import com.sun.org.apache.xerces.internal.impl.PropertyManager;
import com.sun.xml.internal.stream.writers.XMLStreamWriterImpl;
import static com.osmand.osm.io.OsmBaseStorage.*;
public class OSMStorageWriter {
private final Map<Long, Entity> entities;

View file

@ -45,14 +45,14 @@ public class OsmBaseStorage extends DefaultHandler {
protected Entity currentParsedEntity = null;
private boolean parseStarted;
protected boolean parseStarted;
protected Map<Long, Entity> entities = new LinkedHashMap<Long, Entity>();
// this is used to show feedback to user
private IProgress progress;
private InputStream inputStream;
private InputStream streamForProgress;
protected IProgress progress;
protected InputStream inputStream;
protected InputStream streamForProgress;
@ -87,7 +87,7 @@ public class OsmBaseStorage extends DefaultHandler {
}
private SAXParser saxParser;
protected SAXParser saxParser;
public SAXParser initSaxParser(){
if(saxParser != null){
return saxParser;
@ -123,22 +123,24 @@ public class OsmBaseStorage extends DefaultHandler {
return ret;
}
private static final Set<String> supportedVersions = new HashSet<String>();
protected static final Set<String> supportedVersions = new HashSet<String>();
static {
supportedVersions.add("0.6");
supportedVersions.add("0.5");
}
protected void initRootElement(String uri, String localName, String name, Attributes attributes) throws OsmVersionNotSupported{
if(!ELEM_OSM.equals(name) || !supportedVersions.contains(attributes.getValue(ATTR_VERSION))){
throw new OsmVersionNotSupported();
}
parseStarted = true;
}
@Override
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
name = saxParser.isNamespaceAware() ? localName : name;
if(!parseStarted){
if(!ELEM_OSM.equals(name) || !supportedVersions.contains(attributes.getValue(ATTR_VERSION))){
throw new OsmVersionNotSupported();
}
parseStarted = true;
initRootElement(uri, localName, name, attributes);
}
if (currentParsedEntity == null && streamForProgress != null) {
if(progress != null && !progress.isIndeterminate()){

View file

@ -63,7 +63,9 @@ import com.osmand.DefaultLauncherConstants;
import com.osmand.ExceptionHandler;
import com.osmand.IMapLocationListener;
import com.osmand.data.Amenity;
import com.osmand.data.Building;
import com.osmand.data.City;
import com.osmand.data.MapObject;
import com.osmand.data.Region;
import com.osmand.data.Street;
import com.osmand.data.Amenity.AmenityType;
@ -74,7 +76,6 @@ import com.osmand.osm.Entity;
import com.osmand.osm.LatLon;
import com.osmand.osm.MapUtils;
import com.osmand.osm.Node;
import com.osmand.osm.OSMSettings.OSMTagKey;
public class OsmExtractionUI implements IMapLocationListener {
@ -136,10 +137,9 @@ public class OsmExtractionUI implements IMapLocationListener {
for (Street str : ct.getStreets()) {
DefaultMutableTreeNode strTree = new DataExtractionTreeNode(str.getName(), str);
cityNodeTree.add(strTree);
for (Entity e : str.getBuildings()) {
DefaultMutableTreeNode building = new DataExtractionTreeNode(e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER), e);
for (Building b : str.getBuildings()) {
DefaultMutableTreeNode building = new DataExtractionTreeNode(b.getName(), b);
strTree.add(building);
}
}
}
@ -213,41 +213,27 @@ public class OsmExtractionUI implements IMapLocationListener {
treePlaces.setEditable(true);
treePlaces.setCellEditor(new RegionCellEditor(treePlaces, (DefaultTreeCellRenderer) treePlaces.getCellRenderer()));
treePlaces.addTreeSelectionListener(new TreeSelectionListener() {
@SuppressWarnings("unchecked")
@Override
public void valueChanged(TreeSelectionEvent e) {
if (e.getPath() != null) {
if (e.getPath().getLastPathComponent() instanceof DataExtractionTreeNode) {
Object o = ((DataExtractionTreeNode) e.getPath().getLastPathComponent()).getModelObject();
if (o instanceof City) {
City c = (City) o;
mapPanel.setLatLon(c.getNode().getLatitude(), c.getNode().getLongitude());
mapPanel.requestFocus();
} else if (o instanceof Street) {
Street s = (Street) o;
LatLon center = MapUtils.getWeightCenterForNodes(s.getWayNodes());
if(center != null){
mapPanel.setLatLon(center.getLatitude(), center.getLongitude());
if (o instanceof MapObject<?>) {
MapObject<Entity> c = (MapObject<Entity>) o;
LatLon location = c.getLocation();
if(location != null){
mapPanel.setLatLon(location.getLatitude(), location.getLongitude());
mapPanel.requestFocus();
}
} else if (o instanceof Amenity) {
Amenity c = (Amenity) o;
mapPanel.setLatLon(c.getNode().getLatitude(), c.getNode().getLongitude());
mapPanel.requestFocus();
} else if (o instanceof Entity) {
Entity c = (Entity) o;
if (c instanceof Node) {
mapPanel.setLatLon(((Node) c).getLatitude(), ((Node) c).getLongitude());
LatLon latLon = c.getLatLon();
if (latLon != null) {
mapPanel.setLatLon(latLon.getLatitude(), latLon.getLongitude());
mapPanel.requestFocus();
} else {
DataExtractionTreeNode n = (DataExtractionTreeNode) e.getPath().getPathComponent(
e.getPath().getPathCount() - 2);
if (n.getModelObject() instanceof Street) {
Street str = (Street) n.getModelObject();
LatLon l = str.getLocationBuilding(c);
mapPanel.setLatLon(l.getLatitude(), l.getLongitude());
mapPanel.requestFocus();
}
}
}
}
@ -382,10 +368,10 @@ public class OsmExtractionUI implements IMapLocationListener {
@Override
public void valueChanged(ListSelectionEvent e) {
if(searchList.getSelectedValue() != null){
Node node = ((City)searchList.getSelectedValue()).getNode();
Node node = ((City)searchList.getSelectedValue()).getEntity();
String text = "Lat : " + node.getLatitude() + " Lon " + node.getLongitude();
if(selectedCity != null){
text += " distance " + MapUtils.getDistance(selectedCity.getNode(), node);
text += " distance " + MapUtils.getDistance(selectedCity.getEntity(), node);
}
mapPanel.setLatLon(node.getLatitude(), node.getLongitude());
}
@ -515,7 +501,7 @@ public class OsmExtractionUI implements IMapLocationListener {
Collections.sort(closestAmenities, new Comparator<Amenity>() {
@Override
public int compare(Amenity o1, Amenity o2) {
return Double.compare(MapUtils.getDistance(o1.getNode(), newLatitude, newLongitude), MapUtils.getDistance(o2.getNode(),
return Double.compare(MapUtils.getDistance(o2.getLocation(), newLatitude, newLongitude), MapUtils.getDistance(o2.getLocation(),
newLatitude, newLongitude));
}
});
@ -535,7 +521,7 @@ public class OsmExtractionUI implements IMapLocationListener {
((DefaultMutableTreeNode) amenitiesTree.getChildAt(i)).removeAllChildren();
if (filter.get(type) != null) {
for (Amenity n : filter.get(type)) {
int dist = (int) (MapUtils.getDistance(n.getNode(), newLatitude, newLongitude));
int dist = (int) (MapUtils.getDistance(n.getLocation(), newLatitude, newLongitude));
String str = n.getStringWithoutType() + " [" + dist + " m ]";
DataExtractionTreeNode node = new DataExtractionTreeNode(str, n);
((DefaultMutableTreeNode) amenitiesTree.getChildAt(i)).add(node);
@ -547,7 +533,7 @@ public class OsmExtractionUI implements IMapLocationListener {
for (int i = 0; i < 15 && i < closestAmenities.size(); i++) {
Amenity n = closestAmenities.get(i);
int dist = (int) (MapUtils.getDistance(n.getNode(), newLatitude, newLongitude));
int dist = (int) (MapUtils.getDistance(n.getLocation(), newLatitude, newLongitude));
String str = n.getSimpleFormat() + " [" + dist + " m ]";
((DefaultMutableTreeNode) amenitiesTree.getChildAt(0)).add(new DataExtractionTreeNode(str, n));
((DefaultTreeModel)treePlaces.getModel()).nodeStructureChanged(amenitiesTree.getChildAt(0));

View file

@ -105,8 +105,9 @@ public class ProgressDialog extends JDialog implements IProgress {
@Override
public void progress(int deltaWork) {
this.deltaWork += deltaWork;
if(change(progressBar.getValue() + deltaWork)){
progressBar.setValue(progressBar.getValue() + deltaWork);
if(change(progressBar.getValue() + this.deltaWork)){
progressBar.setValue(progressBar.getValue() + this.deltaWork);
this.deltaWork = 0;
updateMessage();
}
}

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry excluding="**/MapPanel*|com/osmand/LogUtil.java|com/osmand/osm/io/OSMStorageWriter.java|com/osmand/DataExtraction.java|com/osmand/swing/|com/osmand/data/preparation/DataExtraction.java" kind="src" path="use"/>
<classpathentry excluding="**/MapPanel*|com/osmand/LogUtil.java|com/osmand/osm/io/OSMStorageWriter.java|com/osmand/DataExtraction.java|com/osmand/swing/|com/osmand/data/preparation/DataExtraction.java|com/osmand/data/preparation/DataIndexBuilder.java" kind="src" path="use"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="lib/bzip2-20090327.jar"/>

View file

@ -34,9 +34,9 @@ public class POIMapLayer implements OsmandMapLayer {
int ey = (int) event.getY();
int radius = getRadiusPoi(view.getZoom()) * 3 / 2;
for(Amenity n : objects){
double tileX = MapUtils.getTileNumberX(view.getZoom(), n.getNode().getLongitude());
double tileX = MapUtils.getTileNumberX(view.getZoom(), n.getLocation().getLongitude());
int x = (int) ((tileX - xTileLeft) * getTileSize());
double tileY = MapUtils.getTileNumberY(view.getZoom(), n.getNode().getLatitude());
double tileY = MapUtils.getTileNumberY(view.getZoom(), n.getLocation().getLatitude());
int y = (int) ((tileY - yTileUp) * getTileSize());
if(Math.abs(x - ex) <= radius && Math.abs(y - ey) <= radius){
Toast.makeText(view.getContext(), n.getSimpleFormat(), Toast.LENGTH_SHORT).show();
@ -95,9 +95,9 @@ public class POIMapLayer implements OsmandMapLayer {
.getLongitudeFromTile(view.getZoom(), xTileLeft), MapUtils.getLatitudeFromTile(view.getZoom(), yTileDown), MapUtils
.getLongitudeFromTile(view.getZoom(), xTileRight));
for (Amenity o : objects) {
double tileX = MapUtils.getTileNumberX(view.getZoom(), o.getNode().getLongitude());
double tileX = MapUtils.getTileNumberX(view.getZoom(), o.getLocation().getLongitude());
int x = (int) ((tileX - xTileLeft) * getTileSize());
double tileY = MapUtils.getTileNumberY(view.getZoom(), o.getNode().getLatitude());
double tileY = MapUtils.getTileNumberY(view.getZoom(), o.getLocation().getLatitude());
int y = (int) ((tileY - yTileUp) * getTileSize());
canvas.drawCircle(x, y, getRadiusPoi(view.getZoom()), pointUI);
}