Search in sources :

Example 21 with MapNode

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

the class OsmMoveAction method getTravelDistance.

/** Returns the distance in KM. */
public float getTravelDistance() {
    float result = 0f;
    int size = Math.abs(toIndex - fromIndex) + 1;
    List<MapNode> nodes = way.getNodes();
    Position pos = new Position(nodes.get(fromIndex));
    for (int i = 1; i < size; i++) {
        MapNode next = nodes.get(fromIndex < toIndex ? fromIndex + i : fromIndex - i);
        result += pos.getDistKM(next);
        pos = new Position(next);
    }
    return result;
}
Also used : Position(aimax.osm.data.Position) MapNode(aimax.osm.data.entities.MapNode)

Example 22 with MapNode

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

the class RouteCalculator method subdivideProblem.

/**
	 * Factory method, responsible for subdividing the overall problem which is
	 * specified by a list of marker nodes. It returns arrays of way nodes.
	 * The arrays will be used to define problems to be solved one after
	 * another. This implementation returns pairs of from and to way nodes.
	 */
protected List<MapNode[]> subdivideProblem(List<MapNode> markers, OsmMap map, MapWayFilter wayFilter) {
    List<MapNode[]> result = new ArrayList<>();
    MapNode fromNode = map.getNearestWayNode(new Position(markers.get(0)), wayFilter);
    for (int i = 1; i < markers.size(); i++) {
        MapNode toNode = map.getNearestWayNode(new Position(markers.get(i)), wayFilter);
        result.add(new MapNode[] { fromNode, toNode });
        fromNode = toNode;
    }
    return result;
}
Also used : Position(aimax.osm.data.Position) ArrayList(java.util.ArrayList) MapNode(aimax.osm.data.entities.MapNode)

Example 23 with MapNode

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

the class DefaultEntityRenderer method printLine.

/** Prints a line or fills an area. */
protected void printLine(UnifiedImageBuilder<?> imageBdr, List<MapNode> nodes, DefaultEntityViewInfo pInfo, boolean asArea, boolean asOneway, NameInfo textInfo) {
    // count++;
    int[] xPoints = new int[nodes.size()];
    int[] yPoints = new int[nodes.size()];
    int viewWidth = !asArea ? imageBdr.getWidth() : -1;
    int viewHeight = !asArea ? imageBdr.getHeight() : -1;
    boolean visible = getViewCoords(nodes, viewWidth, viewHeight, xPoints, yPoints);
    if (visible) {
        boolean filled = false;
        if (asArea) {
            imageBdr.setColor(pInfo.wayFillColor != null ? pInfo.wayFillColor : pInfo.wayColor);
            imageBdr.setLineStyle(false, displayFactor);
            imageBdr.setAreaFilled(true);
            imageBdr.drawPolygon(xPoints, yPoints, nodes.size());
            filled = true;
        }
        if (!filled || pInfo.wayFillColor != null && !pInfo.wayFillColor.equals(pInfo.wayColor)) {
            imageBdr.setColor(pInfo.wayColor);
            imageBdr.setLineStyle(pInfo.wayDashed, pInfo.wayWidth * displayFactorSym);
            imageBdr.setAreaFilled(false);
            imageBdr.drawPolyline(xPoints, yPoints, nodes.size());
        }
        if (asOneway) {
            float x = xPoints[xPoints.length - 1];
            float y = yPoints[yPoints.length - 1];
            double angle = Math.atan2(x - xPoints[xPoints.length - 2], -(y - yPoints[yPoints.length - 2]));
            printOnewayArrow(x, y, angle);
        }
        if (textInfo != null) {
            setWayNamePosition(textInfo, xPoints, yPoints, filled);
            nameInfoBuffer.add(textInfo);
        }
        if (debugMode && scale >= 2 * pInfo.minNameScale * displayFactor) {
            int i = 0;
            for (MapNode node : nodes) {
                textInfo = new NameInfo(Long.toString(node.getId()), pInfo.nameColor, pInfo.printOrder);
                textInfo.x = xPoints[i];
                textInfo.y = yPoints[i];
                nameInfoBuffer.add(textInfo);
                ++i;
            }
        }
    }
}
Also used : MapNode(aimax.osm.data.entities.MapNode)

Example 24 with MapNode

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

the class OsmWriter method writeWay.

/*<node id="83551472" lat="38.8353186" lon="20.7118425" user="aitolos" uid="653" visible="true" version="2" changeset="4440307" timestamp="2010-04-16T16:35:48Z"/>*/
protected void writeWay(OutputStreamWriter writer, MapWay way) throws IOException {
    StringBuffer text = new StringBuffer();
    text.append("<way id=\"");
    text.append(way.getId());
    text.append("\">\n");
    for (MapNode node : way.getNodes()) {
        text.append("  <nd ref=\"");
        text.append(node.getId());
        text.append("\"/>\n");
    }
    addTags(text, way.getName(), way.getAttributes());
    text.append("</way>\n");
    writer.append(text.toString());
}
Also used : MapNode(aimax.osm.data.entities.MapNode)

Example 25 with MapNode

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

the class MapViewPane method removeNearestMarker.

/**
	 * Removes the mark which is the nearest with respect to the given view
	 * coordinates.
	 */
public void removeNearestMarker(int x, int y) {
    List<MapNode> markers = getMap().getMarkers();
    float lat = getTransformer().lat(y);
    float lon = getTransformer().lon(x);
    MapNode marker = new Position(lat, lon).selectNearest(markers, null);
    if (marker != null)
        markers.remove(marker);
    getMap().fireMapDataEvent(new MapEvent(getMap(), MapEvent.Type.MAP_MODIFIED));
}
Also used : Position(aimax.osm.data.Position) MapEvent(aimax.osm.data.MapEvent) MapNode(aimax.osm.data.entities.MapNode)

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