Search in sources :

Example 36 with MapNode

use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.

the class MapViewPane method showMapEntityInfoDialog.

/**
	 * Finds the visible entity next to the specified view coordinates and shows
	 * informations about it.
	 *
	 * @param debug
	 *            Enables a more detailed view.
	 */
public void showMapEntityInfoDialog(MapEntity entity, boolean debug) {
    List<MapEntity> entities = new ArrayList<MapEntity>();
    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);
        }
    }
    boolean done = false;
    for (int i = 0; i < entities.size() && !done; i++) {
        MapEntity me = entities.get(i);
        Object[] content = new Object[] { "", "", "" };
        String text = (me.getName() != null) ? me.getName() : "";
        if (debug)
            text += " (" + ((me instanceof MapNode) ? "Node " : "Way ") + me.getId() + ")";
        content[0] = text;
        if (me instanceof MapNode) {
            PositionPanel pos = new PositionPanel();
            pos.setPosition(((MapNode) me).getLat(), ((MapNode) me).getLon());
            pos.setEnabled(false);
            content[1] = pos;
        }
        if (me.getAttributes().length > 0) {
            EntityAttribute[] atts = me.getAttributes();
            String[][] attTexts = new String[atts.length][2];
            for (int j = 0; j < atts.length; j++) {
                attTexts[j][0] = atts[j].getKey();
                attTexts[j][1] = atts[j].getValue();
            }
            JTable table = new JTable(attTexts, new String[] { "Name", "Value" });
            JScrollPane spane = new JScrollPane(table);
            spane.setPreferredSize(new Dimension(300, 150));
            content[2] = spane;
        }
        Object[] options;
        if (i < entities.size() - 1)
            options = new String[] { "OK", "Next" };
        else
            options = new String[] { "OK" };
        if (JOptionPane.showOptionDialog(this, content, "Map Entity Info", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]) != 1)
            done = true;
    }
}
Also used : WayRef(aimax.osm.data.entities.WayRef) JScrollPane(javax.swing.JScrollPane) EntityAttribute(aimax.osm.data.entities.EntityAttribute) ArrayList(java.util.ArrayList) MapNode(aimax.osm.data.entities.MapNode) Dimension(java.awt.Dimension) JTable(javax.swing.JTable) MapEntity(aimax.osm.data.entities.MapEntity)

Example 37 with MapNode

use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.

the class OsmAgentView method updateTrack.

private void updateTrack(Agent agent, String location) {
    MapAdapter map = (MapAdapter) getMapEnv().getMap();
    MapNode node = map.getWayNode(location);
    if (node != null) {
        int aIdx = getMapEnv().getAgents().indexOf(agent);
        map.getOsmMap().addToTrack(TRACK_NAME + aIdx, new Position(node.getLat(), node.getLon()));
    }
}
Also used : Position(aimax.osm.data.Position) MapNode(aimax.osm.data.entities.MapNode) MapAdapter(aimax.osm.routing.MapAdapter)

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