Skip to content

Commit b152324

Browse files
pjleonard37Release SDK bot for Maps SDK teamevil159
authored andcommitted
Update Standard Style Interactions Examples, Fix Bug (#865)
* Update examples * Group newer examples together --------- Co-authored-by: Release SDK bot for Maps SDK team <[email protected]> Co-authored-by: Roman Laitarenko <[email protected]>
1 parent a4b4651 commit b152324

File tree

6 files changed

+320
-102
lines changed

6 files changed

+320
-102
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
> The iOS minimum deployment target is now iOS 14.0.
66
77
* Update Maps SDK to 11.10.0
8-
* Fix Android throwing NPE when converting a map with null values to a `Value`.
8+
* [Android] Fix bug in `.setStyleImportConfigProperties()` where map values were not being set correctly.
9+
* [Android] Fix throwing NPE when converting a map with null values to a `Value`.
910
* Align tap propagation behavior on Android and iOS.
1011
* Introduce the experimental Interactions API, a toolset that allows you to handle interactions on both layers and basemap features for styles. This API introduces a new concept called `Featureset`, which allows Evolving Basemap styles, such as Standard, to export an abstract set of features, such as POI, buildings, and place labels, regardless of which layers they are rendered on. An `Interaction` can then be targeted to these features, modifying their state when interacted with. For example, you can add a `TapInteraction` to your map which targets the `buildings` `Featureset`. When a user taps on a building, the building will be highlighted and its color will change to blue.
1112

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class StyleController(private val context: Context, private val styleManager: Ma
114114
override fun setStyleImportConfigProperties(importId: String, configs: Map<String, Any>) {
115115
styleManager.setStyleImportConfigProperties(
116116
importId,
117-
configs.mapValues { it.toValue() } as HashMap<String, Value>
117+
configs.mapValues { it.value.toValue() } as HashMap<String, Value>
118118
)
119119
}
120120

example/lib/interactive_features_example.dart

Lines changed: 0 additions & 98 deletions
This file was deleted.

example/lib/main.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import 'package:mapbox_maps_example/ornaments_example.dart';
1010
import 'package:mapbox_maps_example/geojson_line_example.dart';
1111
import 'package:mapbox_maps_example/image_source_example.dart';
1212
import 'package:mapbox_maps_example/map_interface_example.dart';
13-
import 'package:mapbox_maps_example/interactive_features_example.dart';
13+
import 'package:mapbox_maps_example/standard_style_import_example.dart';
14+
import 'package:mapbox_maps_example/standard_style_interactions_example.dart';
1415
import 'package:mapbox_maps_example/polygon_annotations_example.dart';
1516
import 'package:mapbox_maps_example/polyline_annotations_example.dart';
1617
import 'package:mapbox_maps_example/simple_map_example.dart';
@@ -40,9 +41,10 @@ final List<Example> _allPages = <Example>[
4041
ModelLayerExample(),
4142
DebugOptionsExample(),
4243
SpinningGlobeExample(),
44+
StandardStyleImportExample(),
45+
StandardStyleInteractionsExample(),
4346
FullMapExample(),
4447
StyleExample(),
45-
InteractiveFeaturesExample(),
4648
CameraExample(),
4749
ProjectionExample(),
4850
MapInterfaceExample(),
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import 'dart:convert';
2+
import 'package:flutter/material.dart';
3+
import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart';
4+
import 'example.dart';
5+
6+
class StandardStyleImportExample extends StatefulWidget implements Example {
7+
@override
8+
final Widget leading = const Icon(Icons.touch_app);
9+
@override
10+
final String title = 'Standard Style Import';
11+
@override
12+
final String? subtitle = 'Configure the Standard Style and add interactions';
13+
14+
const StandardStyleImportExample({super.key});
15+
16+
@override
17+
State<StatefulWidget> createState() => StandardStyleImportState();
18+
}
19+
20+
class StandardStyleImportState extends State<StandardStyleImportExample> {
21+
StandardStyleImportState();
22+
MapboxMap? mapboxMap;
23+
24+
/// Style import config properties
25+
String lightPreset = 'day';
26+
bool labelsSetting = true;
27+
28+
_onMapCreated(MapboxMap mapboxMap) {
29+
this.mapboxMap = mapboxMap;
30+
mapboxMap.style;
31+
32+
// When the map is ready, add a tap interaction to show a snackbar with the name of the place that was tapped
33+
mapboxMap
34+
.addInteraction(TapInteraction(StandardPlaceLabels(), (feature, _) {
35+
ScaffoldMessenger.of(context).showSnackBar(
36+
SnackBar(content: Text("Tapped place: ${feature.name}")),
37+
);
38+
}));
39+
}
40+
41+
@override
42+
Widget build(BuildContext context) {
43+
return Scaffold(
44+
floatingActionButton: Column(
45+
mainAxisAlignment: MainAxisAlignment.end,
46+
children: [
47+
FloatingActionButton(
48+
heroTag: 'light',
49+
onPressed: _changeLightSetting,
50+
child: Icon(Icons.wb_sunny),
51+
),
52+
SizedBox(height: 16),
53+
FloatingActionButton(
54+
heroTag: 'labels',
55+
onPressed: _changeLabelsSetting,
56+
child: Icon(Icons.label),
57+
),
58+
],
59+
),
60+
body: Stack(children: [
61+
MapWidget(
62+
key: ValueKey("mapWidget"),
63+
cameraOptions: CameraOptions(
64+
center: Point(coordinates: Position(-73.99, 40.72)),
65+
zoom: 11,
66+
pitch: 45),
67+
styleUri: MapboxStyles.STANDARD,
68+
textureView: true,
69+
onMapCreated: _onMapCreated,
70+
onStyleLoadedListener: _onStyleLoaded,
71+
)
72+
]));
73+
}
74+
75+
_onStyleLoaded(StyleLoadedEventData styleLoadedEventData) {
76+
// When the style has finished loading add a line layer representing the border between New York and New Jersey
77+
_addLineLayer();
78+
}
79+
80+
void _addLineLayer() {
81+
final lineLayer = LineLayer(
82+
id: 'line-layer',
83+
sourceId: 'line-layer',
84+
lineColor: Colors.orange.value,
85+
lineWidth: 8,
86+
);
87+
88+
final line = LineString(coordinates: [
89+
Position(-73.91912400100642, 40.913503418907936),
90+
Position(-73.9615887363045, 40.82943110786286),
91+
Position(-74.01409059085539, 40.75461056309348),
92+
Position(-74.02798814058939, 40.69522028220487),
93+
Position(-74.05655532615407, 40.65188756398558),
94+
Position(-74.13916853846217, 40.64339339389301),
95+
]);
96+
97+
final lineSource = GeoJsonSource(
98+
id: 'line-layer',
99+
data: json.encode(line),
100+
);
101+
102+
mapboxMap?.style.addSource(lineSource);
103+
mapboxMap?.style.addLayer(lineLayer);
104+
}
105+
106+
void _changeLightSetting() {
107+
final presets = ['dawn', 'day', 'dusk', 'night'];
108+
final currentIndex = presets.indexOf(lightPreset);
109+
setState(() {
110+
lightPreset = presets[(currentIndex + 1) % presets.length];
111+
_updateMapStyle();
112+
});
113+
}
114+
115+
// Toggle the visibility of the labels
116+
void _changeLabelsSetting() {
117+
setState(() {
118+
labelsSetting = !labelsSetting;
119+
_updateMapStyle();
120+
});
121+
}
122+
123+
void _updateMapStyle() {
124+
// Update the map style's config properties based on the selected options
125+
var configs = {
126+
"lightPreset": lightPreset,
127+
"showPointOfInterestLabels": labelsSetting,
128+
"showTransitLabels": labelsSetting,
129+
"showPlaceLabels": labelsSetting,
130+
};
131+
mapboxMap?.style.setStyleImportConfigProperties("basemap", configs);
132+
}
133+
}

0 commit comments

Comments
 (0)