Skip to content

Commit

Permalink
Merge branch 'master' into reworked-children
Browse files Browse the repository at this point in the history
  • Loading branch information
JaffaKetchup committed Sep 6, 2023
2 parents 68ab1b2 + 8223328 commit 77ca3aa
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 38 deletions.
2 changes: 1 addition & 1 deletion lib/src/gestures/flutter_map_interactive_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class FlutterMapInteractiveViewerState
newCenter,
newZoom,
offset: Offset.zero,
hasGesture: false,
hasGesture: true,
source: MapEventSource.scrollWheel,
id: null,
);
Expand Down
22 changes: 9 additions & 13 deletions lib/src/layer/tile_layer/tile_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,18 @@ part 'wms_tile_layer_options.dart';
/// avoid issues.
@immutable
class TileLayer extends StatefulWidget {
/// Defines the structure to create the URLs for the tiles. `{s}` means one of
/// the available subdomains (can be omitted) `{z}` zoom level `{x}` and `{y}`
/// — tile coordinates `{r}` can be used to add "@2x" to the URL to
/// load retina tiles (can be omitted)
/// The URL template is a string that contains placeholders, which, when filled
/// in, create a URL/URI to a specific tile.
///
/// Example:
///
/// https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png
///
/// Is translated to this:
///
/// https://a.tile.openstreetmap.org/12/2177/1259.png
/// For more information, see <https://docs.fleaflet.dev/layers/tile-layer>.
final String? urlTemplate;

/// Follows the same structure as [urlTemplate]. If specified, this URL is
/// used only if an error occurs when loading the [urlTemplate].
/// Fallback URL template, used if an error occurs when fetching tiles from
/// the [urlTemplate].
///
/// Note that specifying this (non-null) will result in tiles not being cached
/// in memory. This is to avoid issues where the [urlTemplate] is flaky, to
/// prevent different tilesets being displayed at the same time.
///
/// Avoid specifying this when using [AssetTileProvider] or [FileTileProvider],
/// as these providers are less performant and efficient when this is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import 'package:flutter/painting.dart';
import 'package:http/http.dart';

/// Dedicated [ImageProvider] to fetch tiles from the network
///
/// Supports falling back to a secondary URL, if the primary URL fetch fails.
/// Note that specifying a [fallbackUrl] will prevent this image provider from
/// being cached.
@immutable
class FlutterMapNetworkImageProvider
extends ImageProvider<FlutterMapNetworkImageProvider> {
Expand All @@ -14,15 +18,27 @@ class FlutterMapNetworkImageProvider

/// The URL to fetch the tile from (GET request), in the event the original
/// [url] request fails
///
/// If this is non-null, [operator==] will always return `false` (except if
/// the two objects are [identical]). Therefore, if this is non-null, this
/// image provider will not be cached in memory.
final String? fallbackUrl;

/// The HTTP client to use to make network requests
///
/// Not included in [operator==].
final BaseClient httpClient;

/// The headers to include with the tile fetch request
///
/// Not included in [operator==].
final Map<String, String> headers;

/// Dedicated [ImageProvider] to fetch tiles from the network
/// Create a dedicated [ImageProvider] to fetch tiles from the network
///
/// Supports falling back to a secondary URL, if the primary URL fetch fails.
/// Note that specifying a [fallbackUrl] will prevent this image provider from
/// being cached.
const FlutterMapNetworkImageProvider({
required this.url,
required this.fallbackUrl,
Expand Down Expand Up @@ -75,4 +91,15 @@ class FlutterMapNetworkImageProvider

return decode(await ImmutableBuffer.fromUint8List(bytes));
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is FlutterMapNetworkImageProvider &&
fallbackUrl == null &&
url == other.url);

@override
int get hashCode =>
Object.hashAll([url, if (fallbackUrl != null) fallbackUrl]);
}
21 changes: 11 additions & 10 deletions lib/src/map/controller/internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ class FlutterMapInternalController extends ValueNotifier<_InternalState> {
}

if (degree == camera.rotation) {
return const MoveAndRotateResult(false, false);
return const (moveSuccess: false, rotateSuccess: false);
}

if (offset == Offset.zero) {
return MoveAndRotateResult(
true,
rotate(
return (
moveSuccess: true,
rotateSuccess: rotate(
degree,
hasGesture: hasGesture,
source: source,
Expand All @@ -178,8 +178,8 @@ class FlutterMapInternalController extends ValueNotifier<_InternalState> {
: Point(offset!.dx, offset.dy))
.rotate(camera.rotationRad);

return MoveAndRotateResult(
move(
return (
moveSuccess: move(
camera.unproject(
rotationCenter +
(camera.project(camera.center) - rotationCenter)
Expand All @@ -191,7 +191,7 @@ class FlutterMapInternalController extends ValueNotifier<_InternalState> {
source: source,
id: id,
),
rotate(
rotateSuccess: rotate(
camera.rotation + rotationDiff,
hasGesture: hasGesture,
source: source,
Expand All @@ -212,16 +212,17 @@ class FlutterMapInternalController extends ValueNotifier<_InternalState> {
required MapEventSource source,
required String? id,
}) =>
MoveAndRotateResult(
move(
(
moveSuccess: move(
newCenter,
newZoom,
offset: offset,
hasGesture: hasGesture,
source: source,
id: id,
),
rotate(newRotation, id: id, source: source, hasGesture: hasGesture),
rotateSuccess:
rotate(newRotation, id: id, source: source, hasGesture: hasGesture),
);

/// Note: All named parameters are required to prevent inconsistent default
Expand Down
8 changes: 4 additions & 4 deletions lib/src/map/controller/map_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ abstract class MapController {
/// The emitted [MapEventRotate.source]/[MapEventMove.source] properties will
/// be [MapEventSource.mapController].
///
/// The operation was successful if [MoveAndRotateResult.moveSuccess] and
/// [MoveAndRotateResult.rotateSuccess] are `true`.
/// The operation was successful if both fields of the resulting record are
/// `true`.
MoveAndRotateResult rotateAroundPoint(
double degree, {
Point<double>? point,
Expand All @@ -126,8 +126,8 @@ abstract class MapController {
///
/// See documentation on those methods for more details.
///
/// The operation was successful if [MoveAndRotateResult.moveSuccess] and
/// [MoveAndRotateResult.rotateSuccess] are `true`.
/// The operation was successful if both fields of the resulting record are
/// `true`.
MoveAndRotateResult moveAndRotate(
LatLng center,
double zoom,
Expand Down
10 changes: 1 addition & 9 deletions lib/src/misc/move_and_rotate_result.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
import 'package:meta/meta.dart';

@immutable
class MoveAndRotateResult {
final bool moveSuccess;
final bool rotateSuccess;

const MoveAndRotateResult(this.moveSuccess, this.rotateSuccess);
}
typedef MoveAndRotateResult = ({bool moveSuccess, bool rotateSuccess});

0 comments on commit 77ca3aa

Please sign in to comment.