Display multiple overlays

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Display multiple overlays

Postby Hylke1982 » Fri Feb 27, 2009 11:13 am

I want to show to show a set of different icons on map. I tried to add two overlays to a map, but only one overlay is visible. How can I solve this???

TIA

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Drawable yellowBalloon = new SpotBalloon(255,255,255,0);
  3.  
  4. personalOverlay = new SpotOverlay(yellowBalloon);
  5.  
  6.        
  7.  
  8. Drawable greenBalloon = new SpotBalloon(255,0,255,0);
  9.  
  10. publicOverlay = new SpotOverlay(greenBalloon);
  11.  
  12.  
  13.  
  14. mapView.getOverlays().add(personalOverlay);
  15.  
  16. mapView.getOverlays().add(publicOverlay);
  17.  
  18.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
An automaton that is created from biological materials and resembles a human. Also called humanoid.
Hylke1982
Freshman
Freshman
 
Posts: 3
Joined: Fri Feb 13, 2009 10:12 am

Top

Postby Hylke1982 » Mon Mar 02, 2009 2:21 pm

Solved the problem by using one overlay and use the ItemizedOverlay.setMarker(Drawable drawable) method.
An automaton that is created from biological materials and resembles a human. Also called humanoid.
Hylke1982
Freshman
Freshman
 
Posts: 3
Joined: Fri Feb 13, 2009 10:12 am

Postby androidUser » Wed Apr 15, 2009 11:04 am

Could you please post me the full soruce code.
androidUser
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sun Apr 05, 2009 1:08 pm

Postby Hylke1982 » Wed Apr 15, 2009 11:32 am

Example source code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class SpotMap extends MapActivity {
  3.  
  4.        
  5.  
  6.  private MapView mapView;
  7.  
  8.  
  9.  
  10.  // SpotBalloon is a class that extends drawable
  11.  
  12.  private static final Drawable yellowBalloon = new SpotBalloon(255,255,255,0);
  13.  
  14.  private static final Drawable orangeBalloon = new SpotBalloon(255,255,140,0);
  15.  
  16.  private static final Drawable whiteBalloon = new SpotBalloon(255,255,255,255);
  17.  
  18.  
  19.  
  20.  // overlay with default drawable (yellowBalloon)
  21.  
  22.  private static final SpotOverlay personalOverlay = new SpotOverlay(yellowBalloon);
  23.  
  24.  
  25.  
  26.  public void addDifferentMarkersToMap(){
  27.  
  28.  
  29.  
  30.   OverlayItem itemWhite = new OverlayItem(point, "white", "");
  31.  
  32.   itemWhite.setMarker(whiteBalloon); // Another drawable is set here
  33.  
  34.  
  35.  
  36.   OverlayItem itemOrange = new OverlayItem(point, "orange", "");
  37.  
  38.   itemOrange.setMarker(whiteBalloon); // Another drawable is set here
  39.  
  40.  
  41.  
  42.   // Add spot with different markers to overlay
  43.  
  44.   personalOverlay.addOverlayItem(itemWhite);
  45.  
  46.   personalOverlay.addOverlayItem(itemOrange);
  47.  
  48.  
  49.  
  50.   mapView.getOverlays().add(personalOverlay);
  51.  
  52.  
  53.  
  54.  }
  55.  
  56.  
  57.  
  58.  
  59.  
  60. }
  61.  
  62.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


SpotBalloon.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. import android.graphics.Canvas;
  3.  
  4. import android.graphics.ColorFilter;
  5.  
  6. import android.graphics.Paint;
  7.  
  8. import android.graphics.drawable.Drawable;
  9.  
  10.  
  11.  
  12. public class SpotBalloon extends Drawable {
  13.  
  14.        
  15.  
  16.         private Paint spotBalloonPaint = new Paint();
  17.  
  18.         private static final Paint blackTextPaint = new Paint();
  19.  
  20.         private static final int HEIGHT = 20;
  21.  
  22.         private static final int WIDTH = 100;
  23.  
  24.         private String name;
  25.  
  26.        
  27.  
  28.         public SpotBalloon(int alpha, int r, int g, int b) {
  29.  
  30.                 spotBalloonPaint.setARGB(alpha, r, g, b);
  31.  
  32.                 spotBalloonPaint.setAntiAlias(true);
  33.  
  34.                 blackTextPaint.setARGB(255, 0, 0, 0);
  35.  
  36.                 blackTextPaint.setAntiAlias(true);
  37.  
  38.         }
  39.  
  40.  
  41.  
  42.         @Override
  43.  
  44.         public void draw(Canvas canvas) {
  45.  
  46.                
  47.  
  48.                 canvas.setViewport(WIDTH, HEIGHT);
  49.  
  50.                 canvas.drawCircle(0, 0, 5, blackTextPaint);
  51.  
  52.                 canvas.drawCircle(0, 0, 4, spotBalloonPaint);
  53.  
  54.                 // TODO Auto-generated method stub
  55.  
  56.  
  57.  
  58.         }
  59.  
  60.  
  61.  
  62.         @Override
  63.  
  64.         public int getOpacity() {
  65.  
  66.                 // TODO Auto-generated method stub
  67.  
  68.                 return 0;
  69.  
  70.         }
  71.  
  72.  
  73.  
  74.         @Override
  75.  
  76.         public void setAlpha(int alpha) {
  77.  
  78.                 // TODO Auto-generated method stub
  79.  
  80.  
  81.  
  82.         }
  83.  
  84.  
  85.  
  86.         @Override
  87.  
  88.         public void setColorFilter(ColorFilter cf) {
  89.  
  90.                 // TODO Auto-generated method stub
  91.  
  92.  
  93.  
  94.         }
  95.  
  96.        
  97.  
  98.         public void setName(String name){
  99.  
  100.                 this.name = name;
  101.  
  102.         }
  103.  
  104.  
  105.  
  106. }
  107.  
  108.  
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. import com.google.android.maps.ItemizedOverlay;
  3.  
  4. import com.google.android.maps.OverlayItem;
  5.  
  6.  
  7.  
  8. public class SpotOverlay extends ItemizedOverlay<OverlayItem> {
  9.  
  10.        
  11.  
  12.         private ArrayList<OverlayItem> overLayList = new ArrayList<OverlayItem>();
  13.  
  14.        
  15.  
  16.         public SpotOverlay(Drawable defaultMarker) {
  17.  
  18.                 super(boundCenterBottom(defaultMarker));
  19.  
  20.                
  21.  
  22.                
  23.  
  24.         }
  25.  
  26.  
  27.  
  28.         @Override
  29.  
  30.         protected OverlayItem createItem(int i) {
  31.  
  32.                 return overLayList.get(i);
  33.  
  34.         }
  35.  
  36.  
  37.  
  38.         @Override
  39.  
  40.         public int size() {
  41.  
  42.                 return overLayList.size();
  43.  
  44.         }
  45.  
  46.        
  47.  
  48.         public void addOverlayItem(OverlayItem overlayItem) {
  49.  
  50.                 if(!overLayList.contains(overlayItem)){
  51.  
  52.                         overLayList.add(overlayItem);
  53.  
  54.                 }
  55.  
  56.                 populate();
  57.  
  58.         }
  59.  
  60.        
  61.  
  62.         public void clear(){
  63.  
  64.                 overLayList.clear();
  65.  
  66.         }
  67.  
  68.  
  69.  
  70. }
  71.  
  72.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
Last edited by Hylke1982 on Thu Apr 16, 2009 8:24 am, edited 2 times in total.
An automaton that is created from biological materials and resembles a human. Also called humanoid.
Hylke1982
Freshman
Freshman
 
Posts: 3
Joined: Fri Feb 13, 2009 10:12 am

Postby androidUser » Wed Apr 15, 2009 12:39 pm

Please post me the working example with SpotBalloon.java
androidUser
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sun Apr 05, 2009 1:08 pm

Postby hellscarz » Wed Apr 15, 2009 5:15 pm

Please can you give me the code of addOverlayItem method.
Thank you.
hellscarz
Freshman
Freshman
 
Posts: 4
Joined: Thu Mar 26, 2009 5:52 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 3 guests