package com.osmand.data; import java.util.ArrayList; import java.util.Collections; import java.util.List; 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 extends MapObject { private List buildings = new ArrayList(); private List wayNodes = new ArrayList(); public Street(String name){ this.name = name; } public Street(){} public void registerBuilding(Entity e){ Building building = new Building(e); building.setName(e.getTag(OSMTagKey.ADDR_HOUSE_NUMBER)); buildings.add(building); } public void registerBuilding(Building building){ buildings.add(building); } public List getBuildings() { return buildings; } public LatLon getLocation(){ if(entity == null){ calculateCenter(); } return entity == null ? null : entity.getLatLon(); } protected void calculateCenter(){ if(wayNodes.size() == 1){ entity = wayNodes.get(0); return; } LatLon c = MapUtils.getWeightCenterForNodes(wayNodes); double dist = Double.POSITIVE_INFINITY; for(Node n : wayNodes){ if (n != null) { double nd = MapUtils.getDistance(n, c); if (nd < dist) { entity = n; dist = nd; } } } } public List getWayNodes() { return wayNodes; } public void doDataPreparation() { calculateCenter(); Collections.sort(buildings); } }