@@ -79,7 +79,6 @@ class _ThemedTileLayerState extends State<ThemedTileLayer> {
7979 bool get isDark => Theme .of (context).brightness == .dark;
8080
8181 String get _osmUrl => 'https://tile.openstreetmap.org/{z}/{x}/{y}.png' ;
82- // String get _osmUrl => 'http://127.0.0.1:5000/{z}/{x}/{y}.png';
8382
8483 String get _mapboxUrl {
8584 if (layer.source != .mapbox) return _osmUrl;
@@ -225,7 +224,6 @@ class _ThemedTileLayerState extends State<ThemedTileLayer> {
225224 }
226225
227226 String get _layrzAttributionLight => 'https://cdn.layrz.com/resources/layrz/logo/normal.png' ;
228- // String get _layrzAttributionDark => 'https://cdn.layrz.com/resources/layrz/logo/white.png';
229227
230228 String get _mapboxAttributionLight => 'https://cdn.layrz.com/resources/map_attributions/mapbox_maps/normal.png' ;
231229 String get _mapboxAttributionDark => 'https://cdn.layrz.com/resources/map_attributions/mapbox_maps/white.png' ;
@@ -266,46 +264,90 @@ class _ThemedTileLayerState extends State<ThemedTileLayer> {
266264 }
267265 : {};
268266
269- TileLayer _buildTile ({required String urlTemplate}) {
270- return TileLayer (
271- urlTemplate: urlTemplate,
272- minZoom: widget.minZoom,
273- maxZoom: widget.maxZoom,
274- minNativeZoom: widget.minZoom.toInt (),
275- maxNativeZoom: widget.maxZoom.toInt (),
276- tileProvider: NetworkTileProvider (
277- headers: headers,
278-
279- /// Setting for the previous CancellableNetworkTileProvider
280- abortObsoleteRequests: widget.isCancellable,
281- ),
282-
283- keepBuffer: buffer,
284- panBuffer: buffer,
285- );
267+ String _googleUrl = '' ;
268+ String get _urlTemplate {
269+ switch (layer.source) {
270+ case .osm:
271+ return _osmUrl;
272+ case .mapbox:
273+ return _mapboxUrl;
274+ case .here:
275+ return _hereUrl;
276+ case .google:
277+ return _googleUrl;
278+ case .custom:
279+ return _customUrl;
280+ }
281+ }
282+
283+ @override
284+ void initState () {
285+ super .initState ();
286+ if (layer.source == MapSource .google) _initializeGoogleMaps ();
287+ }
288+
289+ @override
290+ void didUpdateWidget (covariant ThemedTileLayer oldWidget) {
291+ super .didUpdateWidget (oldWidget);
292+
293+ if (oldWidget.layer? .id != widget.layer? .id && layer.source == MapSource .google) {
294+ _initializeGoogleMaps ();
295+ }
296+ }
297+
298+ Future <void > _initializeGoogleMaps () async {
299+ setState (() => _googleUrl = '' );
300+ String ? url = await _fetchGoogleAuth (layer: layer);
301+ if (url != null ) setState (() => _googleUrl = url);
286302 }
287303
288304 @override
289305 Widget build (BuildContext context) {
290306 return Stack (
291307 children: [
308+ if (_urlTemplate.isNotEmpty) ...[
309+ TileLayer (
310+ urlTemplate: _urlTemplate,
311+ minZoom: widget.minZoom,
312+ maxZoom: widget.maxZoom,
313+ minNativeZoom: widget.minZoom.toInt (),
314+ maxNativeZoom: widget.maxZoom.toInt (),
315+ tileProvider: NetworkTileProvider (
316+ headers: headers,
317+
318+ /// Setting for the previous CancellableNetworkTileProvider
319+ abortObsoleteRequests: widget.isCancellable,
320+ ),
321+
322+ keepBuffer: buffer,
323+ panBuffer: buffer,
324+ ),
325+ ],
292326 if (layer.source == .osm) ...[
293- _buildTile (urlTemplate: _osmUrl),
294327 Align (
295328 alignment: .bottomLeft,
296329 child: Padding (
297330 padding: const .all (10 ),
298- child: Image .network (
299- _layrzAttributionLight,
300- width: 80 ,
301- height: 20 ,
302- filterQuality: .medium,
303- alignment: .centerLeft,
331+ child: Container (
332+ decoration: generateContainerElevation (context: context, elevation: 0 ),
333+ padding: const EdgeInsets .symmetric (horizontal: 8 , vertical: 2.5 ),
334+ child: RichText (
335+ text: TextSpan (
336+ style: Theme .of (context).textTheme.bodySmall,
337+ children: [
338+ TextSpan (text: "Map data from" ),
339+ TextSpan (
340+ text: " OpenStreetMap " ,
341+ style: Theme .of (context).textTheme.bodySmall? .copyWith (fontWeight: .bold),
342+ ),
343+ TextSpan (text: "and their contributors" ),
344+ ],
345+ ),
346+ ),
304347 ),
305348 ),
306349 ),
307350 ] else if (layer.source == .mapbox) ...[
308- _buildTile (urlTemplate: _mapboxUrl),
309351 Align (
310352 alignment: .bottomLeft,
311353 child: Padding (
@@ -320,7 +362,6 @@ class _ThemedTileLayerState extends State<ThemedTileLayer> {
320362 ),
321363 ),
322364 ] else if (layer.source == MapSource .here) ...[
323- _buildTile (urlTemplate: _hereUrl),
324365 Align (
325366 alignment: Alignment .bottomLeft,
326367 child: Padding (
@@ -335,18 +376,6 @@ class _ThemedTileLayerState extends State<ThemedTileLayer> {
335376 ),
336377 ),
337378 ] else if (layer.source == .google) ...[
338- FutureBuilder <String ?>(
339- future: _fetchGoogleAuth (layer: layer),
340- builder: (context, snapshot) {
341- if (snapshot.hasData) {
342- if (snapshot.data != null ) {
343- return _buildTile (urlTemplate: snapshot.data! );
344- }
345- }
346-
347- return const SizedBox .expand ();
348- },
349- ),
350379 Align (
351380 alignment: .bottomLeft,
352381 child: Padding (
@@ -361,7 +390,6 @@ class _ThemedTileLayerState extends State<ThemedTileLayer> {
361390 ),
362391 ),
363392 ] else ...[
364- _buildTile (urlTemplate: _customUrl),
365393 Align (
366394 alignment: .bottomLeft,
367395 child: Padding (
0 commit comments