From 217780dcffeea718939035c34c7ccffea8d53218 Mon Sep 17 00:00:00 2001 From: Adrien Di Paolo Date: Tue, 7 May 2024 15:07:46 +0200 Subject: [PATCH] fix: jsModule is null for basemap layer --- .../Components/Views/MapView.razor.cs | 3 +- .../Components/BaseMapTests.razor | 30 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/dymaptic.GeoBlazor.Core/Components/Views/MapView.razor.cs b/src/dymaptic.GeoBlazor.Core/Components/Views/MapView.razor.cs index 303ba7a5..4ce18ef2 100644 --- a/src/dymaptic.GeoBlazor.Core/Components/Views/MapView.razor.cs +++ b/src/dymaptic.GeoBlazor.Core/Components/Views/MapView.razor.cs @@ -1339,9 +1339,10 @@ public async Task AddLayer(Layer layer, bool isBasemapLayer = false) { Map!.Layers.Add(layer); layer.Parent ??= Map; - layer.JsModule ??= ViewJsModule; } + layer.JsModule ??= ViewJsModule; + if (ViewJsModule is null) return; if (ProJsViewModule is not null && layer.GetType().Namespace!.Contains("Pro")) diff --git a/test/dymaptic.GeoBlazor.Core.Test.Blazor.Shared/Components/BaseMapTests.razor b/test/dymaptic.GeoBlazor.Core.Test.Blazor.Shared/Components/BaseMapTests.razor index e91d10f2..710fb397 100644 --- a/test/dymaptic.GeoBlazor.Core.Test.Blazor.Shared/Components/BaseMapTests.razor +++ b/test/dymaptic.GeoBlazor.Core.Test.Blazor.Shared/Components/BaseMapTests.razor @@ -4,7 +4,35 @@ base.BuildRenderTree(__builder); } -@code { +@code { + [TestMethod] + public async Task TestCanSetBaseMapLayerVisibility(Action renderHandler) + { + MapView? mapView = null; + async Task OnViewInitialized() + { + await mapView!.AddLayer(new ImageryTileLayer() { Url = "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer" }, isBasemapLayer: true ); + } + AddMapRenderFragment( + @ + + + + + + ); + + await WaitForMapToRender(); + + ImageryTileLayer? imageryTileLayer = mapView!.Map!.Basemap!.Layers.OfType().SingleOrDefault(); + + Assert.IsNotNull(imageryTileLayer); + Assert.IsNotNull(imageryTileLayer.JsModule); + + await imageryTileLayer.SetVisibility(false); + + Assert.IsFalse(imageryTileLayer.Visible); + } [TestMethod] public async Task TestCanRenderArcGisDefaultBasemap(Action renderHandler)