use of aimax.osm.data.Position in project aima-java by aimacode.
the class RouteCalculator method calculateRoute.
/**
* Template method, responsible for shortest path generation between two map
* nodes. It searches for way nodes in the vicinity of the given nodes which
* comply with the specified way selection, searches for a suitable paths,
* and adds the paths as tracks to the provided <code>map</code>. Various
* factory methods can be used to override aspects of the default behavior
* in subclasses if needed.
*
* @param markers
* Nodes, not necessarily way nodes. The first node is used as
* start, last node as finish, all others as via nodes.
* @param map
* The information source.
* @param taskSelection
* Number, indicating which kinds of ways are relevant.
*/
public List<Position> calculateRoute(List<MapNode> markers, OsmMap map, int taskSelection) {
List<Position> result = new ArrayList<>();
try {
MapWayFilter wayFilter = createMapWayFilter(map, taskSelection);
boolean ignoreOneways = (taskSelection == 0);
List<MapNode[]> pNodeList = subdivideProblem(markers, map, wayFilter);
MapNode prevNode = null;
for (int i = 0; i < pNodeList.size() && !CancelableThread.currIsCanceled(); i++) {
Problem<MapNode, OsmMoveAction> problem = createProblem(pNodeList.get(i), map, wayFilter, ignoreOneways, taskSelection);
ToDoubleFunction<Node<MapNode, OsmMoveAction>> h = createHeuristicFunction(pNodeList.get(i), taskSelection);
SearchForActions<MapNode, OsmMoveAction> search = createSearch(h, taskSelection);
List<OsmMoveAction> actions = search.findActions(problem);
if (actions.isEmpty())
break;
for (Object action : actions) {
if (action instanceof OsmMoveAction) {
OsmMoveAction a = (OsmMoveAction) action;
for (MapNode node : a.getNodes()) {
if (prevNode != node) {
result.add(new Position(node.getLat(), node.getLon()));
prevNode = node;
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
use of aimax.osm.data.Position in project aima-java by aimacode.
the class DefaultEntityRenderer method getNextNode.
/**
* Returns the map node which is the nearest with respect to the specified
* view coordinates among the currently displayed nodes.
*/
public MapNode getNextNode(int x, int y) {
Position pos = new Position(transformer.lat(y), transformer.lon(x));
MapNode nextNode = null;
MapNode tmp = null;
for (int i = 0; i < 2; i++) {
List<MapWay> ways = (i == 0) ? areaBuffer : wayBuffer;
for (MapWay way : ways) {
tmp = pos.selectNearest(way.getNodes(), null);
if (nextNode == null || pos.getDistKM(tmp) < pos.getDistKM(nextNode)) {
nextNode = tmp;
}
}
}
for (MapEntity node : nodeBuffer) {
if (node instanceof MapNode) {
tmp = (MapNode) node;
if (tmp != null && tmp.getAttributeValue("marker") == null && (nextNode == null || pos.getDistKM(tmp) < pos.getDistKM(nextNode))) {
nextNode = tmp;
}
}
}
return nextNode;
}
use of aimax.osm.data.Position in project aima-java by aimacode.
the class FindPanel method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == findButton) {
entityFinder = view.getMap().getEntityFinder();
Position pos = view.getCenterPosition();
String pattern = findField.getText();
switch(typeCombo.getSelectedIndex()) {
case 0:
entityFinder.findEntity(pattern, pos);
break;
case 1:
entityFinder.findNode(pattern, pos);
break;
case 2:
entityFinder.findWay(pattern, pos, null);
break;
case 3:
entityFinder.findAddress(pattern, pos);
break;
}
storedMarkers.addAll(currMarkers);
currMarkers.clear();
} else if (e.getSource() == findMoreButton) {
if (!entityFinder.getIntermediateResults().isEmpty()) {
List<MapEntity> entities = getSelectedEntities();
if (entities.size() == 1)
entityFinder.selectIntermediateResult(entities.get(0));
}
entityFinder.findMore();
} else if (e.getSource() == clearButton) {
entityFinder = null;
}
updateResults(entityFinder == null);
updateEnabledState();
}
use of aimax.osm.data.Position in project aima-java by aimacode.
the class MapAdapter method getDistance.
@Override
public Double getDistance(String fromLocation, String toLocation) {
MapNode node1 = getWayNode(fromLocation);
MapNode node2 = getWayNode(toLocation);
if (node1 != null && node2 != null && getPossibleNextLocations(fromLocation).contains(toLocation))
return new Position(node1).getDistKM(node2);
else
return null;
}
use of aimax.osm.data.Position in project aima-java by aimacode.
the class OsmRoutePlannerApp method calculateRoute.
/** Starts route generation after the calculate button has been pressed. */
public void calculateRoute() {
OsmMap map = mapPaneCtrl.getMap();
List<Position> positions = routeCalculator.calculateRoute(map.getMarkers(), map, taskCombo.getSelectionModel().getSelectedIndex());
mapPaneCtrl.getMap().createTrack("Route", positions);
statusLabel.setText(getTrackInfo(mapPaneCtrl.getMap().getTrack("Route")));
}
Aggregations