Skip to content

Commit

Permalink
Added support for null values in FMTCTileProvider.storeNames to e…
Browse files Browse the repository at this point in the history
…xempt stores from `otherStoresStrategy`
  • Loading branch information
JaffaKetchup committed Oct 9, 2024
1 parent ec2130e commit a3eae60
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ class _GreyscaleMaskerRenderer extends RenderProxyBox {
/// very difficult to percieve with the eye, this is acceptable, and improves
/// performance drastically. The ideal amount is calculated and rounded to the
/// nearest level.
static const _greyscaleLevelsCount = 25;
final Map<int, Path> _greyscalePathCache = Map.unmodifiable({
for (int i = 0; i <= _greyscaleLevelsCount; i++) i: Path(),
});
static const _greyscaleLevelsCount = 25;

@override
void dispose() {
Expand Down Expand Up @@ -430,7 +430,7 @@ class _GreyscaleMaskerRenderer extends RenderProxyBox {

/// See [_GreyscaleMaskerRenderer._tileMapping] for documentation
///
/// Is immutable to improve performance.
/// Is mutable to improve performance.
class _TileMappingValue {
_TileMappingValue.newTile({
required this.nwCoord,
Expand Down
37 changes: 13 additions & 24 deletions example/lib/src/screens/main/map_view/map_view.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'dart:async';
import 'dart:io';
import 'dart:math';

import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_animations/flutter_map_animations.dart';
Expand Down Expand Up @@ -62,7 +65,7 @@ class _MapViewState extends State<MapView> with TickerProviderStateMixin {
.then((e) => e[StoreMetadataKeys.urlTemplate.key]),
};
},
);
).distinct(mapEquals);

final _testingCoordsList = [
//TileCoordinates(2212, 1468, 12),
Expand Down Expand Up @@ -336,21 +339,22 @@ class _MapViewState extends State<MapView> with TickerProviderStateMixin {
builder: (context, provider, _) {
final urlTemplate = provider.urlTemplate;

final compiledStoreNames = Map.fromEntries(
stores.entries
.where((e) => e.value == urlTemplate)
.map((e) => e.key)
.map((e) {
final internalBehaviour = provider.currentStores[e];
final compiledStoreNames =
Map<String, BrowseStoreStrategy?>.fromEntries([
...stores.entries.where((e) => e.value == urlTemplate).map((e) {
final internalBehaviour = provider.currentStores[e.key];
final behaviour = internalBehaviour == null
? provider.inheritableBrowseStoreStrategy
: internalBehaviour.toBrowseStoreStrategy(
provider.inheritableBrowseStoreStrategy,
);
if (behaviour == null) return null;
return MapEntry(e, behaviour);
return MapEntry(e.key, behaviour);
}).nonNulls,
);
...stores.entries
.where((e) => e.value != urlTemplate)
.map((e) => MapEntry(e.key, null)),
]);

final attribution = RichAttributionWidget(
alignment: AttributionAlignment.bottomLeft,
Expand Down Expand Up @@ -435,21 +439,6 @@ class _MapViewState extends State<MapView> with TickerProviderStateMixin {
),
PolygonLayer(
polygons: [
Polygon(
points: [
LatLng(-90, 180),
LatLng(90, 180),
LatLng(90, -180),
LatLng(-90, -180),
],
holePointsList: [
const CircleRegion(
LatLng(45.3052535669648, 14.476223064038985),
6,
).toOutline().toList(growable: false),
],
color: Colors.black,
),
Polygon(
points: [
LatLng(-90, 180),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
import 'package:provider/provider.dart';

import '../../../../shared/misc/store_metadata_keys.dart';
import '../../download/download.dart';
import '../../../../shared/state/download_configuration_provider.dart';
import '../../download/download.dart';

class StartDownloadButton extends StatelessWidget {
const StartDownloadButton({
Expand Down
1 change: 1 addition & 0 deletions lib/src/providers/image_provider/internal_get_bytes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ Future<Uint8List> _internalGetBytes({
final writeTileToSpecified = provider.storeNames.entries
.where(
(e) => switch (e.value) {
null => false,
BrowseStoreStrategy.read => false,
BrowseStoreStrategy.readUpdate =>
intersectedExistingStores.contains(e.key),
Expand Down
10 changes: 6 additions & 4 deletions lib/src/providers/tile_provider/tile_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ class FMTCTileProvider extends TileProvider {
///
/// Stores not included will not be used by default. However,
/// [otherStoresStrategy] determines whether & how all other unspecified
/// stores should be used.
///
// TODO: Accept null values to exempt from [otherStoresStrategy]
final Map<String, BrowseStoreStrategy> storeNames;
/// stores should be used. Stores included but with a `null` value will be
/// exempt from [otherStoresStrategy].
final Map<String, BrowseStoreStrategy?> storeNames;

/// The behaviour of all other stores not specified in [storeNames]
///
Expand All @@ -95,6 +94,9 @@ class FMTCTileProvider extends TileProvider {
/// Also see [useOtherStoresAsFallbackOnly] for whether these unspecified
/// stores should only be used as a last resort or in addition to the specified
/// stores as normal.
///
/// Stores specified in [storeNames] but associated with a `null` value will
/// not not gain this behaviour.
final BrowseStoreStrategy? otherStoresStrategy;

/// Determines whether the network or cache is preferred during browse
Expand Down

0 comments on commit a3eae60

Please sign in to comment.