Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add subdomain support #8

Merged
merged 2 commits into from
Mar 2, 2018
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
12 changes: 12 additions & 0 deletions flutter_map/lib/src/layer/tile_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ class TileLayerOptions extends LayerOptions {
final double maxZoom;
final bool zoomReverse;
final double zoomOffset;
final List<String> subdomains;
Map<String, String> additionalOptions;

TileLayerOptions({
this.urlTemplate,
this.tileSize = 256.0,
this.maxZoom = 18.0,
this.zoomReverse = false,
this.zoomOffset = 0.0,
this.additionalOptions = const <String, String>{},
this.subdomains = const <String>[],
});
}

Expand Down Expand Up @@ -64,6 +67,7 @@ class _TileLayerState extends State<TileLayer> {
'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);
Expand Down Expand Up @@ -355,6 +359,14 @@ class _TileLayerState extends State<TileLayer> {
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 {
Expand Down
3 changes: 2 additions & 1 deletion flutter_map_example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)
],
Expand Down