Skip to content

Commit ea9f20f

Browse files
committed
Added ability to place Circles on the map
1 parent 1adca15 commit ea9f20f

File tree

6 files changed

+186
-4
lines changed

6 files changed

+186
-4
lines changed

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ packages:
77
name: apple_maps_flutter
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "0.1.1"
10+
version: "0.1.1+1"
1111
archive:
1212
dependency: transitive
1313
description:

lib/platform_maps_flutter.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ part 'src/marker.dart';
1818
part 'src/polyline.dart';
1919
part 'src/polygon.dart';
2020
part 'src/cap.dart';
21+
part 'src/circle.dart';
2122
part 'src/joint_type.dart';
2223
part 'src/pattern_item.dart';
2324
part 'src/controller.dart';

lib/src/circle.dart

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
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+
}

lib/src/platform_maps.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class PlatformMap extends StatefulWidget {
2323
this.markers,
2424
this.polylines,
2525
this.polygons,
26+
this.circles,
2627
this.onCameraMoveStarted,
2728
this.onCameraMove,
2829
this.onCameraIdle,
@@ -72,6 +73,9 @@ class PlatformMap extends StatefulWidget {
7273
/// Polygons to be placed on the map.
7374
final Set<Polygon> polygons;
7475

76+
/// Polygons to be placed on the map.
77+
final Set<Circle> circles;
78+
7579
/// Called when the camera starts moving.
7680
///
7781
/// This can be initiated by the following:
@@ -175,6 +179,9 @@ class _PlatformMapState extends State<PlatformMap> {
175179
polygons: widget.polygons != null
176180
? Polygon.toGoogleMapsPolygonSet(widget.polygons)
177181
: widget.polygons,
182+
circles: widget.circles != null
183+
? Circle.toGoogleMapsCircleSet(widget.circles)
184+
: widget.circles,
178185
gestureRecognizers: widget.gestureRecognizers,
179186
onCameraIdle: widget.onCameraIdle,
180187
myLocationButtonEnabled: widget.myLocationButtonEnabled,
@@ -209,6 +216,9 @@ class _PlatformMapState extends State<PlatformMap> {
209216
polygons: widget.polygons != null
210217
? Polygon.toAppleMapsPolygonSet(widget.polygons)
211218
: widget.polygons,
219+
circles: widget.circles != null
220+
? Circle.toAppleMapsCircleSet(widget.circles)
221+
: widget.circles,
212222
gestureRecognizers: widget.gestureRecognizers,
213223
onCameraIdle: widget.onCameraIdle,
214224
myLocationButtonEnabled: widget.myLocationButtonEnabled,

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ packages:
77
name: apple_maps_flutter
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "0.1.1"
10+
version: "0.1.1+1"
1111
archive:
1212
dependency: transitive
1313
description:

pubspec.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ name: platform_maps_flutter
22
description: A Flutter package that combines google_maps and apple_maps to provide a crossplatform native map implementation.
33
version: 0.1.5
44
homepage: https://github.com/LuisThein
5-
github: https://github.com/LuisThein/flutter_platform_maps
5+
repository: https://github.com/LuisThein/platform_maps_flutter
6+
issue_tracker: https://github.com/LuisThein/platform_maps_flutter/issues
67

78
environment:
89
sdk: ">=2.1.0 <3.0.0"
@@ -13,7 +14,7 @@ dependencies:
1314

1415
google_maps_flutter: ^0.5.21+7
1516

16-
apple_maps_flutter: ^0.1.1
17+
apple_maps_flutter: ^0.1.1+1
1718

1819

1920
dev_dependencies:

0 commit comments

Comments
 (0)