mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 08:46:18 +01:00
Support rotation in static map
This commit is contained in:
parent
e643f898d3
commit
55880944ce
4 changed files with 20 additions and 27 deletions
|
@ -357,8 +357,7 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
|
|||
stream: context.read<PrefController>().gpsMapProvider,
|
||||
builder: (context, gpsMapProvider) => GpsMap(
|
||||
providerHint: gpsMapProvider.requireData,
|
||||
center: _gps!,
|
||||
zoom: 16,
|
||||
location: CameraPosition(center: _gps!, zoom: 16),
|
||||
onTap: _onMapTap,
|
||||
),
|
||||
),
|
||||
|
|
|
@ -16,8 +16,7 @@ class GpsMap extends StatelessWidget {
|
|||
const GpsMap({
|
||||
super.key,
|
||||
required this.providerHint,
|
||||
required this.center,
|
||||
required this.zoom,
|
||||
required this.location,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
|
@ -26,14 +25,12 @@ class GpsMap extends StatelessWidget {
|
|||
if (providerHint == GpsMapProvider.osm ||
|
||||
(getRawPlatform() == NpPlatform.android && !isNewGMapsRenderer())) {
|
||||
return OsmGpsMap(
|
||||
center: center,
|
||||
zoom: zoom,
|
||||
location: location,
|
||||
onTap: onTap,
|
||||
);
|
||||
} else {
|
||||
return GoogleGpsMap(
|
||||
center: center,
|
||||
zoom: zoom,
|
||||
location: location,
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
|
@ -43,8 +40,6 @@ class GpsMap extends StatelessWidget {
|
|||
/// actual choice may be different depending on the runtime environment
|
||||
final GpsMapProvider providerHint;
|
||||
|
||||
/// A pair of latitude and longitude coordinates, stored as degrees
|
||||
final MapCoord center;
|
||||
final double zoom;
|
||||
final CameraPosition location;
|
||||
final void Function()? onTap;
|
||||
}
|
||||
|
|
|
@ -5,14 +5,13 @@ import 'package:np_gps_map/src/type.dart' as type;
|
|||
class GoogleGpsMap extends StatelessWidget {
|
||||
const GoogleGpsMap({
|
||||
super.key,
|
||||
required this.center,
|
||||
required this.zoom,
|
||||
required this.location,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final centerLl = LatLng(center.latitude, center.longitude);
|
||||
final center = LatLng(location.center.latitude, location.center.longitude);
|
||||
return GoogleMap(
|
||||
compassEnabled: false,
|
||||
mapToolbarEnabled: false,
|
||||
|
@ -25,13 +24,14 @@ class GoogleGpsMap extends StatelessWidget {
|
|||
buildingsEnabled: false,
|
||||
// liteModeEnabled: true,
|
||||
initialCameraPosition: CameraPosition(
|
||||
target: centerLl,
|
||||
zoom: zoom,
|
||||
target: center,
|
||||
zoom: location.zoom,
|
||||
bearing: location.rotation,
|
||||
),
|
||||
markers: {
|
||||
Marker(
|
||||
markerId: const MarkerId("at"),
|
||||
position: centerLl,
|
||||
position: center,
|
||||
// for some reason, GoogleMap's onTap is not triggered if
|
||||
// tapped on top of the marker
|
||||
onTap: onTap,
|
||||
|
@ -46,8 +46,7 @@ class GoogleGpsMap extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
|
||||
final type.MapCoord center;
|
||||
final double zoom;
|
||||
final type.CameraPosition location;
|
||||
final VoidCallback? onTap;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,15 +6,14 @@ import 'package:np_gps_map/src/type.dart';
|
|||
class OsmGpsMap extends StatelessWidget {
|
||||
const OsmGpsMap({
|
||||
super.key,
|
||||
required this.center,
|
||||
required this.zoom,
|
||||
required this.location,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const double pinSize = 48;
|
||||
final centerLl = LatLng(center.latitude, center.longitude);
|
||||
final center = LatLng(location.center.latitude, location.center.longitude);
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
|
@ -23,8 +22,9 @@ class OsmGpsMap extends StatelessWidget {
|
|||
child: IgnorePointer(
|
||||
child: FlutterMap(
|
||||
options: MapOptions(
|
||||
initialCenter: centerLl,
|
||||
initialZoom: zoom,
|
||||
initialCenter: center,
|
||||
initialZoom: location.zoom,
|
||||
initialRotation: (360 - location.rotation) % 360,
|
||||
interactionOptions: const InteractionOptions(
|
||||
flags: InteractiveFlag.none,
|
||||
),
|
||||
|
@ -34,11 +34,12 @@ class OsmGpsMap extends StatelessWidget {
|
|||
urlTemplate: "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
|
||||
),
|
||||
MarkerLayer(
|
||||
rotate: true,
|
||||
markers: [
|
||||
Marker(
|
||||
width: pinSize,
|
||||
height: pinSize,
|
||||
point: centerLl,
|
||||
point: center,
|
||||
alignment: Alignment.topCenter,
|
||||
child: const Image(
|
||||
image: AssetImage(
|
||||
|
@ -56,7 +57,6 @@ class OsmGpsMap extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
|
||||
final MapCoord center;
|
||||
final double zoom;
|
||||
final CameraPosition location;
|
||||
final void Function()? onTap;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue