Skip to content

Commit 9b822b2

Browse files
gabbopalmaCopilot
andauthored
fix: Rollback maplibre-gl version to 4.7.1 (#660)
### Description Closes #651 and #654. - Roll back `maplibre-gl` (web) to `4.7.1` for stability/compatibility of current example, not working with >5.x versions. - Read in #651 the causes of the example not working. - Remove `styleString` from internal `MapLibreMapOptions` (dead/duplicated with runtime style APIs). - Added `styleString` handling directly to `MapLibreMap` constructor initialized. ### Impact No public API changes; internal cleanup only. No migration required. --------- Co-authored-by: Copilot <[email protected]>
1 parent 00c8274 commit 9b822b2

File tree

8 files changed

+84
-55
lines changed

8 files changed

+84
-55
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## [0.24.1](https://github.com/maplibre/flutter-maplibre-gl/compare/v0.24.0...v0.24.1)
7+
8+
### Fixed
9+
* Annotation tap call callbacks twice. (#652)
10+
* Annotation APIs: use null-aware access for manager-backed collections (symbols, lines, circles, fills) to avoid null errors before style load. (#657)
11+
* Add methods enforce explicit manager initialization with clear exceptions when style is not loaded. (#657)
12+
* Calling add* before style load now fails fast with a clear Exception instead of risking null dereferences or silent failures. (#657)
13+
14+
### Changed
15+
* Rollback maplibre-gl to `4.7.1` version. (#660)
16+
* Removed `styleString` from internal MapLibreMapOptions class. (#660)
17+
18+
### Added
19+
* Added `onCameraMove` callback in the controller and in MapLibreMap class. (#643)
20+
621
## [0.24.0](https://github.com/maplibre/flutter-maplibre-gl/compare/v0.23.0...v0.24.0)
722
> **Note**: This release has breaking changes.\
823
> We apologize for the quick change in 0.24.0: this version definitively stabilizes the signatures of feature interaction callbacks.

maplibre_gl/CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
## UNRELEASED
1+
## [0.24.1](https://github.com/maplibre/flutter-maplibre-gl/compare/v0.24.0...v0.24.1)
22

33
### Fixed
4-
* Annotation tap call callbacks twice #652
4+
* Annotation tap call callbacks twice. (#652)
55
* Annotation APIs: use null-aware access for manager-backed collections (symbols, lines, circles, fills) to avoid null errors before style load. (#657)
66
* Add methods enforce explicit manager initialization with clear exceptions when style is not loaded. (#657)
7+
* Calling add* before style load now fails fast with a clear Exception instead of risking null dereferences or silent failures. (#657)
8+
9+
### Changed
10+
* Rollback maplibre-gl to `4.7.1` version. (#660)
11+
* Removed `styleString` from internal MapLibreMapOptions class. (#660)
12+
13+
### Added
14+
* Added `onCameraMove` callback in the controller and in MapLibreMap class. (#643)
715

816
## [0.24.0](https://github.com/maplibre/flutter-maplibre-gl/compare/v0.23.0...v0.24.0)
917
> **Note**: This release has breaking changes.\

maplibre_gl/lib/src/maplibre_map.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ class _MapLibreMapOptions {
378378
_MapLibreMapOptions(
379379
{this.compassEnabled,
380380
this.cameraTargetBounds,
381-
this.styleString,
382381
this.minMaxZoomPreference,
383382
required this.rotateGesturesEnabled,
384383
required this.scrollGesturesEnabled,
@@ -403,7 +402,6 @@ class _MapLibreMapOptions {
403402
locationEnginePlatforms: map.locationEnginePlatforms,
404403
compassEnabled: map.compassEnabled,
405404
cameraTargetBounds: map.cameraTargetBounds,
406-
styleString: map.styleString,
407405
minMaxZoomPreference: map.minMaxZoomPreference,
408406
rotateGesturesEnabled: map.rotateGesturesEnabled,
409407
scrollGesturesEnabled: map.scrollGesturesEnabled,
@@ -428,8 +426,6 @@ class _MapLibreMapOptions {
428426

429427
final CameraTargetBounds? cameraTargetBounds;
430428

431-
final String? styleString;
432-
433429
final MinMaxZoomPreference? minMaxZoomPreference;
434430

435431
final bool rotateGesturesEnabled;
@@ -493,7 +489,6 @@ class _MapLibreMapOptions {
493489

494490
addIfNonNull('compassEnabled', compassEnabled);
495491
addIfNonNull('cameraTargetBounds', cameraTargetBounds?.toJson());
496-
addIfNonNull('styleString', styleString);
497492
addIfNonNull('minMaxZoomPreference', minMaxZoomPreference?.toJson());
498493

499494
addIfNonNull('rotateGesturesEnabled', rotateGesturesEnabled);

maplibre_gl_example/web/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<link rel="shortcut icon" type="image/png" href="/favicon.png"/>
1717

1818
<!-- MapLibre -->
19-
<script src='https://unpkg.com/maplibre-gl@^5.3.0/dist/maplibre-gl.js'></script>
20-
<link href='https://unpkg.com/maplibre-gl@^5.3.0/dist/maplibre-gl.css' rel='stylesheet'/>
19+
<script src='https://unpkg.com/maplibre-gl@^4.7.1/dist/maplibre-gl.js'></script>
20+
<link href='https://unpkg.com/maplibre-gl@^4.7.1/dist/maplibre-gl.css' rel='stylesheet'/>
2121
<script src="https://unpkg.com/[email protected]/dist/pmtiles.js"></script>
2222

2323
<title>example</title>

maplibre_gl_web/CHANGELOG.md

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

3-
See top-level CHANGELOG.md for full details.
5+
* Rollback maplibre-gl to `4.7.1` version. (#660)
6+
* Removed `styleString` from internal MapLibreMapOptions class. (#660)
7+
8+
## 0.24.0
49

510
### Refactor / Quality (web)
611
* Refactored `onMapClick` (degenerate bbox + interactive layer filter) so unmanaged style-layer features now trigger `onFeatureTapped` (feature id + layer id, `annotation = null`).

maplibre_gl_web/lib/src/convert.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ class Convert {
1919
if (options.containsKey('compassEnabled')) {
2020
sink.setCompassEnabled(options['compassEnabled']);
2121
}
22-
if (options.containsKey('styleString')) {
23-
final styleString = options['styleString'];
24-
if (styleString is String &&
25-
(styleString.startsWith('{') || styleString.startsWith('['))) {
26-
sink.setStyle(jsonDecode(styleString));
27-
} else {
28-
sink.setStyle(styleString);
29-
}
30-
}
3122
if (options.containsKey('minMaxZoomPreference')) {
3223
sink.setMinMaxZoomPreference(options['minMaxZoomPreference'][0],
3324
options['minMaxZoomPreference'][1]);

maplibre_gl_web/lib/src/maplibre_web_gl_platform.dart

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,38 +57,43 @@ class MapLibreMapController extends MapLibrePlatform
5757

5858
@override
5959
Future<void> initPlatform(int id) async {
60-
if (_creationParams.containsKey('initialCameraPosition')) {
61-
final camera = _creationParams['initialCameraPosition'];
62-
_dragEnabled = _creationParams['dragEnabled'] ?? true;
63-
64-
_map = MapLibreMap(
65-
MapOptions(
66-
container: _mapElement,
67-
center: LngLat(camera['target'][1], camera['target'][0]),
68-
zoom: camera['zoom'],
69-
bearing: camera['bearing'],
70-
pitch: camera['tilt'],
71-
preserveDrawingBuffer: _creationParams['webPreserveDrawingBuffer'],
72-
attributionControl: false, //avoid duplicate control
73-
),
74-
);
75-
_map.on('style.load', _onStyleLoaded);
76-
_map.on('click', _onMapClick);
77-
// long click not available in web, so it is mapped to double click
78-
_map.on('dblclick', _onMapLongClick);
79-
_map.on('movestart', _onCameraMoveStarted);
80-
_map.on('move', _onCameraMove);
81-
_map.on('moveend', _onCameraIdle);
82-
_map.on('resize', (_) => _onMapResize());
83-
_map.on('styleimagemissing', _loadFromAssets);
84-
if (_dragEnabled) {
85-
_map.on('mouseup', _onMouseUp);
86-
_map.on('mousemove', _onMouseMove);
87-
}
88-
89-
_initResizeObserver();
60+
final camera =
61+
_creationParams['initialCameraPosition'] as Map<String, dynamic>?;
62+
final styleString = _sanitizeStyleObject(_creationParams['styleString']);
63+
_dragEnabled = _creationParams['dragEnabled'] ?? true;
64+
65+
_map = MapLibreMap(
66+
MapOptions(
67+
container: _mapElement,
68+
center: (camera != null)
69+
? LngLat(camera['target'][1], camera['target'][0])
70+
: null,
71+
zoom: camera?['zoom'],
72+
bearing: camera?['bearing'],
73+
pitch: camera?['tilt'],
74+
style: styleString,
75+
preserveDrawingBuffer: _creationParams['webPreserveDrawingBuffer'],
76+
attributionControl: false, //avoid duplicate control
77+
),
78+
);
79+
_map.on('style.load', _onStyleLoaded);
80+
_map.on('click', _onMapClick);
81+
// long click not available in web, so it is mapped to double click
82+
_map.on('dblclick', _onMapLongClick);
83+
_map.on('movestart', _onCameraMoveStarted);
84+
_map.on('move', _onCameraMove);
85+
_map.on('moveend', _onCameraIdle);
86+
_map.on('resize', (_) => _onMapResize());
87+
_map.on('styleimagemissing', _loadFromAssets);
88+
if (_dragEnabled) {
89+
_map.on('mouseup', _onMouseUp);
90+
_map.on('mousemove', _onMouseMove);
9091
}
91-
Convert.interpretMapLibreMapOptions(_creationParams['options'], this);
92+
93+
_initResizeObserver();
94+
95+
final options = _creationParams['options'] ?? {};
96+
Convert.interpretMapLibreMapOptions(options, this);
9297
}
9398

9499
void _initResizeObserver() {
@@ -855,7 +860,20 @@ class MapLibreMapController extends MapLibrePlatform
855860
}
856861
_interactiveFeatureLayerIds.clear();
857862

858-
_map.setStyle(styleObject, {'diff': false});
863+
final sanitizedStyle = _sanitizeStyleObject(styleObject);
864+
_map.setStyle(sanitizedStyle, {'diff': false});
865+
}
866+
867+
/// Sanitizes the style object to ensure it is in the correct format.
868+
/// If the style object is a JSON string, it decodes it into a Map.
869+
/// If it is already a Map or other type, it returns it as is.
870+
dynamic _sanitizeStyleObject(dynamic styleObject) {
871+
if (styleObject is String &&
872+
(styleObject.startsWith('{') || styleObject.startsWith('['))) {
873+
return jsonDecode(styleObject);
874+
} else {
875+
return styleObject;
876+
}
859877
}
860878

861879
@override

maplibre_gl_web/lib/src/options_sink.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ 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-
129
void setMinMaxZoomPreference(num? min, num? max);
1310

1411
void setGestures({

0 commit comments

Comments
 (0)