2

I have faced some problems with the Android MapView API. I get OverlayItems from a database which I want to display in a MapView. If I'm displaying 100 Icons, I have no issues, but if it gets more - like 500 Items in one City - it first looks really bad, while second it slows down a lot. Unfortunately my goal is to display 10000 of them. I think one solution can be to register a listener to ZoomLevels to make them appear/dissapear, but I couldn't find that functionality. Second, I couldn't find a function to scale my Overlays with the Zoom of the Map. Any Ideas are very welcome

Rafael T
  • 15,401
  • 15
  • 83
  • 144

3 Answers3

4

There is a very strange behavior in ItemizedOverlay draw method. When you say: Draw line from (x,y) to (x1,y1) the draw method is called about 20-30-40 times - i don't know why. It is acceptable when you draw one line, but when you draw a thousands of lines,icons and so on...it is very very bad! To solve this problem you should create a cached overlay. This is overlay that catches the first draw, creates the object and then prevents the future draws that do the same draw.

A cluster is a dozen of icons behind one icon. For example if you have 1000 markers on the map, in a specific minimal zoom level you can not see each marker separately - it becomes a mess of icons and colors and so on. And instead of 100 markers that are very very close one by one you place a cluster marker. And on zoom in remove this cluster and create another clusters...do this until the markers became far enough away and you can seen them divided.

Check this: Cluster markers

Plamen Nikolov
  • 4,177
  • 3
  • 23
  • 24
  • Thank You for your explanation, I now have an idea what I have to do. Would you prefer to add an ItemizedOverlay with defaultMarker on each different drawable, or am I just fine if i set a CachedDrawable as ImageResource of an OverlayItem? – Rafael T Jun 16 '11 at 14:33
  • I did not get this. Can you explain it again, sorry. – Plamen Nikolov Jun 16 '11 at 14:46
  • for example: If I create a new ItemizedOverlay, I usually pass a defaultMarker in its Constructor which is used for every OverlayItem. If I have like 10 OverlayItems I can add them to the ItemizedOverlay. They'll all get the defaultMarker as Drawable. If I want one single different Icon in one special OverlayItem i can call setMarker(Drawable d) on an Instance of that OverlayItem. So I have only one ItemizedOverlay, but each OverlayItem has its own Marker which points to a cachedDrawable – Rafael T Jun 16 '11 at 14:57
2

Take the following approaches:

  1. Create a cached overlay to prevent multiple drawing of same clusters;
  2. Draw in thread;
  3. Cluster your markers depending on zoom level and marker proximity.
  4. Each time you draw in the overlay, check for sure is the current marker inside of the visible part of the screen. If it is not, do no draw it!
Plamen Nikolov
  • 4,177
  • 3
  • 23
  • 24
  • 1
    hmm, thx for that answer first. But I don't understand your answer really. What is a cached overlay and cluster, and how to do this? – Rafael T Jun 16 '11 at 09:44
0

I had a similar problem with the icon size and zoom level in my application. What I ended up doing was having 2 sets of overlays containing the markers, one with a "zoomed in" icon and one with a "zoomed out" icon. Then just changed the overlay at a certain zoom level (using a zoom poller - On zoom event for google maps on android)

Community
  • 1
  • 1
Kurru
  • 14,180
  • 18
  • 64
  • 84