|
| 1 | +// Copyright 2019 The Chromium 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 | +part of platform_maps_flutter; |
| 6 | + |
| 7 | +/// Uniquely identifies a [Circle] among [PlatformMap] circles. |
| 8 | +/// |
| 9 | +/// This does not have to be globally unique, only unique among the list. |
| 10 | +@immutable |
| 11 | +class CircleId { |
| 12 | + /// Creates an immutable identifier for a [Circle]. |
| 13 | + CircleId(this.value) : assert(value != null); |
| 14 | + |
| 15 | + /// value of the [CircleId]. |
| 16 | + final String value; |
| 17 | + |
| 18 | + @override |
| 19 | + bool operator ==(Object other) { |
| 20 | + if (identical(this, other)) return true; |
| 21 | + if (other.runtimeType != runtimeType) return false; |
| 22 | + final CircleId typedOther = other; |
| 23 | + return value == typedOther.value; |
| 24 | + } |
| 25 | + |
| 26 | + @override |
| 27 | + int get hashCode => value.hashCode; |
| 28 | + |
| 29 | + @override |
| 30 | + String toString() { |
| 31 | + return 'CircleId{value: $value}'; |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +/// Draws a circle on the map. |
| 36 | +@immutable |
| 37 | +class Circle { |
| 38 | + /// Creates an immutable representation of a [Circle] to draw on [PlatformMap]. |
| 39 | + const Circle({ |
| 40 | + @required this.circleId, |
| 41 | + this.consumeTapEvents = false, |
| 42 | + this.fillColor = Colors.transparent, |
| 43 | + this.center = const LatLng(0.0, 0.0), |
| 44 | + this.radius = 0, |
| 45 | + this.strokeColor = Colors.black, |
| 46 | + this.strokeWidth = 10, |
| 47 | + this.visible = true, |
| 48 | + this.onTap, |
| 49 | + }); |
| 50 | + |
| 51 | + /// Uniquely identifies a [Circle]. |
| 52 | + final CircleId circleId; |
| 53 | + |
| 54 | + /// True if the [Circle] consumes tap events. |
| 55 | + /// |
| 56 | + /// If this is false, [onTap] callback will not be triggered. |
| 57 | + final bool consumeTapEvents; |
| 58 | + |
| 59 | + /// Fill color in ARGB format, the same format used by Color. The default value is transparent (0x00000000). |
| 60 | + final Color fillColor; |
| 61 | + |
| 62 | + /// Geographical location of the circle center. |
| 63 | + final LatLng center; |
| 64 | + |
| 65 | + /// Radius of the circle in meters; must be positive. The default value is 0. |
| 66 | + final double radius; |
| 67 | + |
| 68 | + /// Fill color in ARGB format, the same format used by Color. The default value is black (0xff000000). |
| 69 | + final Color strokeColor; |
| 70 | + |
| 71 | + /// The width of the circle's outline in screen points. |
| 72 | + /// |
| 73 | + /// The width is constant and independent of the camera's zoom level. |
| 74 | + /// The default value is 10. |
| 75 | + /// Setting strokeWidth to 0 results in no stroke. |
| 76 | + final int strokeWidth; |
| 77 | + |
| 78 | + /// True if the circle is visible. |
| 79 | + final bool visible; |
| 80 | + |
| 81 | + /// Callbacks to receive tap events for circle placed on this map. |
| 82 | + final VoidCallback onTap; |
| 83 | + |
| 84 | + /// Creates a new [Circle] object whose values are the same as this instance, |
| 85 | + /// unless overwritten by the specified parameters. |
| 86 | + Circle copyWith({ |
| 87 | + bool consumeTapEventsParam, |
| 88 | + Color fillColorParam, |
| 89 | + LatLng centerParam, |
| 90 | + double radiusParam, |
| 91 | + Color strokeColorParam, |
| 92 | + int strokeWidthParam, |
| 93 | + bool visibleParam, |
| 94 | + VoidCallback onTapParam, |
| 95 | + }) { |
| 96 | + return Circle( |
| 97 | + circleId: circleId, |
| 98 | + consumeTapEvents: consumeTapEventsParam ?? consumeTapEvents, |
| 99 | + fillColor: fillColorParam ?? fillColor, |
| 100 | + center: centerParam ?? center, |
| 101 | + radius: radiusParam ?? radius, |
| 102 | + strokeColor: strokeColorParam ?? strokeColor, |
| 103 | + strokeWidth: strokeWidthParam ?? strokeWidth, |
| 104 | + visible: visibleParam ?? visible, |
| 105 | + onTap: onTapParam ?? onTap, |
| 106 | + ); |
| 107 | + } |
| 108 | + |
| 109 | + /// Creates a new [Circle] object whose values are the same as this instance. |
| 110 | + Circle clone() => copyWith(); |
| 111 | + |
| 112 | + @override |
| 113 | + bool operator ==(Object other) { |
| 114 | + if (identical(this, other)) return true; |
| 115 | + if (other.runtimeType != runtimeType) return false; |
| 116 | + final Circle typedOther = other; |
| 117 | + return circleId == typedOther.circleId && |
| 118 | + consumeTapEvents == typedOther.consumeTapEvents && |
| 119 | + fillColor == typedOther.fillColor && |
| 120 | + center == typedOther.center && |
| 121 | + radius == typedOther.radius && |
| 122 | + strokeColor == typedOther.strokeColor && |
| 123 | + strokeWidth == typedOther.strokeWidth && |
| 124 | + visible == typedOther.visible && |
| 125 | + onTap == typedOther.onTap; |
| 126 | + } |
| 127 | + |
| 128 | + static Set<googleMaps.Circle> toGoogleMapsCircleSet(Set<Circle> circles) { |
| 129 | + List<googleMaps.Circle> _circles = List<googleMaps.Circle>(); |
| 130 | + for (Circle circle in circles) { |
| 131 | + _circles.add(circle.googleMapsCircle); |
| 132 | + } |
| 133 | + return Set.from(_circles); |
| 134 | + } |
| 135 | + |
| 136 | + static Set<appleMaps.Circle> toAppleMapsCircleSet(Set<Circle> circles) { |
| 137 | + List<appleMaps.Circle> _circles = List<appleMaps.Circle>(); |
| 138 | + for (Circle circle in circles) { |
| 139 | + _circles.add(circle.appleMapsCircle); |
| 140 | + } |
| 141 | + return Set.from(_circles); |
| 142 | + } |
| 143 | + |
| 144 | + googleMaps.Circle get googleMapsCircle => googleMaps.Circle( |
| 145 | + circleId: googleMaps.CircleId(this.circleId.value), |
| 146 | + consumeTapEvents: this.consumeTapEvents, |
| 147 | + fillColor: this.fillColor, |
| 148 | + onTap: this.onTap, |
| 149 | + center: this.center.googleLatLng, |
| 150 | + radius: this.radius, |
| 151 | + strokeColor: this.strokeColor, |
| 152 | + strokeWidth: this.strokeWidth, |
| 153 | + visible: this.visible, |
| 154 | + ); |
| 155 | + |
| 156 | + appleMaps.Circle get appleMapsCircle => appleMaps.Circle( |
| 157 | + circleId: appleMaps.CircleId(this.circleId.value), |
| 158 | + consumeTapEvents: this.consumeTapEvents, |
| 159 | + fillColor: this.fillColor, |
| 160 | + onTap: this.onTap, |
| 161 | + center: this.center.appleLatLng, |
| 162 | + radius: this.radius, |
| 163 | + strokeColor: this.strokeColor, |
| 164 | + strokeWidth: this.strokeWidth, |
| 165 | + visible: this.visible, |
| 166 | + ); |
| 167 | + |
| 168 | + @override |
| 169 | + int get hashCode => circleId.hashCode; |
| 170 | +} |
0 commit comments