-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[google_maps_flutter] Add heatmap support #5274
Changes from 1 commit
f2e9806
2203401
bcc8f07
b179c93
6ee7ae8
7f78965
09c1fab
d5d0726
cf29213
b2436f5
37c58ad
789cd9a
977dfd4
d27c28c
2df83b5
efb432a
5703eeb
c47d213
2361e47
72dd326
bc27137
146ea54
5ed26a8
bd51355
876998f
d4b3524
f6d3050
8415953
0a9495c
65bad90
319f84e
b2e7e5e
9cb30af
5039dd1
177def0
ca94502
6ee5fed
d341949
c3e904f
5cd2524
7ad6e7b
7978892
d76e161
dd3c82f
f89a3f4
994fd1f
f96f844
3c6c7cd
f63af88
1160e32
c41b00a
ead58b8
d1a8856
5c78283
b9dd462
d1daad1
35d8715
ccc9ca2
ea1975b
d39a901
89239ab
e5b4943
3c7d7dc
011828d
c39446b
4999d14
681eae8
0bf8dd2
d011011
b7f4f72
906c3f0
09467d1
a5e1e5f
686b60a
70c8dbe
4eaa5d3
b9d33cd
882d3b4
9005231
0c03dad
6d69bed
edcede1
cd24b9e
e67b408
f4d5c86
2f745ab
1ce1595
b2be041
60e15ea
612e5be
7c22792
1d212eb
f1105ad
ef7a9d4
8c7c8f0
43ba954
3928a72
4d6392b
5c8839e
c187469
feeed2c
e7471ea
e779c77
aab722a
e08a292
20591b0
5235dad
55988cc
e6e1af2
28468b2
35d12bd
5c8ce27
597d065
115ed7f
b3e1d4a
38ec627
3639957
89a0e20
88db9ca
34deb7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…-heatmap
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,8 @@ | |
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/foundation.dart' show listEquals; | ||
| import 'package:flutter/material.dart' show Color; | ||
| import 'package:flutter/foundation.dart' show immutable; | ||
| import 'package:flutter/material.dart' show Color; | ||
|
|
||
| import 'types.dart'; | ||
|
|
||
|
|
@@ -24,7 +24,7 @@ class Heatmap implements MapsObject<Heatmap> { | |
| /// [GoogleMap]. | ||
| const Heatmap({ | ||
| required this.heatmapId, | ||
| this.data = const [], | ||
| this.data = const <WeightedLatLng>[], | ||
| this.dissipating = true, | ||
| this.gradient, | ||
| this.maxIntensity, | ||
|
|
@@ -108,12 +108,14 @@ class Heatmap implements MapsObject<Heatmap> { | |
|
|
||
| /// Creates a new [Heatmap] object whose values are the same as this | ||
| /// instance. | ||
| @override | ||
| Heatmap clone() => copyWith( | ||
| dataParam: List.of(data), | ||
| dataParam: List<WeightedLatLng>.of(data), | ||
| gradientParam: gradient?.clone(), | ||
| ); | ||
|
|
||
| /// Converts this object to something serializable in JSON. | ||
| @override | ||
| Object toJson() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per my comments elsewhere about doing serialization in the individual packages, we may be able to completely remove this method.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this is safe to remove. Let me know your thoughts. |
||
| final Map<String, Object> json = <String, Object>{}; | ||
|
|
||
|
|
@@ -124,7 +126,7 @@ class Heatmap implements MapsObject<Heatmap> { | |
| } | ||
|
|
||
| addIfPresent('heatmapId', heatmapId.value); | ||
| addIfPresent('data', data.map((e) => e.toJson()).toList()); | ||
| addIfPresent('data', data.map((WeightedLatLng e) => e.toJson()).toList()); | ||
| addIfPresent('dissipating', dissipating); | ||
| addIfPresent('gradient', gradient?.toJson()); | ||
| addIfPresent('maxIntensity', maxIntensity); | ||
|
|
@@ -138,18 +140,22 @@ class Heatmap implements MapsObject<Heatmap> { | |
|
|
||
| @override | ||
| bool operator ==(Object other) { | ||
| if (identical(this, other)) return true; | ||
| if (other.runtimeType != runtimeType) return false; | ||
| final Heatmap typedOther = other as Heatmap; | ||
| return heatmapId == typedOther.heatmapId && | ||
| listEquals(data, typedOther.data) && | ||
| dissipating == typedOther.dissipating && | ||
| gradient == typedOther.gradient && | ||
| maxIntensity == typedOther.maxIntensity && | ||
| opacity == typedOther.opacity && | ||
| radius == typedOther.radius && | ||
| minimumZoomIntensity == typedOther.minimumZoomIntensity && | ||
| maximumZoomIntensity == typedOther.maximumZoomIntensity; | ||
| if (identical(this, other)) { | ||
| return true; | ||
| } | ||
| if (other.runtimeType != runtimeType) { | ||
| return false; | ||
| } | ||
| return other is Heatmap && | ||
| heatmapId == other.heatmapId && | ||
| listEquals(data, other.data) && | ||
| dissipating == other.dissipating && | ||
| gradient == other.gradient && | ||
| maxIntensity == other.maxIntensity && | ||
| opacity == other.opacity && | ||
| radius == other.radius && | ||
| minimumZoomIntensity == other.minimumZoomIntensity && | ||
| maximumZoomIntensity == other.maximumZoomIntensity; | ||
| } | ||
|
|
||
| @override | ||
|
|
@@ -158,7 +164,17 @@ class Heatmap implements MapsObject<Heatmap> { | |
|
|
||
| /// Represents a mapping of intensity to color. Interpolates between given set | ||
Rexios80 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// intensity and color values to produce a full mapping for the range [0, 1]. | ||
| @immutable | ||
| class HeatmapGradient { | ||
| /// Creates a new [HeatmapGradient] object. | ||
| const HeatmapGradient({ | ||
| required this.colors, | ||
| required this.startPoints, | ||
| this.colorMapSize = 256, | ||
| }) : assert(colors.length == startPoints.length), | ||
| assert(colors.length > 0), | ||
| assert(startPoints.length > 0); | ||
|
|
||
| /// The specific colors for the specific intensities specified by startPoints. | ||
Rexios80 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| final List<Color> colors; | ||
|
|
||
|
|
@@ -172,15 +188,6 @@ class HeatmapGradient { | |
| /// Android and iOS only. | ||
| final int colorMapSize; | ||
|
|
||
| /// Creates a new [HeatmapGradient] object. | ||
| const HeatmapGradient({ | ||
| required this.colors, | ||
| required this.startPoints, | ||
| this.colorMapSize = 256, | ||
| }) : assert(colors.length == startPoints.length), | ||
| assert(colors.length > 0), | ||
| assert(startPoints.length > 0); | ||
|
|
||
| /// Creates a new [HeatmapGradient] object whose values are the same as this | ||
| /// instance, unless overwritten by the specified parameters. | ||
| HeatmapGradient copyWith({ | ||
|
|
@@ -198,8 +205,8 @@ class HeatmapGradient { | |
| /// Creates a new [HeatmapGradient] object whose values are the same as this | ||
| /// instance. | ||
| HeatmapGradient clone() => copyWith( | ||
| colorsParam: List.of(colors), | ||
| startPointsParam: List.of(startPoints), | ||
| colorsParam: List<Color>.of(colors), | ||
| startPointsParam: List<double>.of(startPoints), | ||
| ); | ||
|
|
||
| /// Converts this object to something serializable in JSON. | ||
|
|
@@ -212,7 +219,7 @@ class HeatmapGradient { | |
| } | ||
| } | ||
|
|
||
| addIfPresent('colors', colors.map((e) => e.value).toList()); | ||
| addIfPresent('colors', colors.map((Color e) => e.value).toList()); | ||
| addIfPresent('startPoints', startPoints); | ||
| addIfPresent('colorMapSize', colorMapSize); | ||
|
|
||
|
|
@@ -221,11 +228,18 @@ class HeatmapGradient { | |
|
|
||
| @override | ||
| bool operator ==(Object other) { | ||
| if (identical(this, other)) return true; | ||
| if (other.runtimeType != runtimeType) return false; | ||
| final HeatmapGradient typedOther = other as HeatmapGradient; | ||
| return listEquals(colors, typedOther.colors) && | ||
| listEquals(startPoints, typedOther.startPoints) && | ||
| colorMapSize == typedOther.colorMapSize; | ||
| if (identical(this, other)) { | ||
| return true; | ||
| } | ||
| if (other.runtimeType != runtimeType) { | ||
| return false; | ||
| } | ||
| return other is HeatmapGradient && | ||
| listEquals(colors, other.colors) && | ||
| listEquals(startPoints, other.startPoints) && | ||
| colorMapSize == other.colorMapSize; | ||
| } | ||
|
|
||
| @override | ||
| int get hashCode => Object.hash(colors, startPoints, colorMapSize); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/foundation.dart' | ||
| show objectRuntimeType, visibleForTesting; | ||
| show immutable, objectRuntimeType, visibleForTesting; | ||
|
|
||
| /// A pair of latitude and longitude coordinates, stored as degrees. | ||
| @immutable | ||
|
|
@@ -128,8 +128,9 @@ class LatLngBounds { | |
| } | ||
|
|
||
| @override | ||
| String toString() => | ||
| '${objectRuntimeType(this, 'LatLngBounds')}($southwest, $northeast)'; | ||
| String toString() { | ||
| return '${objectRuntimeType(this, 'LatLngBounds')}($southwest, $northeast)'; | ||
| } | ||
|
|
||
| @override | ||
| bool operator ==(Object other) { | ||
|
|
@@ -153,6 +154,7 @@ class WeightedLatLng extends LatLng { | |
| final double weight; | ||
|
|
||
| /// Converts this object to something serializable in JSON. | ||
| @override | ||
| Object toJson() { | ||
|
||
| return <Object>[super.toJson(), weight]; | ||
| } | ||
|
|
@@ -163,25 +165,26 @@ class WeightedLatLng extends LatLng { | |
| return null; | ||
| } | ||
| assert(json is List && json.length == 2); | ||
| final list = json as List; | ||
| final latLng = LatLng.fromJson(list[0])!; | ||
| final List<dynamic> list = json as List<dynamic>; | ||
| final LatLng latLng = LatLng.fromJson(list[0])!; | ||
| return WeightedLatLng( | ||
| latLng.latitude, | ||
| latLng.longitude, | ||
| weight: list[1], | ||
| weight: list[1] as double, | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| String toString() => | ||
| '${objectRuntimeType(this, 'WeightedLatLng')}($latitude, $longitude, $weight)'; | ||
| String toString() { | ||
| return '${objectRuntimeType(this, 'WeightedLatLng')}($latitude, $longitude, $weight)'; | ||
| } | ||
|
|
||
| @override | ||
| bool operator ==(Object o) { | ||
| return o is WeightedLatLng && | ||
| o.latitude == latitude && | ||
| o.longitude == longitude && | ||
| o.weight == weight; | ||
| bool operator ==(Object other) { | ||
| return other is WeightedLatLng && | ||
| other.latitude == latitude && | ||
| other.longitude == longitude && | ||
| other.weight == weight; | ||
| } | ||
|
|
||
| @override | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.