use of aimax.osm.data.entities.MapWay in project aima-java by aimacode.
the class DefaultEntityRenderer method printBufferedObjects.
// int awnodes = 0;
/** Prints all buffered entities according to their rendering informations. */
public void printBufferedObjects() {
Collections.sort(areaBuffer, new MapAreaComparator());
Comparator<MapEntity> comp = new MapEntityComparator();
if (wayBuffer.size() < 10000)
Collections.sort(wayBuffer, comp);
if (nodeBuffer.size() < 10000)
Collections.sort(nodeBuffer, comp);
for (MapWay area : areaBuffer) printWay(area, (DefaultEntityViewInfo) area.getViewInfo(), true);
for (MapWay way : wayBuffer) printWay(way, (DefaultEntityViewInfo) way.getViewInfo(), false);
for (MapEntity node : nodeBuffer) {
MapNode n;
if (node instanceof MapWay) {
List<MapNode> wayNodes = getWayNodes((MapWay) node);
// needed to show icons for ways, whose abstraction is empty.
if (wayNodes.isEmpty())
wayNodes = ((MapWay) node).getNodes();
n = wayNodes.get(0);
} else
n = (MapNode) node;
printNode(n, (DefaultEntityViewInfo) node.getViewInfo());
}
for (Track track : trackBuffer) printTrack(track);
// System.out.print("NamesOrg: " + nameInfoBuffer.size() + "\n");
Collections.sort(nameInfoBuffer);
// remove names whose positions are to close to each other
int charSize = (int) (defaultFontSize * displayFactorSym);
for (int i = 0; i < nameInfoBuffer.size(); ++i) {
NameInfo info = nameInfoBuffer.get(i);
for (int j = 0; j < i; ++j) {
NameInfo info1 = nameInfoBuffer.get(j);
int fac = (info.name.equals(info1.name)) ? 3 : 2;
if (Math.abs(info.y - info1.y) < charSize * fac) {
fac = (info.x < info1.x) ? info.name.length() : info1.name.length();
if (Math.abs(info.x - info1.x) < charSize * fac) {
nameInfoBuffer.remove(i);
--i;
j = i;
}
}
}
}
for (NameInfo textInfo : nameInfoBuffer) {
imageBdr.setColor(textInfo.color);
imageBdr.drawString(textInfo.name, textInfo.x, textInfo.y);
}
// System.out.print("Areas: " + areaBuffer.size() + " ");
// System.out.print("Ways: " + wayBuffer.size() + " ");
// System.out.print("Nodes: " + nodeBuffer.size() + " ");
// System.out.print("Names: " + nameInfoBuffer.size() + "\n");
}
use of aimax.osm.data.entities.MapWay in project aima-java by aimacode.
the class DefaultEntityRenderer method getNextNode.
/**
* Returns the map node which is the nearest with respect to the specified
* view coordinates among the currently displayed nodes.
*/
public MapNode getNextNode(int x, int y) {
Position pos = new Position(transformer.lat(y), transformer.lon(x));
MapNode nextNode = null;
MapNode tmp = null;
for (int i = 0; i < 2; i++) {
List<MapWay> ways = (i == 0) ? areaBuffer : wayBuffer;
for (MapWay way : ways) {
tmp = pos.selectNearest(way.getNodes(), null);
if (nextNode == null || pos.getDistKM(tmp) < pos.getDistKM(nextNode)) {
nextNode = tmp;
}
}
}
for (MapEntity node : nodeBuffer) {
if (node instanceof MapNode) {
tmp = (MapNode) node;
if (tmp != null && tmp.getAttributeValue("marker") == null && (nextNode == null || pos.getDistKM(tmp) < pos.getDistKM(nextNode))) {
nextNode = tmp;
}
}
}
return nextNode;
}
use of aimax.osm.data.entities.MapWay in project aima-java by aimacode.
the class MapAdapter method getReachableLocations.
private List<String> getReachableLocations(String location, OneWayMode oneWayMode) {
List<String> result = new ArrayList<>();
MapNode node = getWayNode(location);
if (node != null) {
for (WayRef wref : node.getWayRefs()) {
if (filter == null || filter.isAccepted(wref.getWay())) {
MapWay way = wref.getWay();
int nodeIdx = wref.getNodeIdx();
List<MapNode> wayNodes = way.getNodes();
MapNode next;
if (wayNodes.size() > nodeIdx + 1 && (oneWayMode != OneWayMode.TRAVEL_BACKWARDS || !way.isOneway())) {
next = wayNodes.get(nodeIdx + 1);
result.add(Long.toString(next.getId()));
}
if (nodeIdx > 0 && (oneWayMode != OneWayMode.TRAVEL_FORWARD || !way.isOneway())) {
next = wayNodes.get(nodeIdx - 1);
result.add(Long.toString(next.getId()));
}
}
}
}
return result;
}
use of aimax.osm.data.entities.MapWay in project aima-java by aimacode.
the class OsmWriter method writeMap.
/**
* Writes all data from <code>mapData</code> to a stream.
*/
public void writeMap(OutputStreamWriter writer, OsmMap map, BoundingBox bb) {
try {
StringBuffer text = new StringBuffer();
text.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
text.append("<osm version=\"0.6\" generator=\"aimax-osm-writer\">\n");
text.append("<bound box=\"");
text.append(bb.getLatMin() + ",");
text.append(bb.getLonMin() + ",");
text.append(bb.getLatMax() + ",");
text.append(bb.getLonMax());
text.append("\" origin=\"?\"/>\n");
writer.write(text.toString());
HashSet<MapNode> nodeHash = new HashSet<MapNode>();
Collection<MapWay> ways = map.getWays(bb);
for (MapWay way : ways) for (MapNode node : way.getNodes()) if (!nodeHash.contains(node)) {
writeNode(writer, node);
nodeHash.add(node);
}
for (MapNode poi : map.getPois(bb)) if (!nodeHash.contains(poi)) {
writeNode(writer, poi);
nodeHash.add(poi);
}
for (MapWay way : ways) writeWay(writer, way);
writer.write("</osm>\n");
} catch (IOException e) {
throw new OsmRuntimeException("Unable to write XML output to file.", e);
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
LOG.log(Level.SEVERE, "Unable to close output stream.", e);
}
}
}
}
use of aimax.osm.data.entities.MapWay in project aima-java by aimacode.
the class DefaultEntityFinder method find.
/**
* Searches for entities which comply to the current search specification
* and stores them as results.
*/
@Override
protected void find(boolean findMore) {
BestMatchFinder bmf = new BestMatchFinder(pattern);
List<MapEntity> results = getResults();
BoundingBox bb = new BoundingBox(position, nextRadius);
if (!results.isEmpty())
bmf.checkMatchQuality(results.get(0));
if (mode.equals(Mode.ENTITY) || mode.equals(Mode.NODE)) {
for (MapNode node : getStorage().getPois(bb)) {
int match = bmf.checkMatchQuality(node);
if (match >= 0) {
if (match > 0) {
results.clear();
bmf.useAsReference(node);
}
if (position.insertInAscendingDistanceOrder(results, node))
if (results.size() > 100)
results.remove(99);
}
}
}
if (mode.equals(Mode.ENTITY) || mode.equals(Mode.WAY)) {
for (MapWay way : getStorage().getWays(bb)) {
int match = bmf.checkMatchQuality(way);
if (match >= 0) {
if (match > 0) {
results.clear();
bmf.useAsReference(way);
}
if (position.insertInAscendingDistanceOrder(results, way))
if (results.size() > 100)
results.remove(99);
}
}
}
if (mode.equals(Mode.ADDRESS)) {
List<MapEntity> iResults = getIntermediateResults();
StringTokenizer tokenizer = new StringTokenizer(pattern, ",");
String placeName = null;
String wayName = null;
if (tokenizer.hasMoreElements())
placeName = tokenizer.nextToken();
if (tokenizer.hasMoreElements())
wayName = tokenizer.nextToken().trim();
if (placeName != null && !findMore) {
for (MapNode place : getStorage().getPlaces(placeName)) {
position.insertInAscendingDistanceOrder(iResults, place);
if (iResults.size() > 100)
iResults.remove(99);
}
nextRadius = -1;
}
if (iResults.size() == 1 && wayName != null) {
MapNode place = (MapNode) iResults.get(0);
findWay(wayName, new Position(place.getLat(), place.getLon()), null);
}
} else {
nextRadius *= 2;
if (results.isEmpty() && getIntermediateResults().isEmpty() && nextRadius <= getMaxRadius())
find(true);
}
}
Aggregations