Search in sources :

Example 31 with MapNode

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());
}
Also used : Position(aimax.osm.data.Position) MapNode(aimax.osm.data.entities.MapNode) MapAdapter(aimax.osm.routing.MapAdapter)

Example 32 with MapNode

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();
        }
    }
}
Also used : LRTAStarAgent(aima.core.search.online.LRTAStarAgent) Point2D(aima.core.util.math.geom.shapes.Point2D) ArrayList(java.util.ArrayList) MapEnvironment(aima.core.environment.map.MapEnvironment) MapNode(aimax.osm.data.entities.MapNode)

Example 33 with MapNode

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;
}
Also used : MapWay(aimax.osm.data.entities.MapWay) BoundingBox(aimax.osm.data.BoundingBox) ArrayList(java.util.ArrayList) MapNode(aimax.osm.data.entities.MapNode) HashSet(java.util.HashSet)

Example 34 with MapNode

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;
}
Also used : Position(aimax.osm.data.Position) MapNode(aimax.osm.data.entities.MapNode)

Example 35 with MapNode

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;
}
Also used : BoundingBox(aimax.osm.data.BoundingBox) MapNode(aimax.osm.data.entities.MapNode) JTextField(javax.swing.JTextField)

Aggregations

MapNode (aimax.osm.data.entities.MapNode)37 ArrayList (java.util.ArrayList)13 Position (aimax.osm.data.Position)12 MapWay (aimax.osm.data.entities.MapWay)6 MapEntity (aimax.osm.data.entities.MapEntity)5 BoundingBox (aimax.osm.data.BoundingBox)4 WayRef (aimax.osm.data.entities.WayRef)4 MapAdapter (aimax.osm.routing.MapAdapter)4 Point2D (aima.core.util.math.geom.shapes.Point2D)3 MapEvent (aimax.osm.data.MapEvent)3 EntityAttribute (aimax.osm.data.entities.EntityAttribute)3 Node (aima.core.search.framework.Node)2 LRTAStarAgent (aima.core.search.online.LRTAStarAgent)2 IOException (java.io.IOException)2 DecimalFormat (java.text.DecimalFormat)2 HashSet (java.util.HashSet)2 Agent (aima.core.agent.Agent)1 aima.core.environment.map (aima.core.environment.map)1 MapAgent (aima.core.environment.map.MapAgent)1 MapEnvironment (aima.core.environment.map.MapEnvironment)1