Skip to content

Commit

Permalink
Merge branch 'tilesets'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnative committed Jan 15, 2025
2 parents 3c76a6f + e452ac2 commit 58da712
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class TileRegionPack(var name: String, var state: TileRegionPackState = TileRegi

// stored in metadata for resume functionality
var styleURI: String? = null
var tilesets: List<String> = emptyList()
var bounds: Geometry? = null
var zoomRange: ZoomRange? = null

Expand Down Expand Up @@ -79,17 +80,20 @@ class TileRegionPack(var name: String, var state: TileRegionPackState = TileRegi
name: String,
state: TileRegionPackState = TileRegionPackState.UNKNOWN,
styleURI: String,
tilesets: List<String>,
bounds: Geometry,
zoomRange: ZoomRange,
metadata: JSONObject
) : this(name= name, state= state,progress= null, metadata= metadata) {
) : this(name= name, state= state, progress= null, metadata= metadata) {
val rnmeta = JSONObject()
rnmeta.put("styleURI", styleURI)
this.styleURI = styleURI
rnmeta.put("bounds", bounds.toJSONObject())
this.bounds = bounds
rnmeta.put("zoomRange", JSONArray(arrayOf(zoomRange.minZoom, zoomRange.maxZoom)))
this.zoomRange = zoomRange
rnmeta.put("tilesets", JSONArray(tilesets))
this.tilesets = tilesets
this.metadata.put(RNMapboxInfoMetadataKey, rnmeta);
}
}
Expand Down Expand Up @@ -143,9 +147,11 @@ class RNMBXOfflineModule(private val mReactContext: ReactApplicationContext) :
val boundsFC = FeatureCollection.fromJson(boundsStr)
val bounds = convertPointPairToBounds(boundsFC)

val tilesets = options.getArray("tilesets")?.toArrayList()?.map { it as String } ?: emptyList()
val actPack = TileRegionPack(
name = id,
styleURI = options.getString("styleURL")!!,
tilesets = tilesets,
bounds = bounds,
zoomRange = ZoomRange(
minZoom = options.getInt("minZoom").toByte(),
Expand Down Expand Up @@ -280,30 +286,25 @@ class RNMBXOfflineModule(private val mReactContext: ReactApplicationContext) :
?: return Result.failure(IllegalArgumentException("startLoading failed as there is no styleURI in pack"))
val metadata = pack.metadata
?: return Result.failure(IllegalArgumentException("startLoading failed as there is no metadata in pack"))

val stylePackOptions = StylePackLoadOptions.Builder()
.glyphsRasterizationMode(GlyphsRasterizationMode.IDEOGRAPHS_RASTERIZED_LOCALLY)
.metadata(metadata.toMapboxValue())
.build()

val descriptorOptions = TilesetDescriptorOptions.Builder()
.styleURI(styleURI)
.minZoom(zoomRange.minZoom)
.maxZoom(zoomRange.maxZoom)
.stylePackOptions(stylePackOptions)
.pixelRatio(2.0f)
.build()
val tilesetDescriptor = offlineManager.createTilesetDescriptor(descriptorOptions)

val descriptors = getTilesetDescriptors(
offlineManager = offlineManager,
styleURI = styleURI,
minZoom = zoomRange.minZoom,
maxZoom = zoomRange.maxZoom,
stylePackOptions = stylePackOptions,
tilesets = pack.tilesets)
val loadOptions = TileRegionLoadOptions.Builder()
.geometry(bounds)
.descriptors(arrayListOf(tilesetDescriptor))
.descriptors(descriptors)
.metadata(metadata.toMapboxValue())
.acceptExpired(true)
.networkRestriction(NetworkRestriction.NONE)
.averageBytesPerSecond(null)
.build()

var lastProgress: TileRegionLoadProgress? = null
val task = this.tileStore.loadTileRegion(
id, loadOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import com.mapbox.common.toValue
import com.mapbox.maps.OfflineManager
import com.mapbox.maps.OfflineRegionManager
import com.mapbox.maps.ResourceOptions
import com.mapbox.maps.StylePackLoadOptions
import com.mapbox.maps.TilesetDescriptorOptions
import com.mapbox.maps.TilesetDescriptorOptionsForTilesets
import com.mapbox.common.TilesetDescriptor

fun getOfflineRegionManager(getAccessToken: () -> String): OfflineRegionManager {
return OfflineRegionManager(ResourceOptions.Builder().accessToken(getAccessToken()).build())
Expand All @@ -20,6 +24,28 @@ fun getOfflineManager(tileStore: TileStore, getAccessToken: () -> String): Offli
)
}

fun getTilesetDescriptors(offlineManager: OfflineManager, styleURI: String, minZoom: Byte, maxZoom: Byte, stylePackOptions: StylePackLoadOptions, tilesets: List<String>): ArrayList<TilesetDescriptor>{
val descriptorOptions = TilesetDescriptorOptions.Builder()
.styleURI(styleURI)
.minZoom(minZoom)
.maxZoom(maxZoom)
.stylePackOptions(stylePackOptions)
.pixelRatio(2.0f)
.build()
val descriptor = offlineManager.createTilesetDescriptor(descriptorOptions)
val tilesetDescriptorOptions = TilesetDescriptorOptionsForTilesets.Builder()
.tilesets(tilesets)
.minZoom(minZoom)
.maxZoom(maxZoom)
.build()
val tilesetDescriptor = offlineManager.createTilesetDescriptor(tilesetDescriptorOptions)
val descriptors = arrayListOf(descriptor)
if (tilesets.isNotEmpty()) {
descriptors.add(tilesetDescriptor)
}
return descriptors
}

fun TileStore.setAccessToken(token: String) {
this.setOption(TileStoreOptions.MAPBOX_ACCESS_TOKEN, token.toValue());
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,45 @@ import com.mapbox.common.MapboxOptions
import com.mapbox.common.TileStore
import com.mapbox.maps.OfflineManager
import com.mapbox.maps.OfflineRegionManager
import com.mapbox.maps.StylePackLoadOptions
import com.mapbox.maps.TilesetDescriptorOptions
import com.mapbox.common.TilesetDescriptor

fun getOfflineRegionManager(getAccessToken: () -> String): OfflineRegionManager {
return OfflineRegionManager()
}

fun getOfflineManager(tileStore: TileStore, getAccessToken: () -> String): OfflineManager {
return OfflineManager()
}

fun getTilesetDescriptors(offlineManager: OfflineManager, styleURI: String, minZoom: Byte, maxZoom: Byte, stylePackOptions: StylePackLoadOptions, tilesets: List<String>): ArrayList<TilesetDescriptor>{
if (tilesets.isNotEmpty()) {
val descriptorOptions = TilesetDescriptorOptions.Builder()
.styleURI(styleURI)
.minZoom(minZoom)
.maxZoom(maxZoom)
// TODO: When tilesets is passed in the mappack doesn't save -- not sure why
// .tilesets(tilesets)
.stylePackOptions(stylePackOptions)
.pixelRatio(2.0f)
.build()
val descriptor = offlineManager.createTilesetDescriptor(descriptorOptions)
val descriptors = arrayListOf(descriptor)
return descriptors
}
val descriptorOptions = TilesetDescriptorOptions.Builder()
.styleURI(styleURI)
.minZoom(minZoom)
.maxZoom(maxZoom)
.stylePackOptions(stylePackOptions)
.pixelRatio(2.0f)
.build()
val descriptor = offlineManager.createTilesetDescriptor(descriptorOptions)
val descriptors = arrayListOf(descriptor)
return descriptors
}

fun TileStore.setAccessToken(token: String) {
MapboxOptions.accessToken = token
}
2 changes: 1 addition & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ org.gradle.jvmargs=-Xmx2560m -XX:MaxMetaspaceSize=1024m
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true

RNMBX11=false
RNMBX11=true

# Use this property to specify which architecture you want to build.
# You can also override it from the CLI using
Expand Down
37 changes: 37 additions & 0 deletions example/ios/RNMapboxGLExample/PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>CA92.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>C617.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategorySystemBootTime</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>35F9.1</string>
</array>
</dict>
</array>
<key>NSPrivacyCollectedDataTypes</key>
<array/>
<key>NSPrivacyTracking</key>
<false/>
</dict>
</plist>
5 changes: 5 additions & 0 deletions example/src/examples/Map/OfflineExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ const OfflineExample = () => {
const options = {
name: packName,
styleURL: STYLE_URL,
tilesets: [
'mapbox://mapbox.mapbox-streets-v8',
'mapbox://mapbox.mapbox-terrain-dem-v1',
'mapbox://mapbox.country-boundaries-v1',
], // Any tilesets that should be included in the offline download
bounds: [
[bounds[0], bounds[1]],
[bounds[2], bounds[3]],
Expand Down
Loading

0 comments on commit 58da712

Please sign in to comment.