MapView very slow with 1000 overlayitems on the map, even with only 2 visibles

700 Views Asked by At

I have a mapview showing 1000 overlayitems on the mapview. The map moves very slow even if only two overlayitems are visibles on the map (huge zoom applyed)

It is possible to optimice the mapview to move more fast if only low cuantity of overlayitems are visibles?

Thanks

3

There are 3 best solutions below

1
On

You might have fallen in the usual pit. If you've made your own customoverlay make sure that your addOverlay methode don't populate. Populate should first happen when all overlays has been added. If you populate each time you add you'll end up with many overlays on top of each other.

Make sure it uses 2 methods for this process, 1 to add and 1 to populate:

public void addOverlay(CustomOverlayItem overlay) { mOverlays.add(overlay); }

public void populateOverlay() { populate(); }

If that is not the issue then you should look into dynamically removing pins when they are outside the screen range or grouping pins together. I believe there is some open source project that have done the work for you in this regard.

1
On

subclass MapView, override dispatchDraw(). Detect changes in map center or zoom level:

@Override
public void dispatchDraw(Canvas canvas)
{
    super.dispatchDraw(canvas);

    GeoPoint gpCenterPoint = getMapCenter();
    int nZoomLevel = getZoomLevel();

    // either diff't zoom level or change to center point?
    if ( (gpCenterPoint.getLatitudeE6() != mCenterPoint.getLatitudeE6()) ||
         (gpCenterPoint.getLongitudeE6() != mCenterPoint.getLongitudeE6()) ||
         (nZoomLevel != mZoomLevel) )
    {
        // update pins here
                  updatePINS();

        mZoomLevel = nZoomLevel;
            mCenterPoint = gpCenterPoint;
    }
}

void updatePINS()
{
    int nLatitudeSpan = mapView.getLatitudeSpan();
    int nLongitudeSpan = mapView.getLatitudeSpan();

     // TODO insert/remove PINS as needed
}
1
On

Found a link http://onthefencedevelopment.com/blog/using-google-maps-your-android-applications-%E2%80%93-part-3-adding-place-markers drawing only the overlays which are on the screen. haven't tested it yet but seems promising.

EDIT: it works