Annotations in Blazor Maps component
31 Jan 20226 minutes to read
Annotations are used to mark the specific area of interest in the Maps with texts, shapes, or images. Any number of annotations can be added to the Maps component.
Annotation
By using the ContentTemplate
property of MapsAnnotation, text content or an HTML element can be specified to render a new HTML element in Maps.
@using Syncfusion.Blazor.Maps
<SfMaps>
<MapsAnnotations>
<MapsAnnotation X="0%" Y="50%">
<ContentTemplate>
<div>
<img style="height: 30px; width: 40px" src='src/maps/images/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
The stack order of an annotation element can be changed using theĀ ZIndex property in the 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
Annotations can be placed anywhere in the Maps by specifying percentage values to the X and Y properties in the 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
Annotations can be aligned using the HorizontalAlignment and VerticalAlignment properties in the MapsAnnotation. The possible values can be 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
Multiple annotations can be added to the Maps by adding multiple MapsAnnotation in the MapsAnnotations and customization for the annotations can be done with the MapsAnnotation.
@using Syncfusion.Blazor.Maps
<SfMaps>
<MapsAnnotations>
<MapsAnnotation X="0%" Y="50%">
<ContentTemplate>
<div>
<img style="height: 30px; width: 40px" src='src/maps/images/wheel.png'>
</div>
</ContentTemplate>
</MapsAnnotation>
<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>