Skip to content

Commit 20bf0a2

Browse files
committed
Implemented some maps functionality
1 parent 7eae1bb commit 20bf0a2

File tree

10 files changed

+326
-146
lines changed

10 files changed

+326
-146
lines changed

lib/platform_maps_flutter.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ import 'package:apple_maps_flutter/apple_maps_flutter.dart' as appleMaps;
1111
part 'src/camera.dart';
1212
part 'src/platform_maps.dart';
1313
part 'src/location.dart';
14+
part 'src/marker.dart';
15+
part 'src/map_type.dart';

lib/src/camera.dart

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,28 @@ part of flutter_platform_maps;
77
/// The position of the map "camera", the view point from which the world is
88
/// shown in the map view. Aggregates the camera's [target] geographical
99
/// location, its [zoom] level, [pitch] angle, and [heading].
10-
class CameraPosition
11-
implements googleMaps.CameraPosition, appleMaps.CameraPosition {
10+
class CameraPosition {
1211
const CameraPosition({
1312
@required this.target,
14-
this.heading = 0.0,
15-
this.pitch = 0.0,
13+
this.bearing = 0.0,
14+
this.tilt = 0.0,
1615
this.zoom = 0,
1716
}) : assert(target != null),
18-
assert(heading != null),
19-
assert(pitch != null),
17+
assert(bearing != null),
18+
assert(tilt != null),
2019
assert(zoom != null);
2120

2221
/// The camera's bearing in degrees, measured clockwise from north.
2322
///
2423
/// A bearing of 0.0, the default, means the camera points north.
2524
/// A bearing of 90.0 means the camera points east.
26-
final double heading;
25+
final double bearing;
2726

2827
/// The geographical location that the camera is pointing at.
2928
final LatLng target;
3029

3130
// In degrees where 0 is looking straight down. Pitch may be clamped to an appropriate value.
32-
final double pitch;
31+
final double tilt;
3332

3433
/// The zoom level of the camera.
3534
///
@@ -45,21 +44,21 @@ class CameraPosition
4544
/// will be silently clamped to the supported range.
4645
final double zoom;
4746

48-
@override
49-
String toString() =>
50-
'CameraPosition(bearing: $heading, target: $target, tilt: $pitch, zoom: $zoom)';
51-
52-
@override
53-
// TODO: implement bearing
54-
double get bearing => null;
55-
56-
@override
57-
// TODO: implement tilt
58-
double get tilt => null;
47+
appleMaps.CameraPosition appleMapsCameraPosition() {
48+
return appleMaps.CameraPosition(
49+
target: this.target.appleLatLng,
50+
heading: this.bearing,
51+
pitch: this.tilt,
52+
zoom: this.zoom,
53+
);
54+
}
5955

60-
@override
61-
toMap() {
62-
// TODO: implement toMap
63-
return null;
56+
googleMaps.CameraPosition googleMapsCameraPosition() {
57+
return googleMaps.CameraPosition(
58+
target: this.target.googleLatLng,
59+
bearing: this.bearing,
60+
tilt: this.tilt,
61+
zoom: this.zoom,
62+
);
6463
}
6564
}

lib/src/location.dart

Lines changed: 9 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
part of flutter_platform_maps;
66

77
/// A pair of latitude and longitude coordinates, stored as degrees.
8-
class LatLng implements googleMaps.LatLng, appleMaps.LatLng {
8+
class LatLng {
99
/// Creates a geographical location specified in degrees [latitude] and
1010
/// [longitude].
1111
///
@@ -26,17 +26,6 @@ class LatLng implements googleMaps.LatLng, appleMaps.LatLng {
2626
/// The longitude in degrees between -180.0 (inclusive) and 180.0 (exclusive).
2727
final double longitude;
2828

29-
dynamic _toJson() {
30-
return <double>[latitude, longitude];
31-
}
32-
33-
static LatLng _fromJson(dynamic json) {
34-
if (json == null) {
35-
return null;
36-
}
37-
return LatLng(json[0], json[1]);
38-
}
39-
4029
@override
4130
String toString() => '$runtimeType($latitude, $longitude)';
4231

@@ -45,79 +34,13 @@ class LatLng implements googleMaps.LatLng, appleMaps.LatLng {
4534
return o is LatLng && o.latitude == latitude && o.longitude == longitude;
4635
}
4736

48-
@override
49-
int get hashCode => hashValues(latitude, longitude);
50-
}
51-
52-
/// A latitude/longitude aligned rectangle.
53-
///
54-
/// The rectangle conceptually includes all points (lat, lng) where
55-
/// * lat ∈ [`southwest.latitude`, `northeast.latitude`]
56-
/// * lng ∈ [`southwest.longitude`, `northeast.longitude`],
57-
/// if `southwest.longitude``northeast.longitude`,
58-
/// * lng ∈ [-180, `northeast.longitude`] ∪ [`southwest.longitude`, 180[,
59-
/// if `northeast.longitude` < `southwest.longitude`
60-
class LatLngBounds {
61-
/// Creates geographical bounding box with the specified corners.
62-
///
63-
/// The latitude of the southwest corner cannot be larger than the
64-
/// latitude of the northeast corner.
65-
LatLngBounds({@required this.southwest, @required this.northeast})
66-
: assert(southwest != null),
67-
assert(northeast != null),
68-
assert(southwest.latitude <= northeast.latitude);
69-
70-
/// The southwest corner of the rectangle.
71-
final LatLng southwest;
72-
73-
/// The northeast corner of the rectangle.
74-
final LatLng northeast;
75-
76-
dynamic _toList() {
77-
return <dynamic>[southwest._toJson(), northeast._toJson()];
78-
}
79-
80-
/// Returns whether this rectangle contains the given [LatLng].
81-
bool contains(LatLng point) {
82-
return _containsLatitude(point.latitude) &&
83-
_containsLongitude(point.longitude);
84-
}
85-
86-
bool _containsLatitude(double lat) {
87-
return (southwest.latitude <= lat) && (lat <= northeast.latitude);
88-
}
89-
90-
bool _containsLongitude(double lng) {
91-
if (southwest.longitude <= northeast.longitude) {
92-
return southwest.longitude <= lng && lng <= northeast.longitude;
93-
} else {
94-
return southwest.longitude <= lng || lng <= northeast.longitude;
95-
}
96-
}
97-
98-
@visibleForTesting
99-
static LatLngBounds fromList(dynamic json) {
100-
if (json == null) {
101-
return null;
102-
}
103-
return LatLngBounds(
104-
southwest: LatLng._fromJson(json[0]),
105-
northeast: LatLng._fromJson(json[1]),
106-
);
107-
}
108-
109-
@override
110-
String toString() {
111-
return '$runtimeType($southwest, $northeast)';
112-
}
37+
appleMaps.LatLng get appleLatLng => appleMaps.LatLng(
38+
this.latitude,
39+
this.longitude,
40+
);
11341

114-
@override
115-
bool operator ==(Object o) {
116-
return o is LatLngBounds &&
117-
o.southwest == southwest &&
118-
o.northeast == northeast;
119-
}
120-
121-
@override
122-
int get hashCode => hashValues(southwest, northeast);
42+
googleMaps.LatLng get googleLatLng => googleMaps.LatLng(
43+
this.latitude,
44+
this.longitude,
45+
);
12346
}

lib/src/map_type.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
part of flutter_platform_maps;
2+
3+
class MapType {
4+
static get normal {
5+
if (Platform.isIOS) {
6+
return appleMaps.MapType.standard;
7+
} else if (Platform.isAndroid) {
8+
return googleMaps.MapType.normal;
9+
}
10+
}
11+
12+
static get satallite {
13+
if (Platform.isIOS) {
14+
return appleMaps.MapType.satellite;
15+
} else if (Platform.isAndroid) {
16+
return googleMaps.MapType.satellite;
17+
}
18+
}
19+
20+
static get hybrid {
21+
if (Platform.isAndroid) {
22+
return appleMaps.MapType.hybrid;
23+
} else if (Platform.isIOS) {
24+
return googleMaps.MapType.hybrid;
25+
}
26+
}
27+
}

lib/src/marker.dart

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
// Copyright 2018 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 flutter_platform_maps;
6+
7+
dynamic _offsetToJson(Offset offset) {
8+
if (offset == null) {
9+
return null;
10+
}
11+
return <dynamic>[offset.dx, offset.dy];
12+
}
13+
14+
/// Text labels for a [Marker] info window.
15+
class InfoWindow {
16+
const InfoWindow({
17+
this.title,
18+
this.snippet,
19+
this.onTap,
20+
});
21+
22+
/// Text labels specifying that no text is to be displayed.
23+
static const InfoWindow noText = InfoWindow();
24+
25+
/// Text displayed in an info window when the user taps the marker.
26+
///
27+
/// A null value means no title.
28+
final String title;
29+
30+
/// Additional text displayed below the [title].
31+
///
32+
/// A null value means no additional text.
33+
final String snippet;
34+
35+
/// onTap callback for this [InfoWindow].
36+
final VoidCallback onTap;
37+
38+
appleMaps.InfoWindow get appleMapsInfoWindow => appleMaps.InfoWindow(
39+
anchor: Offset(0, 0),
40+
onTap: this.onTap,
41+
snippet: this.snippet,
42+
title: this.title,
43+
);
44+
45+
googleMaps.InfoWindow get googleMapsInfoWindow => googleMaps.InfoWindow(
46+
anchor: Offset(0, 0),
47+
onTap: this.onTap,
48+
snippet: this.snippet,
49+
title: this.title,
50+
);
51+
}
52+
53+
/// Uniquely identifies a [Marker] among [GoogleMap] markers.
54+
///
55+
/// This does not have to be globally unique, only unique among the list.
56+
@immutable
57+
class MarkerId {
58+
MarkerId(this.value) : assert(value != null);
59+
60+
/// value of the [MarkerId].
61+
final String value;
62+
63+
appleMaps.AnnotationId get appleMapsAnnoationId => appleMaps.AnnotationId(
64+
this.value,
65+
);
66+
67+
googleMaps.MarkerId get googleMapsMarkerId => googleMaps.MarkerId(
68+
this.value,
69+
);
70+
}
71+
72+
/// Marks a geographical location on the map.
73+
///
74+
/// A marker icon is drawn oriented against the device's screen rather than
75+
/// the map's surface; that is, it will not necessarily change orientation
76+
/// due to map rotations, tilting, or zooming.
77+
@immutable
78+
class Marker {
79+
/// Creates a set of marker configuration options.
80+
///
81+
/// Default marker options.
82+
///
83+
/// Specifies a marker that
84+
/// * is fully opaque; [alpha] is 1.0
85+
/// * uses icon bottom center to indicate map position; [anchor] is (0.5, 1.0)
86+
/// * has default tap handling; [consumeTapEvents] is false
87+
/// * is stationary; [draggable] is false
88+
/// * is drawn against the screen, not the map; [flat] is false
89+
/// * has a default icon; [icon] is `BitmapDescriptor.defaultMarker`
90+
/// * anchors the info window at top center; [infoWindowAnchor] is (0.5, 0.0)
91+
/// * has no info window text; [infoWindowText] is `InfoWindowText.noText`
92+
/// * is positioned at 0, 0; [position] is `LatLng(0.0, 0.0)`
93+
/// * has an axis-aligned icon; [rotation] is 0.0
94+
/// * is visible; [visible] is true
95+
/// * is placed at the base of the drawing order; [zIndex] is 0.0
96+
const Marker({
97+
@required this.markerId,
98+
this.alpha = 1.0,
99+
this.consumeTapEvents = false,
100+
this.draggable = false,
101+
// this.icon = BitmapDescriptor.defaultMarker,
102+
this.infoWindow = InfoWindow.noText,
103+
this.position = const LatLng(0.0, 0.0),
104+
this.onTap,
105+
}) : assert(alpha == null || (0.0 <= alpha && alpha <= 1.0));
106+
107+
/// Uniquely identifies a [Marker].
108+
final MarkerId markerId;
109+
110+
/// The opacity of the marker, between 0.0 and 1.0 inclusive.
111+
///
112+
/// 0.0 means fully transparent, 1.0 means fully opaque.
113+
final double alpha;
114+
115+
/// True if the marker icon consumes tap events. If not, the map will perform
116+
/// default tap handling by centering the map on the marker and displaying its
117+
/// info window.
118+
final bool consumeTapEvents;
119+
120+
/// True if the marker is draggable by user touch events.
121+
final bool draggable;
122+
123+
/// A description of the bitmap used to draw the marker icon.
124+
// final BitmapDescriptor icon;
125+
126+
/// A Google Maps InfoWindow.
127+
///
128+
/// The window is displayed when the marker is tapped.
129+
final InfoWindow infoWindow;
130+
131+
/// Geographical location of the marker.
132+
final LatLng position;
133+
134+
/// Callbacks to receive tap events for markers placed on this map.
135+
final VoidCallback onTap;
136+
137+
appleMaps.Annotation get appleMapsAnnotation => appleMaps.Annotation(
138+
annotationId: this.markerId.appleMapsAnnoationId,
139+
alpha: this.alpha,
140+
draggable: this.draggable,
141+
infoWindow: this.infoWindow.appleMapsInfoWindow,
142+
onTap: this.onTap,
143+
position: this.position.appleLatLng,
144+
);
145+
}

0 commit comments

Comments
 (0)