Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting style as a json object directly for web #1279

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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