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
Conversation
This isn't perfect: final oldOptions = oldWidget.options.additionalOptions;
final newOptions = options.additionalOptions;
if (oldUrl != newUrl || oldOptions != newOptions) { When you decalre every time a new additionalOptions: <String, String>{
'id': mapboxStyle,
}, Just see this: On the other hand if you cache class _HomePageState extends State<HomePage> {
final params = <String, String>{
'id': 'myStyle',
};
void onEvent() {
setState(() {
params['id'] = 'myStyle2';
});
}
Widget build(BuildContext context) {
...
TileLayerOptions(
urlTemplate: 'https://api.mapbox.com/styles/v1/mapbox/{id}/tiles/{z}/{x}/{y}',
additionalOptions: params,
)
... If an event calls var a = {'x': 1};
a['x'] = 2;
print(a != a); It will print |
Dear @maRci002 thanks for your detailed feedback. What do you recommend to fix this issue? Would using MapEquality help here? |
Yes you can use it, however there are still problems if programmer using explicit print((const MapEquality()).equals({'x': 1}, {'x': 1})); // true
print((const MapEquality()).equals(null, {'x': 1})); // false ! So in You have to handle updates on Map, so this case: additionalOptions = additionalOptions == null
? const <String, String>{}
: Map.from(additionalOptions), // copy Map, so we can safely compare old and new Map inside didUpdateWidget with MapEquality |
…henUrlChanges The option `overrideTilesWhenUrlChanges` currently only works if the URL template changes but not if the options change. For example: ```dart TileLayerOptions( urlTemplate: 'https://api.mapbox.com/styles/v1/mapbox/{id}/tiles/{z}/{x}/{y}', additionalOptions: <String, String>{ 'id': mapboxStyle, }, ``` If the value of `id` (here the Mapbox layer style, e.g. streets, satellite, etc.) changes the option `overrideTilesWhenUrlChanges` should override the tiles as well.
Hey @maRci002 great thanks for your help. I adopted the MR accordingly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The option
overrideTilesWhenUrlChanges
currently only works if the URLtemplate changes but not if the options change.
For example:
If the value of
id
(here the Mapbox layer style, e.g. streets, satellite, etc.)changes the option
overrideTilesWhenUrlChanges
should override the tiles as well.