Skip to content

Commit

Permalink
Expose TileCacheBudget and Emissive Properties (#476)
Browse files Browse the repository at this point in the history
* Initial exposure of RasterArraySource, TileCacheBudget

* Update tileCacheBudget and RasterDataLayers

* Remove RasterArraySource
  • Loading branch information
pjleonard37 committed Apr 11, 2024
1 parent afdd568 commit 0d4b172
Show file tree
Hide file tree
Showing 34 changed files with 470 additions and 43 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,7 @@
### main

* Introduce `TileCacheBudget`, a property to set per-source cache budgets in either megabytes or tiles.
* Expose `iconColorSaturation`, `rasterArrayBand`, `rasterElevation`, `rasterEmissiveStrength`, `hillshadeEmissiveStrength`, and `fillExtrusionEmissiveStrength` on their respective layers.
* Mark `MapboxMapsOptions.get/setWorldview()` and `MapboxMapsOptions.get/setLanguage()` as experimental.
* Bump Pigeon to 17.1.2
* [iOS] Fix crash in `onStyleImageMissingListener`.
Expand Down
Expand Up @@ -713,6 +713,28 @@ class PointAnnotationController(private val delegate: ControllerDelegate) : _Poi
}
}

override fun setIconColorSaturation(
managerId: String,
iconColorSaturation: Double,
callback: (Result<Unit>) -> Unit
) {
val manager = delegate.getManager(managerId) as PointAnnotationManager
manager.iconColorSaturation = iconColorSaturation
callback(Result.success(Unit))
}

override fun getIconColorSaturation(
managerId: String,
callback: (Result<Double?>) -> Unit
) {
val manager = delegate.getManager(managerId) as PointAnnotationManager
if (manager.iconColorSaturation != null) {
callback(Result.success(manager.iconColorSaturation!!))
} else {
callback(Result.success(null))
}
}

override fun setIconTranslate(
managerId: String,
iconTranslate: List<Double?>,
Expand Down
Expand Up @@ -360,7 +360,7 @@ data class PointAnnotation(
val textTransform: TextTransform? = null,
/** The color of the icon. This can only be used with [SDF icons](/help/troubleshooting/using-recolorable-images-in-mapbox-maps/). */
val iconColor: Long? = null,
/** Controls the intensity of light emitted on the source features. This property works only with 3D light, i.e. when `lights` root property is defined. */
/** Controls the intensity of light emitted on the source features. */
val iconEmissiveStrength: Double? = null,
/** Fade out the halo towards the outside. */
val iconHaloBlur: Double? = null,
Expand All @@ -374,7 +374,7 @@ data class PointAnnotation(
val iconOpacity: Double? = null,
/** The color with which the text will be drawn. */
val textColor: Long? = null,
/** Controls the intensity of light emitted on the source features. This property works only with 3D light, i.e. when `lights` root property is defined. */
/** Controls the intensity of light emitted on the source features. */
val textEmissiveStrength: Double? = null,
/** The halo's fadeout distance towards the outside. */
val textHaloBlur: Double? = null,
Expand Down Expand Up @@ -527,7 +527,7 @@ data class PointAnnotationOptions(
val textTransform: TextTransform? = null,
/** The color of the icon. This can only be used with [SDF icons](/help/troubleshooting/using-recolorable-images-in-mapbox-maps/). */
val iconColor: Long? = null,
/** Controls the intensity of light emitted on the source features. This property works only with 3D light, i.e. when `lights` root property is defined. */
/** Controls the intensity of light emitted on the source features. */
val iconEmissiveStrength: Double? = null,
/** Fade out the halo towards the outside. */
val iconHaloBlur: Double? = null,
Expand All @@ -541,7 +541,7 @@ data class PointAnnotationOptions(
val iconOpacity: Double? = null,
/** The color with which the text will be drawn. */
val textColor: Long? = null,
/** Controls the intensity of light emitted on the source features. This property works only with 3D light, i.e. when `lights` root property is defined. */
/** Controls the intensity of light emitted on the source features. */
val textEmissiveStrength: Double? = null,
/** The halo's fadeout distance towards the outside. */
val textHaloBlur: Double? = null,
Expand Down Expand Up @@ -789,6 +789,8 @@ interface _PointAnnotationMessenger {
fun getTextPitchAlignment(managerId: String, callback: (Result<TextPitchAlignment?>) -> Unit)
fun setTextRotationAlignment(managerId: String, textRotationAlignment: TextRotationAlignment, callback: (Result<Unit>) -> Unit)
fun getTextRotationAlignment(managerId: String, callback: (Result<TextRotationAlignment?>) -> Unit)
fun setIconColorSaturation(managerId: String, iconColorSaturation: Double, callback: (Result<Unit>) -> Unit)
fun getIconColorSaturation(managerId: String, callback: (Result<Double?>) -> Unit)
fun setIconTranslate(managerId: String, iconTranslate: List<Double?>, callback: (Result<Unit>) -> Unit)
fun getIconTranslate(managerId: String, callback: (Result<List<Double?>?>) -> Unit)
fun setIconTranslateAnchor(managerId: String, iconTranslateAnchor: IconTranslateAnchor, callback: (Result<Unit>) -> Unit)
Expand Down Expand Up @@ -1747,6 +1749,46 @@ interface _PointAnnotationMessenger {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.mapbox_maps_flutter._PointAnnotationMessenger.setIconColorSaturation", codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val managerIdArg = args[0] as String
val iconColorSaturationArg = args[1] as Double
api.setIconColorSaturation(managerIdArg, iconColorSaturationArg) { result: Result<Unit> ->
val error = result.exceptionOrNull()
if (error != null) {
reply.reply(wrapError(error))
} else {
reply.reply(wrapResult(null))
}
}
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.mapbox_maps_flutter._PointAnnotationMessenger.getIconColorSaturation", codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val managerIdArg = args[0] as String
api.getIconColorSaturation(managerIdArg) { result: Result<Double?> ->
val error = result.exceptionOrNull()
if (error != null) {
reply.reply(wrapError(error))
} else {
val data = result.getOrNull()
reply.reply(wrapResult(data))
}
}
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.mapbox_maps_flutter._PointAnnotationMessenger.setIconTranslate", codec)
if (api != null) {
Expand Down
Expand Up @@ -116,6 +116,10 @@ void main() {
var textRotationAlignment = await manager.getTextRotationAlignment();
expect(TextRotationAlignment.MAP, textRotationAlignment);

await manager.setIconColorSaturation(1.0);
var iconColorSaturation = await manager.getIconColorSaturation();
expect(1.0, iconColorSaturation);

await manager.setIconTranslate([0.0, 1.0]);
var iconTranslate = await manager.getIconTranslate();
expect([0.0, 1.0], iconTranslate);
Expand Down
Expand Up @@ -32,6 +32,7 @@ void main() {
fillExtrusionBase: 1.0,
fillExtrusionColor: Colors.red.value,
fillExtrusionCutoffFadeRange: 1.0,
fillExtrusionEmissiveStrength: 1.0,
fillExtrusionFloodLightColor: Colors.red.value,
fillExtrusionFloodLightGroundAttenuation: 1.0,
fillExtrusionFloodLightGroundRadius: 1.0,
Expand Down Expand Up @@ -61,6 +62,7 @@ void main() {
expect(layer.fillExtrusionBase, 1.0);
expect(layer.fillExtrusionColor, Colors.red.value);
expect(layer.fillExtrusionCutoffFadeRange, 1.0);
expect(layer.fillExtrusionEmissiveStrength, 1.0);
expect(layer.fillExtrusionFloodLightColor, Colors.red.value);
expect(layer.fillExtrusionFloodLightGroundAttenuation, 1.0);
expect(layer.fillExtrusionFloodLightGroundRadius, 1.0);
Expand Down
Expand Up @@ -26,6 +26,7 @@ void main() {
maxZoom: 20.0,
slot: LayerSlot.BOTTOM,
hillshadeAccentColor: Colors.red.value,
hillshadeEmissiveStrength: 1.0,
hillshadeExaggeration: 1.0,
hillshadeHighlightColor: Colors.red.value,
hillshadeIlluminationAnchor: HillshadeIlluminationAnchor.MAP,
Expand All @@ -39,6 +40,7 @@ void main() {
expect(layer.slot, LayerSlot.BOTTOM);
expect(layer.visibility, Visibility.NONE);
expect(layer.hillshadeAccentColor, Colors.red.value);
expect(layer.hillshadeEmissiveStrength, 1.0);
expect(layer.hillshadeExaggeration, 1.0);
expect(layer.hillshadeHighlightColor, Colors.red.value);
expect(layer.hillshadeIlluminationAnchor, HillshadeIlluminationAnchor.MAP);
Expand Down
6 changes: 6 additions & 0 deletions example/integration_test/style/layer/raster_layer_test.dart
Expand Up @@ -29,12 +29,15 @@ void main() {
minZoom: 1.0,
maxZoom: 20.0,
slot: LayerSlot.BOTTOM,
rasterArrayBand: "abc",
rasterBrightnessMax: 1.0,
rasterBrightnessMin: 1.0,
rasterColor: Colors.red.value,
rasterColorMix: [0.0, 1.0, 2.0, 3.0],
rasterColorRange: [0.0, 1.0],
rasterContrast: 1.0,
rasterElevation: 1.0,
rasterEmissiveStrength: 1.0,
rasterFadeDuration: 1.0,
rasterHueRotate: 1.0,
rasterOpacity: 1.0,
Expand All @@ -47,12 +50,15 @@ void main() {
expect(layer.maxZoom, 20);
expect(layer.slot, LayerSlot.BOTTOM);
expect(layer.visibility, Visibility.NONE);
expect(layer.rasterArrayBand, "abc");
expect(layer.rasterBrightnessMax, 1.0);
expect(layer.rasterBrightnessMin, 1.0);
expect(layer.rasterColor, Colors.red.value);
expect(layer.rasterColorMix, [0.0, 1.0, 2.0, 3.0]);
expect(layer.rasterColorRange, [0.0, 1.0]);
expect(layer.rasterContrast, 1.0);
expect(layer.rasterElevation, 1.0);
expect(layer.rasterEmissiveStrength, 1.0);
expect(layer.rasterFadeDuration, 1.0);
expect(layer.rasterHueRotate, 1.0);
expect(layer.rasterOpacity, 1.0);
Expand Down
2 changes: 2 additions & 0 deletions example/integration_test/style/layer/symbol_layer_test.dart
Expand Up @@ -68,6 +68,7 @@ void main() {
textVariableAnchor: ["center", "left"],
textWritingMode: ["horizontal", "vertical"],
iconColor: Colors.red.value,
iconColorSaturation: 1.0,
iconEmissiveStrength: 1.0,
iconHaloBlur: 1.0,
iconHaloColor: Colors.red.value,
Expand Down Expand Up @@ -133,6 +134,7 @@ void main() {
expect(layer.textVariableAnchor, ["center", "left"]);
expect(layer.textWritingMode, ["horizontal", "vertical"]);
expect(layer.iconColor, Colors.red.value);
expect(layer.iconColorSaturation, 1.0);
expect(layer.iconEmissiveStrength, 1.0);
expect(layer.iconHaloBlur, 1.0);
expect(layer.iconHaloColor, Colors.red.value);
Expand Down
10 changes: 9 additions & 1 deletion example/integration_test/style/source/geojson_source_test.dart
Expand Up @@ -47,6 +47,8 @@ void main() {
lineMetrics: true,
generateId: true,
prefetchZoomDelta: 1.0,
tileCacheBudget:
TileCacheBudget.inMegabytes(TileCacheBudgetInMegabytes(size: 3)),
));

var source = await mapboxMap.style.getSource('source') as GeoJsonSource;
Expand Down Expand Up @@ -96,12 +98,18 @@ void main() {
var generateId = await source.generateId;
expect(generateId, true);

// TODO: Investigate why this check is suseptible to fail on iOS
// TODO: Investigate why this check is susceptible to fail on iOS
// https://mapbox.atlassian.net/browse/MAPSFLT-141
if (Platform.isAndroid) {
var prefetchZoomDelta = await source.prefetchZoomDelta;
expect(prefetchZoomDelta, 1.0);
}

var tileCacheBudget = await source.tileCacheBudget;
expect(tileCacheBudget?.size,
TileCacheBudget.inMegabytes(TileCacheBudgetInMegabytes(size: 3)).size);
expect(tileCacheBudget?.type,
TileCacheBudget.inMegabytes(TileCacheBudgetInMegabytes(size: 3)).type);
});
}
// End of generated file.
8 changes: 8 additions & 0 deletions example/integration_test/style/source/raster_source_test.dart
Expand Up @@ -29,6 +29,8 @@ void main() {
attribution: "abc",
volatile: true,
prefetchZoomDelta: 1.0,
tileCacheBudget:
TileCacheBudget.inMegabytes(TileCacheBudgetInMegabytes(size: 3)),
minimumTileUpdateInterval: 1.0,
maxOverscaleFactorForParentTiles: 1.0,
tileRequestsDelay: 1.0,
Expand Down Expand Up @@ -64,6 +66,12 @@ void main() {
var prefetchZoomDelta = await source.prefetchZoomDelta;
expect(prefetchZoomDelta, 1.0);

var tileCacheBudget = await source.tileCacheBudget;
expect(tileCacheBudget?.size,
TileCacheBudget.inMegabytes(TileCacheBudgetInMegabytes(size: 3)).size);
expect(tileCacheBudget?.type,
TileCacheBudget.inMegabytes(TileCacheBudgetInMegabytes(size: 3)).type);

var minimumTileUpdateInterval = await source.minimumTileUpdateInterval;
expect(minimumTileUpdateInterval, 1.0);

Expand Down
Expand Up @@ -29,6 +29,8 @@ void main() {
encoding: Encoding.TERRARIUM,
volatile: true,
prefetchZoomDelta: 1.0,
tileCacheBudget:
TileCacheBudget.inMegabytes(TileCacheBudgetInMegabytes(size: 3)),
minimumTileUpdateInterval: 1.0,
maxOverscaleFactorForParentTiles: 1.0,
tileRequestsDelay: 1.0,
Expand Down Expand Up @@ -64,6 +66,12 @@ void main() {
var prefetchZoomDelta = await source.prefetchZoomDelta;
expect(prefetchZoomDelta, 1.0);

var tileCacheBudget = await source.tileCacheBudget;
expect(tileCacheBudget?.size,
TileCacheBudget.inMegabytes(TileCacheBudgetInMegabytes(size: 3)).size);
expect(tileCacheBudget?.type,
TileCacheBudget.inMegabytes(TileCacheBudgetInMegabytes(size: 3)).type);

var minimumTileUpdateInterval = await source.minimumTileUpdateInterval;
expect(minimumTileUpdateInterval, 1.0);

Expand Down
8 changes: 8 additions & 0 deletions example/integration_test/style/source/vector_source_test.dart
Expand Up @@ -28,6 +28,8 @@ void main() {
attribution: "abc",
volatile: true,
prefetchZoomDelta: 1.0,
tileCacheBudget:
TileCacheBudget.inMegabytes(TileCacheBudgetInMegabytes(size: 3)),
minimumTileUpdateInterval: 1.0,
maxOverscaleFactorForParentTiles: 1.0,
tileRequestsDelay: 1.0,
Expand Down Expand Up @@ -60,6 +62,12 @@ void main() {
var prefetchZoomDelta = await source.prefetchZoomDelta;
expect(prefetchZoomDelta, 1.0);

var tileCacheBudget = await source.tileCacheBudget;
expect(tileCacheBudget?.size,
TileCacheBudget.inMegabytes(TileCacheBudgetInMegabytes(size: 3)).size);
expect(tileCacheBudget?.type,
TileCacheBudget.inMegabytes(TileCacheBudgetInMegabytes(size: 3)).type);

var minimumTileUpdateInterval = await source.minimumTileUpdateInterval;
expect(minimumTileUpdateInterval, 1.0);

Expand Down

0 comments on commit 0d4b172

Please sign in to comment.