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

Fix #629 | Reload map if options changed for overrideTilesWhenUrlChanges #740

Merged
merged 1 commit into from
Jan 29, 2021
Merged
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
15 changes: 13 additions & 2 deletions lib/src/layer/tile_layer.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:math' as math;

import 'package:collection/collection.dart' show MapEquality;
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_map/src/core/bounds.dart';
Expand Down Expand Up @@ -199,7 +200,7 @@ class TileLayerOptions extends LayerOptions {
this.maxNativeZoom,
this.zoomReverse = false,
double zoomOffset = 0.0,
this.additionalOptions = const <String, String>{},
Map<String, String> additionalOptions,
this.subdomains = const <String>[],
this.keepBuffer = 2,
this.backgroundColor = const Color(0xFFE0E0E0),
Expand Down Expand Up @@ -247,6 +248,11 @@ class TileLayerOptions extends LayerOptions {
tileSize = wmsOptions == null && retinaMode && maxZoom > 0.0
? (tileSize / 2.0).floorToDouble()
: tileSize,
// copy additionalOptions Map if not null, so we can safely compare old
// and new Map inside didUpdateWidget with MapEquality.
additionalOptions = additionalOptions == null
? const <String, String>{}
: Map.from(additionalOptions),
super(key: key, rebuild: rebuild);
}

Expand Down Expand Up @@ -424,7 +430,12 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
final oldUrl = oldWidget.options.wmsOptions?._encodedBaseUrl ??
oldWidget.options.urlTemplate;
final newUrl = options.wmsOptions?._encodedBaseUrl ?? options.urlTemplate;
if (oldUrl != newUrl) {

final oldOptions = oldWidget.options.additionalOptions;
final newOptions = options.additionalOptions;

if (oldUrl != newUrl ||
!(const MapEquality()).equals(oldOptions, newOptions)) {
if (options.overrideTilesWhenUrlChanges) {
for (var tile in _tiles.values) {
tile.imageProvider = options.tileProvider
Expand Down