This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Arbitrary offline region shapes #11447
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e8b76aa
[core] offline region definition - add support for arbitrary geometries
ivovandongen 1a9326f
[android] arbitrary offline region geometries
ivovandongen 1a4cc2c
[darwin] arbitrary offline region geometries
ivovandongen f0a4dcb
[offline] Add option to pass geojson input file
ivovandongen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
...ndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineGeometryRegionDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package com.mapbox.mapboxsdk.offline; | ||
|
||
import android.os.Parcel; | ||
import android.os.Parcelable; | ||
|
||
import com.mapbox.geojson.Feature; | ||
import com.mapbox.geojson.Geometry; | ||
import com.mapbox.mapboxsdk.geometry.LatLngBounds; | ||
import com.mapbox.turf.TurfMeasurement; | ||
|
||
/** | ||
* An offline region defined by a style URL, geometry, zoom range, and | ||
* device pixel ratio. | ||
* <p> | ||
* Both minZoom and maxZoom must be ≥ 0, and maxZoom must be ≥ minZoom. | ||
* <p> | ||
* maxZoom may be ∞, in which case for each tile source, the region will include | ||
* tiles from minZoom up to the maximum zoom level provided by that source. | ||
* <p> | ||
* pixelRatio must be ≥ 0 and should typically be 1.0 or 2.0. | ||
*/ | ||
public class OfflineGeometryRegionDefinition implements OfflineRegionDefinition, Parcelable { | ||
|
||
private String styleURL; | ||
private Geometry geometry; | ||
private double minZoom; | ||
private double maxZoom; | ||
private float pixelRatio; | ||
|
||
/** | ||
* Constructor to create an OfflineGeometryRegionDefinition from parameters. | ||
* | ||
* @param styleURL the style | ||
* @param geometry the geometry | ||
* @param minZoom min zoom | ||
* @param maxZoom max zoom | ||
* @param pixelRatio pixel ratio of the device | ||
*/ | ||
public OfflineGeometryRegionDefinition( | ||
String styleURL, Geometry geometry, double minZoom, double maxZoom, float pixelRatio) { | ||
// Note: Also used in JNI | ||
this.styleURL = styleURL; | ||
this.geometry = geometry; | ||
this.minZoom = minZoom; | ||
this.maxZoom = maxZoom; | ||
this.pixelRatio = pixelRatio; | ||
} | ||
|
||
/** | ||
* Constructor to create an OfflineGeometryRegionDefinition from a Parcel. | ||
* | ||
* @param parcel the parcel to create the OfflineGeometryRegionDefinition from | ||
*/ | ||
public OfflineGeometryRegionDefinition(Parcel parcel) { | ||
this.styleURL = parcel.readString(); | ||
this.geometry = Feature.fromJson(parcel.readString()).geometry(); | ||
this.minZoom = parcel.readDouble(); | ||
this.maxZoom = parcel.readDouble(); | ||
this.pixelRatio = parcel.readFloat(); | ||
} | ||
|
||
/* | ||
* Getters | ||
*/ | ||
|
||
public String getStyleURL() { | ||
return styleURL; | ||
} | ||
|
||
public Geometry getGeometry() { | ||
return geometry; | ||
} | ||
|
||
/** | ||
* Calculates the bounding box for the Geometry it contains | ||
* to retain backwards compatibility | ||
* @return the {@link LatLngBounds} or null | ||
*/ | ||
@Override | ||
public LatLngBounds getBounds() { | ||
if (geometry == null) { | ||
return null; | ||
} | ||
|
||
double[] bbox = TurfMeasurement.bbox(geometry); | ||
return LatLngBounds.from(bbox[3], bbox[2], bbox[1], bbox[0]); | ||
} | ||
|
||
public double getMinZoom() { | ||
return minZoom; | ||
} | ||
|
||
public double getMaxZoom() { | ||
return maxZoom; | ||
} | ||
|
||
public float getPixelRatio() { | ||
return pixelRatio; | ||
} | ||
|
||
/* | ||
* Parceable | ||
*/ | ||
|
||
@Override | ||
public int describeContents() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void writeToParcel(Parcel dest, int flags) { | ||
dest.writeString(styleURL); | ||
dest.writeString(Feature.fromGeometry(geometry).toJson()); | ||
dest.writeDouble(minZoom); | ||
dest.writeDouble(maxZoom); | ||
dest.writeFloat(pixelRatio); | ||
} | ||
|
||
public static final Creator CREATOR = new Creator() { | ||
public OfflineGeometryRegionDefinition createFromParcel(Parcel in) { | ||
return new OfflineGeometryRegionDefinition(in); | ||
} | ||
|
||
public OfflineGeometryRegionDefinition[] newArray(int size) { | ||
return new OfflineGeometryRegionDefinition[size]; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
geometry_collection
isn't supported bymbgl::util::TileCover
. How would this be used in defining an offline region?(
MultiPoint
,MultiLineString
, andMultiPolygon
are supported)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be a recursive definition then. Is there any reason not to support it?
Mainly the types the interface accepts should be implemented right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The streaming Tile cover algorithm we are using works on homogeneous geometry types. A mixed type like
geometry_collection
would have to be run on each of the contained types separately and would return duplicates. It might also not return tiles in a consistent order.