[android] consolitdated OfflineRegionDefinitions (#13180)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -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())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user