Annotations in Blazor Maps component
4 Nov 20256 minutes to read
Annotations mark areas of interest on the map using text, shapes, or images. Any number of annotations can be added to the Maps component.
Annotation
Use the ContentTemplate property of MapsAnnotation to render text content or an HTML element as an annotation in Maps.
@using Syncfusion.Blazor.Maps
<SfMaps>
<MapsAnnotations>
<MapsAnnotation X="0%" Y="50%">
<ContentTemplate>
<div>
<img style="height: 30px; width: 40px" src='https://blazor.syncfusion.com/demos/_content/blazor_server_common_net8/images/maps/wheel.png'>
</div>
</ContentTemplate>
</MapsAnnotation>
</MapsAnnotations>
<MapsLayers>
<MapsLayer ShapeData='new {dataOptions ="https://cdn.syncfusion.com/maps/map-data/world-map.json"}'
ShapePropertyPath='new string[] {"name"}' TValue="string">
</MapsLayer>
</MapsLayers>
</SfMaps>Annotation customization
Changing the z-index
Change the stacking order of an annotation element using the ZIndex property of MapsAnnotation.
@using Syncfusion.Blazor.Maps
<SfMaps>
<MapsAnnotations>
<MapsAnnotation X="0%" Y="50%" ZIndex= "-1">
<ContentTemplate>
<div>
<div id="first"><h1>Maps</h1></div>
</div>
</ContentTemplate>
</MapsAnnotation>
</MapsAnnotations>
<MapsLayers>
<MapsLayer ShapeData='new {dataOptions ="https://cdn.syncfusion.com/maps/map-data/world-map.json"}'
ShapePropertyPath='new string[] {"name"}' TValue="string">
</MapsLayer>
</MapsLayers>
</SfMaps>Positioning an annotation
Place annotations anywhere on the map by specifying percentage values for the X and Y properties of MapsAnnotation.
@using Syncfusion.Blazor.Maps
<SfMaps>
<MapsAnnotations>
<MapsAnnotation X="20%" Y="50%" ZIndex= "-1">
<ContentTemplate>
<div>
<div id="first"><h1>Maps</h1></div>
</div>
</ContentTemplate>
</MapsAnnotation>
</MapsAnnotations>
<MapsLayers>
<MapsLayer ShapeData='new {dataOptions ="https://cdn.syncfusion.com/maps/map-data/world-map.json"}'
ShapePropertyPath='new string[] {"name"}' TValue="string">
</MapsLayer>
</MapsLayers>
</SfMaps>Alignment of an annotation
Align annotations using the HorizontalAlignment and VerticalAlignment properties of MapsAnnotation. Possible values: Center, Far, Near and None.
@using Syncfusion.Blazor.Maps
<SfMaps>
<MapsAnnotations>
<MapsAnnotation X="20%" Y="10%" ZIndex= "-1" VerticalAlignment="AnnotationAlignment.Center" HorizontalAlignment="AnnotationAlignment.Center">
<ContentTemplate>
<div>
<div id="first"><h1>Maps</h1></div>
</div>
</ContentTemplate>
</MapsAnnotation>
</MapsAnnotations>
<MapsLayers>
<MapsLayer ShapeData='new {dataOptions ="https://cdn.syncfusion.com/maps/map-data/world-map.json"}'
ShapePropertyPath='new string[] {"name"}' TValue="string">
</MapsLayer>
</MapsLayers>
</SfMaps>Multiple Annotation
Add multiple annotations by including multiple MapsAnnotation elements within MapsAnnotations. Customize each annotation using the MapsAnnotation properties.
@using Syncfusion.Blazor.Maps
<SfMaps>
<MapsAnnotations>
<MapsAnnotation X="0%" Y="50%">
<ContentTemplate>
<div>
<div id="first"><h1>Maps</h1></div>
</div>
</ContentTemplate>
</MapsAnnotation>
<MapsAnnotation ZIndex= "-1" HorizontalAlignment="AnnotationAlignment.Center">
<ContentTemplate>
<div>
<div id="second"><h1>Maps-Annotation</h1></div>
</div>
</ContentTemplate>
</MapsAnnotation>
</MapsAnnotations>
<MapsLayers>
<MapsLayer ShapeData='new {dataOptions ="https://cdn.syncfusion.com/maps/map-data/world-map.json"}'
ShapePropertyPath='new string[] {"name"}' TValue="string">
</MapsLayer>
</MapsLayers>
</SfMaps>