map: removed connectivity check, harmonized layer background

This commit is contained in:
Thibault Deckers 2022-02-08 11:41:37 +09:00
parent 3ea5ddd753
commit b9ef030001
3 changed files with 109 additions and 113 deletions

View file

@ -5,7 +5,6 @@ import 'package:aves/model/entry.dart';
import 'package:aves/model/settings/enums.dart';
import 'package:aves/model/settings/map_style.dart';
import 'package:aves/model/settings/settings.dart';
import 'package:aves/services/common/services.dart';
import 'package:aves/theme/durations.dart';
import 'package:aves/utils/change_notifier.dart';
import 'package:aves/utils/constants.dart';
@ -152,117 +151,111 @@ class _GeoMapState extends State<GeoMap> {
onTap(clusterAverageLocation, markerEntry, getClusterEntries);
}
return FutureBuilder<bool>(
future: availability.isConnected,
builder: (context, snapshot) {
if (snapshot.data != true) return const SizedBox();
return Selector<Settings, EntryMapStyle>(
selector: (context, s) => s.infoMapStyle,
builder: (context, mapStyle, child) {
final isGoogleMaps = mapStyle.isGoogleMaps;
final progressive = !isGoogleMaps;
Widget _buildMarkerWidget(MarkerKey key) => ImageMarker(
key: key,
entry: key.entry,
count: key.count,
extent: GeoMap.markerImageExtent,
arrowSize: GeoMap.markerArrowSize,
progressive: progressive,
);
return Selector<Settings, EntryMapStyle>(
selector: (context, s) => s.infoMapStyle,
builder: (context, mapStyle, child) {
final isGoogleMaps = mapStyle.isGoogleMaps;
final progressive = !isGoogleMaps;
Widget _buildMarkerWidget(MarkerKey key) => ImageMarker(
key: key,
entry: key.entry,
count: key.count,
extent: GeoMap.markerImageExtent,
arrowSize: GeoMap.markerArrowSize,
progressive: progressive,
);
Widget child = isGoogleMaps
? EntryGoogleMap(
controller: widget.controller,
clusterListenable: _clusterChangeNotifier,
boundsNotifier: _boundsNotifier,
minZoom: 0,
maxZoom: 20,
style: mapStyle,
markerClusterBuilder: _buildMarkerClusters,
markerWidgetBuilder: _buildMarkerWidget,
dotLocationNotifier: widget.dotLocationNotifier,
onUserZoomChange: widget.onUserZoomChange,
onMapTap: widget.onMapTap,
onMarkerTap: _onMarkerTap,
openMapPage: widget.openMapPage,
)
: EntryLeafletMap(
controller: widget.controller,
clusterListenable: _clusterChangeNotifier,
boundsNotifier: _boundsNotifier,
minZoom: 2,
maxZoom: 16,
style: mapStyle,
markerClusterBuilder: _buildMarkerClusters,
markerWidgetBuilder: _buildMarkerWidget,
dotLocationNotifier: widget.dotLocationNotifier,
markerSize: Size(
GeoMap.markerImageExtent + ImageMarker.outerBorderWidth * 2,
GeoMap.markerImageExtent + ImageMarker.outerBorderWidth * 2 + GeoMap.markerArrowSize.height,
),
dotMarkerSize: const Size(
DotMarker.diameter + ImageMarker.outerBorderWidth * 2,
DotMarker.diameter + ImageMarker.outerBorderWidth * 2,
),
onUserZoomChange: widget.onUserZoomChange,
onMapTap: widget.onMapTap,
onMarkerTap: _onMarkerTap,
openMapPage: widget.openMapPage,
);
final mapHeight = context.select<MapThemeData, double?>((v) => v.mapHeight);
child = Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
mapHeight != null
? SizedBox(
height: mapHeight,
child: child,
)
: Expanded(child: child),
SafeArea(
top: false,
bottom: false,
child: Attribution(style: mapStyle),
Widget child = isGoogleMaps
? EntryGoogleMap(
controller: widget.controller,
clusterListenable: _clusterChangeNotifier,
boundsNotifier: _boundsNotifier,
minZoom: 0,
maxZoom: 20,
style: mapStyle,
markerClusterBuilder: _buildMarkerClusters,
markerWidgetBuilder: _buildMarkerWidget,
dotLocationNotifier: widget.dotLocationNotifier,
onUserZoomChange: widget.onUserZoomChange,
onMapTap: widget.onMapTap,
onMarkerTap: _onMarkerTap,
openMapPage: widget.openMapPage,
)
: EntryLeafletMap(
controller: widget.controller,
clusterListenable: _clusterChangeNotifier,
boundsNotifier: _boundsNotifier,
minZoom: 2,
maxZoom: 16,
style: mapStyle,
markerClusterBuilder: _buildMarkerClusters,
markerWidgetBuilder: _buildMarkerWidget,
dotLocationNotifier: widget.dotLocationNotifier,
markerSize: Size(
GeoMap.markerImageExtent + ImageMarker.outerBorderWidth * 2,
GeoMap.markerImageExtent + ImageMarker.outerBorderWidth * 2 + GeoMap.markerArrowSize.height,
),
],
);
dotMarkerSize: const Size(
DotMarker.diameter + ImageMarker.outerBorderWidth * 2,
DotMarker.diameter + ImageMarker.outerBorderWidth * 2,
),
onUserZoomChange: widget.onUserZoomChange,
onMapTap: widget.onMapTap,
onMarkerTap: _onMarkerTap,
openMapPage: widget.openMapPage,
);
return AnimatedSize(
alignment: Alignment.topCenter,
curve: Curves.easeInOutCubic,
duration: Durations.mapStyleSwitchAnimation,
child: ValueListenableBuilder<bool>(
valueListenable: widget.isAnimatingNotifier,
builder: (context, animating, child) {
if (!animating && isGoogleMaps) {
_googleMapsLoaded = true;
}
Widget replacement = Stack(
children: [
const MapDecorator(),
MapButtonPanel(
boundsNotifier: _boundsNotifier,
openMapPage: widget.openMapPage,
),
],
);
if (mapHeight != null) {
replacement = SizedBox(
height: mapHeight,
child: replacement,
);
}
return Visibility(
visible: !isGoogleMaps || _googleMapsLoaded,
replacement: replacement,
child: child!,
);
},
child: child,
),
);
},
final mapHeight = context.select<MapThemeData, double?>((v) => v.mapHeight);
child = Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
mapHeight != null
? SizedBox(
height: mapHeight,
child: child,
)
: Expanded(child: child),
SafeArea(
top: false,
bottom: false,
child: Attribution(style: mapStyle),
),
],
);
return AnimatedSize(
alignment: Alignment.topCenter,
curve: Curves.easeInOutCubic,
duration: Durations.mapStyleSwitchAnimation,
child: ValueListenableBuilder<bool>(
valueListenable: widget.isAnimatingNotifier,
builder: (context, animating, child) {
if (!animating && isGoogleMaps) {
_googleMapsLoaded = true;
}
Widget replacement = Stack(
children: [
const MapDecorator(),
MapButtonPanel(
boundsNotifier: _boundsNotifier,
openMapPage: widget.openMapPage,
),
],
);
if (mapHeight != null) {
replacement = SizedBox(
height: mapHeight,
child: replacement,
);
}
return Visibility(
visible: !isGoogleMaps || _googleMapsLoaded,
replacement: replacement,
child: child!,
);
},
child: child,
),
);
},
);

View file

@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:provider/provider.dart';
const _tileLayerBackgroundColor = Colors.transparent;
class OSMHotLayer extends StatelessWidget {
const OSMHotLayer({Key? key}) : super(key: key);
@ -12,6 +14,7 @@ class OSMHotLayer extends StatelessWidget {
options: TileLayerOptions(
urlTemplate: 'https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
backgroundColor: _tileLayerBackgroundColor,
tileProvider: _NetworkTileProvider(),
retinaMode: context.select<MediaQueryData, double>((mq) => mq.devicePixelRatio) > 1,
),
@ -28,6 +31,7 @@ class StamenTonerLayer extends StatelessWidget {
options: TileLayerOptions(
urlTemplate: 'https://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}{r}.png',
subdomains: ['a', 'b', 'c', 'd'],
backgroundColor: _tileLayerBackgroundColor,
tileProvider: _NetworkTileProvider(),
retinaMode: context.select<MediaQueryData, double>((mq) => mq.devicePixelRatio) > 1,
),
@ -44,6 +48,7 @@ class StamenWatercolorLayer extends StatelessWidget {
options: TileLayerOptions(
urlTemplate: 'https://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.jpg',
subdomains: ['a', 'b', 'c', 'd'],
backgroundColor: _tileLayerBackgroundColor,
tileProvider: _NetworkTileProvider(),
retinaMode: context.select<MediaQueryData, double>((mq) => mq.devicePixelRatio) > 1,
),

View file

@ -83,7 +83,7 @@ class _Content extends StatefulWidget {
class _ContentState extends State<_Content> with SingleTickerProviderStateMixin {
final List<StreamSubscription> _subscriptions = [];
final AvesMapController _mapController = AvesMapController();
late final ValueNotifier<bool> _isPageAnimatingNotifier;
final ValueNotifier<bool> _isPageAnimatingNotifier = ValueNotifier(false);
final ValueNotifier<int?> _selectedIndexNotifier = ValueNotifier(0);
final ValueNotifier<CollectionLens?> _regionCollectionNotifier = ValueNotifier(null);
final ValueNotifier<LatLng?> _dotLocationNotifier = ValueNotifier(null);
@ -102,13 +102,11 @@ class _ContentState extends State<_Content> with SingleTickerProviderStateMixin
super.initState();
if (settings.infoMapStyle.isGoogleMaps) {
_isPageAnimatingNotifier = ValueNotifier(true);
_isPageAnimatingNotifier.value = true;
Future.delayed(Durations.pageTransitionAnimation * timeDilation).then((_) {
if (!mounted) return;
_isPageAnimatingNotifier.value = false;
});
} else {
_isPageAnimatingNotifier = ValueNotifier(false);
}
_dotEntryNotifier.addListener(_updateInfoEntry);