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