xujunjie1 / osmdroid

Automatically exported from code.google.com/p/osmdroid
0 stars 0 forks source link

Update OsmdroidMapWrapper on osmdroid-third-party #509

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
OsmdroidMapWrapper don't complies with the IMap interface on v4.0. The 
following changes are needed:

Index: 
osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/v2/OsmdroidMapWra
pper.java
===================================================================
--- 
osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/v2/OsmdroidMapWra
pper.java   (revisión: 1395)
+++ 
osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/v2/OsmdroidMapWra
pper.java   (copia de trabajo)
@@ -169,17 +169,19 @@
                        mPolylines = new HashMap<Integer, PathOverlay>();
                }
                final PathOverlay overlay = new PathOverlay(aPolyline.color, aPolyline.width, getResourceProxy());
-               overlay.addPoints(aPolyline.points);
+        for (IGeoPoint point: aPolyline.points) {
+            overlay.addPoint(point);
+        } 
                mMapView.getOverlays().add(0, overlay); // add polyline overlay below markers, etc
                final int id = random.nextInt();
                mPolylines.put(id, overlay);
                return id;
        }

-       @Override
-       public void addPointsToPolyline(final int id, final IGeoPoint... 
aPoints) {
-               getPolyline(id).addPoints(aPoints);
-       }
+    @Override                                                                  

+    public void addPointToPolyline(final int id, final IGeoPoint aPoint) {     

+        getPolyline(id).addPoint(aPoint);                                      

+    }

        @Override
        public void clearPolyline(final int id) {

Original issue reported on code.google.com by mes...@sindominio.net on 8 Jan 2014 at 9:08

GoogleCodeExporter commented 9 years ago
A second patch implementing 'onCameraChange':

Index: 
osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/v2/OsmdroidMapWra
pper.java
===================================================================
--- 
osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/v2/OsmdroidMapWra
pper.java   (revisión: 1395)
+++ 
osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/v2/OsmdroidMapWra
pper.java   (copia de trabajo)
@@ -13,6 +13,7 @@
 import org.osmdroid.api.OnCameraChangeListener;
 import org.osmdroid.api.Polyline;
 import org.osmdroid.util.GeoPoint;
+import org.osmdroid.util.Position;
 import org.osmdroid.util.ResourceProxyImpl;
 import org.osmdroid.views.MapView;
 import org.osmdroid.views.overlay.ItemizedIconOverlay;
@@ -226,7 +229,11 @@

        private void onCameraChange() {
                if (mOnCameraChangeListener != null) {
-                       mOnCameraChangeListener.onCameraChange(null); // TODO 
set the parameter
+                       IGeoPoint center = getCenter();
+                       Position position = new Position(center.getLatitude(), 
center.getLongitude());
+                       position.setBearing(getBearing());
+                       position.setZoomLevel(getZoomLevel());
+                       mOnCameraChangeListener.onCameraChange(position);
                }
        }
 }

Original comment by mes...@sindominio.net on 8 Jan 2014 at 11:48

GoogleCodeExporter commented 9 years ago
The description of the 'clear()' function on IMap says:
"Removes all markers, polylines, polygons, overlays, etc from the map."

But the actual implementation of OsmdroidMapWrapper don't removes the overlays. 
Here there is a third patch to fix that:

Index: 
osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/v2/OsmdroidMapWra
pper.java
===================================================================
--- 
osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/v2/OsmdroidMapWra
pper.java   (revisión: 1395)
+++ 
osmdroid-third-party/src/main/java/org/osmdroid/google/wrapper/v2/OsmdroidMapWra
pper.java   (copia de trabajo)
@@ -205,11 +208,9 @@
                        mItemizedOverlay.removeAllItems();
                }
                if (mPolylines != null) {
-                       for(final PathOverlay polyline : mPolylines.values()) {
-                               
mMapView.getOverlays().remove(mPolylines.remove(polyline));
-                       }
                        mPolylines.clear();
                }
+               mMapView.getOverlays().clear();
        }

        @Override

Original comment by mes...@sindominio.net on 9 Jan 2014 at 10:37

GoogleCodeExporter commented 9 years ago
I don't understand your first point because IMap has a method 
addPointsToPolyline, not addPointToPolyline.

Your second point could be done, but I figured it's a lot of overhead when you 
may not actually need the position. If the caller needs it then it can also get 
it itself in the same way. The parameter is only there for consistency with 
Google Maps API v2.

Your third point is not right because IMap doesn't have a way to add overlays 
and therefore the implementation doesn't remove them.  Polylines are 
implemented as overlays which is why they're explicitly removed.  If you just 
remove all overlays then you will also remove MyLocationOverlay and anything 
else that may have been added.  Again, the comment is just copied from Google 
Maps API v2.

Original comment by neilboyd on 12 Jan 2014 at 7:30

GoogleCodeExporter commented 9 years ago
I see now that addPointsToPolyline is in the svn, it was not in the 4.0 version 
(what I'm using). Sorry.

I'm ok with discarding my patches. Maybe the documentation could be improved so 
we are not surprise by unexpected behavior, right now you need to read the 
actual implementation to know what will be the result of a method.

Original comment by mes...@sindominio.net on 13 Jan 2014 at 8:54