@@ -37,6 +37,20 @@ class InfoWindow {
37
37
snippet: this .snippet,
38
38
title: this .title,
39
39
);
40
+
41
+ /// Creates a new [InfoWindow] object whose values are the same as this instance,
42
+ /// unless overwritten by the specified parameters.
43
+ InfoWindow copyWith ({
44
+ String titleParam,
45
+ String snippetParam,
46
+ VoidCallback onTapParam,
47
+ }) {
48
+ return InfoWindow (
49
+ title: titleParam ?? title,
50
+ snippet: snippetParam ?? snippet,
51
+ onTap: onTapParam ?? onTap,
52
+ );
53
+ }
40
54
}
41
55
42
56
/// Uniquely identifies a [Marker] among [GoogleMap] markers.
@@ -71,26 +85,24 @@ class Marker {
71
85
///
72
86
/// Specifies a marker that
73
87
/// * is fully opaque; [alpha] is 1.0
74
- /// * uses icon bottom center to indicate map position; [anchor] is (0.5, 1.0)
75
88
/// * has default tap handling; [consumeTapEvents] is false
76
89
/// * is stationary; [draggable] is false
77
- /// * is drawn against the screen, not the map; [flat] is false
78
90
/// * has a default icon; [icon] is `BitmapDescriptor.defaultMarker`
79
- /// * anchors the info window at top center; [infoWindowAnchor] is (0.5, 0.0)
80
91
/// * has no info window text; [infoWindowText] is `InfoWindowText.noText`
81
92
/// * is positioned at 0, 0; [position] is `LatLng(0.0, 0.0)`
82
- /// * has an axis-aligned icon; [rotation] is 0.0
83
93
/// * is visible; [visible] is true
84
94
/// * is placed at the base of the drawing order; [zIndex] is 0.0
85
95
const Marker ({
86
96
@required this .markerId,
87
97
this .alpha = 1.0 ,
88
98
this .consumeTapEvents = false ,
89
99
this .draggable = false ,
90
- // this.icon = BitmapDescriptor.defaultMarker ,
100
+ this .icon,
91
101
this .infoWindow = InfoWindow .noText,
92
102
this .position = const LatLng (0.0 , 0.0 ),
93
103
this .onTap,
104
+ this .visible = true ,
105
+ this .onDragEnd,
94
106
}) : assert (alpha == null || (0.0 <= alpha && alpha <= 1.0 ));
95
107
96
108
/// Uniquely identifies a [Marker] .
@@ -110,7 +122,7 @@ class Marker {
110
122
final bool draggable;
111
123
112
124
/// A description of the bitmap used to draw the marker icon.
113
- // final BitmapDescriptor icon;
125
+ final dynamic icon;
114
126
115
127
/// A Google Maps InfoWindow.
116
128
///
@@ -123,12 +135,23 @@ class Marker {
123
135
/// Callbacks to receive tap events for markers placed on this map.
124
136
final VoidCallback onTap;
125
137
138
+ /// True if the annotation is visible.
139
+ final bool visible;
140
+
141
+ final ValueChanged <LatLng > onDragEnd;
142
+
126
143
appleMaps.Annotation get appleMapsAnnotation => appleMaps.Annotation (
127
144
annotationId: this .markerId.appleMapsAnnoationId,
128
145
alpha: this .alpha,
129
146
draggable: this .draggable,
130
147
infoWindow: this .infoWindow.appleMapsInfoWindow,
131
148
onTap: this .onTap,
149
+ icon: this .icon ?? BitmapDescriptor .defaultMarker,
150
+ visible: this .visible,
151
+ onDragEnd: this .onDragEnd != null
152
+ ? (appleMaps.LatLng latLng) =>
153
+ _onAppleAnnotationDragEnd (latLng, this .onDragEnd)
154
+ : null ,
132
155
position: this .position.appleLatLng,
133
156
);
134
157
@@ -138,45 +161,97 @@ class Marker {
138
161
draggable: this .draggable,
139
162
infoWindow: this .infoWindow.googleMapsInfoWindow,
140
163
onTap: this .onTap,
164
+ icon: this .icon ?? BitmapDescriptor .defaultMarker,
165
+ visible: this .visible,
166
+ onDragEnd: this .onDragEnd != null
167
+ ? (googleMaps.LatLng latLng) =>
168
+ _onGoogleMarkerDragEnd (latLng, this .onDragEnd)
169
+ : null ,
141
170
position: this .position.googleLatLng,
142
171
);
143
172
144
- static appleMaps.Annotation appleMapsAnnotationFromMarker (Marker marker) {
145
- return appleMaps.Annotation (
146
- annotationId: marker.markerId.appleMapsAnnoationId,
147
- alpha: marker.alpha,
148
- draggable: marker.draggable,
149
- infoWindow: marker.infoWindow.appleMapsInfoWindow,
150
- onTap: marker.onTap,
151
- position: marker.position.appleLatLng,
152
- );
153
- }
173
+ static appleMaps.Annotation appleMapsAnnotationFromMarker (Marker marker) =>
174
+ appleMaps.Annotation (
175
+ annotationId: marker.markerId.appleMapsAnnoationId,
176
+ alpha: marker.alpha,
177
+ draggable: marker.draggable,
178
+ infoWindow: marker.infoWindow.appleMapsInfoWindow,
179
+ onTap: marker.onTap,
180
+ icon: marker.icon ?? BitmapDescriptor .defaultMarker,
181
+ visible: marker.visible,
182
+ onDragEnd: marker.onDragEnd != null
183
+ ? (appleMaps.LatLng latLng) =>
184
+ _onAppleAnnotationDragEnd (latLng, marker.onDragEnd)
185
+ : null ,
186
+ position: marker.position.appleLatLng,
187
+ );
154
188
155
- static googleMaps.Marker googleMapsMarkerFromMarker (Marker marker) {
156
- return googleMaps.Marker (
157
- markerId: marker.markerId.googleMapsMarkerId,
158
- alpha: marker.alpha,
159
- draggable: marker.draggable,
160
- infoWindow: marker.infoWindow.googleMapsInfoWindow,
161
- onTap: marker.onTap,
162
- position: marker.position.googleLatLng,
163
- );
164
- }
189
+ static googleMaps.Marker googleMapsMarkerFromMarker (Marker marker) =>
190
+ googleMaps.Marker (
191
+ markerId: marker.markerId.googleMapsMarkerId,
192
+ alpha: marker.alpha,
193
+ draggable: marker.draggable,
194
+ infoWindow: marker.infoWindow.googleMapsInfoWindow,
195
+ onTap: marker.onTap,
196
+ icon: marker.icon ?? BitmapDescriptor .defaultMarker,
197
+ visible: marker.visible,
198
+ onDragEnd: marker.onDragEnd != null
199
+ ? (googleMaps.LatLng latLng) =>
200
+ _onGoogleMarkerDragEnd (latLng, marker.onDragEnd)
201
+ : null ,
202
+ position: marker.position.googleLatLng,
203
+ );
165
204
166
205
static Set <appleMaps.Annotation > toAppleMapsAnnotationSet (
167
206
Set <Marker > markers) {
168
- Set <appleMaps.Annotation > _annotations = Set <appleMaps.Annotation >();
169
- markers. forEach (( marker) {
207
+ List <appleMaps.Annotation > _annotations = List <appleMaps.Annotation >();
208
+ for ( Marker marker in markers ) {
170
209
_annotations.add (appleMapsAnnotationFromMarker (marker));
171
- });
172
- return _annotations;
210
+ }
211
+ return Set . from ( _annotations) ;
173
212
}
174
213
175
214
static Set <googleMaps.Marker > toGoogleMapsMarkerSet (Set <Marker > markers) {
176
- Set <googleMaps.Marker > _markers = Set <googleMaps.Marker >();
177
- markers. forEach (( marker) {
215
+ List <googleMaps.Marker > _markers = List <googleMaps.Marker >();
216
+ for ( Marker marker in markers ) {
178
217
_markers.add (googleMapsMarkerFromMarker (marker));
179
- });
180
- return _markers;
218
+ }
219
+ return Set .from (_markers);
220
+ }
221
+
222
+ Marker copyWith ({
223
+ double alphaParam,
224
+ bool consumeTapEventsParam,
225
+ bool draggableParam,
226
+ dynamic iconParam,
227
+ InfoWindow infoWindowParam,
228
+ LatLng positionParam,
229
+ bool visibleParam,
230
+ VoidCallback onTapParam,
231
+ }) {
232
+ return Marker (
233
+ markerId: markerId,
234
+ alpha: alphaParam ?? alpha,
235
+ consumeTapEvents: consumeTapEventsParam ?? consumeTapEvents,
236
+ draggable: draggableParam ?? draggable,
237
+ icon: iconParam ?? icon,
238
+ infoWindow: infoWindowParam ?? infoWindow,
239
+ position: positionParam ?? position,
240
+ visible: visibleParam ?? visible,
241
+ onTap: onTapParam ?? onTap,
242
+ );
243
+ }
244
+
245
+ static _onGoogleMarkerDragEnd (googleMaps.LatLng latLng, Function onDragEnd) {
246
+ if (onDragEnd != null ) {
247
+ onDragEnd (LatLng ._fromGoogleLatLng (latLng));
248
+ }
249
+ }
250
+
251
+ static _onAppleAnnotationDragEnd (
252
+ appleMaps.LatLng latLng, Function onDragEnd) {
253
+ if (onDragEnd != null ) {
254
+ onDragEnd (LatLng ._fromAppleLatLng (latLng));
255
+ }
181
256
}
182
257
}
0 commit comments