MapBlazor is a Razor Class Library that puts the ArcGIS Maps SDK for JavaScript (Esri) behind a typed .NET API. A Blazor app, whether Server, WebAssembly or Auto, can add 2D maps and 3D scenes, layers, basemaps, drawing, selection, popups and widgets without writing JavaScript. This series covers the architecture behind it: how the JavaScript SDK is bundled and shipped, how the SDK is bootstrapped, how .NET and JS talk to each other, how map state flows back into Blazor, and how it is packaged and tested. Part Topic 01 Goals, project layout and the build pipeline 02 Configuration-first SDK bootstrapping and pluggable authentication (bring your own IdP) 03 The .NET ↔ JavaScript bridge: registry, DTOs, callbacks, disposal 04 The MapView<TMap> component and per-map services 05 Layers, basemaps, 2D/3D, drawing, selection, popups and widgets 06 State with Fluxor, error contracts, packaging and testing Stack: .NET 10 Razor Class Library, ArcGIS Map...
MapBlazor Architecture, Part 6: Fluxor State, Errors, Packaging and Testing
- Get link
- X
- Other Apps
By
abhay menon
-
State
The library publishes what happens on a map as Fluxor state and actions:
[FeatureState]
public sealed record MapViewState(ImmutableDictionary<string, MapState> Maps)
{
public MapViewState() : this(ImmutableDictionary<string, MapState>.Empty) { }
}
public sealed record MapState(Extent? Extent, double Zoom, double Scale, string Basemap,
ViewType ViewType, bool IsBusy, MapPoint? LastClick);
- State is keyed by map id, so the same feature serves every map on the page.
- Layer state (which layers, visible, opacity, load status) is also per map. A single global layer list mixes maps up.
- Actions are generic over the map:
MapExtentChanged<TMap>,MapClicked<TMap>,LayerAdded<TMap>,DrawCompleted<TMap>,PopupActionTriggered<TMap>,TokenExpired.
Consumers choose a style:
@inject IState<MapViewState> MapState // render from state
...
SubscribeToAction<MapClicked<DetailMap>>(a => ShowDetails(a.Point)); // react to events
Keep reducers pure. Do JS calls in effects or services, never in reducers. Add a reducer for every success action you dispatch, including scene layers and opacity changes, so state never drifts from the map.
Error contracts
Pick one contract and use it everywhere:
| Situation | Contract |
|---|---|
| Expected failure (layer URL 404, query error, user cancelled a draw) | Result / Result<T> (FluentResults) with a reason |
| Programming error (map not initialized, unknown layer id) | Exception (InvalidOperationException) |
| JS-side failure | JS returns { ok: false, error }. .NET turns it into Result.Fail |
export async function addFeatureLayer(mapId: string, dto: FeatureLayerDto): Promise<JsResult> {
try { const l = new FeatureLayer(dto); await l.load(); attach(mapId, dto.id, l, dto.index); return { ok: true }; }
catch (e) { return { ok: false, error: describe(e) }; }
}
Mixing bool, void and silent console.error catches makes failures invisible to consumers.
Logging: use ILogger<T> on the .NET side. On the JS side, use a small logger gated by the configured log level. Never log configuration objects that may contain keys or tokens.
Packaging
<PropertyGroup>
<PackageId>MapBlazor</PackageId>
<Version>1.4.0-sdk5.0.18</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
<StaticWebAssetBasePath>_content/MapBlazor</StaticWebAssetBasePath>
</PropertyGroup>
- The package carries
wwwroot/js(bundles and chunks) andwwwroot/assets(SDK assets). That's large, about tens of MB, because the SDK's workers and locales are included. - Offer a CDN mode as well:
AssetsPath = https://js.arcgis.com/5.0/@arcgis/core/assets. Self-hosting is still the default for intranets. - Build packages in CI (
dotnet pack -c Release) and push them to a feed. Don't commit.nupkgfiles to the repository.
Testing
| Layer | How |
|---|---|
| TS units | node:test or Vitest on pure modules (extent rounding, URL → layer-type inference, scale labels) with SDK modules stubbed |
| .NET units | xUnit on DTO mapping, reducers, services with a fake MapJs |
| Components | bUnit: MapView renders a container, calls init after the first render, disposes the engine |
| End to end | Playwright against the sample app: map appears, layer loads, draw → select returns ids, 2D↔3D keeps layers |
[Fact]
public void Extent_changes_are_kept_per_map()
{
var s = new MapViewState();
s = Reducers.OnExtent(s, new MapExtentChanged<OverviewMap>(E1, 1000, 5));
s = Reducers.OnExtent(s, new MapExtentChanged<DetailMap>(E2, 500, 7));
Assert.Equal(E1, s.Maps["overview"].Extent);
Assert.Equal(E2, s.Maps["detail"].Extent);
}
Keep the sample app compiling in CI. It's the first thing new users copy.
Checklist
- ☐ Config-first bootstrap; the facade can't load the SDK early
- ☐ Every JS callback, handle and layer cache is per map
- ☐
MapViewdisposes its map - ☐ Tokens come from a host-supplied
IMapTokenProvider; Bearer tokens only go to trusted servers - ☐ One error contract across services
- ☐ Host controls height, widgets, theme and locale
- ☐ Package version shows the SDK version. Docs are generated from the code
- ☐ Unit, component and end-to-end tests in CI, including the sample app
- Get link
- X
- Other Apps
Popular posts from this blog
QtDD12 - Creating Mac GUIs with Qt - James Turner
By
abhay menon
-
My Cloud Notes
By
abhay menon
-
Cloud Notes - Docker-Compose Download docker-compose sudo curl -L "https://github.com/docker/compose/releases/download/v2.2.3/docker-compose- $( uname -s ) - $( uname -m ) " -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose sudo docker-compose -v Oracle Cloud Base Ampere A1 - 4 OCPU & 24 GB RAMs - 180 GB (SSD) On AAPanel Install Docker-Compose On Oracle Linux 8 on OCI Download docker-ce sudo yum update sudo yum upgrade -y sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo yum update --skip-broken --nobest sudo yum install docker-ce docker-ce-cli containerd.io -y sudo docker -v sudo groupadd docker sudo usermod -aG docker < your_username > sudo newgrp docker sudo systemctl enable docker sudo systemctl start docker Disk resize on Oracle Cloud Instance sudo su - # Check Disk Size df -hT | g...
My CSharp Notes
By
abhay menon
-
My Notes - C# Replace Data : Lambda function (⋋) in C-Sharp var ReplaceData = (string val) => { string v = string.Empty; switch (val) { case "92": v = "B"; break; case "93": v = "A"; break; case "94": v = "X"; break; case "95": v = "V"; break; case "96": v = "W"; break; case "97": v = "G"; break; case "8": v = "N"; break; case "26": v = "D"; break; case "27": v = "E"; break; case "40": v = "H"; break; case "47": v = "I"; break; case "54": v = "L"; break; case "59": v = "P"; break; case "74": v = "Q"; break; case "77": v = "C"; break; default: v = ...
Comments