diff options
author | tobrun <tobrun.van.nuland@gmail.com> | 2018-08-21 11:49:18 +0200 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2018-08-21 18:49:35 +0200 |
commit | 0218c01095bf0109ae23e268553eb741fe887f28 (patch) | |
tree | 81684ba2dcb790281424e4bb2a482c1b3d07fc8f | |
parent | a842c198acf0766beee786cb6eab079c67b9dfd2 (diff) | |
download | qtlocation-mapboxgl-0218c01095bf0109ae23e268553eb741fe887f28.tar.gz |
[android] - update map intializer for OfflineRegionDefintion with OfflineGeometryRegionDefinition
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | 44 |
1 files changed, 35 insertions, 9 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 aaed71ddec..d480d28f26 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 @@ -37,11 +37,13 @@ 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.maps.renderer.MapRenderer; import com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer; import com.mapbox.mapboxsdk.maps.renderer.textureview.TextureViewMapRenderer; import com.mapbox.mapboxsdk.maps.widgets.CompassView; import com.mapbox.mapboxsdk.net.ConnectivityReceiver; +import com.mapbox.mapboxsdk.offline.OfflineGeometryRegionDefinition; import com.mapbox.mapboxsdk.offline.OfflineRegionDefinition; import com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition; import com.mapbox.mapboxsdk.storage.FileSource; @@ -567,22 +569,46 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { return; } - OfflineTilePyramidRegionDefinition regionDefinition = (OfflineTilePyramidRegionDefinition) definition; - setStyleUrl(regionDefinition.getStyleURL()); + if (definition instanceof OfflineTilePyramidRegionDefinition) { + setOfflineTilePyramidRegionDefinition((OfflineTilePyramidRegionDefinition) definition); + } else if (definition instanceof OfflineGeometryRegionDefinition) { + setOfflineGeometryRegionDefinition((OfflineGeometryRegionDefinition) definition); + } else { + throw new UnsupportedOperationException("OfflineRegionDefintion instance not supported"); + } + } + + private void setOfflineRegionDefinition(String styleUrl, LatLng cameraTarget, double minZoom, double maxZoom) { CameraPosition cameraPosition = new CameraPosition.Builder() - .target(regionDefinition.getBounds().getCenter()) - .zoom(regionDefinition.getMinZoom()) + .target(cameraTarget) + .zoom(minZoom) .build(); - + setStyleUrl(styleUrl); if (!isMapInitialized()) { mapboxMapOptions.camera(cameraPosition); - mapboxMapOptions.minZoomPreference(regionDefinition.getMinZoom()); - mapboxMapOptions.maxZoomPreference(regionDefinition.getMaxZoom()); + mapboxMapOptions.minZoomPreference(minZoom); + mapboxMapOptions.maxZoomPreference(maxZoom); return; } mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); - mapboxMap.setMinZoomPreference(regionDefinition.getMinZoom()); - mapboxMap.setMaxZoomPreference(regionDefinition.getMaxZoom()); + mapboxMap.setMinZoomPreference(minZoom); + mapboxMap.setMaxZoomPreference(maxZoom); + } + + 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() + ); } // |