Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
bump flutter_map to 3.0.0
  • Loading branch information
ankiimation committed Feb 26, 2023
1 parent 358fd5c commit a8007ae
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 194 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.0

* PUMP flutter_map to 3.0.0

## 0.0.4

* UPGRADE PACKAGES
Expand Down
58 changes: 27 additions & 31 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class _MapScreenState extends State<MapScreen> with TickerProviderStateMixin {
final Location location = new Location();
final geodesy.Geodesy _geodesy = geodesy.Geodesy();
final BehaviorSubject<LocationData> locationSC = BehaviorSubject();
late final AnimatedMapController mapController =
AnimatedMapController(vsync: this);
final mapController = MapController();

LocationData? lastFix;
int duration = 0;
Expand Down Expand Up @@ -97,13 +96,9 @@ class _MapScreenState extends State<MapScreen> with TickerProviderStateMixin {
.toDouble();
lastFix = event;

mapController.animatedTo(
mapController.move(
LatLng(lastFix?.latitude ?? 0, lastFix?.longitude ?? 0),
destZoom: 16,
destBearing: -(max(0, lastFix?.heading ?? 0).toDouble()),
duration: Duration(
milliseconds: duration,
),
16,
);
});
}
Expand Down Expand Up @@ -132,36 +127,37 @@ class _MapScreenState extends State<MapScreen> with TickerProviderStateMixin {
return FlutterMap(
mapController: mapController,
options: MapOptions(
center: LatLng(51.509364, -0.128928),
zoom: 9.2,
plugins: [AnimatedMarkerPlugin()]),
layers: [
TileLayerOptions(
urlTemplate: "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
center: LatLng(51.509364, -0.128928),
zoom: 9.2,
),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
),
if (locationData != null) ...[
AnimatedMarkerLayerOptions(
duration: Duration(
milliseconds: duration,
),
marker: Marker(
width: 30,
height: 30,
point: LatLng(
nextSimulateLocation.latitude,
nextSimulateLocation.longitude,
if (locationData != null)
AnimatedMarkerLayer(
options: AnimatedMarkerLayerOptions(
duration: Duration(
milliseconds: duration,
),
builder: (context) => Center(
child: Transform.rotate(
angle: max(0, locationData.heading ?? 0) * pi / 180,
child: Image.asset(
'lib/assets/puck.png',
marker: Marker(
width: 30,
height: 30,
point: LatLng(
nextSimulateLocation.latitude,
nextSimulateLocation.longitude,
),
builder: (context) => Center(
child: Transform.rotate(
angle: max(0, locationData.heading ?? 0) * pi / 180,
child: Image.asset(
'lib/assets/puck.png',
),
),
),
),
),
),
],
],
);
});
Expand Down
45 changes: 19 additions & 26 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
version: "2.9.0"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,21 +21,14 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
version: "1.2.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
collection:
dependency: transitive
description:
Expand All @@ -56,14 +49,14 @@ packages:
name: dart_exporter_annotation
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
version: "2.0.3"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.3.1"
fixnum:
dependency: "direct main"
description:
Expand All @@ -82,14 +75,14 @@ packages:
name: flutter_map
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
version: "3.1.0"
flutter_map_animated_marker:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "0.0.4"
version: "1.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -120,7 +113,7 @@ packages:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.3"
version: "0.13.5"
http_parser:
dependency: transitive
description:
Expand Down Expand Up @@ -183,21 +176,21 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
mgrs_dart:
dependency: transitive
description:
Expand All @@ -211,7 +204,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
pedantic:
dependency: transitive
description:
Expand Down Expand Up @@ -253,7 +246,7 @@ packages:
name: proj4dart
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0"
quiver:
dependency: transitive
description:
Expand All @@ -279,7 +272,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
version: "1.9.0"
stack_trace:
dependency: transitive
description:
Expand All @@ -300,21 +293,21 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
version: "0.4.12"
tuple:
dependency: transitive
description:
Expand Down Expand Up @@ -358,5 +351,5 @@ packages:
source: hosted
version: "5.1.2"
sdks:
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.0.0"
dart: ">=2.18.0 <3.0.0"
flutter: ">=3.3.0"
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
flutter_map: ^2.2.0
flutter_map: ^3.1.0
latlong2: ^0.8.1
flutter_map_animated_marker:
path: ..
Expand Down
86 changes: 27 additions & 59 deletions lib/src/animated_marker_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ import 'package:flutter_map/plugin_api.dart';
import 'package:flutter_map_animated_marker/src/animated_marker_layer_options.dart';
import 'package:latlong2/latlong.dart';

@doNotExport
@Export()
class AnimatedMarkerLayer<T> extends ImplicitlyAnimatedWidget {
final AnimatedMarkerLayerOptions<T> options;
final MapState map;
final Stream<T>? stream;
AnimatedMarkerLayer({
Key? key,
required this.options,
required this.map,
this.stream,
}) : super(
key: key,
duration: options.duration,
Expand Down Expand Up @@ -55,63 +51,35 @@ class _AnimatedMarkerLayerState
@override
Widget build(BuildContext context) {
super.build(context);

return StreamBuilder(
stream: widget.stream,
builder: (context, snapshot) {
final pxPoint = widget.map.project(LatLng(latitude, longitude));
final width = marker.width - marker.anchor.left;
final height = marker.height - marker.anchor.top;
var sw = CustomPoint(pxPoint.x + width, pxPoint.y - height);
var ne = CustomPoint(pxPoint.x - width, pxPoint.y + height);
if (!widget.map.pixelBounds.containsPartialBounds(Bounds(sw, ne))) {
return const SizedBox();
}
final pos = pxPoint - widget.map.getPixelOrigin();
final markerWidget = (marker.rotate ?? widget.options.rotate ?? false)
// Counter rotated marker to the map rotation
? Transform.rotate(
angle: -widget.map.rotationRad,
origin: marker.rotateOrigin ?? widget.options.rotateOrigin,
alignment:
marker.rotateAlignment ?? widget.options.rotateAlignment,
child: marker.builder(context),
)
: marker.builder(context);
return Positioned(
key: marker.key,
width: marker.width,
height: marker.height,
left: pos.x - width,
top: pos.y - height,
child: markerWidget,
);
},
final map = FlutterMapState.maybeOf(context)!;
final pxPoint = map.project(LatLng(latitude, longitude));
final width = marker.width - marker.anchor.left;
final height = marker.height - marker.anchor.top;
var sw = CustomPoint(pxPoint.x + width, pxPoint.y - height);
var ne = CustomPoint(pxPoint.x - width, pxPoint.y + height);
if (!map.pixelBounds.containsPartialBounds(Bounds(sw, ne))) {
return const SizedBox();
}
final pos = pxPoint - map.pixelOrigin;
final markerWidget = (marker.rotate ?? widget.options.rotate ?? false)
// Counter rotated marker to the map rotation
? Transform.rotate(
angle: -map.rotationRad,
origin: marker.rotateOrigin ?? widget.options.rotateOrigin,
alignment: marker.rotateAlignment ?? widget.options.rotateAlignment,
child: marker.builder(context),
)
: marker.builder(context);
return Positioned(
key: marker.key,
width: marker.width,
height: marker.height,
left: pos.x - width,
top: pos.y - height,
child: markerWidget,
);
}

@override
bool get wantKeepAlive => true;
}

class AnimatedMarkerLayerWidget<T> extends StatelessWidget {
final AnimatedMarkerLayerOptions<T> options;
final Duration duration;
final Curve curve;
const AnimatedMarkerLayerWidget({
Key? key,
required this.options,
this.duration = const Duration(milliseconds: 300),
this.curve = Curves.linear,
}) : super(key: key);

@override
Widget build(BuildContext context) {
final mapState = MapState.maybeOf(context)!;
return AnimatedMarkerLayer(
options: options,
map: mapState,
stream: mapState.onMoved,
);
}
}
4 changes: 3 additions & 1 deletion lib/src/animated_marker_layer_options.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:dart_exporter_annotation/dart_exporter_annotation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';

class AnimatedMarkerLayerOptions<T> extends LayerOptions {
@Export()
class AnimatedMarkerLayerOptions<T> {
final Duration duration;
final Curve curve;
final Marker marker;
Expand Down
Loading

0 comments on commit a8007ae

Please sign in to comment.