@@ -37,6 +37,20 @@ class InfoWindow {
3737 snippet: this .snippet,
3838 title: this .title,
3939 );
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+ }
4054}
4155
4256/// Uniquely identifies a [Marker] among [GoogleMap] markers.
@@ -71,26 +85,24 @@ class Marker {
7185 ///
7286 /// Specifies a marker that
7387 /// * is fully opaque; [alpha] is 1.0
74- /// * uses icon bottom center to indicate map position; [anchor] is (0.5, 1.0)
7588 /// * has default tap handling; [consumeTapEvents] is false
7689 /// * is stationary; [draggable] is false
77- /// * is drawn against the screen, not the map; [flat] is false
7890 /// * has a default icon; [icon] is `BitmapDescriptor.defaultMarker`
79- /// * anchors the info window at top center; [infoWindowAnchor] is (0.5, 0.0)
8091 /// * has no info window text; [infoWindowText] is `InfoWindowText.noText`
8192 /// * is positioned at 0, 0; [position] is `LatLng(0.0, 0.0)`
82- /// * has an axis-aligned icon; [rotation] is 0.0
8393 /// * is visible; [visible] is true
8494 /// * is placed at the base of the drawing order; [zIndex] is 0.0
8595 const Marker ({
8696 @required this .markerId,
8797 this .alpha = 1.0 ,
8898 this .consumeTapEvents = false ,
8999 this .draggable = false ,
90- // this.icon = BitmapDescriptor.defaultMarker ,
100+ this .icon,
91101 this .infoWindow = InfoWindow .noText,
92102 this .position = const LatLng (0.0 , 0.0 ),
93103 this .onTap,
104+ this .visible = true ,
105+ this .onDragEnd,
94106 }) : assert (alpha == null || (0.0 <= alpha && alpha <= 1.0 ));
95107
96108 /// Uniquely identifies a [Marker] .
@@ -110,7 +122,7 @@ class Marker {
110122 final bool draggable;
111123
112124 /// A description of the bitmap used to draw the marker icon.
113- // final BitmapDescriptor icon;
125+ final dynamic icon;
114126
115127 /// A Google Maps InfoWindow.
116128 ///
@@ -123,12 +135,23 @@ class Marker {
123135 /// Callbacks to receive tap events for markers placed on this map.
124136 final VoidCallback onTap;
125137
138+ /// True if the annotation is visible.
139+ final bool visible;
140+
141+ final ValueChanged <LatLng > onDragEnd;
142+
126143 appleMaps.Annotation get appleMapsAnnotation => appleMaps.Annotation (
127144 annotationId: this .markerId.appleMapsAnnoationId,
128145 alpha: this .alpha,
129146 draggable: this .draggable,
130147 infoWindow: this .infoWindow.appleMapsInfoWindow,
131148 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 ,
132155 position: this .position.appleLatLng,
133156 );
134157
@@ -138,45 +161,97 @@ class Marker {
138161 draggable: this .draggable,
139162 infoWindow: this .infoWindow.googleMapsInfoWindow,
140163 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 ,
141170 position: this .position.googleLatLng,
142171 );
143172
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+ );
154188
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+ );
165204
166205 static Set <appleMaps.Annotation > toAppleMapsAnnotationSet (
167206 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 ) {
170209 _annotations.add (appleMapsAnnotationFromMarker (marker));
171- });
172- return _annotations;
210+ }
211+ return Set . from ( _annotations) ;
173212 }
174213
175214 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 ) {
178217 _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+ }
181256 }
182257}
0 commit comments