Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(mobile): map heatmap color and location picker #6553

Merged
merged 8 commits into from
Feb 8, 2024
2 changes: 1 addition & 1 deletion mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 64c9b5291666c0ca3caabdfe9865c141ac40321d

COCOAPODS: 1.12.1
COCOAPODS: 1.11.3
8 changes: 4 additions & 4 deletions mobile/lib/extensions/build_context_extensions.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:flutter/material.dart';

extension ContextHelper on BuildContext {
// Returns the current size from MediaQuery
Size get size => MediaQuery.sizeOf(this);
// Returns the current padding from MediaQuery
EdgeInsets get padding => MediaQuery.paddingOf(this);

// Returns the current width from MediaQuery
double get width => size.width;
double get width => MediaQuery.sizeOf(this).width;

// Returns the current height from MediaQuery
double get height => size.height;
double get height => MediaQuery.sizeOf(this).height;

// Returns true if the app is running on a mobile device (!tablets)
bool get isMobile => width < 550;
Expand Down
21 changes: 11 additions & 10 deletions mobile/lib/modules/map/utils/map_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ class MapUtils {
["linear"],
["heatmap-density"],
0.0,
"rgba(246,239,247,0.0)",
0.2,
"rgb(208,209,230)",
0.4,
"rgb(166,189,219)",
0.6,
"rgb(103,169,207)",
0.8,
"rgb(28,144,153)",
"rgba(103,58,183,0.0)",
0.3,
"rgb(103,58,183)",
0.5,
"rgb(33,149,243)",
0.7,
"rgb(76,175,79)",
0.95,
"rgb(255,235,59)",
1.0,
"rgb(1,108,89)",
"rgb(255,86,34)",
],
heatmapIntensity: [
Expressions.interpolate, ["linear"], //
Expand All @@ -44,6 +44,7 @@ class MapUtils {
4, 8,
9, 16,
],
heatmapOpacity: 0.7,
);

static Map<String, dynamic> _addFeature(MapMarker marker) => {
Expand Down
150 changes: 72 additions & 78 deletions mobile/lib/modules/map/views/map_location_picker_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'package:immich_mobile/extensions/maplibrecontroller_extensions.dart';
import 'package:immich_mobile/modules/map/widgets/map_theme_override.dart';
import 'package:maplibre_gl/maplibre_gl.dart';
import 'package:immich_mobile/modules/map/utils/map_utils.dart';
import 'package:geolocator/geolocator.dart';

@RoutePage<LatLng?>()
class MapLocationPickerPage extends HookConsumerWidget {
Expand Down Expand Up @@ -46,15 +45,13 @@ class MapLocationPickerPage extends HookConsumerWidget {
}

Future<void> getCurrentLocation() async {
var (currentLocation, locationPermission) =
var (currentLocation, _) =
await MapUtils.checkPermAndGetLocation(context);
if (locationPermission == LocationPermission.denied ||
locationPermission == LocationPermission.deniedForever) {
return;
}

if (currentLocation == null) {
return;
}

var currentLatLng =
LatLng(currentLocation.latitude, currentLocation.longitude);
selectedLatLng.value = currentLatLng;
Expand All @@ -67,40 +64,35 @@ class MapLocationPickerPage extends HookConsumerWidget {
backgroundColor: ctx.themeData.cardColor,
appBar: _AppBar(onClose: onClose),
extendBodyBehindAppBar: true,
body: Column(
children: [
style.widgetWhen(
onData: (style) => Expanded(
child: Container(
clipBehavior: Clip.antiAliasWithSaveLayer,
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(40),
bottomRight: Radius.circular(40),
),
),
child: MaplibreMap(
initialCameraPosition:
CameraPosition(target: initialLatLng, zoom: 12),
styleString: style,
onMapCreated: (mapController) =>
controller.value = mapController,
onStyleLoadedCallback: onStyleLoaded,
onMapClick: onMapClick,
dragEnabled: false,
tiltGesturesEnabled: false,
myLocationEnabled: false,
attributionButtonMargins: const Point(20, 15),
),
),
primary: true,
body: style.widgetWhen(
onData: (style) => Container(
clipBehavior: Clip.antiAliasWithSaveLayer,
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(40),
bottomRight: Radius.circular(40),
),
),
_BottomBar(
selectedLatLng: selectedLatLng,
onUseLocation: () => onClose(selectedLatLng.value),
onGetCurrentLocation: getCurrentLocation,
child: MaplibreMap(
initialCameraPosition:
CameraPosition(target: initialLatLng, zoom: 12),
styleString: style,
onMapCreated: (mapController) =>
controller.value = mapController,
onStyleLoadedCallback: onStyleLoaded,
onMapClick: onMapClick,
dragEnabled: false,
tiltGesturesEnabled: false,
myLocationEnabled: false,
attributionButtonMargins: const Point(20, 15),
),
],
),
),
bottomNavigationBar: _BottomBar(
selectedLatLng: selectedLatLng,
onUseLocation: () => onClose(selectedLatLng.value),
onGetCurrentLocation: getCurrentLocation,
),
),
),
Expand All @@ -116,17 +108,15 @@ class _AppBar extends StatelessWidget implements PreferredSizeWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.only(top: MediaQuery.paddingOf(context).top + 25),
child: Expanded(
child: Align(
alignment: Alignment.centerLeft,
child: ElevatedButton(
onPressed: onClose,
style: ElevatedButton.styleFrom(
shape: const CircleBorder(),
),
child: const Icon(Icons.arrow_back_ios_new_rounded),
padding: const EdgeInsets.only(top: 25),
child: Align(
alignment: Alignment.centerLeft,
child: ElevatedButton(
onPressed: onClose,
style: ElevatedButton.styleFrom(
shape: const CircleBorder(),
),
child: const Icon(Icons.arrow_back_ios_new_rounded),
),
),
);
Expand All @@ -150,38 +140,42 @@ class _BottomBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SizedBox(
height: 150,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.public, size: 18),
const SizedBox(width: 15),
ValueListenableBuilder(
valueListenable: selectedLatLng,
builder: (_, value, __) => Text(
"${value.latitude.toStringAsFixed(4)}, ${value.longitude.toStringAsFixed(4)}",
height: 150 + context.padding.bottom,
child: Padding(
padding: EdgeInsets.only(bottom: context.padding.bottom),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.public, size: 18),
const SizedBox(width: 15),
ValueListenableBuilder(
valueListenable: selectedLatLng,
builder: (_, value, __) => Text(
"${value.latitude.toStringAsFixed(4)}, ${value.longitude.toStringAsFixed(4)}",
),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
onPressed: onUseLocation,
child: const Text("map_location_picker_page_use_location").tr(),
),
ElevatedButton(
onPressed: onGetCurrentLocation,
child: const Icon(Icons.my_location),
),
],
),
],
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
onPressed: onUseLocation,
child:
const Text("map_location_picker_page_use_location").tr(),
),
ElevatedButton(
onPressed: onGetCurrentLocation,
child: const Icon(Icons.my_location),
),
],
),
],
),
),
);
}
Expand Down
12 changes: 6 additions & 6 deletions mobile/lib/modules/map/views/map_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,9 @@ class MapPage extends HookConsumerWidget {
}

void onZoomToLocation() async {
final location = await MapUtils.checkPermAndGetLocation(context);
if (location.$2 != null) {
if (location.$2 == LocationPermission.unableToDetermine &&
context.mounted) {
final (location, error) = await MapUtils.checkPermAndGetLocation(context);
if (error != null) {
if (error == LocationPermission.unableToDetermine && context.mounted) {
ImmichToast.show(
context: context,
gravity: ToastGravity.BOTTOM,
Expand All @@ -234,10 +233,10 @@ class MapPage extends HookConsumerWidget {
return;
}

if (mapController.value != null && location.$1 != null) {
if (mapController.value != null && location != null) {
mapController.value!.animateCamera(
CameraUpdate.newLatLngZoom(
LatLng(location.$1!.latitude, location.$1!.longitude),
LatLng(location.latitude, location.longitude),
mapZoomToAssetLevel,
),
duration: const Duration(milliseconds: 800),
Expand Down Expand Up @@ -389,6 +388,7 @@ class _MapWithMarker extends StatelessWidget {
dragEnabled: false,
myLocationEnabled: false,
attributionButtonPosition: AttributionButtonPosition.TopRight,
rotateGesturesEnabled: false,
),
),
ValueListenableBuilder(
Expand Down
9 changes: 8 additions & 1 deletion mobile/lib/modules/map/widgets/map_asset_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,14 @@ class _MapSheetDragRegion extends StatelessWidget {
physics: const ClampingScrollPhysics(),
child: Card(
margin: EdgeInsets.zero,
shape: context.isMobile ? null : const BeveledRectangleBorder(),
shape: context.isMobile
? const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(20),
topLeft: Radius.circular(20),
),
)
: const BeveledRectangleBorder(),
elevation: 0.0,
child: Stack(
children: [
Expand Down