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;
}
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;
}
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;
}
}
}
}
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());
}
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));
}
Aggregations