// 1. determine visible route segments
// 2. if there are too many route try to remove some by merging
public static void optimizeWaypoints() {
TileCanvas canvas = CloudGps.getTileCanvas();
Options options = Options.getInstance();
OptimizedRoute or = options.navContext.optimizedRoute;
if (or != null && or.visibleSegments != null && or.zoom == options.zoom
&& or.horizontalTilesCount == canvas.horizontalTilesCount
&& or.verticalTilesCount == canvas.verticalTilesCount && or.latitude == canvas.latitude
&& or.longitude == canvas.longitude && or.tileSize == canvas.tileSize) {
return;
}
if (or == null) {
or = new OptimizedRoute();
options.navContext.optimizedRoute = or;
}
or.zoom = options.zoom;
or.horizontalTilesCount = canvas.horizontalTilesCount;
or.verticalTilesCount = canvas.verticalTilesCount;
or.latitude = canvas.latitude;
or.longitude = canvas.longitude;
or.tileSize = canvas.tileSize;
Route r = options.route;
or.segmentsSCmaxZoom = null;
or.visibleSegments = null;
or.visibleSegmentDirections = null;
Vector visibleSegments = new Vector(100, 200);
Vector visibleSegmentDirections = new Vector(100, 200);
int directionIdx = 0;
if (r != null && r.waypoints.size() > 1) {
int count = 1;
if (or.waypointsTC == null || ((TileCoordinate) or.waypointsTC.elementAt(0)).zoom != options.zoom) {
or.waypointsTC = new Vector(r.waypoints.size());
for (int i = 0; i < r.waypoints.size(); i++) {
or.waypointsTC.addElement(ProjectionTool.toTileCoordinate((WorldCoordinate) r.waypoints
.elementAt(i), options.zoom, options.getTileFactory().getTileSize()));
}
}
TileCoordinate t1 = (TileCoordinate) or.waypointsTC.elementAt(0), t2;
ScreenCoordinate s1 = toSC(t1, or.latitude, or.longitude, or.tileSize), s2;
int maxX = options.getTileFactory().getTileSize() * or.horizontalTilesCount;
int maxY = options.getTileFactory().getTileSize() * or.verticalTilesCount;
for (int i = 1; i < or.waypointsTC.size(); i++) {
t2 = (TileCoordinate) or.waypointsTC.elementAt(i);
s2 = toSC(t2, or.latitude, or.longitude, or.tileSize);