use of net.osmand.router.BinaryRoutePlanner.RouteSegmentVisitor in project OsmAnd-tools by osmandapp.
the class MapRouterLayer method createSegmentVisitor.
private RouteSegmentVisitor createSegmentVisitor(final boolean animateRoutingCalculation, final DataTileManager<Entity> points) {
return new RouteSegmentVisitor() {
private List<RouteSegment> cache = new ArrayList<RouteSegment>();
private List<RouteSegment> pollCache = new ArrayList<RouteSegment>();
private List<Integer> cacheInt = new ArrayList<Integer>();
@Override
public void visitSegment(RouteSegment s, int endSegment, boolean poll) {
if (stop) {
throw new RuntimeException("Interrupted");
}
if (!animateRoutingCalculation) {
return;
}
if (!poll && pause) {
pollCache.add(s);
return;
}
cache.add(s);
cacheInt.add(endSegment);
if (cache.size() < steps) {
return;
}
if (pause) {
registerObjects(points, poll, pollCache, null);
pollCache.clear();
}
registerObjects(points, !poll, cache, cacheInt);
cache.clear();
cacheInt.clear();
redraw();
if (pause) {
waitNextPress();
}
}
private void registerObjects(final DataTileManager<Entity> points, boolean white, List<RouteSegment> registerCache, List<Integer> cacheInt) {
for (int l = 0; l < registerCache.size(); l++) {
RouteSegment segment = registerCache.get(l);
Way way = new Way(-1);
way.putTag(OSMTagKey.NAME.getValue(), segment.getTestName());
if (white) {
way.putTag("color", "white");
}
int from = cacheInt != null ? segment.getSegmentStart() : segment.getSegmentStart() - 2;
int to = cacheInt != null ? cacheInt.get(l) : segment.getSegmentStart() + 2;
if (from > to) {
int x = from;
from = to;
to = x;
}
for (int i = from; i <= to; i++) {
if (i >= 0 && i < segment.getRoad().getPointsLength()) {
net.osmand.osm.edit.Node n = createNode(segment, i);
way.addNode(n);
}
}
LatLon n = way.getLatLon();
points.registerObject(n.getLatitude(), n.getLongitude(), way);
}
}
};
}
use of net.osmand.router.BinaryRoutePlanner.RouteSegmentVisitor in project OsmAnd-tools by osmandapp.
the class MapClusterLayer method clustering.
private List<RouteSegment> clustering(final ClusteringContext clusterCtx, double lat, double lon, final DataTileManager<Way> points) throws IOException {
List<BinaryMapIndexReader> rs = new ArrayList<BinaryMapIndexReader>();
for (File f : new File(DataExtractionSettings.getSettings().getBinaryFilesDir()).listFiles()) {
if (f.getName().endsWith(".obf")) {
// $NON-NLS-1$ //$NON-NLS-2$
RandomAccessFile raf = new RandomAccessFile(f, "r");
rs.add(new BinaryMapIndexReader(raf, f));
}
}
RoutePlannerFrontEnd router = new RoutePlannerFrontEnd(true);
Builder builder = RoutingConfiguration.getDefault();
RoutingConfiguration config = builder.build("car", RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3);
RoutingContext ctx = router.buildRoutingContext(config, NativeSwingRendering.getDefaultFromSettings(), rs.toArray(new BinaryMapIndexReader[rs.size()]), clusterCtx.BASEMAP_CLUSTERING ? RouteCalculationMode.BASE : RouteCalculationMode.NORMAL);
// find closest way
RouteSegment st = router.findRouteSegment(lat, lon, ctx, null);
if (st != null) {
RouteDataObject road = st.getRoad();
String highway = getHighway(road);
log.info(// road.getName() + " "
"ROAD TO START " + highway + " " + +road.id);
}
map.setPoints(points);
ctx.setVisitor(new RouteSegmentVisitor() {
private List<RouteSegment> cache = new ArrayList<RouteSegment>();
@Override
public void visitSegment(RouteSegment s, int endSegment, boolean poll) {
if (!clusterCtx.ANIMATE_CLUSTERING) {
return;
}
cache.add(s);
if (cache.size() < SIZE_OF_ROUTES_TO_ANIMATE) {
return;
}
for (RouteSegment segment : cache) {
Way way = new Way(-1);
for (int i = 0; i < segment.getRoad().getPointsLength(); i++) {
net.osmand.osm.edit.Node n = new net.osmand.osm.edit.Node(MapUtils.get31LatitudeY(segment.getRoad().getPoint31YTile(i)), MapUtils.get31LongitudeX(segment.getRoad().getPoint31XTile(i)), -1);
way.addNode(n);
}
way.putTag("color", "white");
LatLon n = way.getLatLon();
points.registerObject(n.getLatitude(), n.getLongitude(), way);
}
cache.clear();
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
map.prepareImage();
}
});
} catch (InterruptedException e1) {
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
});
List<RouteSegment> results = searchCluster(clusterCtx, ctx, st);
return results;
}
Aggregations