use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class OsmAgentBaseApp 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 OsmLRTAStarAgentApp method simulate.
/** Starts the experiment. */
public void simulate() {
List<MapNode> markers = map.getOsmMap().getMarkers();
if (markers.size() < 2) {
simPaneCtrl.setStatus("Error: Please set two markers with mouse-left.");
} else {
List<String> locations = new ArrayList<>(markers.size());
for (MapNode node : markers) {
Point2D pt = new Point2D(node.getLon(), node.getLat());
locations.add(map.getNearestLocation(pt));
}
Agent agent = createAgent(locations);
env = new MapEnvironment(map);
env.addEnvironmentView(new TrackUpdater());
env.addAgent(agent, locations.get(0));
while (!env.isDone() && !CancelableThread.currIsCanceled()) {
env.step();
simPaneCtrl.waitAfterStep();
}
}
}
use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class MapAdapter method getLocations.
/** {@inheritDoc} Very expensive for large maps! */
@Override
public List<String> getLocations() {
List<String> result = new ArrayList<>();
HashSet<MapNode> nodeHash = new HashSet<>();
for (MapWay way : osmMap.getWays(new BoundingBox(-90, -180, 90, 180))) {
if (filter == null || filter.isAccepted(way)) {
for (MapNode node : way.getNodes()) if (!nodeHash.contains(node)) {
result.add(Long.toString(node.getId()));
nodeHash.add(node);
}
}
}
return result;
}
use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class MapAdapter method getNearestLocation.
/**
* Returns the ID of the way node in the underlying OSM map which is nearest
* with respect to the specified coordinates and additionally passes the
* filter.
*/
public String getNearestLocation(Point2D pt) {
Position pos = new Position((float) pt.getY(), (float) pt.getX());
MapNode node = osmMap.getNearestWayNode(pos, filter);
return (node != null) ? Long.toString(node.getId()) : null;
}
use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class MapViewFrame method askForBoundingBox.
protected BoundingBox askForBoundingBox() {
BoundingBox result = null;
JTextField minLat = new JTextField("-90");
JTextField minLon = new JTextField("-180");
JTextField maxLat = new JTextField("90");
JTextField maxLon = new JTextField("180");
if (getMap().getMarkers().size() == 2) {
MapNode m1 = getMap().getMarkers().get(0);
MapNode m2 = getMap().getMarkers().get(1);
minLat.setText(Float.toString(Math.min(m1.getLat(), m2.getLat())));
minLon.setText(Float.toString(Math.min(m1.getLon(), m2.getLon())));
maxLat.setText(Float.toString(Math.max(m1.getLat(), m2.getLat())));
maxLon.setText(Float.toString(Math.max(m1.getLon(), m2.getLon())));
}
Object[] content = new Object[] { "Min Latitude:", minLat, "Min Longitude:", minLon, "Max Latitude:", maxLat, "Max Longitude:", maxLon };
boolean done;
do {
done = true;
if (JOptionPane.showConfirmDialog(this, content, "Specify Bounding Box", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
try {
result = new BoundingBox(Float.parseFloat(minLat.getText()), Float.parseFloat(minLon.getText()), Float.parseFloat(maxLat.getText()), Float.parseFloat(maxLon.getText()));
} catch (NumberFormatException e) {
done = false;
}
}
} while (!done);
return result;
}
Aggregations