Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] consolitdated OfflineRegionDefinitions
Browse files Browse the repository at this point in the history
  • Loading branch information
“osana” committed Oct 30, 2018
1 parent 434f186 commit 18cd3dd
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@
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;
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;
import com.mapbox.mapboxsdk.utils.BitmapUtils;

Expand Down Expand Up @@ -553,21 +550,15 @@ public void setOfflineRegionDefinition(OfflineRegionDefinition definition) {
return;
}

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);
setStyleUrl(definition.getStyleURL());

if (!isMapInitialized()) {
mapboxMapOptions.camera(cameraPosition);
mapboxMapOptions.minZoomPreference(minZoom);
Expand All @@ -579,22 +570,6 @@ private void setOfflineRegionDefinition(String styleUrl, LatLng cameraTarget, do
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()
);
}

//
// Rendering
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
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;

import java.lang.reflect.Field;

Expand Down Expand Up @@ -114,22 +112,12 @@ public boolean setSessionIdRotationInterval(int interval) {

@Override
public void onCreateOfflineRegion(OfflineRegionDefinition offlineDefinition) {
MapEventFactory mapEventFactory = new MapEventFactory();

Event mapOfflineEvent;
if (offlineDefinition instanceof OfflineTilePyramidRegionDefinition) {
OfflineTilePyramidRegionDefinition tileDefinition =
(OfflineTilePyramidRegionDefinition)offlineDefinition;
mapOfflineEvent = mapEventFactory.buildMapOfflineEvent(
tileDefinition.getMinZoom(), tileDefinition.getMaxZoom(), "bounds",
new String[]{tileDefinition.getStyleURL()});
} else {
OfflineGeometryRegionDefinition geometryDefinition =
(OfflineGeometryRegionDefinition) offlineDefinition;
mapOfflineEvent = mapEventFactory.buildMapOfflineEvent(
geometryDefinition.getMinZoom(), geometryDefinition.getMaxZoom(), geometryDefinition.getGeometry().type(),
new String[]{geometryDefinition.getStyleURL()});
}
telemetry.push(
new MapEventFactory().buildMapOfflineEvent(
offlineDefinition.getMinZoom(),
offlineDefinition.getMaxZoom(),
offlineDefinition.getType(),
new String[]{offlineDefinition.getStyleURL()}));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ public OfflineGeometryRegionDefinition(Parcel parcel) {
this.pixelRatio = parcel.readFloat();
}

/*
* Getters
*/

@Override
public String getStyleURL() {
return styleURL;
}
Expand All @@ -93,18 +90,26 @@ public LatLngBounds getBounds() {
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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,51 @@
@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();

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,37 @@ public OfflineTilePyramidRegionDefinition(Parcel parcel) {
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
*/
Expand Down

0 comments on commit 18cd3dd

Please sign in to comment.