diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index fb8134e8af..7aefb77375 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -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) } diff --git a/DataExtractionOSM/src/com/osmand/data/Amenity.java b/DataExtractionOSM/src/com/osmand/data/Amenity.java index 9ab2a281d7..6b46e2bbff 100644 --- a/DataExtractionOSM/src/com/osmand/data/Amenity.java +++ b/DataExtractionOSM/src/com/osmand/data/Amenity.java @@ -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 { // 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); @@ -125,6 +120,11 @@ public class Amenity { } return false; } + + @Override + public Node getEntity() { + return node; + } public String getSimpleFormat(){ String name = node.getTag(OSMTagKey.NAME); diff --git a/DataExtractionOSM/src/com/osmand/data/Building.java b/DataExtractionOSM/src/com/osmand/data/Building.java new file mode 100644 index 0000000000..ee08103f97 --- /dev/null +++ b/DataExtractionOSM/src/com/osmand/data/Building.java @@ -0,0 +1,18 @@ +package com.osmand.data; + +import com.osmand.osm.Entity; + +public class Building extends MapObject { + + private final Entity e; + + public Building(Entity e){ + this.e = e; + } + + @Override + public Entity getEntity() { + return e; + } + +} diff --git a/DataExtractionOSM/src/com/osmand/data/City.java b/DataExtractionOSM/src/com/osmand/data/City.java index 87bfbaf6de..c1eebde596 100644 --- a/DataExtractionOSM/src/com/osmand/data/City.java +++ b/DataExtractionOSM/src/com/osmand/data/City.java @@ -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 { 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 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(); + } + } } diff --git a/DataExtractionOSM/src/com/osmand/data/DataTileManager.java b/DataExtractionOSM/src/com/osmand/data/DataTileManager.java index 718c60c464..e1954d20b1 100644 --- a/DataExtractionOSM/src/com/osmand/data/DataTileManager.java +++ b/DataExtractionOSM/src/com/osmand/data/DataTileManager.java @@ -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 { 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 r){ if(objects.containsKey(evTile(tx, ty))){ r.addAll(objects.get(evTile(tx, ty))); @@ -65,7 +84,24 @@ public class DataTileManager { * returns not exactly sorted list, * however the first objects are from closer tile than last */ - public List getClosestObjects(double latitude, double longitude, int depth){ + public List getClosestObjects(double latitude, double longitude, int defaultStep){ + if(isEmpty()){ + return Collections.emptyList(); + } + int dp = 1; + List l = null; + while (l == null || l.isEmpty()) { + l = getClosestObjects(latitude, longitude, dp, dp + defaultStep); + dp += defaultStep; + } + return l; + } + + public List getClosestObjects(double latitude, double longitude){ + return getClosestObjects(latitude, longitude, 3); + } + + public List getClosestObjects(double latitude, double longitude, int startDepth, int depth){ int tileX = (int) MapUtils.getTileNumberX(zoom, longitude); int tileY = (int) MapUtils.getTileNumberY(zoom, latitude); List result = new ArrayList(); @@ -78,9 +114,9 @@ public class DataTileManager { // 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 � + // goes for (int j = 0; j <= i; j++) { // left & right int dx = j == 0 ? 0 : -1; @@ -119,10 +155,6 @@ public class DataTileManager { return tile; } - public boolean isEmpty(){ - return objects.isEmpty(); - } - } diff --git a/DataExtractionOSM/src/com/osmand/data/MapObject.java b/DataExtractionOSM/src/com/osmand/data/MapObject.java new file mode 100644 index 0000000000..7ad8476c3b --- /dev/null +++ b/DataExtractionOSM/src/com/osmand/data/MapObject.java @@ -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 implements Comparable> { + + 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 o) { + return getName().compareTo(o.getName()); + } + +} diff --git a/DataExtractionOSM/src/com/osmand/data/Region.java b/DataExtractionOSM/src/com/osmand/data/Region.java index 6709b90ef8..63b9c5b451 100644 --- a/DataExtractionOSM/src/com/osmand/data/Region.java +++ b/DataExtractionOSM/src/com/osmand/data/Region.java @@ -33,8 +33,10 @@ public class Region { } } + private DataTileManager cityManager = new DataTileManager(); private Map> cities = new HashMap>(); { + cityManager.setZoom(10); for(CityType type : CityType.values()){ cities.put(type, new ArrayList()); } @@ -113,18 +115,16 @@ public class Region { return l; } - public City getClosestCity(LatLon point){ + 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 - } - if(rel < relDist){ - closest = c; - relDist = rel; + 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 getClosestAmenities(double latitude, double longitude){ - return amenities.getClosestObjects(latitude, longitude, 2); + return amenities.getClosestObjects(latitude, longitude); } public DataTileManager 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,8 +160,12 @@ 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(); + } } + } } diff --git a/DataExtractionOSM/src/com/osmand/data/Street.java b/DataExtractionOSM/src/com/osmand/data/Street.java index 49dd13606a..198115ce76 100644 --- a/DataExtractionOSM/src/com/osmand/data/Street.java +++ b/DataExtractionOSM/src/com/osmand/data/Street.java @@ -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 { private final String name; - private Map buildings = new HashMap(); - private List wayNodes = new ArrayList(); + private List buildings = new ArrayList(); + private List wayNodes = new ArrayList(); + 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 getBuildings() { - return buildings.keySet(); - } - - public LatLon getLocationBuilding(Entity e){ - return buildings.get(e); + public List 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 getWayNodes() { return wayNodes; } + public void doDataPreparation() { + calculateCenter(); + Collections.sort(buildings); + } + + @Override + public Entity getEntity() { + return center; + } + } diff --git a/DataExtractionOSM/src/com/osmand/data/preparation/DataExtraction.java b/DataExtractionOSM/src/com/osmand/data/preparation/DataExtraction.java index e5681b70cd..8c0960c872 100644 --- a/DataExtractionOSM/src/com/osmand/data/preparation/DataExtraction.java +++ b/DataExtractionOSM/src/com/osmand/data/preparation/DataExtraction.java @@ -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(); 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,7 +241,26 @@ public class DataExtraction { waysManager.registerObject(center.getLatitude(), center.getLongitude(), w); } } - /// way with name : МЗОР, ул. ..., + 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; diff --git a/DataExtractionOSM/src/com/osmand/data/preparation/DataIndexBuilder.java b/DataExtractionOSM/src/com/osmand/data/preparation/DataIndexBuilder.java index 80e1e0a29d..9d28cfe63e 100644 --- a/DataExtractionOSM/src/com/osmand/data/preparation/DataIndexBuilder.java +++ b/DataExtractionOSM/src/com/osmand/data/preparation/DataIndexBuilder.java @@ -61,7 +61,7 @@ public class DataIndexBuilder { List list = region.getAmenityManager().getAllObjects(); List interestedObjects = new ArrayList(list.size()); for(Amenity a : list) { - interestedObjects.add(a.getNode().getId()); + interestedObjects.add(a.getEntity().getId()); } OutputStream output = checkFile("POI/"+region.getName()+".osm"); try { diff --git a/DataExtractionOSM/src/com/osmand/osm/MapUtils.java b/DataExtractionOSM/src/com/osmand/osm/MapUtils.java index 50346bbcec..e519d3faae 100644 --- a/DataExtractionOSM/src/com/osmand/osm/MapUtils.java +++ b/DataExtractionOSM/src/com/osmand/osm/MapUtils.java @@ -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); } @@ -46,7 +51,21 @@ public class MapUtils { public static double getDistance(LatLon l1, LatLon l2){ 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 list = new ArrayList(); + for(Entity fe : ((Relation) e).getMembers(null)){ + list.add(getCenter(fe)); + } + return getWeightCenter(list); + } + return null; + } public static LatLon getWeightCenter(Collection nodes){ if(nodes.isEmpty()){ diff --git a/DataExtractionOSM/src/com/osmand/osm/Way.java b/DataExtractionOSM/src/com/osmand/osm/Way.java index adfaa1b37f..352210aa5a 100644 --- a/DataExtractionOSM/src/com/osmand/osm/Way.java +++ b/DataExtractionOSM/src/com/osmand/osm/Way.java @@ -67,13 +67,7 @@ public class Way extends Entity { if(nodes == null){ return null; } - List list = new ArrayList(nodes.size()); - for(Node n : nodes){ - if(n != null){ - list.add(n.getLatLon()); - } - } - return MapUtils.getWeightCenter(list); + return MapUtils.getWeightCenterForNodes(nodes); } diff --git a/DataExtractionOSM/src/com/osmand/osm/io/OSMIndexStorage.java b/DataExtractionOSM/src/com/osmand/osm/io/OSMIndexStorage.java new file mode 100644 index 0000000000..cc75538519 --- /dev/null +++ b/DataExtractionOSM/src/com/osmand/osm/io/OSMIndexStorage.java @@ -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); + } + + } +} diff --git a/DataExtractionOSM/src/com/osmand/osm/io/OSMStorageWriter.java b/DataExtractionOSM/src/com/osmand/osm/io/OSMStorageWriter.java index 36e3adee6c..27341ab00c 100644 --- a/DataExtractionOSM/src/com/osmand/osm/io/OSMStorageWriter.java +++ b/DataExtractionOSM/src/com/osmand/osm/io/OSMStorageWriter.java @@ -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 entities; diff --git a/DataExtractionOSM/src/com/osmand/osm/io/OsmBaseStorage.java b/DataExtractionOSM/src/com/osmand/osm/io/OsmBaseStorage.java index fe33b2ac81..27b3bfa684 100644 --- a/DataExtractionOSM/src/com/osmand/osm/io/OsmBaseStorage.java +++ b/DataExtractionOSM/src/com/osmand/osm/io/OsmBaseStorage.java @@ -45,14 +45,14 @@ public class OsmBaseStorage extends DefaultHandler { protected Entity currentParsedEntity = null; - private boolean parseStarted; + protected boolean parseStarted; protected Map entities = new LinkedHashMap(); // 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 supportedVersions = new HashSet(); + protected static final Set supportedVersions = new HashSet(); 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()){ diff --git a/DataExtractionOSM/src/com/osmand/swing/OsmExtractionUI.java b/DataExtractionOSM/src/com/osmand/swing/OsmExtractionUI.java index ce5cccb1f9..3358f9ab4f 100644 --- a/DataExtractionOSM/src/com/osmand/swing/OsmExtractionUI.java +++ b/DataExtractionOSM/src/com/osmand/swing/OsmExtractionUI.java @@ -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,42 +213,28 @@ 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 c = (MapObject) 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() { @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)); diff --git a/DataExtractionOSM/src/com/osmand/swing/ProgressDialog.java b/DataExtractionOSM/src/com/osmand/swing/ProgressDialog.java index cb4014ea45..75c85404fb 100644 --- a/DataExtractionOSM/src/com/osmand/swing/ProgressDialog.java +++ b/DataExtractionOSM/src/com/osmand/swing/ProgressDialog.java @@ -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(); } } diff --git a/OsmAnd/.classpath b/OsmAnd/.classpath index 88a4835117..a212a99534 100644 --- a/OsmAnd/.classpath +++ b/OsmAnd/.classpath @@ -1,7 +1,7 @@ - + diff --git a/OsmAnd/src/com/osmand/views/POIMapLayer.java b/OsmAnd/src/com/osmand/views/POIMapLayer.java index 08c029c5fd..f561a4f372 100644 --- a/OsmAnd/src/com/osmand/views/POIMapLayer.java +++ b/OsmAnd/src/com/osmand/views/POIMapLayer.java @@ -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); }