DeepWorks Studios Blazor Component Library

Demo user Administrator ยท Blazor Server Library 20261206222504-6e8ff32.dirty

DwsMarkerMap

A DwsMap for places in groups. Every group (category) gets a theme color and an icon of its own, so groups differ by shape as well as by color, and a legend lists them with their number of markers: clicking an entry shows or hides a group, pointing at it highlights its markers. Panning, zooming, clusters, the marker detail and selection are the map's, and Map gives access to all of it.

API Reference

Basic

Groups takes DwsMarkerMapGroup items, each with a Name and its Markers (DwsMapMarker). Groups without a color take the theme colors in turn, groups without an icon a circle, square, diamond, star or triangle; the map fits all markers when it first appears (FitOnLoad). Hover a marker or a legend entry to highlight its group.

Vienna: museums, cafés, parks and stations
Map data: Natural Earth
The map and its markers are two Tab stops. On the map the arrow keys move it, Page Up and Page Down move it further, plus and minus zoom, Home returns to the start view. Tab goes on to the markers, which are one stop together: there the arrow keys move to the nearest marker in that direction, Home and End to the first and the last, Enter opens one, and Shift+Tab goes back to the map.
Show Code
Razor
<DwsMarkerMap Name="MarkerMapDemo_Basic" Groups="@_vienna" Title="Vienna: museums, cafés, parks and stations" />
C#
// Places in Vienna, in four groups.
private readonly List<DwsMarkerMapGroup> _vienna = CreateVienna();

private static List<DwsMarkerMapGroup> CreateVienna(bool stationsVisible = true) =>
[
    new DwsMarkerMapGroup("Museums")
        .AddMarker("albertina", 48.2045, 16.3681, "Albertina", "Graphic art from the Renaissance to today.")
        .AddMarker("khm", 48.2038, 16.3617, "Kunsthistorisches Museum", "Old masters, Egyptian and Greek antiquities.")
        .AddMarker("belvedere", 48.1915, 16.3809, "Upper Belvedere", "Klimt's The Kiss.")
        .AddMarker("leopold", 48.2032, 16.3592, "Leopold Museum", "Schiele and Viennese modernism.")
        .AddMarker("mak", 48.2075, 16.3818, "MAK", "Applied arts and design."),
    new DwsMarkerMapGroup("Cafés")
        .AddMarker("central", 48.2104, 16.3655, "Café Central", "Since 1876, in the Palais Ferstel.")
        .AddMarker("sacher", 48.2039, 16.3696, "Café Sacher", "Home of the Sachertorte.")
        .AddMarker("landtmann", 48.2125, 16.3614, "Café Landtmann", "Next to the Burgtheater.")
        .AddMarker("hawelka", 48.2083, 16.3704, "Café Hawelka", "Buchteln after 10 p.m."),
    new DwsMarkerMapGroup("Parks")
        .AddMarker("stadtpark", 48.2046, 16.3794, "Stadtpark", "The golden Johann Strauss statue.")
        .AddMarker("burggarten", 48.2049, 16.3666, "Burggarten", "The Palm House and the Mozart statue.")
        .AddMarker("prater", 48.2166, 16.3970, "Prater", "The Giant Ferris Wheel.")
        .AddMarker("schoenbrunn", 48.1810, 16.3122, "Schönbrunn Palace Park", "The Gloriette and the zoo."),
    new DwsMarkerMapGroup("Stations") { Visible = stationsVisible }
        .AddMarker("hbf", 48.1851, 16.3753, "Wien Hauptbahnhof", "Main station: long-distance trains in every direction.")
        .AddMarker("westbahnhof", 48.1966, 16.3378, "Westbahnhof", "Trains to Salzburg.")
        .AddMarker("praterstern", 48.2186, 16.3925, "Praterstern", "S-Bahn and U1 / U2.")
        .AddMarker("mitte", 48.2063, 16.3846, "Wien Mitte", "City Airport Train to the airport."),
];

Colors and icons

A group takes its ThemeColor (or any CSS Color) and its Icon; groups without a color take the next color of Colors, or the default palette. All colors are theme variables, so the map follows the active theme. DistinctGroupIcons = false draws plain pins for groups without an icon. A marker's own ThemeColor or Icon wins over its group's (here: the Opera).

Map data: Natural Earth
The map and its markers are two Tab stops. On the map the arrow keys move it, Page Up and Page Down move it further, plus and minus zoom, Home returns to the start view. Tab goes on to the markers, which are one stop together: there the arrow keys move to the nearest marker in that direction, Home and End to the first and the last, Enter opens one, and Shift+Tab goes back to the map.
Show Code
Razor
@foreach ((string label, DwsColor[]? colors) in _palettes)
{
    <DwsButton Name="@($"MarkerMapDemo_Palette_{label.Replace(" ", string.Empty)}")"
               Appearance="@(_palette == colors ? DwsAppearance.Filled : DwsAppearance.Outline)"
               ButtonSize="DwsSize.Small"
               OnClick="() => _palette = colors">@label</DwsButton>
}
<DwsSwitch Name="MarkerMapDemo_DistinctIcons" @bind-Value="_distinctIcons" Label="DistinctGroupIcons" />
<DwsMarkerMap Name="MarkerMapDemo_Colors" Groups="@_viennaWithIcons" Colors="@_palette" DistinctGroupIcons="@_distinctIcons" Height="360" />
C#
private readonly List<DwsMarkerMapGroup> _viennaWithIcons = CreateViennaWithIcons();

// CreateVienna: see Basic.
private static List<DwsMarkerMapGroup> CreateViennaWithIcons()
{
    List<DwsMarkerMapGroup> groups = CreateVienna();
    groups[0].Icon = Icons.Solid.Landmark;
    groups[1].Icon = Icons.Solid.MugHot;
    groups[2].Icon = Icons.Solid.Tree;
    groups[3].Icon = Icons.Solid.Train;

    // A marker's own ThemeColor and Icon win over its group's.
    groups[0].Markers.Add(new DwsMapMarker
    {
        Id = "opera",
        Position = new DwsGeoPoint(48.2030, 16.3690),
        Label = "Vienna State Opera",
        Description = "A marker with its own ThemeColor and Icon.",
        ThemeColor = DwsColor.Error,
        Icon = Icons.Solid.Music
    });

    return groups;
}

private readonly (string Label, DwsColor[]? Colors)[] _palettes =
[
    ("Default", null),
    ("Primary and Accent", [DwsColor.Primary, DwsColor.Accent, DwsColor.Link, DwsColor.Info]),
    ("Status", [DwsColor.Success, DwsColor.Info, DwsColor.Warning, DwsColor.Error]),
];

private DwsColor[]? _palette;
private bool _distinctIcons = true;

Interface-Description

Name Typ Default Description
Map DwsMap? null The DwsMap inside, for its view and methods (SetViewAsync, FitBoundsAsync, ZoomInAsync, CurrentCenter, CurrentZoom, CurrentBounds, ...). Null until rendered.
Name Typ Parameters Description
IsGroupVisible bool int groupIndex Whether the group at this position in Groups is shown (not hidden through the legend).
SetGroupVisibleAsync Task int groupIndex, bool visible Shows or hides the group at this position, as its legend entry does.
SetAllGroupsVisibleAsync Task bool visible Shows or hides every group at once, as the legend's "Show all" / "Hide all" entry does. VisibleGroupsChanged is raised once.
FitToMarkersAsync Task Moves and zooms the map so every shown marker fits. Does nothing without markers.
Name Typ Default Description
Groups IReadOnlyList<DwsMarkerMapGroup>? null The groups in legend order. A DwsMarkerMapGroup has a Name, a ThemeColor or CSS Color, an Icon, Visible (whether it starts shown), Data and Markers (DwsMapMarker: Id, Position, Label, Description, Metadata, Icon, ThemeColor / Color, Data). AddMarker(id, latitude, longitude, label, description) chains. Marker ids must be unique across groups (a duplicate is skipped with a warning); markers without one get an id from their position. A marker's own ThemeColor, Color or Icon wins over its group's.
Title string? null Caption above the map, also its accessible name (else the localized "Marker map").
Colors IReadOnlyList<DwsColor>? null Theme colors for the groups without a color of their own, in turn. Null or empty uses Primary, Success, Warning, Error, Info, Accent, Link and Secondary.
DistinctGroupIcons bool true Groups without an Icon take a circle, square, diamond, star and triangle in turn, so they differ by shape as well as by color. Off draws plain pins.
WithLegend bool true Shows a legend with one entry per group: its pin, its name and its number of markers.
LegendPosition DwsChartLegendPosition Bottom Bottom, Top, Left or Right of the map. Left and Right move below it on screens narrower than 576px.
ToggleGroupOnLegendClick bool true Clicking a legend entry (a toggle button with aria-pressed) hides its group's markers, clicking it again shows them. With false the entries are buttons only while OnLegendItemClick has a handler.
ShowLegendToggleAll bool true With ToggleGroupOnLegendClick and more than two groups: ends the legend with a "Hide all" button that hides every group at once and reads "Show all" as soon as one is hidden. VisibleGroupsChanged is raised once.
ShowGroupCounts bool true Shows each group's number of markers in its legend entry (and in its accessible name).
HighlightOnHover bool true Fades the other groups' markers while the pointer is on a legend entry or a marker (or a marker has the focus).
FitOnGroupToggle bool false After a group is shown or hidden, the map fits the markers that are left.
FitOnLoad bool true Fits every shown marker into the map once, the first time there are any. Off starts at Center and Zoom.
Center DwsGeoPoint 20° N, 0° E The point in the middle of the map; bind it with @bind-Center.
Zoom double 2 Zoom level (at 0 the world is 256 px wide, every level doubles it); bind it with @bind-Zoom.
MinZoom double 1 The smallest zoom the user can reach, 0 .. 22.
MaxZoom double 18 The largest zoom the user can reach, MinZoom .. 22.
Width int? null Width in px. Null fills the container.
Height int? null Height of the map (without caption and legend) in px. Null uses 400.
ClusterMarkers bool false Merges markers closer together than ClusterRadius pixels into a badge with their count; clicking it zooms in until they separate. Hidden groups take no part.
ClusterRadius int 60 How close markers have to be, in pixels on screen, to form a cluster.
AutoClusterMarkers bool true With more shown markers than AutoClusterThreshold the map clusters them even while ClusterMarkers is off. Off leaves clustering to ClusterMarkers alone.
AutoClusterThreshold int 100 The number of shown markers above which AutoClusterMarkers starts clustering.
MarkerKeyboardNavigation bool true The markers and clusters are one Tab stop and the arrow keys move to the nearest one in that direction (Home / End: first / last). Off makes every marker a Tab stop of its own.
AllowSelection bool true Clicking a marker selects it and pins its detail.
SelectedMarkerId string? null Id of the selected marker; bind it with @bind-SelectedMarkerId.
ShowMarkerDetail bool true Shows the detail of the hovered, focused or selected marker.
MarkerDetailTemplate RenderFragment<DwsMarkerMapItem>? null Content of the marker detail; gets the marker as given, its group, their positions, color and icon. Null shows the group, label, description and metadata.
CooperativeGestures bool true The wheel zooms only with Ctrl, and one finger scrolls the page on touch screens.
ShowZoomControls bool true Shows the zoom in / zoom out buttons.
ShowResetControl bool true Shows the button that returns to the start view.
ShowAttribution bool true Shows where the map data comes from.
CullMarkers bool? null Draws only the markers and clusters in and around the view, as on DwsMap. Null switches it on with more shown markers than AutoClusterThreshold.
ShowScaleBar bool true Shows a scale bar in the bottom corner opposite the attribution.
ScaleBarUnits DwsMapScaleUnits DwsMapScaleUnits.Auto Units of the scale bar; Auto follows the region of the current culture.
ShowLocateControl bool false Adds a 'my position' button that asks the browser for the user's position, moves the map there and marks it; a failure is shown on the map and raised through OnLocateFailed.
MaxBounds DwsGeoBounds? null Keeps the view inside this area.
TileUrlTemplate string? null URL of raster tiles with {z}, {x} and {y}, drawn under the countries (see DwsMap).
TileAttribution string? null Attribution the tile provider requires.
LandColor DwsColor Undefined Theme color of the land. Undefined uses the page background.
WaterColor DwsColor Undefined Theme color of the water. Undefined uses a tint of the info color.
BorderColor DwsColor Undefined Theme color of the country borders. Undefined uses a muted text color.
Name Typ Description
OnLocated EventCallback<DwsMapLocatedEventArgs> Raised when the browser reported the user's position.
OnLocateFailed EventCallback<DwsMapLocateStatus> Raised with the reason when the position could not be read.
OnMarkerClick EventCallback<DwsMarkerMapMarkerEventArgs> Raised when a marker is clicked or activated with Enter/Space. Item has the marker as given, its group and their positions.
OnMarkerMouseEnter EventCallback<DwsMarkerMapMarkerEventArgs> Raised when the pointer enters a marker or it gets the focus.
OnMarkerMouseLeave EventCallback<DwsMarkerMapMarkerEventArgs> Raised when the pointer leaves a marker or it loses the focus.
OnClusterClick EventCallback<DwsMarkerMapClusterEventArgs> Raised when a cluster is clicked or activated, before the map zooms in to it: Items (with their groups) and Bounds.
OnLegendItemClick EventCallback<DwsMarkerMapGroup> Raised when a legend entry is clicked or activated, after its group was shown or hidden.
VisibleGroupsChanged EventCallback<IReadOnlyList<DwsMarkerMapGroup>> Raised with the groups that are shown whenever a group is shown or hidden through the legend - e.g. to store the choice and restore it through DwsMarkerMapGroup.Visible.
OnMapClick EventCallback<DwsMapClickEventArgs> Raised when the map itself (not a marker or control) is clicked, with the position and country under the pointer.
OnViewChanged EventCallback<DwsMapViewChangedEventArgs> Raised when the map has come to rest after it was moved or zoomed.
CenterChanged EventCallback<DwsGeoPoint> Raised when the map centre changes. Supports @bind-Center.
ZoomChanged EventCallback<double> Raised when the zoom level changes. Supports @bind-Zoom.
SelectedMarkerIdChanged EventCallback<string?> Raised when the selected marker changes. Supports @bind-SelectedMarkerId.
Name Typ Default Description
Element ElementReference The associated web component. May be null if accessed before the component is rendered.
ComponentGuid Guid Unique identifier for the component.
TypeString string The name of the component type, obtained from reflection.
Authorized_RegisterEnabled bool false Indicates whether this component is enabled through a permission registry.
Authorized_RegisterSelected bool false Indicates whether this component is selected in permission selection mode.
GetInitializedState bool false Returns whether the component is initialized.
GetRenderModeState DwsRenderMode Returns the current render mode.
GetComponentState DwsComponentStateType Returns the current component state.
GetIsInteractiveState bool false Returns whether the component is interactive.
GetIsPrerenderingState bool false Returns whether the component is prerendering.
GetComponentLoadingState bool false Returns whether the component is loading.
IsFormBusy bool false Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState).
Name Typ Parameters Description
DebugInfo void Logs debug information about the component.
UpdateState void Updates the component's state and triggers StateHasChanged.
UpdateStateAsync Task Asynchronously updates the component's state and triggers StateHasChanged.
Dispose void Disposes the component and releases resources.
FocusAsync ValueTask bool containedInScrollableList Sets focus to the component's element.
Name Typ Default Description
Name string Required unique identifier for the component within its container.
Visible bool true Determines if the component is visible in the UI.
Disabled bool false Disables the form control, ensuring it doesn't participate in form submission.
ComponentNameSpace string The namespace for permission-based access control.
PermissionKey string? null A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins.
Class string Optional CSS class names.
Style string Optional in-line styles.
Tag object An optional user-defined object to store any additional data with the component.
BackReference DwsReference A reference to the enclosing component.
ID string The HTML ID attribute for the component.
AdditionalAttributes Dictionary<string, object> Additional HTML attributes for the component's root element.
IgnorePermissionChecks bool false Bypasses all permission checks for this component.
IgnorePermissionSelection bool false Ignore permission selection mode for this component.
IgnoreFormBusy bool false Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it.
Name Typ Description
OnInitializedCallbackStarted EventCallback Callback when OnInitialized starts.
OnInitializedCallback EventCallback Callback during OnInitialized.
OnInitializedCallbackCompleted EventCallback Callback when OnInitialized completes.
OnInitializedAsyncCallbackStarted EventCallback Callback when OnInitializedAsync starts.
OnInitializedAsyncCallback EventCallback Callback during OnInitializedAsync.
OnInitializedAsyncCallbackCompleted EventCallback Callback when OnInitializedAsync completes.
OnIsComponentLoadingChanged EventCallback<bool> Callback when IsComponentLoading changes.
OnCurrentRenderModeChanged EventCallback<DwsRenderMode> Callback when CurrentRenderMode changes.
OnComponentStateChanged EventCallback<DwsComponentStateType> Callback when ComponentState changes.
An error has occurred. This app may no longer respond until reloaded.