- android: ConcurrentModificationException with map overlays
- public void addPolyLines(ArrayList<KrollDict> polyLines){
- // Remove the line overlay
- List<Overlay> mMapOverlays = view.getOverlays();
- boolean rm = mMapOverlays.remove(polyLineOverlay);
- polyLineOverlay = new PolygonOverlay(polyLines); // KEY LINE
- mMapOverlays.add(polyLineOverlay);
- view.invalidate();
- }
- ArrayList<KrollDict> mPolyLines;
- public PolygonOverlay(ArrayList<KrollDict> polyLines){
- mPolyLines = polyLines;
- }
- public void drawLines(MapView mv, Canvas canvas) {
- Iterator<KrollDict> it = mPolyLines.iterator();
- // Go through each line
- while(it.hasNext()){// CONCURRENTMODIFICATIONEXCEPTION THROWN HERE
- KrollDict kd = it.next();
- String[] pointsArr = kd.getStringArray("points");
- String color = kd.getString("color");
- float width = new Float(kd.getDouble("width")).floatValue();
- int alpha = kd.getInt("alpha");
- int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
- Paint paint = new Paint();
- paint.setColor(Color.parseColor(color));
- paint.setStyle(Paint.Style.STROKE);
- paint.setStrokeWidth(width);
- //paint.setAlpha(alpha);
- // Loop through the coordinates
- for(int i = 0; i< pointsArr.length; i++){
- String[] coordinates = convertStringToArray(pointsArr[i]);
- Double latitude = new Double(Double.parseDouble(coordinates[3]) * 1E6);
- Double longitude = new Double(Double.parseDouble(coordinates[1]) * 1E6);
- GeoPoint gp = new GeoPoint(latitude.intValue(), longitude.intValue());
- Point point = new Point();
- point = mv.getProjection().toPixels(gp, point);
- x2 = point.x;
- y2 = point.y;
- if (i > 0) {
- canvas.drawLine(x1, y1, x2, y2, paint);
- }
- x1 = x2;
- y1 = y2;
- }
- }// while
- }
- public PolygonOverlay(ArrayList<KrollDict> polyLines){
- mPolyLines = (ArrayList<KrollDict>)polyLines.clone();
- }