开发者

How to Display thousands of OverlayItems in an Android MapView

开发者 https://www.devze.com 2023-03-13 14:35 出处:网络
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 -

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 ba开发者_如何学Pythond, 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


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


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!


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消