Skip to content

Commit 51af82f

Browse files
committed
Polyline implementation
1 parent c67cf64 commit 51af82f

10 files changed

+400
-7
lines changed

example/pubspec.lock

+1-1
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.0.4"
10+
version: "0.0.5"
1111
async:
1212
dependency: transitive
1313
description:

lib/platform_maps_flutter.dart

+5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ import 'dart:io';
55
import 'package:flutter/cupertino.dart';
66
import 'package:flutter/foundation.dart';
77
import 'package:flutter/gestures.dart';
8+
import 'package:flutter/material.dart';
89
import 'package:google_maps_flutter/google_maps_flutter.dart' as googleMaps;
910
import 'package:apple_maps_flutter/apple_maps_flutter.dart' as appleMaps;
1011

1112
part 'src/camera.dart';
1213
part 'src/platform_maps.dart';
1314
part 'src/location.dart';
1415
part 'src/marker.dart';
16+
part 'src/polyline.dart';
17+
part 'src/cap.dart';
18+
part 'src/joint_type.dart';
19+
part 'src/pattern_item.dart';
1520
part 'src/controller.dart';
1621
part 'src/ui.dart';

lib/src/cap.dart

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2019 The Chromium Authors. All rights reserved.
2+
part of flutter_platform_maps;
3+
4+
enum Cap {
5+
buttCap,
6+
roundCap,
7+
squareCap,
8+
}
9+
10+
/// Cap that can be applied at the start or end vertex of a [Polyline].
11+
@immutable
12+
class _Cap {
13+
static const Map<Cap, googleMaps.Cap> googleMapsCaps = {
14+
Cap.buttCap: googleMaps.Cap.buttCap,
15+
Cap.roundCap: googleMaps.Cap.roundCap,
16+
Cap.squareCap: googleMaps.Cap.squareCap,
17+
};
18+
19+
static const Map<Cap, appleMaps.Cap> appleMapsCaps = {
20+
Cap.buttCap: appleMaps.Cap.buttCap,
21+
Cap.roundCap: appleMaps.Cap.roundCap,
22+
Cap.squareCap: appleMaps.Cap.squareCap,
23+
};
24+
25+
static googleMaps.Cap googlePolylineCap(Cap cap) {
26+
return googleMapsCaps[cap];
27+
}
28+
29+
static appleMaps.Cap applePolylineCap(Cap cap) {
30+
print('Cap: ${cap}');
31+
return appleMapsCaps[cap];
32+
}
33+
}

lib/src/joint_type.dart

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 flutter_platform_maps;
6+
7+
/// Joint types for [Polyline].
8+
@immutable
9+
class JointType {
10+
const JointType._(this.value);
11+
12+
/// The value representing the [JointType] on the sdk.
13+
final int value;
14+
15+
static const List<googleMaps.JointType> googleMapsJointTypes = const [
16+
googleMaps.JointType.mitered,
17+
googleMaps.JointType.bevel,
18+
googleMaps.JointType.round,
19+
];
20+
21+
static const List<appleMaps.JointType> appleMapsJointTypes = const [
22+
appleMaps.JointType.mitered,
23+
appleMaps.JointType.bevel,
24+
appleMaps.JointType.round,
25+
];
26+
27+
/// Mitered joint, with fixed pointed extrusion equal to half the stroke width on the outside of the joint.
28+
///
29+
/// Constant Value: 0
30+
static const JointType mitered = JointType._(0);
31+
32+
/// Flat bevel on the outside of the joint.
33+
///
34+
/// Constant Value: 1
35+
static const JointType bevel = JointType._(1);
36+
37+
/// Rounded on the outside of the joint by an arc of radius equal to half the stroke width, centered at the vertex.
38+
///
39+
/// Constant Value: 2
40+
static const JointType round = JointType._(2);
41+
42+
static googleMaps.JointType getGoogleMapsJointType(JointType jointType) {
43+
return googleMapsJointTypes[jointType.value];
44+
}
45+
46+
static appleMaps.JointType getAppleMapsJointType(JointType jointType) {
47+
return appleMapsJointTypes[jointType.value];
48+
}
49+
}

lib/src/location.dart

+17
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ class LatLng {
4040
this.latitude,
4141
this.longitude,
4242
);
43+
44+
static List<googleMaps.LatLng> googleMapsLatLngsFromList(
45+
List<LatLng> latlngs) {
46+
List<googleMaps.LatLng> googleMapsLatLngs = List();
47+
latlngs.forEach((LatLng latlng) {
48+
googleMapsLatLngs.add(latlng.googleLatLng);
49+
});
50+
return googleMapsLatLngs;
51+
}
52+
53+
static List<appleMaps.LatLng> appleMapsLatLngsFromList(List<LatLng> latlngs) {
54+
List<appleMaps.LatLng> appleMapsLatLngs = List();
55+
latlngs.forEach((LatLng latlng) {
56+
appleMapsLatLngs.add(latlng.appleLatLng);
57+
});
58+
return appleMapsLatLngs;
59+
}
4360
}
4461

4562
class LatLngBounds {

lib/src/pattern_item.dart

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
part of flutter_platform_maps;
2+
3+
/// Item used in the stroke pattern for a Polyline.
4+
@immutable
5+
class PatternItem {
6+
const PatternItem._(this._json);
7+
8+
static const PatternItem dot = PatternItem._(<dynamic>['dot']);
9+
10+
/// A dash used in the stroke pattern for a [Polyline].
11+
///
12+
/// [length] has to be non-negative.
13+
static PatternItem dash(double length) {
14+
assert(length >= 0.0);
15+
return PatternItem._(<dynamic>['dash', length]);
16+
}
17+
18+
/// A gap used in the stroke pattern for a [Polyline].
19+
///
20+
/// [length] has to be non-negative.
21+
static PatternItem gap(double length) {
22+
assert(length >= 0.0);
23+
return PatternItem._(<dynamic>['gap', length]);
24+
}
25+
26+
static googleMaps.PatternItem _googleMapsPatternItem(
27+
PatternItem patternItem) {
28+
if (patternItem._json[0] == 'dash') {
29+
return googleMaps.PatternItem.dash(patternItem._json[1]);
30+
} else if (patternItem._json[0] == 'gap') {
31+
return googleMaps.PatternItem.gap(patternItem._json[1]);
32+
}
33+
return googleMaps.PatternItem.dot;
34+
}
35+
36+
static appleMaps.PatternItem _appleMapsPatternItem(PatternItem patternItem) {
37+
if (patternItem._json[0] == 'dash') {
38+
return appleMaps.PatternItem.dash(patternItem._json[1]);
39+
} else if (patternItem._json[0] == 'gap') {
40+
return appleMaps.PatternItem.gap(patternItem._json[1]);
41+
}
42+
return appleMaps.PatternItem.dot;
43+
}
44+
45+
final dynamic _json;
46+
47+
static List<googleMaps.PatternItem> getGoogleMapsPatternItemList(
48+
List<PatternItem> patternItems) {
49+
List<googleMaps.PatternItem> googleMapsPatternItems = List();
50+
patternItems.forEach((PatternItem patternItem) {
51+
googleMapsPatternItems.add(
52+
_googleMapsPatternItem(patternItem),
53+
);
54+
});
55+
return googleMapsPatternItems;
56+
}
57+
58+
static List<appleMaps.PatternItem> getAppleMapsPatternItemList(
59+
List<PatternItem> patternItems) {
60+
List<appleMaps.PatternItem> appleMapsPatternItems = List();
61+
patternItems.forEach((PatternItem patternItem) {
62+
appleMapsPatternItems.add(
63+
_appleMapsPatternItem(patternItem),
64+
);
65+
});
66+
return appleMapsPatternItems;
67+
}
68+
}

lib/src/platform_maps.dart

+16-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ part of flutter_platform_maps;
22

33
typedef void MapCreatedCallback(PlatformMapController controller);
44

5-
/// A Calculator.
65
class PlatformMap extends StatefulWidget {
76
const PlatformMap({
87
Key key,
@@ -19,6 +18,7 @@ class PlatformMap extends StatefulWidget {
1918
this.myLocationEnabled = false,
2019
this.myLocationButtonEnabled = true,
2120
this.markers,
21+
this.polylines,
2222
this.onCameraMoveStarted,
2323
this.onCameraMove,
2424
this.onCameraIdle,
@@ -62,6 +62,9 @@ class PlatformMap extends StatefulWidget {
6262
/// Markers to be placed on the map.
6363
final Set<Marker> markers;
6464

65+
/// Polylines to be placed on the map.
66+
final Set<Polyline> polylines;
67+
6568
/// Called when the camera starts moving.
6669
///
6770
/// This can be initiated by the following:
@@ -150,7 +153,12 @@ class _PlatformMapState extends State<PlatformMap> {
150153
widget.initialCameraPosition.googleMapsCameraPosition,
151154
compassEnabled: widget.compassEnabled,
152155
mapType: _getGoogleMapType(),
153-
markers: Marker.toGoogleMapsMarkerSet(widget.markers),
156+
markers: widget.markers != null
157+
? Marker.toGoogleMapsMarkerSet(widget.markers)
158+
: widget.markers,
159+
polylines: widget.polylines != null
160+
? Polyline.toGoogleMapsPolylines(widget.polylines)
161+
: widget.polylines,
154162
gestureRecognizers: widget.gestureRecognizers,
155163
onCameraIdle: widget.onCameraIdle,
156164
myLocationButtonEnabled: widget.myLocationButtonEnabled,
@@ -175,7 +183,12 @@ class _PlatformMapState extends State<PlatformMap> {
175183
widget.initialCameraPosition.appleMapsCameraPosition,
176184
compassEnabled: widget.compassEnabled,
177185
mapType: _getAppleMapType(),
178-
annotations: Marker.toAppleMapsAnnotationSet(widget.markers),
186+
annotations: widget.markers != null
187+
? Marker.toAppleMapsAnnotationSet(widget.markers)
188+
: widget.markers,
189+
polylines: widget.polylines != null
190+
? Polyline.toAppleMapsPolylines(widget.polylines)
191+
: widget.polylines,
179192
gestureRecognizers: widget.gestureRecognizers,
180193
onCameraIdle: widget.onCameraIdle,
181194
myLocationButtonEnabled: widget.myLocationButtonEnabled,

0 commit comments

Comments
 (0)