Tha*_*ana 6 android map openstreetmap osmdroid
我在我的Android应用程序中包含了Open Street Maps.在mapview中,用户应该能够在地图完全加载后捕获屏幕.但是,即使仍在加载mapview,用户也可以捕获图像.有人能告诉我如何检测mapview何时完全加载?
下面是我加载mapview的代码:
public class MainActivity extends Activity {
MapView mapView;
MyLocationOverlay myLocationOverlay = null;
ArrayList<OverlayItem> anotherOverlayItemArray;
protected ItemizedOverlayWithBubble<ExtendedOverlayItem> itineraryMarkers;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
final ArrayList<ExtendedOverlayItem> waypointsItems = new ArrayList<ExtendedOverlayItem>();
itineraryMarkers = new ItemizedOverlayWithBubble<ExtendedOverlayItem>(this, waypointsItems, mapView, new ViaPointInfoWindow(R.layout.itinerary_bubble, mapView));
mapView.getOverlays().add(itineraryMarkers);
mapView.setTileSource(TileSourceFactory.MAPNIK);
mapView.setBuiltInZoomControls(true);
MapController mapController = mapView.getController();
mapController.setZoom(1);
GeoPoint point2 = new GeoPoint(51496994, -134733);
mapController.setCenter(point2);
Drawable marker=getResources().getDrawable(android.R.drawable.star_big_on);
GeoPoint myPoint1 = new GeoPoint(0*1000000, 0*1000000);
ExtendedOverlayItem overlayItem = new ExtendedOverlayItem("Title Test Loc", "Desc", myPoint1, this);
overlayItem.setMarkerHotspot(OverlayItem.HotspotPlace.BOTTOM_CENTER);
overlayItem.setMarker(marker);
overlayItem.setRelatedObject(0);
itineraryMarkers.addItem(overlayItem);
mapView.invalidate();
myLocationOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocationOverlay);
myLocationOverlay.enableMyLocation();
myLocationOverlay.runOnFirstFix(new Runnable() {
public void run() {
mapView.getController().animateTo(myLocationOverlay.getMyLocation());
}
});
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
myLocationOverlay.enableMyLocation();
myLocationOverlay.enableCompass();
myLocationOverlay.enableFollowLocation();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
myLocationOverlay.disableMyLocation();
myLocationOverlay.disableCompass();
myLocationOverlay.disableFollowLocation();
}
Run Code Online (Sandbox Code Playgroud)
我通过扩展 TilesOverlay 创建了一个名为“MyTileOverlay”的类,它包含此类:
然后在设置地图视图时,我这样做:
this.mTilesOverlay = new MyTileOverlay(mProvider, this.getBaseContext());
Run Code Online (Sandbox Code Playgroud)
按照 kurtzmarc 的指示,我使用 handleTile() 来检查是否所有图块都已加载:
@Override
public void handleTile(final Canvas pCanvas, final int pTileSizePx,
final MapTile pTile, final int pX, final int pY) {
Drawable currentMapTile = mTileProvider.getMapTile(pTile);
if (currentMapTile == null) {
currentMapTile = getLoadingTile();
Log.d("Tile Null", "Null");
} else {
Log.d("Tile Not Null", "Not Null");
}
if (currentMapTile != null) {
mTileRect.set(pX * pTileSizePx, pY * pTileSizePx, pX
* pTileSizePx + pTileSizePx, pY * pTileSizePx
+ pTileSizePx);
onTileReadyToDraw(pCanvas, currentMapTile, mTileRect);
}
if (DEBUGMODE) {
mTileRect.set(pX * pTileSizePx, pY * pTileSizePx, pX
* pTileSizePx + pTileSizePx, pY * pTileSizePx
+ pTileSizePx);
mTileRect.offset(-mWorldSize_2, -mWorldSize_2);
pCanvas.drawText(pTile.toString(), mTileRect.left + 1,
mTileRect.top + mDebugPaint.getTextSize(),
mDebugPaint);
pCanvas.drawLine(mTileRect.left, mTileRect.top,
mTileRect.right, mTileRect.top, mDebugPaint);
pCanvas.drawLine(mTileRect.left, mTileRect.top,
mTileRect.left, mTileRect.bottom, mDebugPaint);
}
}
Run Code Online (Sandbox Code Playgroud)
该方法确保加载过程是否完成:
@Override
public void finaliseLoop() {
Log.d("Loop Finalized", "Finalized");
}
Run Code Online (Sandbox Code Playgroud)
我还可以使用此方法来确定是否所有图块都已加载:
public int getLoadingBackgroundColor() {
return mLoadingBackgroundColor;
}
Run Code Online (Sandbox Code Playgroud)
希望这对某人有帮助!
| 归档时间: |
|
| 查看次数: |
1730 次 |
| 最近记录: |