gpt4 book ai didi

android - 在 Android 中限制在离线 map 上滚动

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:28:21 25 4
gpt4 key购买 nike

我从 osmdroid 那里得到了这些代码或补丁,我决定寻求你们的帮助,因为我没有足够的知识来组合这些代码来解决我的问题,滚动限制离线 map 。我在网上搜索,并修改了教程。老实说,我试图修改这些代码,但我没有发现任何进展。基本上我有一个来自 mapnik 的离线 map ,以及一些叠加层。我不知道在哪里正确放置这些代码集。你的想法和修改将是一个很大的帮助,也帮助我继续我的项目,我想你的答案肯定会帮助其他人在未来遇到与我相同的问题。我知道这太多了。谢谢先生们的宝贵时间,上帝保佑。

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

另一个:

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

最佳答案

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

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

它将下载一个稳定的版本

然后按照以下步骤导入您下载的文件夹的内容:

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
  1. 现在打开这个java文件-->osmdroid-android/src/org/osmdroid/view/MapView.java
  2. 现在如本patch file所述,修改MapView.java(添加在任何地方编码 + ,在任何地方删除代码 -)
  3. 同时修改 MapView.java 中的 computeScroll() here
  4. 现在,要使用这个修改后的 .java 文件,您需要创建一个新的 jar您可以包含在项目中的文件这是一个循序渐进的过程 to create jar

  5. 将这个新创建的 jar 文件添加到项目的构建路径中,然后您 准备好使用你修改后的 jar

  6. 现在在您的 Activity 类中使用它:

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

关于android - 在 Android 中限制在离线 map 上滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7898313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com