diff options
author | Osana Babayan <32496536+osana@users.noreply.github.com> | 2018-10-30 15:31:04 -0400 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2018-10-31 14:53:56 +0100 |
commit | cfe21330d67c0336d518ffa29dd1d534e062ac5b (patch) | |
tree | 5ad5c227678c196ee38bbc711d53a46b34e8e330 /platform | |
parent | 48bbaa6c6ed2306c59fcab58d455bdeb5ddc91c3 (diff) | |
download | qtlocation-mapboxgl-cfe21330d67c0336d518ffa29dd1d534e062ac5b.tar.gz |
[android] consolitdated OfflineRegionDefinitions (#13180)
Diffstat (limited to 'platform')
5 files changed, 80 insertions, 59 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index 4b6e0a03af..7411ace6a4 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -32,7 +32,6 @@ import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.constants.Style; -import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.location.LocationComponent; import com.mapbox.mapboxsdk.maps.renderer.MapRenderer; import com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer; @@ -525,46 +524,24 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { * @see OfflineRegionDefinition */ public void setOfflineRegionDefinition(OfflineRegionDefinition definition) { - if (definition instanceof OfflineTilePyramidRegionDefinition) { - setOfflineTilePyramidRegionDefinition((OfflineTilePyramidRegionDefinition) definition); - } else if (definition instanceof OfflineGeometryRegionDefinition) { - setOfflineGeometryRegionDefinition((OfflineGeometryRegionDefinition) definition); - } else { - throw new UnsupportedOperationException("OfflineRegionDefintion instance not supported"); - } - } + double minZoom = definition.getMinZoom(); + double maxZoom = definition.getMaxZoom(); - private void setOfflineRegionDefinition(String styleUrl, LatLng cameraTarget, double minZoom, double maxZoom) { CameraPosition cameraPosition = new CameraPosition.Builder() - .target(cameraTarget) + .target(definition.getBounds().getCenter()) .zoom(minZoom) .build(); - setStyleUrl(styleUrl); - if (mapboxMap != null) { - mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); - mapboxMap.setMinZoomPreference(minZoom); - mapboxMap.setMaxZoomPreference(maxZoom); - } else { + setStyleUrl(definition.getStyleURL()); + + if (mapboxMap == null) { mapboxMapOptions.camera(cameraPosition); mapboxMapOptions.minZoomPreference(minZoom); mapboxMapOptions.maxZoomPreference(maxZoom); + return; } - } - - private void setOfflineTilePyramidRegionDefinition(OfflineTilePyramidRegionDefinition regionDefinition) { - setOfflineRegionDefinition(regionDefinition.getStyleURL(), - regionDefinition.getBounds().getCenter(), - regionDefinition.getMinZoom(), - regionDefinition.getMaxZoom() - ); - } - - private void setOfflineGeometryRegionDefinition(OfflineGeometryRegionDefinition regionDefinition) { - setOfflineRegionDefinition(regionDefinition.getStyleURL(), - regionDefinition.getBounds().getCenter(), - regionDefinition.getMinZoom(), - regionDefinition.getMaxZoom() - ); + mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); + mapboxMap.setMinZoomPreference(minZoom); + mapboxMap.setMaxZoomPreference(maxZoom); } // diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/TelemetryImpl.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/TelemetryImpl.java index c083fb98d6..ad761ac965 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/TelemetryImpl.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/TelemetryImpl.java @@ -15,7 +15,6 @@ import com.mapbox.mapboxsdk.MapStrictMode; import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.log.Logger; import com.mapbox.mapboxsdk.maps.TelemetryDefinition; -import com.mapbox.mapboxsdk.offline.OfflineGeometryRegionDefinition; import com.mapbox.mapboxsdk.offline.OfflineRegionDefinition; import com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition; @@ -117,24 +116,12 @@ public class TelemetryImpl implements TelemetryDefinition { @Override public void onCreateOfflineRegion(@NonNull OfflineRegionDefinition offlineDefinition) { MapEventFactory mapEventFactory = new MapEventFactory(); - - if (offlineDefinition instanceof OfflineTilePyramidRegionDefinition) { - OfflineTilePyramidRegionDefinition tileDefinition = - (OfflineTilePyramidRegionDefinition)offlineDefinition; - telemetry.push(mapEventFactory.createOfflineDownloadStartEvent( - "tileregion", - tileDefinition.getMinZoom(), - tileDefinition.getMaxZoom(), - tileDefinition.getStyleURL())); - } else { - OfflineGeometryRegionDefinition geometryDefinition = - (OfflineGeometryRegionDefinition) offlineDefinition; - telemetry.push(mapEventFactory.createOfflineDownloadStartEvent( - "shaperegion", - geometryDefinition.getMinZoom(), - geometryDefinition.getMaxZoom(), - geometryDefinition.getStyleURL())); - } + telemetry.push(mapEventFactory.createOfflineDownloadStartEvent( + offlineDefinition instanceof OfflineTilePyramidRegionDefinition ? "tileregion" : "shaperegion", + offlineDefinition.getMinZoom(), + offlineDefinition.getMaxZoom(), + offlineDefinition.getStyleURL()) + ); } /** diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineGeometryRegionDefinition.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineGeometryRegionDefinition.java index 73e277dda3..97225e7283 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineGeometryRegionDefinition.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineGeometryRegionDefinition.java @@ -66,10 +66,7 @@ public class OfflineGeometryRegionDefinition implements OfflineRegionDefinition, this.pixelRatio = parcel.readFloat(); } - /* - * Getters - */ - + @Override public String getStyleURL() { return styleURL; } @@ -93,18 +90,26 @@ public class OfflineGeometryRegionDefinition implements OfflineRegionDefinition, return LatLngBounds.from(bbox[3], bbox[2], bbox[1], bbox[0]); } + @Override public double getMinZoom() { return minZoom; } + @Override public double getMaxZoom() { return maxZoom; } + @Override public float getPixelRatio() { return pixelRatio; } + @Override + public String getType() { + return "shaperegion"; + } + /* * Parceable */ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionDefinition.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionDefinition.java index d1b18445fa..2631f74ccf 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionDefinition.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionDefinition.java @@ -12,6 +12,51 @@ import com.mapbox.mapboxsdk.geometry.LatLngBounds; @Keep public interface OfflineRegionDefinition { + /** + * Gets the bounds of the OfflineRegion. + * + * @return the bounds of the OfflineRegion. + */ LatLngBounds getBounds(); + /** + * Returns the map style url of the OfflineRegion. + * + * @return The URL of the map style. + * @since 7.0.0 + */ + String getStyleURL(); + + /** + * Gets the minimum zoom level the OfflineRegion map can be displayed at. + * + * @return The minimum zoom level. + * @since 7.0.0 + */ + double getMinZoom(); + + /** + * Gets the maximum zoom level the OfflineRegion map can be displayed at. + * + * @return The maximum zoom level. + * @since 7.0.0 + */ + double getMaxZoom(); + + /** + * Gets the pixel ratio of the OfflineRegion map. + * + * @return The pixel ratio of the OfflineRegion map. + * @since 7.0.0 + */ + float getPixelRatio(); + + /** + * Gest the type of the OfflineRegionDefinition for telemetry ("tileregion", "shaperegion"). + * + * @return The type of the OfflineRegionDefinition. + * @since 7.0.0 + */ + String getType(); + } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineTilePyramidRegionDefinition.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineTilePyramidRegionDefinition.java index b0d12859ed..7458481d71 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineTilePyramidRegionDefinition.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineTilePyramidRegionDefinition.java @@ -67,30 +67,37 @@ public class OfflineTilePyramidRegionDefinition implements OfflineRegionDefiniti this.pixelRatio = parcel.readFloat(); } - /* - * Getters - */ + @Override public String getStyleURL() { return styleURL; } + @Override public LatLngBounds getBounds() { return bounds; } + @Override public double getMinZoom() { return minZoom; } + @Override public double getMaxZoom() { return maxZoom; } + @Override public float getPixelRatio() { return pixelRatio; } + @Override + public String getType() { + return "tileregion"; + } + /* * Parceable */ |