Skip to content

Commit 5578523

Browse files
committed
fix: Rollback styleString from MapLibreMapOptions and update related methods.
1 parent 9b822b2 commit 5578523

File tree

8 files changed

+30
-12
lines changed

8 files changed

+30
-12
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
1313

1414
### Changed
1515
* Rollback maplibre-gl to `4.7.1` version. (#660)
16-
* Removed `styleString` from internal MapLibreMapOptions class. (#660)
1716

1817
### Added
1918
* Added `onCameraMove` callback in the controller and in MapLibreMap class. (#643)

maplibre_gl/CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
### Changed
1010
* Rollback maplibre-gl to `4.7.1` version. (#660)
11-
* Removed `styleString` from internal MapLibreMapOptions class. (#660)
1211

1312
### Added
1413
* Added `onCameraMove` callback in the controller and in MapLibreMap class. (#643)

maplibre_gl/lib/src/maplibre_map.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ class _MapLibreMapOptions {
378378
_MapLibreMapOptions(
379379
{this.compassEnabled,
380380
this.cameraTargetBounds,
381+
this.styleString,
381382
this.minMaxZoomPreference,
382383
required this.rotateGesturesEnabled,
383384
required this.scrollGesturesEnabled,
@@ -402,6 +403,7 @@ class _MapLibreMapOptions {
402403
locationEnginePlatforms: map.locationEnginePlatforms,
403404
compassEnabled: map.compassEnabled,
404405
cameraTargetBounds: map.cameraTargetBounds,
406+
styleString: map.styleString,
405407
minMaxZoomPreference: map.minMaxZoomPreference,
406408
rotateGesturesEnabled: map.rotateGesturesEnabled,
407409
scrollGesturesEnabled: map.scrollGesturesEnabled,
@@ -426,6 +428,8 @@ class _MapLibreMapOptions {
426428

427429
final CameraTargetBounds? cameraTargetBounds;
428430

431+
final String? styleString;
432+
429433
final MinMaxZoomPreference? minMaxZoomPreference;
430434

431435
final bool rotateGesturesEnabled;
@@ -489,6 +493,7 @@ class _MapLibreMapOptions {
489493

490494
addIfNonNull('compassEnabled', compassEnabled);
491495
addIfNonNull('cameraTargetBounds', cameraTargetBounds?.toJson());
496+
addIfNonNull('styleString', styleString);
492497
addIfNonNull('minMaxZoomPreference', minMaxZoomPreference?.toJson());
493498

494499
addIfNonNull('rotateGesturesEnabled', rotateGesturesEnabled);

maplibre_gl_web/CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ See top-level [CHANGELOG.md](../CHANGELOG.md) for full details.
33
## [0.24.1](https://github.com/maplibre/flutter-maplibre-gl/compare/v0.24.0...v0.24.1)
44

55
* Rollback maplibre-gl to `4.7.1` version. (#660)
6-
* Removed `styleString` from internal MapLibreMapOptions class. (#660)
76

87
## 0.24.0
98

maplibre_gl_web/lib/src/convert.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
part of '../maplibre_gl_web.dart';
22

33
class Convert {
4+
/// Interprets the map options and applies them to the sink.
5+
///
6+
/// [ignoreStyle] if true, will not apply styleString changes.
7+
/// This is useful when the style is handled separately (like MapLibreMap initialization).
48
static void interpretMapLibreMapOptions(
5-
Map<String, dynamic> options, MapLibreMapOptionsSink sink) {
9+
Map<String, dynamic> options,
10+
MapLibreMapOptionsSink sink, {
11+
bool ignoreStyle = false,
12+
}) {
613
if (options.containsKey('cameraTargetBounds')) {
714
final bounds = options['cameraTargetBounds'][0];
815
if (bounds == null) {
@@ -19,6 +26,12 @@ class Convert {
1926
if (options.containsKey('compassEnabled')) {
2027
sink.setCompassEnabled(options['compassEnabled']);
2128
}
29+
if (options.containsKey('styleString') && !ignoreStyle) {
30+
final styleString = options['styleString'];
31+
if (styleString == null) return;
32+
33+
sink.setStyle(styleString);
34+
}
2235
if (options.containsKey('minMaxZoomPreference')) {
2336
sink.setMinMaxZoomPreference(options['minMaxZoomPreference'][0],
2437
options['minMaxZoomPreference'][1]);

maplibre_gl_web/lib/src/maplibre_web_gl_platform.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class MapLibreMapController extends MapLibrePlatform
9393
_initResizeObserver();
9494

9595
final options = _creationParams['options'] ?? {};
96-
Convert.interpretMapLibreMapOptions(options, this);
96+
Convert.interpretMapLibreMapOptions(options, this, ignoreStyle: true);
9797
}
9898

9999
void _initResizeObserver() {
@@ -178,8 +178,8 @@ class MapLibreMapController extends MapLibrePlatform
178178

179179
@override
180180
Future<CameraPosition?> updateMapOptions(
181-
Map<String, dynamic> optionsUpdate) async {
182-
// FIX: why is called indefinitely? (map_ui page)
181+
Map<String, dynamic> optionsUpdate,
182+
) async {
183183
Convert.interpretMapLibreMapOptions(optionsUpdate, this);
184184
return _getCameraPosition();
185185
}
@@ -444,7 +444,7 @@ class MapLibreMapController extends MapLibrePlatform
444444
if (filter != null) {
445445
parameters['filter'] = filter;
446446
}
447-
print(parameters);
447+
print('Query source features parameters: $parameters');
448448

449449
return _map
450450
.querySourceFeatures(sourceId, parameters)

maplibre_gl_web/lib/src/options_sink.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ abstract class MapLibreMapOptionsSink {
66

77
void setCompassEnabled(bool compassEnabled);
88

9+
// TODO: styleString is not actually a part of options. consider moving
10+
void setStyle(dynamic styleObject);
11+
912
void setMinMaxZoomPreference(num? min, num? max);
1013

1114
void setGestures({

maplibre_gl_web/lib/src/ui/map.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class MapLibreMap extends Camera {
143143
/// var mapDiv = document.getElementById('map');
144144
/// if (mapDiv.style.visibility === true) map.resize();
145145
MapLibreMap resize([dynamic eventData]) =>
146-
MapLibreMap.fromJsObject(jsObject.resize());
146+
MapLibreMap.fromJsObject(jsObject.resize(eventData));
147147

148148
/// Returns the map's geographical bounds. When the bearing or pitch is non-zero, the visible region is not
149149
/// an axis-aligned rectangle, and the result is the smallest bounds that encompasses the visible region.
@@ -230,7 +230,7 @@ class MapLibreMap extends Camera {
230230
/// If `null` or `undefined` is provided, the function removes the current minimum pitch (i.e. sets it to 0).
231231
/// @returns {MapLibreMap} `this`
232232
MapLibreMap setMinPitch([num? minPitch]) =>
233-
MapLibreMap.fromJsObject(jsObject.setMinPitch());
233+
MapLibreMap.fromJsObject(jsObject.setMinPitch(minPitch));
234234

235235
/// Returns the map's minimum allowable pitch.
236236
///
@@ -245,7 +245,7 @@ class MapLibreMap extends Camera {
245245
/// If `null` or `undefined` is provided, the function removes the current maximum pitch (sets it to 60).
246246
/// @returns {MapLibreMap} `this`
247247
MapLibreMap setMaxPitch([num? maxPitch]) =>
248-
MapLibreMap.fromJsObject(jsObject.setMaxPitch());
248+
MapLibreMap.fromJsObject(jsObject.setMaxPitch(maxPitch));
249249

250250
/// Returns the map's maximum allowable pitch.
251251
///
@@ -1268,7 +1268,7 @@ class MapOptions extends JsObjectWrapper<MapOptionsJsImpl> {
12681268
maxZoom: maxZoom,
12691269
minPitch: minPitch,
12701270
maxPitch: maxPitch,
1271-
style: style,
1271+
style: jsify(style),
12721272
boxZoom: boxZoom,
12731273
dragRotate: dragRotate,
12741274
dragPan: dragPan ?? true,

0 commit comments

Comments
 (0)