Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中限制脱机地图的滚动_Android_Maps_Openstreetmap_Osmdroid - Fatal编程技术网

在Android中限制脱机地图的滚动

在Android中限制脱机地图的滚动,android,maps,openstreetmap,osmdroid,Android,Maps,Openstreetmap,Osmdroid,我从osmdroid那里得到了这些代码或补丁,我决定寻求你们的帮助,因为我没有足够的知识来结合这些代码来解决我的问题,在离线地图上滚动限制。我在网上搜索,修改了教程。老实说,我试图修改这些代码,但我没有发现任何进展。基本上,我有一张来自mapnik的离线地图和一些覆盖图。我不知道该把这些代码放在哪里。你的想法和修改将是一个很大的帮助,也有助于我继续我的项目,我想你的答案肯定会帮助其他人与我在未来同样的问题。我知道这太过分了。谢谢各位,先生们,愿上帝保佑你们 public void onCreat

我从osmdroid那里得到了这些代码或补丁,我决定寻求你们的帮助,因为我没有足够的知识来结合这些代码来解决我的问题,在离线地图上滚动限制。我在网上搜索,修改了教程。老实说,我试图修改这些代码,但我没有发现任何进展。基本上,我有一张来自mapnik的离线地图和一些覆盖图。我不知道该把这些代码放在哪里。你的想法和修改将是一个很大的帮助,也有助于我继续我的项目,我想你的答案肯定会帮助其他人与我在未来同样的问题。我知道这太过分了。谢谢各位,先生们,愿上帝保佑你们

public void onCreate(Bundle savedInstanceState) {
        ...
        ...
        m_mapView = (MapView) findViewById(R.id.mapview);
        m_mapView.setTileSource(TileSourceFactory.MAPNIK);
    }
第一:边界框

BoundingBoxE6 bbox = new BoundingBoxE6(9.37398, 123.33761, 9.23948, 123.25035);
this.setScrollableAreaLimit(bbox);
第二:LimitScrollToGeographicArea.patch

Index: MapView.java
===================================================================
--- MapView.java    (revision 944)
+++ MapView.java    (working copy)
@@ -103,6 +103,8 @@

    protected MapListener mListener;

+   protected Rect mScrollableAreaLimit;
+
    // for speed (avoiding allocations)
    private final Matrix mMatrix = new Matrix();
    private final MapTileProviderBase mTileProvider;
@@ -505,6 +507,36 @@
        mMapOverlay.setUseDataConnection(aMode);
    }

+   /**
+    * Set the map to limit it's scrollable view to the specified BoundingBoxE6. Note that, like
+    * North/South bounds limiting, this allows an overscroll of half the screen size. This means
+    * each border can be scrolled to the center of the screen.
+    * 
+    * @param boundingBox
+    *            A lat/long bounding box to limit scrolling to, or null to remove any scrolling
+    *            limitations
+    */
+   public void setScrollableAreaLimit(BoundingBoxE6 boundingBox) {
+       final int worldSize_2 = TileSystem.MapSize(MapViewConstants.MAXIMUM_ZOOMLEVEL) / 2;
+
+       // Clear scrollable area limit if null passed.
+       if (boundingBox == null) {
+           mScrollableAreaLimit = null;
+           return;
+       }
+
+       // Get NW/upper-left
+       final Point upperLeft = TileSystem.LatLongToPixelXY(boundingBox.getLatNorthE6() / 1E6,
+               boundingBox.getLonWestE6() / 1E6, MapViewConstants.MAXIMUM_ZOOMLEVEL, null);
+       upperLeft.offset(-worldSize_2, -worldSize_2);
+
+       // Get SE/lower-right
+       final Point lowerRight = TileSystem.LatLongToPixelXY(boundingBox.getLatSouthE6() / 1E6,
+               boundingBox.getLonEastE6() / 1E6, MapViewConstants.MAXIMUM_ZOOMLEVEL, null);
+       lowerRight.offset(-worldSize_2, -worldSize_2);
+       mScrollableAreaLimit = new Rect(upperLeft.x, upperLeft.y, lowerRight.x, lowerRight.y);
+   }
+
    // ===========================================================
    // Methods from SuperClass/Interfaces
    // ===========================================================
@@ -772,10 +804,26 @@
    //I am confused with these codes below, where should I declare it? Int x, y in the          onCreate method?

            x += (worldSize_2 * 2);
        while (x > worldSize_2)
            x -= (worldSize_2 * 2);
-       while (y < -worldSize_2)
-           y += (worldSize_2 * 2);
-       while (y > worldSize_2)
-           y -= (worldSize_2 * 2);
+       if (y < -worldSize_2)
+           y = -worldSize_2;
+       if (y > worldSize_2)
+           y = worldSize_2;
+
+       if (mScrollableAreaLimit != null) {
+           final int zoomDiff = MapViewConstants.MAXIMUM_ZOOMLEVEL - getZoomLevel();
+           final int minX = mScrollableAreaLimit.left >> zoomDiff;
+           final int minY = mScrollableAreaLimit.top >> zoomDiff;
+           final int maxX = mScrollableAreaLimit.right >> zoomDiff;
+           final int maxY = mScrollableAreaLimit.bottom >> zoomDiff;
+           if (x < minX)
+               x = minX;
+           else if (x > maxX)
+               x = maxX;
+           if (y < minY)
+               y = minY;
+           else if (y > maxY)
+               y = maxY;
+       }
        super.scrollTo(x, y);

        // do callback on listener
索引:MapView.java
===================================================================
---MapView.java(修订版944)
+++MapView.java(工作副本)
@@ -103,6 +103,8 @@
受保护的映射侦听器;
+受保护的Rect MSCROLLABLE区域限制;
+
//速度(避免分配)
私有最终矩阵mMatrix=新矩阵();
私有最终MapTileProviderBase mTileProvider;
@@ -505,6 +507,36 @@
mMapOverlay.setUseDataConnection(aMode);
}
+   /**
+*将地图设置为将其可滚动视图限制为指定的边界框6。注意,比如
+*北/南边界限制,允许屏幕大小一半的过卷。这意味着
+*每个边框都可以滚动到屏幕中央。
+    * 
+*@param边界框
+*用于限制滚动的横向/纵向边界框,或用于删除任何滚动的null
+*限制
+    */
+公共无效设置CrollableRealimit(边界框6边界框){
+final int worldSize_2=TileSystem.MapSize(MapViewConstants.MAXIMUM_ZOOMLEVEL)/2;
+
+//如果通过null,则清除可滚动区域限制。
+如果(boundingBox==null){
+mScrollableAreaLimit=null;
+返回;
+       }
+
+//向西北方向/左上角
+最后一点左上=TileSystem.LatLongToPixelXY(boundingBox.getLatNorthE6()/1E6,
+boundingBox.GetLonWest6()/1E6,MapViewConstants.MAXIMUM\u ZOOMLEVEL,null);
+左上角。偏移量(-worldSize_2,-worldSize_2);
+
+//获取SE/右下角
+终点lowerRight=TileSystem.LatLongToPixelXY(boundingBox.getLatSouthE6()/1E6,
+boundingBox.GetLonEast6()/1E6,MapViewConstants.MAXIMUM\u ZOOMLEVEL,null);
+右下角偏移量(-worldSize_2,-worldSize_2);
+mScrollableAreaLimit=新矩形(左上角.x,左上角.y,右下角.x,右下角.y);
+   }
+
// ===========================================================
//来自超类/接口的方法
// ===========================================================
@@ -772,10 +804,26 @@
//我对下面的代码感到困惑,我应该在哪里声明?onCreate方法中的Int x,y?
x+=(世界大小2*2);
而(x>世界大小2)
x-=(世界规模2*2);
-而(y<-世界尺寸2)
-y+=(世界大小2*2);
-而(y>worldSize_2)
-y-=(世界规模2*2);
+如果(y<-世界尺寸2)
+y=-世界大小_2;
+如果(y>worldSize_2)
+y=世界尺寸_2;
+
+如果(mScrollableAreaLimit!=null){
+final int zoomDiff=MapViewConstants.max_ZOOMLEVEL-getZoomLevel();
+final int minX=mScrollableAreaLimit.left>>zoomDiff;
+final int minY=mScrollableAreaLimit.top>>zoomDiff;
+final int maxX=mScrollableAreaLimit.right>>zoomDiff;
+final int maxY=mScrollableAreaLimit.bottom>>zoomDiff;
+if(xmaxX)
+x=最大x;
+if(ymaxY),则为else
+y=最大值;
+       }
super.scrollTo(x,y);
//对侦听器执行回调
另一个:

 scrollToMethod
public void scrollTo(int x, int y) {
        int curZoomLevel = mZoomLevel;
        final int worldSize_2 = TileSystem.MapSize(curZoomLevel) / 2;
        Log.v("HELP", "Scrolling to X=" + x + " Y=" + y + " ZL=" + curZoomLevel + " - WW="+worldSize_2);

        while (x < -worldSize_2)
            x += (worldSize_2 * 2);
        while (x > worldSize_2)
            x -= (worldSize_2 * 2);
        if (y < -worldSize_2)
            y = -worldSize_2;
        if (y > worldSize_2)
            y = worldSize_2;

        if (mScrollableAreaLimit != null) {
                int targetZoomLevel = getZoomLevel();
                final int zoomDiff = MapViewConstants.MAXIMUM_ZOOMLEVEL - targetZoomLevel;
                //final int zoomDiff = MapViewConstants.MAXIMUM_ZOOMLEVEL - mZoomLevel;
                final int minX = mScrollableAreaLimit.left >> zoomDiff;
                final int minY = mScrollableAreaLimit.top >> zoomDiff;
                final int maxX = mScrollableAreaLimit.right >> zoomDiff;
                final int maxY = mScrollableAreaLimit.bottom >> zoomDiff;

                Log.v("HELP", "Limit: minX=" + minX + " maxX=" + maxX + " minY=" + minY + " maxY=" + maxY + " ZL=" + curZoomLevel + " ZLTarget="+ targetZoomLevel + " ZD="+zoomDiff);

                if (x < minX) {
                    Log.v("HELP", "!!! X=" + x + " minX=" + minX + " CORRECTION:" + (minX-x));
                    x = minX;
                } else if (x > maxX) {
                    Log.v("HELP", "!!! X=" + x + " maxX=" + maxX + " CORRECTION:" + (maxX-x));
                    x = maxX;
                }

                if (y < minY) {
                    Log.v("HELP", "!!! Y=" + y + " minY=" + minY + " CORRECTION:" + (minY-y));
                    y = minY;
                } else if (y > maxY) {
                    Log.v("HELP", "!!! Y=" + y + " maxY=" + maxY + " CORRECTION:" + (maxY-y));
                    y = maxY;   
                }
        }

        super.scrollTo(x, y);

        // do callback on listener
        if (mListener != null) {
            final ScrollEvent event = new ScrollEvent(this, x, y);
            mListener.onScroll(event);
        }
    }
scrollToMethod
公共无效滚动到(整数x,整数y){
int curZoomLevel=mZoomLevel;
最终int worldSize_2=TileSystem.MapSize(curZoomLevel)/2;
Log.v(“帮助”,“滚动到X=“+X+”Y=“+Y+”ZL=“+curZoomLevel+”-WW=“+worldSize_2”);
而(x<-世界尺寸2)
x+=(世界大小2*2);
而(x>世界大小2)
x-=(世界规模2*2);
如果(y<-世界尺寸2)
y=-世界大小_2;
如果(y>worldSize_2)
y=世界尺寸_2;
如果(mScrollableAreaLimit!=null){
int targetZoomLevel=getZoomLevel();
final int zoomDiff=MapViewConstants.MAXIMUM_ZOOMLEVEL-targetZoomLevel;
//final int zoomDiff=MapViewConstants.MAXIMUM_ZOOMLEVEL-mZoomLevel;
final int minX=mScrollableAreaLimit.left>>zoomDiff;
final int minY=mScrollableAreaLimit.top>>zoomDiff;
final int maxX=mScrollableAreaLimit.right>>zoomDiff;
final int maxY=mScrollableAreaLimit.bottom>>zoomDiff;
Log.v(“帮助”,“限制:minX=“+minX+”maxX=“+maxX+”minY=“+minY+”maxY=“+maxY+”ZL=“+curZoomLevel+”ZLTarget=“+targetZoomLevel+”ZD=“+zoomDiff”);
if(xmaxX){
Log.v(“帮助”,“!!!X=“+X+”maxX=“+maxX+”更正:”+(maxX-X));
x=最大x;
}
if(ymaxY),则为else{
对数v(
svn checkout http://osmdroid.googlecode.com/svn/branches/release_3_0_5
click on Import...
select General -> Existing Projects into Workspace
click Next
click Browse...
select the checked out projects' directories
    osmdroid-android (import as a java project)
    OSMMapTilePackager (import as a java project)
    OpenStreetMapViewer (mport as an android project) 
click OK
click Finish
BoundingBoxE6 bbox  = new BoundingBoxE6(limit north, limit east, limit south, limit west);          
mapView.setScrollableAreaLimit(bbox);