限制滚动的离线地图,在Android中离线、地图、Android

2023-09-05 11:14:04 作者:流年~轻描淡写的伤

我得到了这些片codeS或osmdroid补丁,我决定找你帮忙球员,因为我没有足够的知识来组合这些codeS上拿出一个解决方案我的问题,在一个离线地图滚动限制。我搜索整个网络,并修改教程。老实说,我试图修改C $ CS这些$,但我还没有发现任何进展。基本上我有Mapnik的离线地图,和一些重叠。我不知道在哪里可以适当地将这些集codeS。你的想法和修改将是一个很大的帮助,也有助于我保持我的项目中去,我想你的答案一定会帮助其他有同样问题,因为煤矿的未来。我知道这是要多。感谢您的先生们的宝贵时间,上帝保佑。

 公共无效的onCreate(包savedInstanceState){
        ...
        ...
        m_mapView =(图形页面)findViewById(R.id.mapview);
        m_mapView.setTileSource(TileSourceFactory.MAPNIK);
    }
 

第一:BoundingBox的

  BoundingBoxE6 BBOX =新BoundingBoxE6(9.37398,123.33761,9.23948,123.25035);
this.setScrollableAreaLimit(BBOX);
 

二:LimitScrollToGeographicArea.patch

 索引:MapView.java
================================================== =================
--- MapView.java(修订版944)
+++ MapView.java(工作拷贝)
@@ -103,6 +103,8 @@

    保护MapListener mListener;

+保护的矩形mScrollableAreaLimit;
+
    //速度(避免分配)
    私人最终矩阵mMatrix =新的Matrix();
    私人最终MapTileProviderBase mTileProvider;
@@ -505,6 +507,36 @@
        mMapOverlay.setUseDataConnection(AMODE);
    }

+ / **
+ *设置地图来限制它的滚动视图到指定BoundingBoxE6。需要注意的是,像
+ *北/南边界限制,这使得一半的屏幕大小的overscroll。意即
+ *每个边界可以滚动到屏幕的中心。
+ *
+ * @参数boundingBox的
+ *纬度/经度边框限制滚动,或者为null,以消除任何滚动
+ *限制
+ * /
+公共无效setScrollableAreaLimit(BoundingBoxE6 boundingBox的){
+最终诠释worldSize_2 = TileSystem.MapSize(MapViewConstants.MAXIMUM_ZOOMLEVEL)/ 2;
+
如果空过去了+ //清除滚动区域限制。
+如果(boundingBox的== NULL){
+ mScrollableAreaLimit = NULL;
+返回​​;
+}
+
+ //获取NW /左上角
+最后一点upperLeft = TileSystem.LatLongToPixelXY(boundingBox.getLatNorthE6()/ 1E6,
+ boundingBox.getLonWestE6()/ 1E6,MapViewConstants.MAXIMUM_ZOOMLEVEL,NULL);
+ upperLeft.offset(-worldSize_2,-worldSize_2);
+
+ //获取SE /右下
+最后一点lowerRight = TileSystem.LatLongToPixelXY(boundingBox.getLatSouthE6()/ 1E6,
+ boundingBox.getLonEastE6()/ 1E6,MapViewConstants.MAXIMUM_ZOOMLEVEL,NULL);
+ lowerRight.offset(-worldSize_2,-worldSize_2);
+ mScrollableAreaLimit =新的矩形(upperLeft.x,upperLeft.y,lowerRight.x,lowerRight.y);
+}
+
    // ================================================ ===========
    从父类/接口//方法
    // ================================================ ===========
@@ -772,10 +804,26 @@
    //我很困惑下面这些codeS,我应该在哪里申报呢?诠释的x,y在onCreate方法?

            X + =(worldSize_2 * 2);
        而(X> worldSize_2)
            x  -  =(worldSize_2 * 2);
 - 而(Y< -worldSize_2)
 -  Y + =(worldSize_2 * 2);
 - 而(Y> worldSize_2)
 -  Y  -  =(worldSize_2 * 2);
+如果(Y< -worldSize_2)
+ Y = -worldSize_2;
+如果(Y> worldSize_2)
+ Y = worldSize_2;
+
+如果(mScrollableAreaLimit!= NULL){
+最终诠释zoomDiff = MapViewConstants.MAXIMUM_ZOOMLEVEL  -  getZoomLevel();
+最终诠释其minX = mScrollableAreaLimit.left>> zoomDiff;
+最终诠释MINY = mScrollableAreaLimit.top>> zoomDiff;
+最终诠释MAXX = mScrollableAreaLimit.right>> zoomDiff;
+最终诠释MAXY = mScrollableAreaLimit.bottom>> zoomDiff;
+如果(X<其minX)
+ X =其minX;
+否则,如果(X> MAXX)
+ X = MAXX;
+如果(Y< MINY)
+ Y = MINY;
+否则,如果(Y> MAXY)
+ Y = MAXY;
+}
        super.scrollTo(X,Y);

        //做侦听器回调
 
在高德地图中删除离线地图的图文教程

还有一句:

  scrollToMethod
公共无效scrollTo(INT X,int y)对{
        INT curZoomLevel = mZoomLevel;
        最终诠释worldSize_2 = TileSystem.MapSize(curZoomLevel)/ 2;
        Log.v(帮助,滚动到X =+ X +Y =+ Y +ZL =+ curZoomLevel + -  WW =+ worldSize_2);

        而(X< -worldSize_2)
            X + =(worldSize_2 * 2);
        而(X> worldSize_2)
            x  -  =(worldSize_2 * 2);
        如果(Y< -worldSize_2)
            Y = -worldSize_2;
        如果(Y> worldSize_2)
            Y = worldSize_2;

        如果(mScrollableAreaLimit!= NULL){
                INT targetZoomLevel = getZoomLevel();
                最终诠释zoomDiff = MapViewConstants.MAXIMUM_ZOOMLEVEL  -  targetZoomLevel;
                //最终诠释zoomDiff = MapViewConstants.MAXIMUM_ZOOMLEVEL  -  mZoomLevel;
                最终诠释其minX = mScrollableAreaLimit.left>> zoomDiff;
                最终诠释MINY = mScrollableAreaLimit.top>> zoomDiff;
                最终诠释MAXX = mScrollableAreaLimit.right>> zoomDiff;
                最终诠释MAXY = mScrollableAreaLimit.bottom>> zoomDiff;

                Log.v(帮助,限制:其minX =+其minX +MAXX =+ MAXX +MINY =+ MINY +MAXY =+ MAXY +ZL =+ curZoomLevel +ZLTarget =+ targetZoomLevel +ZD =+ zoomDiff);

                如果(X<其minX){
                    Log.v(帮助,!!! X =+ X +其minX =+其minX +更正:+(其minX-X));
                    X =其minX;
                }否则如果(X> MAXX){
                    Log.v(帮助,!!! X =+ X +MAXX =+ MAXX +更正:+(MAXX-X));
                    X = MAXX;
                }

                如果(Y< MINY){
                    Log.v(帮助,!!! Y =+ Y +MINY =+ MINY +更正:+(MINY-Y));
                    Y = MINY;
                }否则如果(Y> MAXY){
                    Log.v(帮助,!!! Y =+ Y +MAXY =+ MAXY +更正:+(MAXY-Y));
                    Y = MAXY;
                }
        }

        super.scrollTo(X,Y);

        //做侦听器回调
        如果(mListener!= NULL){
            最终表示ScrollEvent事件=新表示ScrollEvent(此,X,Y);
            mListener.onScroll(事件);
        }
    }
 

解决方案

首先在终端上使用这个命令:

  svn签HTTP://osmdroid.google$c$c.com/svn/branches/release_3_0_5
 

这将下载一个稳定版本

然后按照这个导入û下载的文件夹中的内容:

  

在Eclipse中,在包装区域单击鼠标右键,并选择以下:

 点击导入...
选择General  - >现有项目到工作区
点击下一步
点击浏览...
选择签出项目的目录
    osmdroid-机器人(进口作为一个Java项目)
    OSMMapTilePackager(进口作为一个Java项目)
    OpenStreetMapViewer(mport作为一个Android项目)
单击确定
单击Finish
 

现在,打开这个的Java文件 - > osmdroid-的Andr​​oid / SRC /组织/ osmdroid /视图/ MapView.java 现在,在这个规定patch文件,修改MapView.java(加 code +的地方,删除code的地方 - ) 同时修改 computeScroll()在MapView.java作为陈述的这里

现在,用这个修改后的.java文件,U需要创建一个新的jar 文件ü可以在项目中包含 这是一个循序渐进的过程创建的jar

添加这个新创建的jar文件到你的项目的构建路径,你     读准备使用您的修改后的jar

现在在您的活动类中使用这样的:

  

BoundingBoxE6 BBOX =新BoundingBoxE6(限华北,华东限制​​,限制   南,西限制);       mapView.setScrollableAreaLimit(BBOX);

I got these piece of codes or patches from osmdroid, and I decided to ask for your help guys because i don't have the enough knowledge to combine these codes to come up with on a solution on my problem, Scrolling limit on an offline map. I searched across the web, and modified tutorials. Honestly I tried to modify these codes but i have not found any progress. Basically I have an offline map from mapnik, and a few overlays. I don't know where to properly place these set of codes. Your ideas and modification will be a great help and also helps me keep going with my project and I guess your answers will definitely help others with the same problem as mine in the future. I know this is to much. Thank you sirs for your time, and God Bless.

public void onCreate(Bundle savedInstanceState) {
        ...
        ...
        m_mapView = (MapView) findViewById(R.id.mapview);
        m_mapView.setTileSource(TileSourceFactory.MAPNIK);
    }

First: BoundingBox

BoundingBoxE6 bbox = new BoundingBoxE6(9.37398, 123.33761, 9.23948, 123.25035);
this.setScrollableAreaLimit(bbox);

Second: 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

Another one:

 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);
        }
    }

解决方案

First of all use this command on your terminal:

svn checkout http://osmdroid.googlecode.com/svn/branches/release_3_0_5

It will download a stable version

Then follow this to import contents of the folder u downloaded:

In Eclipse, right-click on the Package area, and select the following:

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

Now open this java file--> osmdroid-android/src/org/osmdroid/view/MapView.java Now as stated in this patch file, modify MapView.java ( add code wherever + , remove code wherever -) Also modify computeScroll() in MapView.java as stated here

Now, to use this modified .java file, u need to create a new jar file that u can include in your project Here is a step by step process to create jar

Add this newly created jar file to your project's build path and you r ready to use your modified jar

Now use this in your activity class:

BoundingBoxE6 bbox = new BoundingBoxE6(limit north, limit east, limit south, limit west); mapView.setScrollableAreaLimit(bbox);