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
|
|
|
|
|
|
|
private final String name;
|
2010-05-14 23:05:18 +02:00
|
|
|
private List<Building> buildings = new ArrayList<Building>();
|
|
|
|
private List<Node> wayNodes = new ArrayList<Node>();
|
|
|
|
private Node center = null;
|
2010-04-26 17:20:50 +02:00
|
|
|
|
|
|
|
public Street(String name){
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
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-14 23:05:18 +02:00
|
|
|
public List<Building> getBuildings() {
|
|
|
|
return buildings;
|
2010-04-26 17:20:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
2010-05-14 23:05:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
public LatLon getLocation(){
|
|
|
|
if(center == null){
|
|
|
|
calculateCenter();
|
|
|
|
}
|
2010-05-15 14:54:26 +02:00
|
|
|
return center == null ? null : center.getLatLon();
|
2010-05-14 23:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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){
|
2010-05-15 14:54:26 +02:00
|
|
|
if (n != null) {
|
|
|
|
double nd = MapUtils.getDistance(n, c);
|
|
|
|
if (nd < dist) {
|
|
|
|
center = n;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Entity getEntity() {
|
|
|
|
return center;
|
|
|
|
}
|
|
|
|
|
2010-04-26 17:20:50 +02:00
|
|
|
}
|