Skip to content

Commit efa96f4

Browse files
pjleonard37Release SDK bot for Maps SDK team
andauthored
Update Android Expression handling (#1014)
* Update Android expression handling * Fix ktlint --------- Co-authored-by: Release SDK bot for Maps SDK team <[email protected]>
1 parent 45cc334 commit efa96f4

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
### main
22

3+
* Fix Mapbox expression handling on Android by converting List expressions starting with strings to JSON format.
4+
35
### 2.10.0
46

57
* Update Maps SDK to v11.14.0

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/Extentions.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,11 @@ fun Any.toValue(): Value {
988988
val valueArray = this.map { it?.toValue() }
989989
Value(valueArray)
990990
} else if (this is List<*>) {
991+
// Any List starting with a string is potentially a Mapbox expression.
992+
// Convert it to JSON string.
993+
if (this.isNotEmpty() && this[0] is String) {
994+
return Gson().toJson(this).toValue()
995+
}
991996
val valueArray = this.map { it?.toValue() }
992997
Value(valueArray)
993998
} else if (this is HashMap<*, *>) {

example/integration_test/style/style_test.dart

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,73 @@ void main() {
765765
expect(styleImports[1]?.type, "import");
766766
expect(styleImports.length, 2);
767767
});
768+
769+
testWidgets('Match expression with concat type mismatch', (WidgetTester tester) async {
770+
final mapFuture = app.main();
771+
await tester.pumpAndSettle();
772+
final mapboxMap = await mapFuture;
773+
var style = mapboxMap.style;
774+
775+
// Create a GeoJSON source with features that have numeric properties
776+
var geoJsonData = {
777+
"type": "FeatureCollection",
778+
"features": [
779+
{
780+
"type": "Feature",
781+
"properties": {
782+
"testProperty": 123,
783+
"testProperty2": 456
784+
},
785+
"geometry": {
786+
"type": "Point",
787+
"coordinates": [20, 60]
788+
}
789+
}
790+
]
791+
};
792+
793+
var source = {
794+
"type": "geojson",
795+
"data": geoJsonData
796+
};
797+
798+
await style.addStyleSource('test-source', json.encode(source));
799+
800+
var matchExpression = [
801+
"match",
802+
["concat", ["get", "testProperty"], ["get", "testProperty2"]],
803+
"123456", "red",
804+
"5234534", "green",
805+
"yellow"
806+
];
807+
808+
// Create the layer without the expression
809+
var layer = {
810+
"id": "test-layer",
811+
"type": "circle",
812+
"source": "test-source",
813+
"paint": {
814+
"circle-radius": 10,
815+
}
816+
};
817+
await style.addStyleLayer(json.encode(layer), null);
818+
819+
// Then set the expression using setStyleLayerProperty
820+
// This now works on both iOS and Android after the fix
821+
await style.setStyleLayerProperty("test-layer", "circle-color", matchExpression);
822+
823+
// Verify that the expression was set correctly
824+
var retrievedProperty = await style.getStyleLayerProperty("test-layer", "circle-color");
825+
826+
var retrievedExpression = retrievedProperty.value as List;
827+
expect(retrievedExpression[0], "match");
828+
expect(retrievedExpression[1], matchExpression[1]);
829+
expect(retrievedExpression[2], "123456");
830+
expect(retrievedExpression[3], ['rgba', 255.0, 0.0, 0.0, 1.0]);
831+
expect(retrievedExpression[4], "5234534");
832+
expect(retrievedExpression[5], ['rgba', 0.0, 128.0, 0.0, 1.0]);
833+
expect(retrievedExpression[6], ['rgba', 255.0, 255.0, 0.0, 1.0]);
834+
});
768835
}
769836

770837
extension ToJSON on TransitionOptions {

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ packages:
269269
path: ".."
270270
relative: true
271271
source: path
272-
version: "2.10.0-rc.1"
272+
version: "2.10.0"
273273
matcher:
274274
dependency: transitive
275275
description:

0 commit comments

Comments
 (0)