Skip to content

Commit

Permalink
'User-Agent' Header Generation & More (#1294)
Browse files Browse the repository at this point in the history
* Added `userAgentPackageName` implementation
Improved headers implementation
Deprecated `NonCachingNetworkTileProvider` in favour of `NetworkNoRetryTileProvider`
Updated example pages with changes
Improved documentation

* Temporarily fixed multiple User-Agent headers
Fixed usage of `NetworkTileProvider`
Fixed deprecation notice invalid symbol reference

* Removed some old TODOs
Simplified `_positionedForOverlay` (solved TODO)
Improved maintainability
Improved documentation

* Removed old deprecations (`placeholderImage` and `attributionBuilder`)

* Atempt to fix `HttpOverrides` issue - unsuccessful: dart-lang/sdk#49382 (comment)

* Fixed issues
Added custom `ImageProvider`s
Reduced reliance on 'universal_io' library
Prepared for review

* Fixed web platform support
Seperated tile_provider.dart for web and other plaforms
Removed 'universal_io' dependency
Updated CHANGELOG

* Fixed 'Refused to set unsafe header' error

* Improved in-code documentation

* Removed deprecated API remenant `attributionAlignment` from `TileLayerOptions`

* Fix false positive linter warning: see https://github.com/dart-lang/linter/issues/1381

* Improved documentation
Refactored base `TileProvider` into independent file
  • Loading branch information
JaffaKetchup authored Jul 11, 2022
1 parent 9de1b0f commit f55e156
Show file tree
Hide file tree
Showing 49 changed files with 594 additions and 252 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Changelog

## [2.0.0] - 2022/XX/XX

Contains the following additions/removals:

- Added adjustable mouse wheel zoom speed - [#1289](https://github.com/fleaflet/flutter_map/pull/1289)
- Multiple changes - [#1294](https://github.com/fleaflet/flutter_map/pull/1294)
- Added advanced header support, including 'User-Agent'
- Refactored `TileProvider`s
- Resolved multiple TODOs within codebase
- Removed old deprecated code

Contains the following bug fixes:

- Fixed unsymmetrical markers disappearing with unusually positioned anchors - [#1291](https://github.com/fleaflet/flutter_map/pull/1291)
- Fixed potential for error 403s due to invalid/blocked 'User-Agent' header - [#1294](https://github.com/fleaflet/flutter_map/pull/1294)

In other news:

- None

Many thanks to these contributors (in no particular order):

- @mboe
- @aytunch
- @MichalTorma
- ... and all the maintainers

## [1.1.1] - 2022/06/25

Contains the following additions/removals:
Expand Down
8 changes: 5 additions & 3 deletions example/lib/pages/animated_map_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,11 @@ class AnimatedMapControllerPageState extends State<AnimatedMapControllerPage>
minZoom: 3.0),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c']),
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
MarkerLayerOptions(markers: markers)
],
),
Expand Down
8 changes: 5 additions & 3 deletions example/lib/pages/circle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ class CirclePage extends StatelessWidget {
),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c']),
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
CircleLayerOptions(circles: circleMarkers)
],
),
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/epsg4326_crs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class EPSG4326Page extends StatelessWidget {
baseUrl: 'https://ows.mundialis.de/services/service?',
layers: ['TOPO-OSM-WMS'],
),
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
)
],
),
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/esri.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class EsriPage extends StatelessWidget {
TileLayerOptions(
urlTemplate:
'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
],
),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class HomePage extends StatelessWidget {
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
tileProvider: const NonCachingNetworkTileProvider(),
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
MarkerLayerOptions(markers: markers)
],
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/interactive_test_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class _InteractiveTestPageState extends State<InteractiveTestPage> {
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
],
),
Expand Down
5 changes: 1 addition & 4 deletions example/lib/pages/live_location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ class _LiveLocationPageState extends State<LiveLocationPage> {
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
// For example purposes. It is recommended to use
// TileProvider with a caching and retry strategy, like
// NetworkTileProvider or CachedNetworkTileProvider
tileProvider: const NonCachingNetworkTileProvider(),
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
MarkerLayerOptions(markers: markers)
],
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/many_markers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class _ManyMarkersPageState extends State<ManyMarkersPage> {
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
MarkerLayerOptions(
markers: allMarkers.sublist(
Expand Down
8 changes: 5 additions & 3 deletions example/lib/pages/map_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,11 @@ class MapControllerPageState extends State<MapControllerPage> {
),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c']),
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
MarkerLayerOptions(markers: markers)
],
),
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/map_inside_listview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class MapInsideListViewPage extends StatelessWidget {
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
),
],
Expand Down
8 changes: 5 additions & 3 deletions example/lib/pages/marker_anchor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ class MarkerAnchorPageState extends State<MarkerAnchorPage> {
),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c']),
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
MarkerLayerOptions(markers: markers)
],
),
Expand Down
8 changes: 5 additions & 3 deletions example/lib/pages/marker_rotate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ class MarkerRotatePageState extends State<MarkerRotatePage> {
),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c']),
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
MarkerLayerOptions(
rotate: rotateMarkerLayerOptions,
markers: markers,
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/max_bounds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class MaxBoundsPage extends StatelessWidget {
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
],
),
Expand Down
8 changes: 5 additions & 3 deletions example/lib/pages/moving_markers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ class _MovingMarkersPageState extends State<MovingMarkersPage> {
),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c']),
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
MarkerLayerOptions(markers: [_marker!])
],
),
Expand Down
17 changes: 9 additions & 8 deletions example/lib/pages/network_tile_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ class NetworkTileProviderPage extends StatelessWidget {
children: [
Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
child: Wrap(children: const [
Text('This Provider does not provide caching.'),
Text(
'For further options about that, check flutter_map\'s README on GitHub.'),
]),
child: Wrap(
children: const [
Text(
'This provider will automatically retry failed requests, unlike the other pages.'),
Text(
'For further information, check the documentation website.'),
],
),
),
Flexible(
child: FlutterMap(
Expand All @@ -67,10 +70,8 @@ class NetworkTileProviderPage extends StatelessWidget {
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
// For example purposes. It is recommended to use
// TileProvider with a caching and retry strategy, like
// NetworkTileProvider or CachedNetworkTileProvider
tileProvider: NetworkTileProvider(),
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
MarkerLayerOptions(markers: markers)
],
Expand Down
2 changes: 1 addition & 1 deletion example/lib/pages/offline_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class OfflineMapPage extends StatelessWidget {
),
layers: [
TileLayerOptions(
tileProvider: const AssetTileProvider(),
tileProvider: AssetTileProvider(),
maxZoom: 14.0,
urlTemplate: 'assets/map/anholt_osmbright/{z}/{x}/{y}.png',
),
Expand Down
8 changes: 5 additions & 3 deletions example/lib/pages/on_tap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ class OnTapPageState extends State<OnTapPage> {
),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c']),
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
MarkerLayerOptions(markers: markers)
],
),
Expand Down
8 changes: 5 additions & 3 deletions example/lib/pages/overlay_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ class OverlayImagePage extends StatelessWidget {
),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c']),
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
OverlayImageLayerOptions(overlayImages: overlayImages)
],
),
Expand Down
8 changes: 5 additions & 3 deletions example/lib/pages/plugin_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ class PluginPage extends StatelessWidget {
),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c']),
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
],
nonRotatedLayers: [
MyCustomPluginOptions(text: "I'm a plugin!"),
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/plugin_scalebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class PluginScaleBar extends StatelessWidget {
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
],
nonRotatedLayers: [
Expand Down
2 changes: 1 addition & 1 deletion example/lib/pages/plugin_zoombuttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PluginZoomButtons extends StatelessWidget {
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
tileProvider: const NonCachingNetworkTileProvider(),
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
],
nonRotatedLayers: [
Expand Down
8 changes: 5 additions & 3 deletions example/lib/pages/point_to_latlng.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ class PointToLatlngPage extends State<PointToLatLngPage> {
children: [
TileLayerWidget(
options: TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'])),
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
)),
if (latLng != null)
MarkerLayerWidget(
options: MarkerLayerOptions(
Expand Down
8 changes: 5 additions & 3 deletions example/lib/pages/polygon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ class PolygonPage extends StatelessWidget {
),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c']),
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
PolygonLayerOptions(polygons: [
Polygon(
points: notFilledPoints,
Expand Down
9 changes: 6 additions & 3 deletions example/lib/pages/polyline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ class _PolylinePageState extends State<PolylinePage> {
),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c']),
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
userAgentPackageName:
'dev.fleaflet.flutter_map.example',
),
PolylineLayerOptions(
polylines: [
Polyline(
Expand Down
8 changes: 5 additions & 3 deletions example/lib/pages/reset_tile_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ class ResetTileLayerPageState extends State<ResetTileLayerPage> {
),
layers: [
TileLayerOptions(
reset: resetController.stream,
urlTemplate: layerToggle ? layer1 : layer2,
subdomains: ['a', 'b', 'c']),
reset: resetController.stream,
urlTemplate: layerToggle ? layer1 : layer2,
subdomains: ['a', 'b', 'c'],
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
MarkerLayerOptions(markers: markers)
],
),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/pages/sliding_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SlidingMapPage extends StatelessWidget {
),
layers: [
TileLayerOptions(
tileProvider: const AssetTileProvider(),
tileProvider: AssetTileProvider(),
maxZoom: 14.0,
urlTemplate: 'assets/map/anholt_osmbright/{z}/{x}/{y}.png',
),
Expand Down
5 changes: 1 addition & 4 deletions example/lib/pages/stateful_markers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ class _StatefulMarkersPageState extends State<StatefulMarkersPage> {
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
// For example purposes. It is recommended to use
// TileProvider with a caching and retry strategy, like
// NetworkTileProvider or CachedNetworkTileProvider
tileProvider: const NonCachingNetworkTileProvider(),
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
MarkerLayerOptions(markers: _markers)
],
Expand Down
1 change: 1 addition & 0 deletions example/lib/pages/tap_to_add.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class TapToAddPageState extends State<TapToAddPage> {
TileLayerOptions(
urlTemplate:
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
),
MarkerLayerOptions(markers: markers)
],
Expand Down
2 changes: 1 addition & 1 deletion example/lib/pages/tile_builder_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class _TileBuilderPageState extends State<TileBuilderPage> {
TileLayerOptions(
urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
tileProvider: const NonCachingNetworkTileProvider(),
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
tileBuilder: tileBuilder,
tilesContainerBuilder:
darkMode ? darkModeTilesContainerBuilder : null,
Expand Down
Loading

0 comments on commit f55e156

Please sign in to comment.