Skip to content

Commit 9ce250b

Browse files
committed
Fixed marker Bug.
1 parent e796134 commit 9ce250b

File tree

11 files changed

+236
-66
lines changed

11 files changed

+236
-66
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.4+1
2+
3+
* Fixed Marker icon Bug
4+
15
## 0.1.4
26

37
* Added ability to place polylines.

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ packages:
9494
path: ".."
9595
relative: true
9696
source: path
97-
version: "0.1.4"
97+
version: "0.1.4+1"
9898
quiver:
9999
dependency: transitive
100100
description:

lib/platform_maps_flutter.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import 'package:flutter/cupertino.dart';
66
import 'package:flutter/foundation.dart';
77
import 'package:flutter/gestures.dart';
88
import 'package:flutter/material.dart';
9+
import 'package:flutter/services.dart';
910
import 'package:google_maps_flutter/google_maps_flutter.dart' as googleMaps;
1011
import 'package:apple_maps_flutter/apple_maps_flutter.dart' as appleMaps;
1112

13+
part 'src/bitmap.dart';
1214
part 'src/camera.dart';
1315
part 'src/platform_maps.dart';
1416
part 'src/location.dart';

lib/src/bitmap.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
part of flutter_platform_maps;
2+
3+
/// Defines a bitmap image. For a marker, this class can be used to set the
4+
/// image of the marker icon. For a ground overlay, it can be used to set the
5+
/// image to place on the surface of the earth.
6+
7+
class BitmapDescriptor {
8+
/// Creates a BitmapDescriptor that refers to the default marker image.
9+
static dynamic get defaultMarker {
10+
if (Platform.isIOS) {
11+
return appleMaps.BitmapDescriptor.defaultAnnotation;
12+
} else if (Platform.isAndroid) {
13+
return googleMaps.BitmapDescriptor.defaultMarker;
14+
}
15+
return null;
16+
}
17+
18+
static dynamic fromAssetImage(
19+
ImageConfiguration configuration,
20+
String assetName, {
21+
AssetBundle bundle,
22+
String package,
23+
}) {
24+
if (Platform.isIOS) {
25+
return appleMaps.BitmapDescriptor.fromAssetImage(
26+
configuration,
27+
assetName,
28+
bundle: bundle,
29+
package: package,
30+
);
31+
} else if (Platform.isAndroid) {
32+
return googleMaps.BitmapDescriptor.fromAssetImage(
33+
configuration,
34+
assetName,
35+
bundle: bundle,
36+
package: package,
37+
);
38+
}
39+
}
40+
}

lib/src/camera.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ class CameraPosition {
5757
zoom: this.zoom,
5858
);
5959
}
60+
61+
static CameraPosition fromAppleMapCameraPosition(
62+
appleMaps.CameraPosition cameraPosition) {
63+
return CameraPosition(
64+
target: LatLng._fromAppleLatLng(cameraPosition.target),
65+
bearing: cameraPosition.heading,
66+
tilt: cameraPosition.pitch,
67+
zoom: cameraPosition.zoom,
68+
);
69+
}
70+
71+
static CameraPosition fromGoogleMapCameraPosition(
72+
googleMaps.CameraPosition cameraPosition) {
73+
return CameraPosition(
74+
target: LatLng._fromGoogleLatLng(cameraPosition.target),
75+
bearing: cameraPosition.bearing,
76+
tilt: cameraPosition.tilt,
77+
zoom: cameraPosition.zoom,
78+
);
79+
}
6080
}
6181

6282
class CameraUpdate implements googleMaps.CameraUpdate, appleMaps.CameraUpdate {

lib/src/cap.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class _Cap {
2727
}
2828

2929
static appleMaps.Cap applePolylineCap(Cap cap) {
30-
print('Cap: ${cap}');
3130
return appleMapsCaps[cap];
3231
}
3332
}

lib/src/controller.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class PlatformMapController {
2828
///
2929
/// The returned [Future] completes after the change has been made on the
3030
/// platform side.
31-
Future<void> moveCamera(CameraUpdate cameraUpdate) async {
31+
Future<void> moveCamera(cameraUpdate) async {
3232
if (Platform.isIOS) {
3333
return this.appleController.moveCamera(cameraUpdate);
3434
} else if (Platform.isAndroid) {

lib/src/marker.dart

Lines changed: 109 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)