Map
BitMap is a generic, provider-pluggable interactive map component. It supports Leaflet, MapLibre GL, Mapbox GL, OpenLayers, ArcGIS, Azure Maps, and CesiumJS.
Notes
To use this component, install the
Bit.BlazorUI.Extras
nuget package.
BitMap<TMapProvider> is generic - choose a provider class as the type argument and pass a configured instance via Provider.
Providers: BitLeafletMapProvider, BitMapLibreMapProvider, BitMapboxMapProvider,
BitOpenLayersMapProvider, BitArcGisMapProvider, BitAzureMapsMapProvider, BitCesiumMapProvider.
Mapbox, Azure Maps, and ArcGIS (for non-OSM basemaps) require an API key on the provider instance.
Usage
Basic
The simplest usage: a Leaflet map centered on London using the bundled Leaflet 1.9.4 library (no CDN, no token).
Markers
Add markers with HTML popups, tooltips, and drag support via the imperative API.
Always wait for
OnReady before calling map methods.
Seed markers are added on OnReady. Try the buttons.
Vectors
Draw polylines, polygons, circles, and rectangles. Each layer has a string id so you can remove or replace it individually.
Clicking a shape raises
OnVectorClick.
Click Redraw to draw shapes, then click a shape.
GeoJSON
Load any GeoJSON string as a styled layer. Feature clicks forward the feature's
properties as a JsonElement.
Click 'Load GeoJSON', then click a feature.
Custom tiles
Switch the base tile layer at runtime by updating the
Provider parameter.
Any Leaflet-compatible XYZ template is accepted.
Events
OnClick returns the clicked coordinate. OnViewChanged fires after every pan or zoom.
Use FlyTo for animated navigation and InvalidateSize after a container resize.
Pan/zoom or click the map.
Advanced
Interaction toggles, scale bar, pan limits (
MaxBounds), marker tooltips, z-order, and tile overlays.
Toggle options or use the buttons.
MapLibre GL
MapLibre GL JS is loaded from unpkg on first render. No token required for the default demo style.
OpenLayers
OpenLayers 10 is loaded as ES modules from esm.sh. No token required; defaults to OpenStreetMap tiles.
Mapbox GL (token required)
Mapbox GL JS requires a public access token to load
To get started:
Security: only ship a public token (
mapbox:// styles.
To get started:
- Create a free account at mapbox.com
- Copy your default public token from the Access Tokens page
- Pass it to
BitMapboxMapProvider.AccessToken
Security: only ship a public token (
pk.*) to the browser, never a secret token (sk.*).
Public tokens are visible to anyone using your site, so restrict each token to your production domains via the
URL allowlist on the Access Tokens page,
set a billing cap, and use a separate token per environment so you can rotate or revoke without downtime.
For stricter scenarios, mint a short-lived token from a server endpoint or proxy tile requests through your backend.
ArcGIS Maps SDK
ArcGIS Maps SDK 5.0 is loaded as an ES module from the Esri CDN.
The
Security: if you supply an API key for non-OSM basemaps, configure HTTP referrer restrictions on the key in the ArcGIS Developer dashboard so it can only be used from your own domains, and scope it to the minimum required services.
osm basemap works without an API key.
Security: if you supply an API key for non-OSM basemaps, configure HTTP referrer restrictions on the key in the ArcGIS Developer dashboard so it can only be used from your own domains, and scope it to the minimum required services.
Azure Maps (subscription key required)
Azure Maps Web SDK v3 requires a subscription key for authentication.
To get started:
Security: shipping a shared subscription key to the browser is fine for demos but not recommended for production. For production, prefer Microsoft Entra ID or SAS token authentication: a backend mints a short-lived token and the client uses that instead of the primary key. If you must use a subscription key, restrict allowed origins on the Maps account and set usage alerts so a leaked key cannot quietly drain your quota.
To get started:
- Create an Azure Maps account in the Azure Portal
- Navigate to your Maps account → Authentication → Shared Key Authentication
- Copy the Primary Key and pass it to
BitAzureMapsMapProvider.SubscriptionKey
Security: shipping a shared subscription key to the browser is fine for demos but not recommended for production. For production, prefer Microsoft Entra ID or SAS token authentication: a backend mints a short-lived token and the client uses that instead of the primary key. If you must use a subscription key, restrict allowed origins on the Maps account and set usage alerts so a leaked key cannot quietly drain your quota.
CesiumJS 3D globe
CesiumJS renders a 3D globe. OSM imagery and smooth-ellipsoid terrain work without a token.
A Cesium ion token unlocks Cesium World Terrain and Bing imagery.
Security: if you provide a Cesium ion token, create a dedicated token in the Cesium ion dashboard, grant only the asset access it needs, and add your production domains to the token's allowed URLs list so a copied token cannot be used from other origins.
Security: if you provide a Cesium ion token, create a dedicated token in the Cesium ion dashboard, grant only the asset access it needs, and add your production domains to the token's allowed URLs list so a copied token cannot be used from other origins.
API
BitMap parameters
Name |
Type |
Default value |
Description |
|---|---|---|---|
| TMapProvider | Type (generic) | The map provider type. One of: BitLeafletMapProvider, BitMapLibreMapProvider, BitMapboxMapProvider, BitOpenLayersMapProvider, BitArcGisMapProvider, BitAzureMapsMapProvider, BitCesiumMapProvider. | |
| Provider | TMapProvider? | null | Provider configuration instance (center, zoom, tokens, etc.). When null a default instance is created. |
| ChildContent | RenderFragment? | null | Optional content rendered above the map canvas. |
| ReplayStateOnProviderSwap | bool | false | When true, imperatively-added markers, vector layers, and tile overlays are replayed after a destructive provider swap (different JsObjectName). |
| OnReady | EventCallback | Fires after the map is ready for imperative calls. Fires once on initial mount, and fires again after a destructive provider swap each time the new provider becomes ready. | |
| OnClick | EventCallback<BitMapLatLng> | Fires when the user clicks the map canvas. | |
| OnDoubleClick | EventCallback<BitMapLatLng> | Fires when the user double-clicks the map. | |
| OnViewChanged | EventCallback<BitMapViewState> | Fires whenever the map view changes. | |
| OnMarkerClick | EventCallback<string> | Fires when the user clicks a marker (argument is the marker id). | |
| OnMarkerDragEnd | EventCallback<BitMapMarkerDragEndArgs> | Fires when a draggable marker is dropped. | |
| OnVectorClick | EventCallback<BitMapVectorClickArgs> | Fires when the user clicks a vector layer. | |
| OnGeoJsonFeatureClick | EventCallback<BitMapGeoJsonFeatureClickArgs> | Fires when the user clicks a GeoJSON feature. | |
| OnInteropError | EventCallback<BitMapInteropErrorArgs> | Fires when an interop call into the underlying provider fails. Lets consumers surface errors that the component would otherwise swallow to prevent circuit-breaking exceptions. |
BitMap public members
Name |
Type |
Default value |
Description |
|---|---|---|---|
| IsReady | bool | false | True after the map is ready for interop calls. |
| GetView | Func<ValueTask<BitMapViewState>> | Returns a snapshot of the current viewport. | |
| SetView | Func<BitMapLatLng, double?, bool, ValueTask> | Pan and optionally zoom to the given center. | |
| FlyTo | Func<BitMapLatLng, double?, ValueTask> | Animated pan/zoom to the given center. | |
| FitBounds | Func<BitMapLatLngBounds, int, ValueTask> | Fit the view to the given bounding box. | |
| FitBoundsToMarkers | Func<int, ValueTask> | Fit the view to include all current markers. | |
| InvalidateSize | Func<ValueTask> | Recalculate map size after a container resize. | |
| AddMarker | Func<BitMapMarker, ValueTask> | Add a marker to the map. | |
| RemoveMarker | Func<string, ValueTask> | Remove a marker by id. | |
| ClearMarkers | Func<ValueTask> | Remove all markers. | |
| SetMarkerPosition | Func<string, BitMapLatLng, ValueTask> | Move a marker to a new position. | |
| OpenMarkerPopup | Func<string, ValueTask> | Open a marker's popup. | |
| SyncMarkers | Func<IEnumerable<BitMapMarker>, ValueTask> | Replace all markers in one batch. | |
| AddPolyline | Func<string, IReadOnlyList<BitMapLatLng>, BitMapVectorPathStyle?, ValueTask> | Add a polyline. | |
| AddPolygon | Func<string, IReadOnlyList<BitMapLatLng>, BitMapVectorPathStyle?, ValueTask> | Add a polygon. | |
| AddCircle | Func<string, BitMapLatLng, double, BitMapVectorPathStyle?, ValueTask> | Add a circle (radius in meters). | |
| AddRectangle | Func<string, BitMapLatLngBounds, BitMapVectorPathStyle?, ValueTask> | Add a rectangle. | |
| AddGeoJson | Func<string, string, BitMapVectorPathStyle?, ValueTask> | Add a GeoJSON layer. | |
| RemoveLayer | Func<string, ValueTask> | Remove a vector layer by id. | |
| ClearVectorLayers | Func<ValueTask> | Remove all vector layers. | |
| AddTileOverlay | Func<BitMapTileOverlay, ValueTask> | Add a tile overlay above the base map. | |
| RemoveTileOverlay | Func<string, ValueTask> | Remove a tile overlay by id. |
BitComponentBase parameters
Name |
Type |
Default value |
Description |
|---|---|---|---|
| AriaLabel | string? | null | Gets or sets the accessible label for the component, used by assistive technologies. |
| Class | string? | null | Gets or sets the CSS class name(s) to apply to the rendered element. |
| Dir | BitDir? | null | Gets or sets the text directionality for the component's content. |
| HtmlAttributes | Dictionary<string, object> | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. |
| Id | string? | null | Gets or sets the unique identifier for the component's root element. |
| IsEnabled | bool | true | Gets or sets a value indicating whether the component is enabled and can respond to user interaction. |
| Style | string? | null | Gets or sets the CSS style string to apply to the rendered element. |
| TabIndex | string? | null | Gets or sets the tab order index for the component when navigating with the keyboard. |
| Visibility | BitVisibility | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. |
BitComponentBase public members
Name |
Type |
Default value |
Description |
|---|---|---|---|
| UniqueId | Guid | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. |
| RootElement | ElementReference | Gets the reference to the root HTML element associated with this component. |
BitVisibility enum
Name |
Value |
Description |
|---|---|---|
| Visible | 0 | The content of the component is visible. |
| Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). |
| Collapsed | 2 | The component is hidden (display:none). |
BitDir enum
Name |
Value |
Description |
|---|---|---|
| Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). |
| Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). |
| Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. |
Feedback
You can give us your feedback through our GitHub repo by filing a new Issue or starting a new Discussion.
Or you can review / edit this page on GitHub.
Or you can review / edit this component on GitHub.
- On this page