-
-
Notifications
You must be signed in to change notification settings - Fork 264
Add BitMap component (#10110) #12360
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
Merged
msynk
merged 31 commits into
bitfoundation:develop
from
msynk:10110-blazorui-map-component
May 29, 2026
Merged
Changes from 27 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
1c01bc3
add BitMap component #10110
msynk 3f0880d
resolve review comments
msynk 478dcbf
resolve review comments II
msynk 3454a53
resolve review comments II
msynk 7931795
resolve review comments III
msynk ff02e84
resolve review comments V
msynk b79069b
resolve review comments VI
msynk bf9d3b1
resolve review comments VII
msynk 3e5b401
resolve review comments VIII
msynk dc14dbb
resolve review comments IX
msynk 1776a3f
resolve review comments X
msynk 77a0b9b
resolve review comments XI
msynk 60e697a
resolve review comments XII
msynk 206411c
resolve review comments XIII
msynk 7006eb6
resolve review comments XIV
msynk 225538f
resolve review comments XV
msynk 3cbb988
resolve review comments XVI
msynk c075067
resolve review comments XVII
msynk e63ad39
resolve review comments XVIII
msynk f0c26dd
resolve review comments XIX
msynk 997c2a1
resolve review comments XX
msynk 0d473e8
resolve review comments XXI
msynk 7ce7be8
resovle review comments XXII
msynk f71637b
resolve review comments XXIII
msynk 94be3f0
resolve review comments XXIV
msynk aba18f5
resolve local review findings
msynk 708c184
resolve review comments XXV
msynk 523041d
resolve review comments XXVI
msynk b68b140
code formatting on demo page
msynk c41d99f
resolve review comments XXVII
msynk e426258
resolve review comments XXVIII
msynk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/BlazorUI/Bit.BlazorUI.Extras/Components/Map/BitMap.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| @namespace Bit.BlazorUI | ||
| @inherits BitComponentBase | ||
| @typeparam TMapProvider where TMapProvider : class, IBitMapProvider, new() | ||
|
|
||
| <div @ref="RootElement" | ||
| @attributes="HtmlAttributes" | ||
| id="@_Id" | ||
| style="@StyleBuilder.Value" | ||
| class="@ClassBuilder.Value" | ||
| dir="@Dir?.ToString().ToLowerInvariant()"> | ||
| <div id="@_canvasId" | ||
| @ref="_mapElement" | ||
| class="bit-map-canvas" | ||
| tabindex="0" | ||
| role="region" | ||
| aria-label="@(AriaLabel ?? "Map")"></div> | ||
| @if (ChildContent is not null) | ||
| { | ||
| <div class="bit-map-overlay">@ChildContent</div> | ||
| } | ||
| </div> |
966 changes: 966 additions & 0 deletions
966
src/BlazorUI/Bit.BlazorUI.Extras/Components/Map/BitMap.razor.cs
Large diffs are not rendered by default.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
src/BlazorUI/Bit.BlazorUI.Extras/Components/Map/BitMap.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| .bit-map { | ||
| width: 100%; | ||
| height: 100%; | ||
| box-sizing: border-box; | ||
| position: relative; | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| .bit-map-canvas { | ||
| position: absolute; | ||
| inset: 0; | ||
| width: 100%; | ||
| height: 100%; | ||
| } | ||
|
|
||
| .bit-map-canvas:focus-visible { | ||
| outline: 2px solid Highlight; | ||
| outline: 2px solid -webkit-focus-ring-color; | ||
| outline-offset: -2px; | ||
| } | ||
|
|
||
| .bit-map-overlay { | ||
| position: absolute; | ||
| inset: 0; | ||
| pointer-events: none; | ||
| z-index: 1; | ||
|
|
||
| > * { | ||
| pointer-events: auto; | ||
| } | ||
| } | ||
|
|
||
| // OpenLayers popup. Styles live here (instead of inline cssText in the TS provider) | ||
| // so they aren't blocked under strict CSP configurations that disallow inline styles | ||
| // and so consumers can theme them from their own stylesheets. | ||
| .bit-map-ol-popup { | ||
| position: relative; | ||
| max-width: 280px; | ||
| padding: 10px 12px; | ||
| background: #fff; | ||
| border-radius: 6px; | ||
| box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25); | ||
| overflow-wrap: break-word; | ||
| } | ||
|
|
||
| .bit-map-ol-popup--hidden { | ||
| display: none; | ||
| } | ||
|
|
||
| .bit-map-ol-popup__close { | ||
| position: absolute; | ||
| top: 2px; | ||
| right: 6px; | ||
| padding: 2px 4px; | ||
| border: none; | ||
| background: transparent; | ||
| color: #666; | ||
| font-size: 16px; | ||
| line-height: 1; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .bit-map-ol-popup__content { | ||
| margin-top: 4px; | ||
| } | ||
44 changes: 44 additions & 0 deletions
44
src/BlazorUI/Bit.BlazorUI.Extras/Components/Map/BitMapInteropErrorArgs.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| namespace Bit.BlazorUI; | ||
|
|
||
| /// <summary> | ||
| /// Source of a <see cref="BitMap{TMapProvider}.OnInteropError"/> event. | ||
| /// </summary> | ||
| public enum BitMapInteropErrorSource | ||
| { | ||
| /// <summary>Loading the provider's external scripts failed.</summary> | ||
| ScriptLoad, | ||
|
|
||
| /// <summary>Loading the provider's external stylesheets failed.</summary> | ||
| StylesheetLoad, | ||
|
|
||
| /// <summary>The provider's <c>init</c> JS call failed.</summary> | ||
| Init, | ||
|
|
||
| /// <summary>The provider's <c>sync</c> JS call failed.</summary> | ||
| Sync, | ||
|
|
||
| /// <summary>The provider's <c>dispose</c> JS call failed.</summary> | ||
| Dispose, | ||
|
|
||
| /// <summary>An imperative call (add/remove/update) into the provider failed.</summary> | ||
| Imperative, | ||
|
|
||
| /// <summary>A consumer-supplied event handler threw while processing a JS-invoked callback.</summary> | ||
| Callback, | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Payload for <see cref="BitMap{TMapProvider}.OnInteropError"/>. Carries the underlying | ||
| /// exception and a tag indicating which interop call site produced it. | ||
| /// </summary> | ||
| public sealed class BitMapInteropErrorArgs | ||
| { | ||
| /// <summary>Where the error originated.</summary> | ||
| public required BitMapInteropErrorSource Source { get; init; } | ||
|
|
||
| /// <summary>The exception that was caught.</summary> | ||
| public required Exception Exception { get; init; } | ||
|
|
||
| /// <summary>Optional context (e.g. method name, marker id) for diagnostics.</summary> | ||
| public string? Context { get; init; } | ||
| } |
148 changes: 148 additions & 0 deletions
148
src/BlazorUI/Bit.BlazorUI.Extras/Components/Map/BitMapJsRuntimeExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| namespace Bit.BlazorUI; | ||
|
|
||
| /// <summary> | ||
| /// Provider-agnostic JS runtime helpers for <see cref="BitMap{TMapProvider}"/>. | ||
| /// All calls go through <c>BitBlazorUI.<JsObjectName>.<method></c> so each | ||
| /// provider exposes its own implementation under the same shape. | ||
| /// </summary> | ||
| internal static class BitMapJsRuntimeExtensions | ||
| { | ||
| public static ValueTask BitMapInit<TProvider>(this IJSRuntime jsRuntime, | ||
| string jsObjectName, | ||
| string id, | ||
| string canvasId, | ||
| ElementReference element, | ||
| DotNetObjectReference<BitMap<TProvider>>? dotnetObj, | ||
| object options) | ||
| where TProvider : class, IBitMapProvider, new() | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.init", id, canvasId, element, dotnetObj, options); | ||
| } | ||
|
|
||
| public static ValueTask BitMapSync(this IJSRuntime jsRuntime, string jsObjectName, string id, object options) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.sync", id, options); | ||
| } | ||
|
|
||
| public static ValueTask BitMapDispose(this IJSRuntime jsRuntime, string jsObjectName, string id) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.dispose", id); | ||
| } | ||
|
|
||
| public static ValueTask BitMapInvalidateSize(this IJSRuntime jsRuntime, string jsObjectName, string id) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.invalidateSize", id); | ||
| } | ||
|
|
||
| public static ValueTask<System.Text.Json.JsonElement> BitMapGetView(this IJSRuntime jsRuntime, string jsObjectName, string id) | ||
| { | ||
| return jsRuntime.Invoke<System.Text.Json.JsonElement>($"BitBlazorUI.{jsObjectName}.getView", id); | ||
| } | ||
|
|
||
| public static ValueTask BitMapSetView(this IJSRuntime jsRuntime, string jsObjectName, string id, | ||
| double lat, double lng, double? zoom, bool animate) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.setView", id, lat, lng, zoom, animate); | ||
| } | ||
|
|
||
| public static ValueTask BitMapFlyTo(this IJSRuntime jsRuntime, string jsObjectName, string id, | ||
| double lat, double lng, double? zoom) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.flyTo", id, lat, lng, zoom); | ||
| } | ||
|
|
||
| public static ValueTask BitMapFitBounds(this IJSRuntime jsRuntime, string jsObjectName, string id, | ||
| double swLat, double swLng, | ||
| double neLat, double neLng, | ||
| int paddingPixels) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.fitBounds", id, swLat, swLng, neLat, neLng, paddingPixels); | ||
| } | ||
|
|
||
| public static ValueTask BitMapFitBoundsToMarkers(this IJSRuntime jsRuntime, string jsObjectName, string id, int paddingPixels) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.fitBoundsToMarkers", id, paddingPixels); | ||
| } | ||
|
|
||
| public static ValueTask BitMapAddMarker(this IJSRuntime jsRuntime, string jsObjectName, string id, string markerId, object marker) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.addMarker", id, markerId, marker); | ||
| } | ||
|
|
||
| public static ValueTask BitMapRemoveMarker(this IJSRuntime jsRuntime, string jsObjectName, string id, string markerId) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.removeMarker", id, markerId); | ||
| } | ||
|
|
||
| public static ValueTask BitMapClearMarkers(this IJSRuntime jsRuntime, string jsObjectName, string id) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.clearMarkers", id); | ||
| } | ||
|
|
||
| public static ValueTask BitMapSyncMarkers(this IJSRuntime jsRuntime, string jsObjectName, string id, string[] markerIds, object[] markers) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.syncMarkers", id, markerIds, markers); | ||
| } | ||
|
|
||
| public static ValueTask BitMapSetMarkerPosition(this IJSRuntime jsRuntime, string jsObjectName, string id, | ||
| string markerId, double lat, double lng) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.setMarkerPosition", id, markerId, lat, lng); | ||
| } | ||
|
|
||
| public static ValueTask BitMapOpenMarkerPopup(this IJSRuntime jsRuntime, string jsObjectName, string id, string markerId) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.openMarkerPopup", id, markerId); | ||
| } | ||
|
|
||
| public static ValueTask BitMapAddPolyline(this IJSRuntime jsRuntime, string jsObjectName, string id, | ||
| string layerId, object[] path, object? style) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.addPolyline", id, layerId, path, style); | ||
| } | ||
|
|
||
| public static ValueTask BitMapAddPolygon(this IJSRuntime jsRuntime, string jsObjectName, string id, | ||
| string layerId, object[] ring, object? style) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.addPolygon", id, layerId, ring, style); | ||
| } | ||
|
|
||
| public static ValueTask BitMapAddCircle(this IJSRuntime jsRuntime, string jsObjectName, string id, | ||
| string layerId, double lat, double lng, double radiusMeters, object? style) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.addCircle", id, layerId, lat, lng, radiusMeters, style); | ||
| } | ||
|
|
||
| public static ValueTask BitMapAddRectangle(this IJSRuntime jsRuntime, string jsObjectName, string id, | ||
| string layerId, double swLat, double swLng, | ||
| double neLat, double neLng, object? style) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.addRectangle", id, layerId, swLat, swLng, neLat, neLng, style); | ||
| } | ||
|
|
||
| public static ValueTask BitMapAddGeoJson(this IJSRuntime jsRuntime, string jsObjectName, string id, | ||
| string layerId, string geoJson, object? style) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.addGeoJson", id, layerId, geoJson, style); | ||
| } | ||
|
|
||
| public static ValueTask BitMapRemoveLayer(this IJSRuntime jsRuntime, string jsObjectName, string id, string layerId) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.removeLayer", id, layerId); | ||
| } | ||
|
|
||
| public static ValueTask BitMapClearVectorLayers(this IJSRuntime jsRuntime, string jsObjectName, string id) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.clearVectorLayers", id); | ||
| } | ||
|
|
||
| public static ValueTask BitMapAddTileOverlay(this IJSRuntime jsRuntime, string jsObjectName, string id, object overlay) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.addTileOverlay", id, overlay); | ||
| } | ||
|
|
||
| public static ValueTask BitMapRemoveTileOverlay(this IJSRuntime jsRuntime, string jsObjectName, string id, string overlayId) | ||
| { | ||
| return jsRuntime.InvokeVoid($"BitBlazorUI.{jsObjectName}.removeTileOverlay", id, overlayId); | ||
| } | ||
| } |
72 changes: 72 additions & 0 deletions
72
src/BlazorUI/Bit.BlazorUI.Extras/Components/Map/BitMapLatLng.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| namespace Bit.BlazorUI; | ||
|
|
||
| /// <summary> | ||
| /// Geographic coordinate in WGS84 (EPSG:4326). | ||
| /// </summary> | ||
| public readonly record struct BitMapLatLng | ||
| { | ||
| private readonly double _latitude; | ||
| private readonly double _longitude; | ||
|
|
||
| /// <summary> | ||
| /// Creates a new <see cref="BitMapLatLng"/> with the given coordinates. | ||
| /// </summary> | ||
| /// <param name="latitude">Latitude in degrees. Must be within [-90, 90].</param> | ||
| /// <param name="longitude">Longitude in degrees. Must be within [-180, 180].</param> | ||
| /// <exception cref="ArgumentOutOfRangeException">Thrown when either value is outside its valid range or NaN.</exception> | ||
| public BitMapLatLng(double latitude, double longitude) | ||
| { | ||
| _latitude = ValidateLatitude(latitude); | ||
| _longitude = ValidateLongitude(longitude); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Latitude in degrees. Must be within [-90, 90]. | ||
| /// </summary> | ||
| /// <exception cref="ArgumentOutOfRangeException">Thrown when the value is outside the valid range.</exception> | ||
| public double Latitude | ||
| { | ||
| get => _latitude; | ||
| init => _latitude = ValidateLatitude(value); | ||
| } | ||
|
msynk marked this conversation as resolved.
msynk marked this conversation as resolved.
msynk marked this conversation as resolved.
|
||
|
|
||
| /// <summary> | ||
| /// Longitude in degrees. Must be within [-180, 180]. | ||
| /// </summary> | ||
| /// <exception cref="ArgumentOutOfRangeException">Thrown when the value is outside the valid range.</exception> | ||
| public double Longitude | ||
| { | ||
| get => _longitude; | ||
| init => _longitude = ValidateLongitude(value); | ||
| } | ||
|
msynk marked this conversation as resolved.
msynk marked this conversation as resolved.
msynk marked this conversation as resolved.
msynk marked this conversation as resolved.
|
||
|
|
||
| /// <summary>Shorthand for <see cref="Latitude"/>.</summary> | ||
| public double Lat => Latitude; | ||
|
|
||
| /// <summary>Shorthand for <see cref="Longitude"/>.</summary> | ||
| public double Lng => Longitude; | ||
|
|
||
| private static double ValidateLatitude(double value) | ||
| { | ||
| if (double.IsNaN(value) || value < -90 || value > 90) | ||
| { | ||
| throw new ArgumentOutOfRangeException( | ||
| nameof(Latitude), | ||
| value, | ||
| $"{nameof(BitMapLatLng)}.{nameof(Latitude)} must be a number between -90 and 90 (inclusive)."); | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| private static double ValidateLongitude(double value) | ||
| { | ||
| if (double.IsNaN(value) || value < -180 || value > 180) | ||
| { | ||
| throw new ArgumentOutOfRangeException( | ||
| nameof(Longitude), | ||
| value, | ||
| $"{nameof(BitMapLatLng)}.{nameof(Longitude)} must be a number between -180 and 180 (inclusive)."); | ||
| } | ||
| return value; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.