use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class BoundingBox method adjust.
/**
* Makes sure, that all given nodes are within the box and extends the
* bounds if necessary.
*/
public void adjust(Collection<MapNode> nodes) {
for (MapNode node : nodes) {
if (Float.isNaN(latMin)) {
latMin = latMax = node.getLat();
lonMin = lonMax = node.getLon();
} else if (node.hasPosition()) {
if (node.getLat() < latMin)
latMin = node.getLat();
else if (node.getLat() > latMax)
latMax = node.getLat();
if (node.getLon() < lonMin)
lonMin = node.getLon();
else if (node.getLon() > lonMax)
lonMax = node.getLon();
}
}
}
use of aimax.osm.data.entities.MapNode 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;
}
use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class Position method getTrackLengthKM.
/** Computes the total length of a track in kilometers. */
public static double getTrackLengthKM(List<MapNode> nodes) {
double result = 0.0;
for (int i = 1; i < nodes.size(); i++) {
MapNode n1 = nodes.get(i - 1);
MapNode n2 = nodes.get(i);
result += getDistKM(n1.getLat(), n1.getLon(), n2.getLat(), n2.getLon());
}
return result;
}
use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class DefaultMap method getPlaces.
/** {@inheritDoc} */
@Override
public List<MapNode> getPlaces(String name) {
String pattern = name.toLowerCase();
List<MapNode> results = new ArrayList<MapNode>();
for (MapNode node : pois) {
if (node.getAttributeValue("place") != null && node.getName() != null && node.getName().toLowerCase().startsWith(pattern))
results.add(node);
}
return results;
}
use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class DefaultMap method addMarker.
/** {@inheritDoc} */
@Override
public MapNode addMarker(float lat, float lon) {
long id = 1;
for (MapNode node : markers) if (node.getId() >= id)
id = node.getId() + 1;
MapNode node = new DefaultMapNode(id);
node.setName(Long.toString(id));
List<EntityAttribute> atts = new ArrayList<EntityAttribute>(1);
atts.add(new EntityAttribute("marker", "yes"));
node.setAttributes(atts);
node.setPosition(lat, lon);
updateEntityViewInfo(node, false);
markers.add(node);
fireMapDataEvent(new MapEvent(this, MapEvent.Type.MARKER_ADDED, node.getId()));
return node;
}
Aggregations