Skip to content

Commit

Permalink
Setting style as a json object directly for web (#1279)
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Irmančnik <simon@naviter.com>
  • Loading branch information
srmncnk and Simon Irmančnik committed Apr 14, 2023
1 parent 9eef30d commit 622146f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions mapbox_gl_web/lib/mapbox_gl_web.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
library mapbox_gl_web;

import 'dart:async';
import 'dart:convert';
// FIXED HERE: https://github.com/dart-lang/linter/pull/1985
// ignore_for_file: avoid_web_libraries_in_flutter
import 'dart:html';
Expand All @@ -21,6 +22,7 @@ import 'package:mapbox_gl_platform_interface/mapbox_gl_platform_interface.dart';
import 'package:mapbox_gl_dart/mapbox_gl_dart.dart' hide Point, Source;
import 'package:mapbox_gl_dart/mapbox_gl_dart.dart' as mapbox show Point;
import 'package:image/image.dart' hide Point;
import 'package:js/js_util.dart' as jsUtil;
import 'package:mapbox_gl_web/src/layer_tools.dart';

part 'src/convert.dart';
Expand Down
8 changes: 7 additions & 1 deletion mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,13 @@ class MapboxWebGlPlatform extends MapboxGlPlatform
}
_interactiveFeatureLayerIds.clear();

_map.setStyle(styleString);
try {
final styleJson = jsonDecode(styleString ?? '');
final styleJsObject = jsUtil.jsify(styleJson);
_map.setStyle(styleJsObject);
} catch(_) {
_map.setStyle(styleString);
}
// catch style loaded for later style changes
if (_mapReady) {
_map.once("styledata", _onStyleLoaded);
Expand Down

0 comments on commit 622146f

Please sign in to comment.