Search results

Getting Started

Syncfusion Blazor Maps component is ideal for rendering maps from GeoJSON data or from other map providers such as OpenStreetMap and Bing Maps. For example, you can render the World map or the United States map and customize it to the desired look using built-in options in the Blazor Maps component.

This section briefly explains how to include maps in your Blazor client-side application to demonstrate the permanent and non-permanent countries in the United Nations Security council. Refer to the Getting Started with Syncfusion Blazor for Client-Side in Visual Studio 2019 Preview documentation for introduction and configuring common specifications.

You can explore some useful features in the Maps component using the following video.

Importing Syncfusion Blazor component in an application

  1. Install Syncfusion.EJ2.Blazor NuGet package in an application using the NuGet Package Manager. Make sure to check the Include prerelease option.
  2. Add the client-side resources through CDN in the <head> element of the ~/wwwroot/index.html page.
<head>
    <environment include="Development">
        <script src="https://cdn.syncfusion.com/ej2/17.3.29/dist/ej2.min.js"></script>
     </environment>
</head>

Adding component package to an application

Open the ~/_Imports.razor file, and import the Syncfusion.EJ2.Blazor.Maps package.

@using Syncfusion.EJ2.Blazor
@using Syncfusion.EJ2.Blazor.Maps

Adding the Maps component to an application

Now, add the Syncfusion Blazor Maps component in razor web page in the Pages folder. For example, the Maps component can be added to the ~/Pages/Index.razor page.

<EjsMaps></EjsMaps>

Since it does not contain any details related to the shape of a layer, it will not show any shape on the web page.

Adding GeoJSON data in Maps layer

Bind GeoJSON data to the Maps to render any geometric shape in SVG (Scalable Vector Graphics) for powerful data visualization of shapes. For example, you can render the world map and make desired customizations on it. You can also add any number of layers in the maps.

You can use the ShapeData property in MapsLayer to load the GeoJSON shape data into the Maps component.

@using Syncfusion.EJ2.Blazor.Maps

<EjsMaps>
   <MapsLayers>
       @* load shape data *@
       <MapsLayer ShapeData='new {dataOptions= "https://cdn.syncfusion.com/maps/map-data/world-map.json"}'>
       </MapsLayer>
   </MapsLayers>
</EjsMaps>

Map with GeoJSON layer

The “world-map.json” file contains the world map GeoJSON data.

Bind data source

The DataSource property is used to represent statistical data in the Maps component. Define an list of objects as a data source to the Maps component. This data source will be further used to color the map, display data labels, display tooltips, and more. Assign this to the DataSource property in MapsLayer.

@code {
    private List<UNCouncilCountry> securityCouncilDetails = new List<UNCouncilCountry>{
         new UNCouncilCountry { Name= "China", Membership= "Permanent"},
         new UNCouncilCountry { Name= "France", Membership= "Permanent" },
         new UNCouncilCountry { Name= "Russia", Membership= "Permanent"},
         new UNCouncilCountry { Name= "Kazakhstan", Membership= "Non-Permanent"},
         new UNCouncilCountry { Name= "Poland", Membership= "Non-Permanent"},
         new UNCouncilCountry { Name= "Sweden", Membership= "Non-Permanent"},
         new UNCouncilCountry { Name= "United Kingdom", Membership= "Permanent"},
         new UNCouncilCountry { Name= "United States", Membership= "Permanent"},
         new UNCouncilCountry { Name= "Bolivia", Membership= "Non-Permanent"},
         new UNCouncilCountry { Name= "Eq. Guinea", Membership= "Non-Permanent"},
         new UNCouncilCountry { Name= "Ethiopia", Membership= "Non-Permanent"},
         new UNCouncilCountry { Name= "Côte d Ivoire", Membership= "Permanent"},
         new UNCouncilCountry { Name= "Kuwait", Membership= "Non-Permanent"},
         new UNCouncilCountry { Name= "Netherlands", Membership= "Non-Permanent"},
         new UNCouncilCountry { Name= "Peru", Membership= "Non-Permanent"}
    };

    public class UNCouncilCountry
    {
        public string Name;
        public string Membership;
    };
}

United Nations Security Council data is referred from source.

You should also specify the field names in the shape data and data source to the ShapePropertyPath and ShapeDataPath properties, respectively. These are used to identify the appropriate shapes and match the specific data source values to them.

Please refer to the section for more information on data binding.

@using Syncfusion.EJ2.Blazor.Maps

<EjsMaps>
    <MapsLayers>
        <MapsLayer ShapeData='new {dataOptions= "https://cdn.syncfusion.com/maps/map-data/world-map.json"}'
                   @* To map shape data name field *@
                   ShapePropertyPath='@("name")'
                   DataSource="@securityCouncilDetails"
                   @* To map data source field *@
                   ShapeDataPath="Name">
        </MapsLayer>
    </MapsLayers>
</EjsMaps>

For example, consider the field names specified in ShapePropertyPath and ShapeDataPath have the same value: ‘United States’. So corresponding color, data label and tooltip related settings will be applied to the United States shape.

Apply color mapping

The color mapping feature supports customization of shape colors based on the underlying value of shape received from bound data. Specify the field name from values that have to be compared for the shapes in the ColorValuePath property in MapsShapeSettings.

Specify color and value in MapsShapeColorMapping. Here, ‘#EDB46F’ is specified for ‘Permanent’ and ‘#F1931B’ is specified for ‘Non-Permanent’.

@using Syncfusion.EJ2.Blazor.Maps

<EjsMaps>
    <MapsLayers>
        <MapsLayer ShapeData='new {dataOptions= "https://cdn.syncfusion.com/maps/map-data/world-map.json"}'
                   ShapePropertyPath='@("name")'
                   DataSource="@securityCouncilDetails"
                   ShapeDataPath="Name">
            @* color mapping related configuration *@
            <MapsShapeSettings Fill="#E5E5E5" ColorValuePath="Membership">
                <MapsShapeColorMappings>
                    <MapsShapeColorMapping Value="Permanent" Color="@("#EDB46F")"></MapsShapeColorMapping>
                    <MapsShapeColorMapping Value="Non-Permanent" Color="@("#F1931B")"></MapsShapeColorMapping>
                </MapsShapeColorMappings>
            </MapsShapeSettings>
        </MapsLayer>
    </MapsLayers>
</EjsMaps>

Map with color mapping

Refer code block to know the property value of securityCouncilDetails.

Add data labels

You can add label text to the shapes in the Maps component using MapsDataLabelSettings, and it provides information to users about the shapes.

@using Syncfusion.EJ2.Blazor.Maps

<EjsMaps>
    <MapsLayers>
        <MapsLayer ShapeData='new {dataOptions= "https://cdn.syncfusion.com/maps/map-data/world-map.json"}'
                   ShapePropertyPath='@("name")'
                   DataSource="@securityCouncilDetails"
                   ShapeDataPath="Name">
            @* To add data labels *@
            <MapsDataLabelSettings Visible="true" LabelPath="Name" IntersectionAction="IntersectAction.Hide"></MapsDataLabelSettings>
            <MapsShapeSettings Fill="#E5E5E5" ColorValuePath="Membership">
                <MapsShapeColorMappings>
                    <MapsShapeColorMapping Value="Permanent" Color="@("#EDB46F")"></MapsShapeColorMapping>
                    <MapsShapeColorMapping Value="Non-Permanent" Color="@("#F1931B")"></MapsShapeColorMapping>
                </MapsShapeColorMappings>
            </MapsShapeSettings>
        </MapsLayer>
    </MapsLayers>
</EjsMaps>

Refer code block to know the property value of securityCouncilDetails.

Map with labels

Add title for Maps

You can add a title using MapsTitleSettings to the maps to provide quick information to users about the shapes rendered in the maps.

@using Syncfusion.EJ2.Blazor.Maps

<EjsMaps>
    @* To add title *@
    <MapsTitleSettings Text="Members of the UN Security Council"></MapsTitleSettings>
    <MapsLayers>
        <MapsLayer ShapeData='new {dataOptions= "https://cdn.syncfusion.com/maps/map-data/world-map.json"}'
                   ShapePropertyPath='@("name")'
                   DataSource="@securityCouncilDetails"
                   ShapeDataPath="Name">
            <MapsDataLabelSettings Visible="true" LabelPath="Name" IntersectionAction="IntersectAction.Hide"></MapsDataLabelSettings>
            <MapsShapeSettings Fill="#E5E5E5" ColorValuePath="Membership">
                <MapsShapeColorMappings>
                    <MapsShapeColorMapping Value="Permanent" Color="@("#EDB46F")"></MapsShapeColorMapping>
                    <MapsShapeColorMapping Value="Non-Permanent" Color="@("#F1931B")"></MapsShapeColorMapping>
                </MapsShapeColorMappings>
            </MapsShapeSettings>
        </MapsLayer>
    </MapsLayers>
</EjsMaps>

Refer code block to know the property value of securityCouncilDetails.

Map with title

Enable legend

The legend items are used to denote color mapping categories, and you can show legend for the maps by setting true to the Visible property in MapsLegendSettings.

@using Syncfusion.EJ2.Blazor.Maps

<EjsMaps>
    <MapsTitleSettings Text="Members of the UN Security Council"></MapsTitleSettings>
    @* To add legend *@
    <MapsLegendSettings Visible="true"></MapsLegendSettings>
    <MapsLayers>
        <MapsLayer ShapeData='new {dataOptions= "https://cdn.syncfusion.com/maps/map-data/world-map.json"}'
                   ShapePropertyPath='@("name")'
                   DataSource="@securityCouncilDetails"
                   ShapeDataPath="Name">
            <MapsDataLabelSettings Visible="true" LabelPath="Name" IntersectionAction="IntersectAction.Hide"></MapsDataLabelSettings>
            <MapsShapeSettings Fill="#E5E5E5" ColorValuePath="Membership">
                <MapsShapeColorMappings>
                    <MapsShapeColorMapping Value="Permanent" Color="@("#EDB46F")"></MapsShapeColorMapping>
                    <MapsShapeColorMapping Value="Non-Permanent" Color="@("#F1931B")"></MapsShapeColorMapping>
                </MapsShapeColorMappings>
            </MapsShapeSettings>
        </MapsLayer>
    </MapsLayers>
</EjsMaps>

Refer code block to know the property value of securityCouncilDetails.

Map with legend

Enable tooltip

The tooltip is used when you cannot display information using the data labels due to space constraints.

You can enable tooltip by setting the Visible property to true in MapsLayerTooltipSettings.

@using Syncfusion.EJ2.Blazor.Maps

<EjsMaps>
    <MapsTitleSettings Text="Members of the UN Security Council"></MapsTitleSettings>
    <MapsLegendSettings Visible="true"></MapsLegendSettings>
    <MapsLayers>
        <MapsLayer ShapeData='new {dataOptions= "https://cdn.syncfusion.com/maps/map-data/world-map.json"}'
                   ShapePropertyPath='@("name")'
                   DataSource="@securityCouncilDetails"
                   ShapeDataPath="Name">
            <MapsDataLabelSettings Visible="true" LabelPath="Name" IntersectionAction="IntersectAction.Hide"></MapsDataLabelSettings>
            <MapsShapeSettings Fill="#E5E5E5" ColorValuePath="Membership">
                <MapsShapeColorMappings>
                    <MapsShapeColorMapping Value="Permanent" Color="@("#EDB46F")"></MapsShapeColorMapping>
                    <MapsShapeColorMapping Value="Non-Permanent" Color="@("#F1931B")"></MapsShapeColorMapping>
                </MapsShapeColorMappings>
            </MapsShapeSettings>
            @* To add tooltip for map shape *@
            <MapsLayerTooltipSettings Visible='true' ValuePath="Name"></MapsLayerTooltipSettings>
        </MapsLayer>
    </MapsLayers>
</EjsMaps>

Refer code block to know the property value of securityCouncilDetails.

Map with tooltip

The download example shows all syntax and code snippets described on this page.

See also