Skip to content

Commit 4f17aa0

Browse files
igotinfectedJason REBELO NEVES
andauthored
✨ Allow invalidating map size manually (#11)
Co-authored-by: Jason REBELO NEVES <REBEJas70@cfl.lu>
1 parent e4953a4 commit 4f17aa0

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/Spillgebees.Blazor.Map.Samples/Spillgebees.Blazor.Map.Samples.Shared/Examples/ThemeExample.razor

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<div>
88
<h3>Map theme switching</h3>
99
<p>This example demonstrates how to switch between the default and dark themes.</p>
10-
10+
1111
<!-- use tailwind classes to style the buttons -->
1212
<div class="mb-3 flex gap-2">
1313
<button
@@ -21,7 +21,7 @@
2121
Dark Theme
2222
</button>
2323
</div>
24-
24+
2525
<CodeSnippet Code="@Code">
2626
<Component>
2727
<SgbMap MapOptions="@_mapOptions"
@@ -41,7 +41,7 @@
4141
4242
// marker with tooltip
4343
private readonly List<Marker> _markers = [
44-
new(""marker-1"", new Coordinate(49.5999673, 6.1342483), ""Luxembourg"",
44+
new(""marker-1"", new Coordinate(49.5999673, 6.1342483), ""Luxembourg"",
4545
Tooltip: new TooltipOptions(""This is a tooltip to test the dark theme styling!""))
4646
];
4747
@@ -52,7 +52,7 @@ private void SetTheme(MapTheme theme)
5252
StateHasChanged();
5353
}";
5454

55-
private readonly List<TileLayer> _tileLayers = [TileLayer.OpenStreetMap];
55+
private readonly List<TileLayer> _tileLayers = [TileLayer.OpenDataBaseMap];
5656

5757
private MapOptions _mapOptions = MapOptions.Default with
5858
{
@@ -63,7 +63,7 @@ private void SetTheme(MapTheme theme)
6363

6464
private readonly List<Marker> _markers =
6565
[
66-
new("marker-1", new Coordinate(49.5999673, 6.1342483), "Luxembourg",
66+
new("marker-1", new Coordinate(49.5999673, 6.1342483), "Luxembourg",
6767
Tooltip: new TooltipOptions("This is a tooltip to test the dark theme styling. Hover over the marker to see it!"))
6868
];
6969

src/Spillgebees.Blazor.Map/Components/BaseMap.razor.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ public abstract partial class BaseMap : ComponentBase, IAsyncDisposable
109109
public ValueTask FitBoundsAsync(FitBoundsOptions options)
110110
=> MapJs.FitBoundsAsync(JsRuntime, Logger.Value, MapReference, options);
111111

112+
/// <summary>
113+
/// Triggers a size recalculation on the map. Useful when dynamically changing the height, especially if you notice
114+
/// that the map has unloaded spots.
115+
/// </summary>
116+
public ValueTask InvalidateMapSizeAsync()
117+
=> MapJs.InvalidateSizeAsync(JsRuntime, Logger.Value, MapReference);
118+
112119
public virtual async ValueTask DisposeAsync()
113120
{
114121
if (IsDisposing)
@@ -237,7 +244,4 @@ private ValueTask SetMapControlsAsync()
237244

238245
private ValueTask SetMapOptionsAsync()
239246
=> MapJs.SetMapOptionsAsync(JsRuntime, Logger.Value, MapReference, InternalMapOptions);
240-
241-
private ValueTask InvalidateMapSizeAsync()
242-
=> MapJs.InvalidateSizeAsync(JsRuntime, Logger.Value, MapReference);
243247
}

src/Spillgebees.Blazor.Map/Models/Layers/TileLayer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,8 @@ public record TileLayer(
4545
UrlTemplate: "https://tileserver.memomaps.de/tilegen/{z}/{x}/{y}.png",
4646
Attribution: "&copy; <a href='memomaps.de'>memomaps.de</a> <a href='https://creativecommons.org/licenses/by-sa/2.0/CC-BY-SA'>CC-BY-SA</a> | &copy; <a href='https://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors"
4747
);
48+
49+
public static readonly TileLayer OpenDataBaseMap = new(
50+
UrlTemplate: "https://wmts1.geoportail.lu/opendata/wmts/basemap/GLOBAL_WEBMERCATOR/{z}/{x}/{y}.png",
51+
Attribution: "&copy; <a href='https://data.public.lu/en/datasets/carte-de-base-webservices-wms-et-wmts'>OpenData</a> <a href='https://creativecommons.org/publicdomain/zero/1.0/'>CC0</a>/<a href='https://creativecommons.org/licenses/by/4.0/deed.en'>CC-BY</a> | &copy; <a href='https://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors");
4852
}

0 commit comments

Comments
 (0)