diff --git a/flutter_map/lib/src/layer/tile_layer.dart b/flutter_map/lib/src/layer/tile_layer.dart index df6f3b9b8..87214f779 100644 --- a/flutter_map/lib/src/layer/tile_layer.dart +++ b/flutter_map/lib/src/layer/tile_layer.dart @@ -17,7 +17,9 @@ class TileLayerOptions extends LayerOptions { final double maxZoom; final bool zoomReverse; final double zoomOffset; + final List subdomains; Map additionalOptions; + TileLayerOptions({ this.urlTemplate, this.tileSize = 256.0, @@ -25,6 +27,7 @@ class TileLayerOptions extends LayerOptions { this.zoomReverse = false, this.zoomOffset = 0.0, this.additionalOptions = const {}, + this.subdomains = const [], }); } @@ -64,6 +67,7 @@ class _TileLayerState extends State { 'x': coords.x.round().toString(), 'y': coords.y.round().toString(), 'z': coords.z.round().toString(), + 's': _getSubdomain(coords) }; var allOpts = new Map.from(data)..addAll(this.options.additionalOptions); return util.template(this.options.urlTemplate, allOpts); @@ -355,6 +359,14 @@ class _TileLayerState extends State { var level = _levels[coords.z]; return coords.scaleBy(this.getTileSize()) - level.origin; } + + String _getSubdomain(Coords coords) { + if (options.subdomains.isEmpty) { + return ""; + } + var index = (coords.x + coords.y).round() % this.options.subdomains.length; + return options.subdomains[index]; + } } class Tile { diff --git a/flutter_map_example/lib/main.dart b/flutter_map_example/lib/main.dart index a21217ebd..f09243371 100644 --- a/flutter_map_example/lib/main.dart +++ b/flutter_map_example/lib/main.dart @@ -74,7 +74,8 @@ class HomePage extends StatelessWidget { layers: [ new TileLayerOptions( urlTemplate: - "https://tile.openstreetmap.org/{z}/{x}/{y}.png", + "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", + subdomains: ['a','b','c'] ), new MarkerLayerOptions(markers: markers) ],