Class MapLegend
Represents the map legend to show legend for the bubbles or shapes.
Information provided in the legend helps to identify the data rendered in the map shapes or bubbles.
Inheritance
Namespace: Syncfusion.Maui.Maps
Assembly: Syncfusion.Maui.Maps.dll
Syntax
public class MapLegend : BindableObject, ILegend
Examples
<map:SfMaps>
<map:SfMaps.BindingContext>
<local:BubbleViewModel/>
</map:SfMaps.BindingContext>
<map:SfMaps.Layer>
<map:MapShapeLayer x:Name="layer"
ShapesSource="https://cdn.syncfusion.com/maps/map-data/world-map.json"
DataSource="{Binding Details}"
ShapeDataField="name"
PrimaryValuePath="CountryName"
ShowBubbles="True">
<map:MapShapeLayer.BubbleSettings>
<map:MapBubbleSettings SizeValuePath="UsersCount"
ColorValuePath="UserCount">
<map:MapBubbleSettings.ColorMappings>
<map:RangeColorMapping Color="#809fff" From="0" To="100" Text="0-100" />
<map:RangeColorMapping Color="#3366ff" From="100" To="200" Text="100-200" />
<map:RangeColorMapping Color="#0039e6" From="200" To="300" Text="200-300" />
</map:MapBubbleSettings.ColorMappings>
</map:MapShapeLayer.BubbleSettings>
<map:MapShapeLayer.Legend>
<map:MapLegend Placement="Bottom"
SourceType="Bubble">
<map:MapLegend.TextStyle>
<map:MapLabelStyle TextColor="Green"
FontSize="12"
FontAttributes="Bold" />
</map:MapLegend.TextStyle>
</map:MapLegend>
</map:MapShapeLayer.Legend>
</map:MapShapeLayer>
</map:SfMaps.Layer>
</map:SfMaps>
Constructors
MapLegend()
Initializes a new instance of the MapLegend class.
Declaration
public MapLegend()
Fields
IconSizeProperty
Identifies the IconSize dependency property.
Declaration
public static readonly BindableProperty IconSizeProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for IconSize dependency property. |
IconTypeProperty
Identifies the IconType dependency property.
Declaration
public static readonly BindableProperty IconTypeProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for IconType dependency property. |
ItemsLayoutProperty
Identifies the ItemsLayout dependency property.
Declaration
public static readonly BindableProperty ItemsLayoutProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ItemsLayout dependency property. |
ItemTemplateProperty
Identifies the ItemTemplate dependency property.
Declaration
public static readonly BindableProperty ItemTemplateProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for ItemTemplate dependency property. |
PlacementProperty
Identifies the Placement dependency property.
Declaration
public static readonly BindableProperty PlacementProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for Placement dependency property. |
SourceTypeProperty
Identifies the SourceType dependency property.
Declaration
public static readonly BindableProperty SourceTypeProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for SourceType dependency property. |
TextStyleProperty
Identifies the TextStyle dependency property.
Declaration
public static readonly BindableProperty TextStyleProperty
Field Value
Type | Description |
---|---|
Microsoft.Maui.Controls.BindableProperty | The identifier for TextStyle dependency property. |
Properties
IconSize
Gets or sets the icon size of legend.
Declaration
public Size IconSize { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.Maui.Graphics.Size | It specifies the size of the legend.The default value is Height=12, Width=12. |
Examples
<map:SfMaps>
<map:SfMaps.Layer>
<map:MapShapeLayer x:Name="layer"
ShapesSource="https://cdn.syncfusion.com/maps/map-data/world-map.json"
DataSource="{Binding Details}"
ShapeDataField="name"
PrimaryValuePath="CountryName"
ShowBubbles="True">
<map:MapShapeLayer.BubbleSettings>
<map:MapBubbleSettings SizeValuePath="UsersCount"
ColorValuePath="UserCount">
<map:MapBubbleSettings.ColorMappings>
<map:RangeColorMapping Color="#809fff" From="0" To="100" Text="0-100" />
<map:RangeColorMapping Color="#3366ff" From="100" To="200" Text="100-200" />
<map:RangeColorMapping Color="#0039e6" From="200" To="300" Text="200-300" />
</map:MapBubbleSettings.ColorMappings>
</map:MapShapeLayer.BubbleSettings>
<map:MapShapeLayer.Legend>
<map:MapLegend Placement="Bottom"
SourceType="Bubble"
IconSize="20,20"/>
</map:MapShapeLayer.Legend>
</map:MapShapeLayer>
</map:SfMaps.Layer>
</map:SfMaps>
IconType
Gets or sets the icon type of legend.
Declaration
public ShapeType IconType { get; set; }
Property Value
Type | Description |
---|---|
ShapeType | One of the enumeration values that specifies the icon type of legend. The default is Rectangle. |
Examples
<map:SfMaps>
<map:SfMaps.Layer>
<map:MapShapeLayer x:Name="layer"
ShapesSource="https://cdn.syncfusion.com/maps/map-data/world-map.json"
DataSource="{Binding Details}"
ShapeDataField="name"
PrimaryValuePath="CountryName"
ShowBubbles="True">
<map:MapShapeLayer.BubbleSettings>
<map:MapBubbleSettings SizeValuePath="UsersCount"
ColorValuePath="UserCount">
<map:MapBubbleSettings.ColorMappings>
<map:RangeColorMapping Color="#809fff" From="0" To="100" Text="0-100" />
<map:RangeColorMapping Color="#3366ff" From="100" To="200" Text="100-200" />
<map:RangeColorMapping Color="#0039e6" From="200" To="300" Text="200-300" />
</map:MapBubbleSettings.ColorMappings>
</map:MapShapeLayer.BubbleSettings>
<map:MapShapeLayer.Legend>
<map:MapLegend Placement="Bottom"
SourceType="Bubble"
IconSize="20,20"
IconType="Diamond"/>
</map:MapShapeLayer.Legend>
</map:MapShapeLayer>
</map:SfMaps.Layer>
</map:SfMaps>
ItemsLayout
Gets or sets the layout configuration for the items in the map legend. This property allows you to define how individual legend items are arranged within the legend.
Declaration
public Layout ItemsLayout { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.Maui.Controls.Layout | It accepts the Microsoft.Maui.Controls.Layoutvalue and its default value is null. |
Examples
<map:SfMaps>
<map:SfMaps.Layer>
<map:MapShapeLayer ShapesSource="https://cdn.syncfusion.com/maps/map-data/world-map.json"
DataSource="{Binding Data}"
PrimaryValuePath="State"
ShapeDataField="name"
ShapeStroke="DarkGray"
ShapeColorValuePath="Population">
<map:MapShapeLayer.ColorMappings>
<map:RangeColorMapping Color="Red"
From="0"
To="100"
Text="0 - 100/km" />
<map:RangeColorMapping Color="LightGreen"
From="101"
To="200"
Text="100 - 200/km" />
<map:RangeColorMapping Color="Blue"
From="201"
To="300"
Text="200 - 300/km" />
<map:RangeColorMapping Color="Orange"
From="301"
To="400"
Text="300 - 400/km" />
<map:RangeColorMapping Color="Teal"
From="401"
To="500"
Text="400 - 500/km" />
<map:RangeColorMapping Color="Purple"
From="501"
To="600"
Text="500 - 600/km" />
</map:MapShapeLayer.ColorMappings>
<map:MapShapeLayer.Legend>
<map:MapLegend SourceType="Shape"
Placement="Top">
<map:MapLegend.ItemsLayout>
<FlexLayout Wrap="Wrap" WidthRequest="300" BackgroundColor="LightBlue"/>
</map:MapLegend.ItemsLayout>
</map:MapLegend>
</map:MapShapeLayer.Legend>
</map:MapShapeLayer>
</map:SfMaps.Layer>
</map:SfMaps>
ItemTemplate
Gets or sets a template to customize the appearance of each legend item.
Declaration
public DataTemplate ItemTemplate { get; set; }
Property Value
Type | Description |
---|---|
Microsoft.Maui.Controls.DataTemplate | It accepts Microsoft.Maui.Controls.DataTemplate value. |
Examples
<map:SfMaps x:Name="map">
<map:SfMaps.Layer>
<map:MapShapeLayer ShapesSource = "https://cdn.syncfusion.com/maps/map-data/world-map.json"
DataSource="{Binding Data}"
PrimaryValuePath="State"
ShapeDataField="name"
ShapeStroke="DarkGray"
ShapeColorValuePath="Population">
<map:MapShapeLayer.ColorMappings>
<map:RangeColorMapping Color = "Red"
From="0"
To="100"
Text="0 - 100/km" />
<map:RangeColorMapping Color = "LightGreen"
From="101"
To="200"
Text="100 - 200/km" />
<map:RangeColorMapping Color = "Blue"
From="201"
To="300"
Text="200 - 300/km" />
<map:RangeColorMapping Color = "Orange"
From="301"
To="400"
Text="300 - 400/km" />
<map:RangeColorMapping Color = "Teal"
From="401"
To="500"
Text="400 - 500/km" />
<map:RangeColorMapping Color = "Purple"
From="501"
To="600"
Text="500 - 600/km" />
</map:MapShapeLayer.ColorMappings>
<map:MapShapeLayer.Legend>
<map:MapLegend SourceType = "Shape" Placement="Right">
<map:MapLegend.ItemTemplate>
<DataTemplate>
<HorizontalStackLayout >
<Rectangle HeightRequest = "{Binding IconHeight}" Margin="3,0"
WidthRequest="{Binding IconWidth}"
Background="{Binding IconBrush}" />
<Label Text = "{Binding Text}" Margin="3,0"
FontAttributes="Bold"
TextColor="Black"
/>
</HorizontalStackLayout>
</DataTemplate>
</map:MapLegend.ItemTemplate>
</map:MapLegend>
</map:MapShapeLayer.Legend>
</map:MapShapeLayer>
</map:SfMaps.Layer>
</map:SfMaps>
Placement
Gets or sets the placement position of the legend.
Declaration
public LegendPlacement Placement { get; set; }
Property Value
Type | Description |
---|---|
LegendPlacement | One of the enumeration values that specifies the placement of legend. The default is Top. |
Examples
<map:SfMaps>
<map:SfMaps.Layer>
<map:MapShapeLayer x:Name="layer"
ShapesSource="https://cdn.syncfusion.com/maps/map-data/world-map.json"
DataSource="{Binding Details}"
ShapeDataField="name"
PrimaryValuePath="CountryName"
ShowBubbles="True">
<map:MapShapeLayer.BubbleSettings>
<map:MapBubbleSettings SizeValuePath="UsersCount"
ColorValuePath="UserCount">
<map:MapBubbleSettings.ColorMappings>
<map:RangeColorMapping Color="#809fff" From="0" To="100" Text="0-100" />
<map:RangeColorMapping Color="#3366ff" From="100" To="200" Text="100-200" />
<map:RangeColorMapping Color="#0039e6" From="200" To="300" Text="200-300" />
</map:MapBubbleSettings.ColorMappings>
</map:MapShapeLayer.BubbleSettings>
<map:MapShapeLayer.Legend>
<map:MapLegend Placement="Bottom"
SourceType="Bubble" />
</map:MapShapeLayer.Legend>
</map:MapShapeLayer>
</map:SfMaps.Layer>
</map:SfMaps>
SourceType
Gets or sets the source type of the legend that determines for which map element the legend need to be render.
Declaration
public LegendSourceType SourceType { get; set; }
Property Value
Type | Description |
---|---|
LegendSourceType | One of the enumeration values that specifies the source type of map legend. The default is Shape. |
Examples
<map:SfMaps>
<map:SfMaps.Layer>
<map:MapShapeLayer x:Name="layer"
ShapesSource="https://cdn.syncfusion.com/maps/map-data/world-map.json"
DataSource="{Binding Details}"
ShapeDataField="name"
PrimaryValuePath="CountryName"
ShowBubbles="True">
<map:MapShapeLayer.BubbleSettings>
<map:MapBubbleSettings SizeValuePath="UsersCount"
ColorValuePath="UserCount">
<map:MapBubbleSettings.ColorMappings>
<map:RangeColorMapping Color="#809fff" From="0" To="100" Text="0-100" />
<map:RangeColorMapping Color="#3366ff" From="100" To="200" Text="100-200" />
<map:RangeColorMapping Color="#0039e6" From="200" To="300" Text="200-300" />
</map:MapBubbleSettings.ColorMappings>
</map:MapShapeLayer.BubbleSettings>
<map:MapShapeLayer.Legend>
<map:MapLegend Placement="Bottom"
SourceType="Bubble" />
</map:MapShapeLayer.Legend>
</map:MapShapeLayer>
</map:SfMaps.Layer>
</map:SfMaps>
TextStyle
Gets or sets the label style to customize the appearance of the legend labels.
Declaration
public MapLabelStyle TextStyle { get; set; }
Property Value
Type | Description |
---|---|
MapLabelStyle | Apply when customization required for legend labels. |
Examples
<map:SfMaps>
<map:SfMaps.Layer>
<map:MapShapeLayer x:Name="layer"
ShapesSource="https://cdn.syncfusion.com/maps/map-data/world-map.json">
DataSource="{Binding Details}"
ShapeDataField="name"
PrimaryValuePath="CountryName"
ShowBubbles="True">
<map:MapShapeLayer.BubbleSettings>
<map:MapBubbleSettings SizeValuePath="UsersCount"
ColorValuePath="UserCount">
<map:MapBubbleSettings.ColorMappings>
<map:RangeColorMapping Color="#809fff" From="0" To="100" Text="0-100" />
<map:RangeColorMapping Color="#3366ff" From="100" To="200" Text="100-200" />
<map:RangeColorMapping Color="#0039e6" From="200" To="300" Text="200-300" />
</map:MapBubbleSettings.ColorMappings>
</map:MapShapeLayer.BubbleSettings>
<map:MapShapeLayer.Legend>
<map:MapLegend Placement="Bottom"
SourceType="Bubble"
IconSize="20,20"
IconType="Diamond">
<map:MapLegend.TextStyle>
<map:MapLabelStyle TextColor="Green"
FontSize="12"
FontAttributes="Bold" />
</map:MapLegend.TextStyle>
</map:MapLegend>
</map:MapShapeLayer.Legend>
</map:MapShapeLayer>
</map:SfMaps.Layer>
</map:SfMaps>
Methods
GetMaximumSizeCoefficient()
Used to specify the maximum size coefficient for the map legend.
Declaration
protected virtual double GetMaximumSizeCoefficient()
Returns
Type | Description |
---|---|
System.Double | It accepts the |
Remarks
The value must be between 0 and 1.
OnBindingContextChanged()
Invoked whenever the binding context of the View changes.
Declaration
protected override void OnBindingContextChanged()