Search in sources :

Example 1 with WayRef

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

Example 2 with WayRef

use of aimax.osm.data.entities.WayRef 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;
    }
}
Also used : WayRef(aimax.osm.data.entities.WayRef) EntityAttribute(aimax.osm.data.entities.EntityAttribute) ArrayList(java.util.ArrayList) Alert(javafx.scene.control.Alert) MapEntity(aimax.osm.data.entities.MapEntity) MapNode(aimax.osm.data.entities.MapNode) ButtonType(javafx.scene.control.ButtonType)

Example 3 with WayRef

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

the class Position method selectNearest.

/**
	 * Returns the node from <code>nodes</code> which is nearest to this
	 * position. If a filter is given, only those nodes are inspected, which are
	 * part of a way accepted by the filter.
	 * 
	 * @param nodes
	 * @param filter
	 *            possibly null
	 * @return A node or null
	 */
public MapNode selectNearest(Collection<MapNode> nodes, MapWayFilter filter) {
    MapNode result = null;
    double dist = Double.MAX_VALUE;
    double newDist;
    for (MapNode node : nodes) {
        newDist = getDistKM(node);
        boolean found = (newDist < dist);
        if (found && filter != null) {
            found = false;
            for (WayRef ref : node.getWayRefs()) {
                if (filter.isAccepted(ref.getWay()))
                    found = true;
            }
        }
        if (found) {
            result = node;
            dist = newDist;
        }
    }
    return result;
}
Also used : WayRef(aimax.osm.data.entities.WayRef) MapNode(aimax.osm.data.entities.MapNode)

Example 4 with WayRef

use of aimax.osm.data.entities.WayRef 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)

Aggregations

MapNode (aimax.osm.data.entities.MapNode)4 WayRef (aimax.osm.data.entities.WayRef)4 ArrayList (java.util.ArrayList)3 EntityAttribute (aimax.osm.data.entities.EntityAttribute)2 MapEntity (aimax.osm.data.entities.MapEntity)2 MapWay (aimax.osm.data.entities.MapWay)1 Dimension (java.awt.Dimension)1 Alert (javafx.scene.control.Alert)1 ButtonType (javafx.scene.control.ButtonType)1 JScrollPane (javax.swing.JScrollPane)1 JTable (javax.swing.JTable)1