2011-10-26 9 views
5

Obtuve estos códigos o parches de osmdroid, y decidí pedirles ayuda, porque no tengo los conocimientos suficientes para combinar estos códigos y poder crearlos. solución en mi problema, Límite de desplazamiento en un mapa sin conexión. Busqué en la web y modifiqué tutoriales. Honestamente traté de modificar estos códigos, pero no encontré ningún progreso. Básicamente tengo un mapa sin conexión de mapnik y algunas superposiciones. No sé dónde colocar correctamente estos conjuntos de códigos. Sus ideas y modificaciones serán de gran ayuda y también me ayudarán a continuar con mi proyecto y supongo que sus respuestas definitivamente ayudarán a otros con el mismo problema que el mío en el futuro. Sé que esto es mucho. Gracias señores por su tiempo, y Dios los bendiga.Limite Desplazamiento en mapas sin conexión, en Android

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

Primero: BoundingBox

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

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

Otra:

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

También tengo errores en este: super.scrollTo (x, y); // realiza una devolución de llamada en el oyente if (mListener! = Null) { evento ScrollEvent final = nuevo ScrollEvent (this, x, y); mListener.onScroll (evento); } – rahstame

Respuesta

7

En primer lugar utilizar este comando en el terminal:

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

Se descargará una versión estable

A continuación, siga este importar contenido de la carpeta u descargado:

En Eclipse, haga clic en el área de paquete, y seleccionar la siguiente :

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. Ahora abrir este archivo Java -> osmdroid-android/src/org/osmdroid/view/MapView.java
  2. Ahora bien, como se indica en este patch file, modificar MapView.java (añadir código donde quiera +, eliminar código donde quiera -)
  3. también modificar computeScroll() en MapView.java como se indica here
  4. Ahora, para utilizar este archivo .java modificado, u necesidad de crear un nuevo archivo jar que u puede incluir en su proyecto Aquí es un proceso paso a paso to create jar

  5. Añadir este archivo JAR recién creado para la ruta de compilación de su proyecto y le r listo para usar su frasco modificado

  6. Ahora utilizar esto en su clase de actividad:

    BoundingBoxE6 Bbox = new BoundingBoxE6 (límite norte, límite al este, límite sur, límite oeste);
    mapView.setScrollableAreaLimit (bbox);

Cuestiones relacionadas