osmdroid 当前地图不是全屏时候(缩放全图测试)

  1、当你MapView 不是全屏时候,需要缩放到全图或者固定位置又或者是图层的点。你会发现MapView里面的设置中心是错的,你的设置缩放范围也是错的zoomToBoundingBox
  2、看源码是因为this.getWidth() 和  this.getHeight(),因为里面里面使用的是全屏的窗口的值。就是说在windows里面位置的值。所以不一样
  3、所以你需要根据里面方法,自已重写就好

以下是源码的zoomToBoundingBox

    public void zoomToBoundingBox(BoundingBox boundingBox, boolean animated, int borderSizeInPixels) {double nextZoom = mTileSystem.getBoundingBoxZoom(boundingBox, this.getWidth() - 2 * borderSizeInPixels, this.getHeight() - 2 * borderSizeInPixels);if (nextZoom != 4.9E-324D) {nextZoom = Math.min(this.getMaxZoomLevel(), Math.max(nextZoom, this.getMinZoomLevel()));IGeoPoint center = boundingBox.getCenterWithDateLine();if (animated) {this.getController().setCenter(center);this.getController().zoomTo(nextZoom);} else {this.getController().setZoom(nextZoom);this.getController().setCenter(center);}}}

自已重写后

        double nextZoom = mapView.getTileSystem().getBoundingBoxZoom(simpleFastPointOverlay.getBoundingBox(), mapView.getWidth() - 2 * dip2px(10) , mapView.getHeight() - 2 * dip2px(10));if (nextZoom != 4.9E-324D) {nextZoom = Math.min(mapView.getMaxZoomLevel(), Math.max(nextZoom, mapView.getMinZoomLevel()));IGeoPoint center = simpleFastPointOverlay.getBoundingBox().getCenterWithDateLine();mapView.getController().setCenter(center);mapView.getController().zoomTo(nextZoom);}else {mapView.getController().setZoom(18.0);//移动到某个位置mapView.getController().animateTo(new GeoPoint(x, y));}mapView.invalidate();
     public static TileSystem getTileSystem() {return mTileSystem;}public static void setTileSystem(TileSystem pTileSystem) {mTileSystem = pTileSystem;}

这两个方法在MapView

最后提示:

如果设置缩放到中心(setCenter)不行,就用
mapView.getController().animateTo(new GeoPoint(x, y));


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部