Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
channel: "stable"
cache: true
- name: Build Android Application
run: flutter build apk
run: flutter build apk --dart-define=flutter.flutter_map.unblockOSM="${{ secrets.UNBLOCK_OSM }}"
- name: Archive Artifact
uses: actions/upload-artifact@v4
with:
Expand All @@ -105,7 +105,7 @@ jobs:
channel: "stable"
cache: true
- name: Build Windows Application
run: flutter build windows
run: flutter build windows --dart-define=flutter.flutter_map.unblockOSM="${{ secrets.UNBLOCK_OSM }}"
- name: Create Windows Application Installer
run: iscc "windowsApplicationInstallerSetup.iss"
working-directory: .
Expand All @@ -131,7 +131,7 @@ jobs:
channel: "stable"
cache: true
- name: Build Web Application
run: flutter build web --wasm
run: flutter build web --wasm --dart-define=flutter.flutter_map.unblockOSM="${{ secrets.UNBLOCK_OSM }}"
- name: Archive Artifact
uses: actions/upload-artifact@v4
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
channel: "stable"
cache: true
- name: Build Android Application
run: flutter build apk
run: flutter build apk --dart-define=flutter.flutter_map.unblockOSM="${{ secrets.UNBLOCK_OSM }}"
- name: Archive Artifact
uses: actions/upload-artifact@v4
with:
Expand All @@ -76,7 +76,7 @@ jobs:
channel: "stable"
cache: true
- name: Build Windows Application
run: flutter build windows
run: flutter build windows --dart-define=flutter.flutter_map.unblockOSM="${{ secrets.UNBLOCK_OSM }}"
- name: Create Windows Application Installer
run: iscc "windowsApplicationInstallerSetup.iss"
working-directory: .
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
channel: "stable"
cache: true
- name: Build Web Application
run: flutter build web --wasm
run: flutter build web --wasm --dart-define=flutter.flutter_map.unblockOSM="${{ secrets.UNBLOCK_OSM }}"
- name: Archive Artifact
uses: actions/upload-artifact@v4
with:
Expand Down
49 changes: 48 additions & 1 deletion lib/src/layer/tile_layer/tile_layer.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:async';
import 'dart:math';

import 'package:collection/collection.dart' show MapEquality;
import 'package:collection/collection.dart' show MapEquality, ListEquality;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
Expand All @@ -12,6 +12,7 @@ import 'package:flutter_map/src/layer/tile_layer/tile_image_manager.dart';
import 'package:flutter_map/src/layer/tile_layer/tile_range.dart';
import 'package:flutter_map/src/layer/tile_layer/tile_range_calculator.dart';
import 'package:flutter_map/src/layer/tile_layer/tile_scale_calculator.dart';
import 'package:flutter_map/src/layer/tile_layer/unblock_osm.dart';
import 'package:flutter_map/src/misc/extensions.dart';
import 'package:http/http.dart';
import 'package:http/retry.dart';
Expand Down Expand Up @@ -343,6 +344,41 @@ class TileLayer extends StatefulWidget {
}

class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
static const _openStreetMapUrls = {
'tile.openstreetmap.org',
'tile.osm.org',
};
bool get _isOpenStreetMapUrl =>
widget.urlTemplate != null &&
_openStreetMapUrls.any((target) => widget.urlTemplate!.contains(target));

static const _unblockOpenStreetMapUrlEnv =
String.fromEnvironment('flutter.flutter_map.unblockOSM');
static bool get _unblockOpenStreetMapUrl => const ListEquality<int>()
.equals(_unblockOpenStreetMapUrlEnv.codeUnits, unblockOSM);

static final _blockOpenStreetMapUrl =
// ignore: dead_code
false && (kReleaseMode || kProfileMode) && !_unblockOpenStreetMapUrl;
void _warnOpenStreetMapUrl() {
if (!_isOpenStreetMapUrl || !kDebugMode || _unblockOpenStreetMapUrl) return;
Logger(printer: PrettyPrinter(methodCount: 0)).e(
'''\x1B[1m\x1B[3mflutter_map\x1B[0m
flutter_map wants to help keep map data available for everyone.
We use the public OpenStreetMap tile servers in our code examples & demo app,
but they are NOT free to use by everyone.
In an upcoming non-major release, requests to 'tile.openstreetmap.org' or
'tile.osm.org' will be blocked by default in release mode.
Please review https://operations.osmfoundation.org/policies/tiles/ to see if
your project is compliant with their Tile Usage Policy.
For more information, see https://docs.fleaflet.dev/tile-servers/using-openstreetmap-direct.
It describes in additional detail why we feel it is important to do this, how
you can unblock the tile servers if your use-case is acceptable, the timeframes
for this new policy, and how we're working to reduce requests without any extra
work from you.''',
);
}

bool _initializedFromMapCamera = false;

final _tileImageManager = TileImageManager();
Expand Down Expand Up @@ -371,6 +407,7 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
super.initState();
_resetSub = widget.reset?.listen(_resetStreamHandler);
_tileRangeCalculator = TileRangeCalculator(tileDimension: _tileDimension);
_warnOpenStreetMapUrl();
}

// This is called on every map movement so we should avoid expensive logic
Expand Down Expand Up @@ -428,6 +465,8 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
super.didUpdateWidget(oldWidget);
var reloadTiles = false;

_warnOpenStreetMapUrl();

// There is no caching in TileRangeCalculator so we can just replace it.
_tileRangeCalculator = TileRangeCalculator(tileDimension: _tileDimension);

Expand Down Expand Up @@ -505,6 +544,10 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {

if (_outsideZoomLimits(map.zoom.round())) return const SizedBox.shrink();

if (_isOpenStreetMapUrl && _blockOpenStreetMapUrl) {
return const SizedBox.shrink();
}

final tileZoom = _clampToNativeZoom(map.zoom);
final tileBoundsAtZoom = _tileBounds.atZoom(tileZoom);
final visibleTileRange = _tileRangeCalculator.calculate(
Expand Down Expand Up @@ -667,6 +710,10 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
DiscreteTileRange tileLoadRange, {
required bool pruneAfterLoad,
}) {
if (_isOpenStreetMapUrl && _blockOpenStreetMapUrl) {
return;
}

final tileZoom = tileLoadRange.zoom;
final expandedTileLoadRange = tileLoadRange.expand(widget.panBuffer);

Expand Down
28 changes: 28 additions & 0 deletions lib/src/layer/tile_layer/unblock_osm.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// @nodoc
final unblockOSM = [
79,
117,
114,
32,
116,
105,
108,
101,
32,
115,
101,
114,
118,
101,
114,
115,
32,
97,
114,
101,
32,
110,
111,
116,
46,
];