2010-04-26 18:24:27 +02:00
|
|
|
package com.osmand.data;
|
2010-04-26 17:20:50 +02:00
|
|
|
|
2010-05-14 13:44:35 +02:00
|
|
|
import java.util.ArrayList;
|
2010-05-14 23:05:18 +02:00
|
|
|
import java.util.Collections;
|
2010-05-14 13:44:35 +02:00
|
|
|
import java.util.List;
|
2010-04-26 17:20:50 +02:00
|
|
|
|
2010-04-27 14:37:49 +02:00
|
|
|
import com.osmand.osm.Entity;
|
|
|
|
import com.osmand.osm.LatLon;
|
2010-05-14 23:05:18 +02:00
|
|
|
import com.osmand.osm.MapUtils;
|
2010-05-14 13:44:35 +02:00
|
|
|
import com.osmand.osm.Node;
|
2010-05-14 23:05:18 +02:00
|
|
|
import com.osmand.osm.OSMSettings.OSMTagKey;
|
2010-04-26 17:20:50 +02:00
|
|
|
|
2010-05-14 23:05:18 +02:00
|
|
|
public class Street extends MapObject<Entity> {
|
2010-04-26 17:20:50 +02:00
|
|
|
|
2010-05-14 23:05:18 +02:00
|
|
|
private List<Building> buildings = new ArrayList<Building>();
|
|
|
|
private List<Node> wayNodes = new ArrayList<Node>();
|
2010-04-26 17:20:50 +02:00
|
|
|
|
|
|
|
public Street(String name){
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
2010-05-16 23:49:11 +02:00
|
|
|
public Street(){}
|
|
|
|
|
2010-05-14 23:05:18 +02:00
|
|
|
public void registerBuilding(Entity e){
|
|
|
|
Building building = new Building(e);
|
|
|
|
building.setName(e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER));
|
|
|
|
buildings.add(building);
|
2010-04-26 17:20:50 +02:00
|
|
|
}
|
|
|
|
|
2010-05-16 23:49:11 +02:00
|
|
|
public void registerBuilding(Building building){
|
|
|
|
buildings.add(building);
|
2010-04-26 17:20:50 +02:00
|
|
|
}
|
|
|
|
|
2010-05-16 23:49:11 +02:00
|
|
|
public List<Building> getBuildings() {
|
|
|
|
return buildings;
|
2010-04-26 17:20:50 +02:00
|
|
|
}
|
2010-05-14 23:05:18 +02:00
|
|
|
|
|
|
|
public LatLon getLocation(){
|
2010-05-17 14:03:16 +02:00
|
|
|
if(entity == null){
|
2010-05-14 23:05:18 +02:00
|
|
|
calculateCenter();
|
|
|
|
}
|
2010-05-17 14:03:16 +02:00
|
|
|
return entity == null ? null : entity.getLatLon();
|
2010-05-14 23:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void calculateCenter(){
|
|
|
|
if(wayNodes.size() == 1){
|
2010-05-17 14:03:16 +02:00
|
|
|
entity = wayNodes.get(0);
|
2010-05-14 23:05:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
LatLon c = MapUtils.getWeightCenterForNodes(wayNodes);
|
|
|
|
double dist = Double.POSITIVE_INFINITY;
|
|
|
|
for(Node n : wayNodes){
|
2010-05-15 14:54:26 +02:00
|
|
|
if (n != null) {
|
|
|
|
double nd = MapUtils.getDistance(n, c);
|
|
|
|
if (nd < dist) {
|
2010-05-17 14:03:16 +02:00
|
|
|
entity = n;
|
2010-05-15 14:54:26 +02:00
|
|
|
dist = nd;
|
|
|
|
}
|
2010-05-14 23:05:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-14 13:44:35 +02:00
|
|
|
|
|
|
|
public List<Node> getWayNodes() {
|
|
|
|
return wayNodes;
|
|
|
|
}
|
2010-04-26 17:20:50 +02:00
|
|
|
|
2010-05-14 23:05:18 +02:00
|
|
|
public void doDataPreparation() {
|
|
|
|
calculateCenter();
|
|
|
|
Collections.sort(buildings);
|
|
|
|
}
|
|
|
|
|
2010-04-26 17:20:50 +02:00
|
|
|
}
|