Skip to content

Commit 52baeca

Browse files
committed
add JS binding for MapStyler
1 parent d8adca1 commit 52baeca

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

packages/google_maps_flutter/google_maps_flutter_web/lib/google_maps_flutter_web.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import 'package:web/web.dart';
2323

2424
import 'src/dom_window_extension.dart';
2525
import 'src/google_maps_inspector_web.dart';
26+
import 'src/map_styler.dart';
2627
import 'src/third_party/to_screen_location/to_screen_location.dart';
2728
import 'src/types.dart';
2829
import 'src/utils.dart';

packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,11 @@ List<gmaps.MapTypeStyle> _mapStyles(String? mapStyleJson) {
139139
styles =
140140
(json.decode(mapStyleJson, reviver: (Object? key, Object? value) {
141141
if (value is Map && _isJsonMapStyle(value as Map<String, Object?>)) {
142-
List<Object?> stylers = <Object?>[];
142+
List<MapStyler> stylers = <MapStyler>[];
143143
if (value['stylers'] != null) {
144144
stylers = (value['stylers']! as List<Object?>)
145-
.map<Object?>((Object? e) => e != null ? jsify(e) : null)
145+
.whereType<Map<String, Object?>>()
146+
.map(MapStyler.fromJson)
146147
.toList();
147148
}
148149
return gmaps.MapTypeStyle()
@@ -277,6 +278,8 @@ gmaps.Icon? _gmIconFromBitmapDescriptor(BitmapDescriptor bitmapDescriptor) {
277278
'The bytes for a BitmapDescriptor icon must be a Uint8List',
278279
);
279280

281+
// TODO(ditman): Improve this conversion
282+
// See https://github.com/dart-lang/web/issues/180
280283
blob = Blob(<JSUint8Array>[(bytes as Uint8List).toJS].toJS);
281284

282285
icon = gmaps.Icon()..url = URL.createObjectURL(blob as JSObject);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:js_interop';
6+
7+
/// The interop type for a Google Maps Map Styler.
8+
///
9+
/// See: https://developers.google.com/maps/documentation/javascript/style-reference#stylers
10+
@JS()
11+
@staticInterop
12+
@anonymous
13+
extension type MapStyler._(JSObject _) implements JSObject {
14+
/// Create a new [MapStyler] instance.
15+
external factory MapStyler({
16+
String? hue,
17+
num? lightness,
18+
num? saturation,
19+
num? gamma,
20+
// ignore: non_constant_identifier_names
21+
bool? invert_lightness,
22+
String? visibility,
23+
String? color,
24+
int? weight,
25+
});
26+
27+
/// Create a new [MapStyler] instance from the given [json].
28+
factory MapStyler.fromJson(Map<String, Object?> json) {
29+
return MapStyler(
30+
hue: json['hue'] as String?,
31+
lightness: json['lightness'] as num?,
32+
saturation: json['saturation'] as num?,
33+
gamma: json['gamma'] as num?,
34+
invert_lightness: json['invert_lightness'] as bool?,
35+
visibility: json['visibility'] as String?,
36+
color: json['color'] as String?,
37+
weight: json['weight'] as int?,
38+
);
39+
}
40+
}

0 commit comments

Comments
 (0)