mapjs.append(color).append("\", 2));\n");
}
private static void trksegToEncodedGPolyline(Trkpt[] pts, String color,
Appendable mapjs) throws IOException {
GpsFormat format = GpsFormat.getInstance();
final int len = pts.length;
int[] ilevels = new int[len];
mapjs.append("//new segment\n");
/*
* we encode at most 100 points simultaneously to avoid big rounding
* errors and overlong strings
*/
for (int start = 0, stop = 100; stop != len; start = stop - 1) {
mapjs.append("map.addOverlay(GPolyline.fromEncoded({\n");
mapjs.append(" color: \"").append(color).append("\",\n");
mapjs.append(" weight: 2,\n");
mapjs.append(" opacity: 0.5,\n");
/* encode first point */
mapjs.append(" points: \"");
Trkpt previous;
Trkpt current = pts[start];
format.asGPolylineCoordinate(current.getLat(), null, mapjs);
format.asGPolylineCoordinate(current.getLon(), null, mapjs);
stop = start + 100;
if (len <= stop) {
stop = len;
}
/* encode other points */
for (int i = start + 1; i < stop; i++) {
previous = current;
current = pts[i];
format.asGPolylineCoordinate(current.getLat(),
previous.getLat(), mapjs);
format.asGPolylineCoordinate(current.getLon(),
previous.getLon(), mapjs);
}
mapjs.append("\",\n");
/* calculate and encode levels */
mapjs.append(" levels: \"");
calculateLevels(pts, start, stop, ilevels);
for (int i = start; i < stop; i++) {
format.gEncodeUnsignedInt(ilevels[i], mapjs);
}
mapjs.append("\",\n");
mapjs.append(" zoomFactor: 2,\n");
mapjs.append(" numLevels: 18\n");