2011-11-28 79 views
0

我有一个Android MapView,其中我需要在MapView已经处理的地图上叠加第二层图层。第二层地图视图上的叠加

为了达到这个目的,我在我的MapView上放置了一个FrameLayout,并在我的布局中放置了我的针脚作为ImageViews。

我已经覆盖了ImageViews的Draw()方法来更新自己的位置时,地图上移动(使得销移动与它)是这样的:

public void draw(Canvas canvas) { 
    if(mCoordinates != null && mapView != null){ 
     LayoutParams mParams = (LayoutParams)this.getLayoutParams(); 
     mapView.getProjection().toPixels(mCoordinates, newPosition); 
     mParams.leftMargin = newPosition.x; 
     mParams.topMargin = newPosition.y; 
    } 
    super.draw(canvas); 
} 

问题:视图更新太慢,所以当我移动地图时,引脚似乎落后于它。

的办法或实施任何见解欢迎

回答

0

最后,我们只是疯狂的一种方法,每次都会订购叠加层,以便大型叠加层总是先绘制,而小叠加层则绘制在这些叠加层上。

0

我有一个使用多重叠加来完成这项工作的应用程序。根据需要处理每个叠加层。在处理结束时,函数调用地图更新例程。这是更新例程的一个框架。

private void updateMap() { 
    GeoPoint geoPoint; 
    overlayList = mapView.getOverlays(); 
    overlayList.clear(); 
    locationOverlay = new MapOverlay(); 
    pushpinOverlay = new MapOverlay(); 
    arrowOverlay = new ArrowOverlay(); 
    tapOverlay = new TapOverlay(); 
    if (hasCurrentPosition) { 
     locationOverlay.setDrawId(R.drawable.man); 
     geoPoint = new GeoPoint(currentLatitudeE6, currentLongitudeE6); 
     locationOverlay.setPointToDraw(geoPoint); 
     if (isFirstFix) { 
      mapController.animateTo(geoPoint); 
      isFirstFix = false; 
     } 
    } 
    if (hasPushpinPosition) { 
     pushpinOverlay.setDrawId(R.drawable.locationmarker); 
     geoPoint = new GeoPoint(pushpinLatitudeE6, pushpinLongitudeE6); 
     pushpinOverlay.setPointToDraw(geoPoint); 
    } 
    calcDistance(); 
    if (findFlag) { 
     calcArrowRotation(); 
    } 
    setStatusMessage(); 
    overlayList.add(locationOverlay); 
    overlayList.add(pushpinOverlay); 
    if (findFlag) { 
     overlayList.add(arrowOverlay); 
    } 
    overlayList.add(tapOverlay); 
    mapView.invalidate(); 
} 

轻拍叠加层是“顶部”叠加层,必须最后添加。因为它们被指定为lat和long,所以jpushpin和位置图像被“锁定”到地图上。自来水叠加层返回被点击的地图点,而不是屏幕点。箭头位于屏幕上,只能旋转,不能水平或垂直移动。此外,用户可以打开和关闭箭头叠加层(findFlag是由按钮切换的布尔值)。

也许你可以使用这个主题的变体作为分层叠加之一的分项叠加?

+0

谢谢你的回答,但正如我所说我不能使用MapView.getOverlays(),由于在应用 – Arcantos

+0

的具体要求。错过了... –