|
LazyLoading
Howto for lazyloading marker(OverlayItems).
Phase-Implementation IntroductionIf you want to use a lots of marker in your MapView, it makes sense to lazyload only those which are visible for the current viewport. The mapview-overlay-manager provides an easy callback-feature for this. LazyLoadCallbackYou enable lazyloading by just adding an implementation of the LazyLoadCallback to your ManagedOverlay. This LazyLoadCallback will be invoked when the user:
or you call ManagedOverlay.invokeLazyLoad(long delay) by hand public interface LazyLoadCallback {
public List<ManagedOverlayItem> lazyload(GeoPoint topLeft, GeoPoint bottomRight, ManagedOverlay overlay) throws LazyLoadException;
}Important Notes
Example: managedOverlay.setLazyLoadCallback(new LazyLoadCallback() {
@Override
public List<ManagedOverlayItem> lazyload(GeoPoint topLeft, GeoPoint bottomRight, ManagedOverlay overlay) throws LazyLoadException
List<ManagedOverlayItem> items = null;
try {
items = httpRequestHelper.findMarker(topLeft, bottomRight);
} catch (Exception e) {
throw new LazyLoadException(e.getMessage());
}
return items;
}
});LazyLoadListenerYou can attach a LazyLoadListener to the ManagedOverlay. Following events will be fired when lazyloading is invoked.
public interface LazyLoadListener {
public void onBegin(ManagedOverlay overlay);
public void onSuccess(ManagedOverlay overlay);
public void onError(LazyLoadException exception, ManagedOverlay overlay);
}Note: This will run in the UI-Thread. So you can make a Toast or other stuff with Views from the Activity. LazyLoadAnimationIt makes sense to inform the user about background activities by displaying an indicator. The mapview-overlay-manager has a built-in loading animation. You only need to provide an ImageView. ImageView imageView = (ImageView) findViewById(R.id.loader); managedOverlay.enableLazyLoadAnimation(imageView); You can also use a custom animation: LazyLoadAnimation animation = managedOverlay.enableLazyLoadAnimation(imageView); animation.setAnimationDrawable((AnimationDrawable) this.getResources().getDrawable(R.anim.animation1)); If you wanna do more freaky stuff: use the LazyLoadListener! RemarksMapController.animateTo(GeoPoint)This will scroll the MapView to a new point on the map, but will not invoke lazyloading! Nevertheless you could do this by hand: managedOverlay.invokeLazyLoad(long delay); |
I can't seem to get it working on my site... Handbags