@@ -55,7 +55,7 @@ final class MapLibreMapStateWeb extends MapLibreMapState {
5555 _map = interop.JsMap (
5656 interop.MapOptions (
5757 container: _htmlElement,
58- style: _styleAsJsonOrUrl (options.initStyle),
58+ style: _prepareStyleString (options.initStyle),
5959 zoom: options.initZoom,
6060 center: options.initCenter? .toLngLat (),
6161 bearing: options.initBearing,
@@ -480,12 +480,28 @@ final class MapLibreMapStateWeb extends MapLibreMapState {
480480 .toList (growable: false );
481481 }
482482
483- JSAny _styleAsJsonOrUrl (String styleString) {
484- JSAny ? ret;
485- if (styleString.startsWith ('{' ) || styleString.startsWith ('[' )) {
486- ret = (jsonDecode (styleString) as Map <String , dynamic >).jsify ();
483+ JSAny _prepareStyleString (String style) {
484+ final trimmed = style.trim ();
485+ if (trimmed.startsWith ('{' )) {
486+ // Raw JSON
487+ final json = jsonDecode (trimmed) as Map <String , dynamic >;
488+ final jsified = json.jsify ();
489+ if (jsified == null ) {
490+ throw StateError ('Failed to convert style JSON to JS object.' );
491+ }
492+ return jsified;
493+ } else if (trimmed.startsWith ('/' )) {
494+ // path
495+ return trimmed.toJS;
496+ } else if (! trimmed.startsWith ('http://' ) &&
497+ ! trimmed.startsWith ('https://' ) &&
498+ ! trimmed.startsWith ('mapbox://' )) {
499+ // flutter asset
500+ return AssetManager ().getAssetUrl (trimmed).toJS;
501+ } else {
502+ // URI
503+ return trimmed.toJS;
487504 }
488- return ret ?? styleString.toJS;
489505 }
490506
491507 @override
@@ -496,7 +512,7 @@ final class MapLibreMapStateWeb extends MapLibreMapState {
496512 _onStyleLoaded ();
497513 }.toJS,
498514 );
499- _map.setStyle (_styleAsJsonOrUrl (style));
515+ _map.setStyle (_prepareStyleString (style));
500516 }
501517
502518 void _onStyleLoaded () {
0 commit comments