Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 2.23 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. android: ConcurrentModificationException with map overlays
  2. public void addPolyLines(ArrayList<KrollDict> polyLines){
  3.     // Remove the line overlay
  4.     List<Overlay> mMapOverlays = view.getOverlays();
  5.     boolean rm = mMapOverlays.remove(polyLineOverlay);    
  6.  
  7.     polyLineOverlay = new PolygonOverlay(polyLines); // KEY LINE
  8.  
  9.     mMapOverlays.add(polyLineOverlay);
  10.     view.invalidate();
  11. }
  12.        
  13. ArrayList<KrollDict> mPolyLines;
  14.  
  15. public PolygonOverlay(ArrayList<KrollDict> polyLines){
  16.         mPolyLines = polyLines;
  17. }
  18.  
  19. public void drawLines(MapView mv, Canvas canvas) {
  20.         Iterator<KrollDict> it = mPolyLines.iterator();
  21.  
  22.         // Go through each line
  23.         while(it.hasNext()){// CONCURRENTMODIFICATIONEXCEPTION THROWN HERE
  24.             KrollDict kd = it.next();
  25.             String[] pointsArr = kd.getStringArray("points");
  26.             String color = kd.getString("color");
  27.             float width = new Float(kd.getDouble("width")).floatValue();
  28.             int alpha = kd.getInt("alpha");
  29.  
  30.             int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
  31.             Paint paint = new Paint();
  32.             paint.setColor(Color.parseColor(color));
  33.             paint.setStyle(Paint.Style.STROKE);
  34.             paint.setStrokeWidth(width);
  35.             //paint.setAlpha(alpha);
  36.  
  37.             // Loop through the coordinates
  38.             for(int i = 0; i< pointsArr.length; i++){
  39.                 String[] coordinates = convertStringToArray(pointsArr[i]);
  40.                 Double latitude = new Double(Double.parseDouble(coordinates[3]) * 1E6);
  41.                 Double longitude = new Double(Double.parseDouble(coordinates[1]) * 1E6);
  42.                 GeoPoint gp = new GeoPoint(latitude.intValue(), longitude.intValue());                                      
  43.  
  44.                 Point point = new Point();
  45.                 point = mv.getProjection().toPixels(gp, point);                
  46.  
  47.                 x2 = point.x;
  48.                 y2 = point.y;
  49.                 if (i > 0) {                        
  50.                     canvas.drawLine(x1, y1, x2, y2, paint);
  51.                 }
  52.                 x1 = x2;
  53.                 y1 = y2;
  54.             }
  55.         }// while
  56.     }
  57.        
  58. public PolygonOverlay(ArrayList<KrollDict> polyLines){  
  59.     mPolyLines = (ArrayList<KrollDict>)polyLines.clone();  
  60. }