use of aimax.osm.data.entities.MapNode 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.MapNode in project aima-java by aimacode.
the class OsmRoutePlannerApp method getTrackInfo.
protected String getTrackInfo(Track track) {
List<MapNode> nodes = track.getNodes();
DecimalFormat f1 = new DecimalFormat("#0.00");
double km = Position.getTrackLengthKM(nodes);
String info = track.getName() + ": Length " + f1.format(km) + " km";
if (nodes.size() == 2) {
DecimalFormat f2 = new DecimalFormat("#000");
MapNode m1 = nodes.get(nodes.size() - 2);
MapNode m2 = nodes.get(nodes.size() - 1);
int course = new Position(m1).getCourseTo(m2);
info += "; Direction " + f2.format(course);
}
return info;
}
use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class MapPaneCtrl method showMapEntityInfoDialog.
/**
* Finds the visible entity next to the specified view coordinates and shows
* informations about it.
*
* @param debug
* Enables a more detailed view.
*/
private void showMapEntityInfoDialog(MapEntity entity, boolean debug) {
List<MapEntity> entities = new ArrayList<>();
if (entity.getName() != null || entity.getAttributes().length > 0 || debug)
entities.add(entity);
if (entity instanceof MapNode) {
MapNode mNode = (MapNode) entity;
for (WayRef ref : mNode.getWayRefs()) {
MapEntity me = ref.getWay();
if (me.getName() != null || me.getAttributes().length > 0 || debug)
entities.add(me);
}
}
for (MapEntity me : entities) {
String header = (me.getName() != null) ? me.getName() : "";
StringBuilder content = new StringBuilder();
if (debug)
header += " (" + ((me instanceof MapNode) ? "Node " : "Way ") + me.getId() + ")";
if (me instanceof MapNode) {
content.append("Lat: ").append(((MapNode) me).getLat()).append(" Lon: ").append(((MapNode) me).getLon()).append(" ");
}
if (me.getAttributes().length > 0) {
EntityAttribute[] atts = me.getAttributes();
content.append("Attributs: ");
for (EntityAttribute att : atts) {
content.append(att.getKey()).append("=").append(att.getValue()).append(" ");
}
}
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Map Entity Info");
alert.setHeaderText(header);
alert.setContentText(content.toString());
Optional<ButtonType> result = alert.showAndWait();
if (!result.isPresent())
break;
}
}
use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class OsmLRTAStarAgentApp method updateTrack.
/** Visualizes agent positions. Call from simulation thread. */
private void updateTrack(Agent agent, Metrics metrics) {
MapAdapter map = (MapAdapter) env.getMap();
MapNode node = map.getWayNode(env.getAgentLocation(agent));
if (node != null) {
Platform.runLater(() -> map.getOsmMap().addToTrack(TRACK_NAME, new Position(node.getLat(), node.getLon())));
}
simPaneCtrl.setStatus(metrics.toString());
}
use of aimax.osm.data.entities.MapNode 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);
}
}
}
}
Aggregations