Legend in Angular Maps component
27 Apr 202424 minutes to read
A Legend is a visual representation of the symbols used on the Maps. It can be represented in various colors, shapes or other identifiers based on the data and provides valuable information for interpreting what the Maps are displaying. It explains what each symbol in the Maps represents. Legends are enabled by setting the visible
property of legendSettings
property to true.
Modes of legend
Legend had two types of mode.
- Default mode
- Interactive mode
Default mode
Default mode legends having symbols with legend labels, used to identify the shape or bubble or marker color. To enable this option by setting the mode
property of legendSettings
as Default.
Interactive mode
The legends can be made interactive with an arrow mark indicating the exact range color in the legend when the mouse hovers over the corresponding shapes. To enable this type of mode by setting the mode
property of legendSettings
as Interactive. The invertedPointer
property is used to enable or disable the visibility of the inverted pointer in interactive legend in Maps.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { LegendService } from '@syncfusion/ej2-angular-maps'
import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
providers: [LegendService],
standalone: true,
selector: 'app-container',
template:
`<ejs-maps id='rn-container' [legendSettings] = 'legendSettings'>
<e-layers>
<e-layer [shapeData]= 'shapeData' [shapePropertyPath]= 'shapePropertyPath' [shapeDataPath]= 'shapeDataPath' [dataSource] = 'dataSource' [shapeSettings] = 'shapeSettings'></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public dataSource?: object[];
public shapeData?: object;
public shapePropertyPath?: string;
public shapeDataPath?: string;
public shapeSettings?: object;
public legendSettings?: object;
ngOnInit(): void {
this.dataSource = [
{ "Country": "China", "Membership": "Permanent" },
{ "Country": "France", "Membership": "Permanent" },
{ "Country": "Russia", "Membership": "Permanent" },
{ "Country": "Kazakhstan", "Membership": "Non-Permanent" },
{ "Country": "Poland", "Membership": "Non-Permanent" },
{ "Country": "Sweden", "Membership": "Non-Permanent" }];
this.shapeData = world_map;
this.shapePropertyPath = 'name';
this.shapeDataPath = 'Country';
this.shapeSettings = {
colorValuePath: 'Membership',
colorMapping: [
{
value: 'Permanent', color: '#D84444'
},
{
value: 'Non-Permanent', color: '#316DB5'
}]
};
this.legendSettings = {
visible: true,
mode: 'Interactive',
invertedPointer: true
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Positioning of the legend
The legend can be positioned in the following two ways:
- Absolute position
- Dock position
Absolute position
The legend of the Maps can be positioned using the location
property in the legendSettings
property. For positioning the legend based on co-ordinates corresponding to a Maps, the position
property is set as Float.
Dock position
Legends are positioned in the following locations within the container. The position
property in legendSettings
property is used to set these options in Maps.
- Top
- Left
- Bottom
- Right
The above four positions can be aligned with combination of Near, Center and Far using alignment
property in legendSettings
property. So, the legend can be aligned to 12 positions.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { LegendService } from '@syncfusion/ej2-angular-maps'
import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
providers: [LegendService],
standalone: true,
selector: 'app-container',
template:
`<ejs-maps id='rn-container' [legendSettings] = 'legendSettings'>
<e-layers>
<e-layer [shapeData]= 'shapeData' [shapePropertyPath]= 'shapePropertyPath' [shapeDataPath]= 'shapeDataPath' [dataSource] = 'dataSource' [shapeSettings] = 'shapeSettings'></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public dataSource?: object[];
public shapeData?: object;
public shapePropertyPath?: string;
public shapeDataPath?: string;
public shapeSettings?: object;
public legendSettings?: object;
ngOnInit(): void {
this.dataSource = [
{ "Country": "China", "Membership": "Permanent" },
{ "Country": "France", "Membership": "Permanent" },
{ "Country": "Russia", "Membership": "Permanent" },
{ "Country": "Kazakhstan", "Membership": "Non-Permanent" },
{ "Country": "Poland", "Membership": "Non-Permanent" },
{ "Country": "Sweden", "Membership": "Non-Permanent" }];
this.shapeData = world_map;
this.shapePropertyPath = 'name';
this.shapeDataPath = 'Country';
this.shapeSettings = {
colorValuePath: 'Membership',
colorMapping: [
{
value: 'Permanent', color: '#D84444'
},
{
value: 'Non-Permanent', color: '#316DB5'
}]
};
this.legendSettings = {
visible: true,
position: 'Top',
alignment: 'Near'
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Legend for shapes
Legend for shapes can be generated from color mapping types such as equal color mapping, range color mapping and desaturation color mapping.
The below code snippet demonstrate the equal color mapping legends for the shapes. To bind the given data source to the dataSource
property of layerSettings
property. Set the value of shapePropertyPath
to name and shapeDataPath
to Country. To enable equal color mapping, set the colorMapping
as an array in shapeSettings
property. Finally, set the visible
property of legendSettings
as true. The label
property in colorMapping
property is used to set the text name for legend in Maps.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { LegendService } from '@syncfusion/ej2-angular-maps'
import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
providers: [LegendService],
standalone: true,
selector: 'app-container',
template:
`<ejs-maps id='rn-container' [legendSettings] = 'legendSettings'>
<e-layers>
<e-layer [shapeData]= 'shapeData' [shapePropertyPath]= 'shapePropertyPath' [shapeDataPath]= 'shapeDataPath' [dataSource] = 'dataSource' [shapeSettings] = 'shapeSettings'></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public dataSource?: object[];
public shapeData?: object;
public shapePropertyPath?: string;
public shapeDataPath?: string;
public shapeSettings?: object;
public legendSettings?: object;
ngOnInit(): void {
this.dataSource = [
{ "Country": "China", "Membership": "Permanent" },
{ "Country": "France", "Membership": "Permanent" },
{ "Country": "Russia", "Membership": "Permanent" },
{ "Country": "Kazakhstan","Membership": "Non-Permanent" },
{ "Country": "Poland", "Membership": "Non-Permanent" },
{ "Country": "Sweden", "Membership": "Non-Permanent" }];
this.shapeData = world_map;
this.shapePropertyPath = 'name';
this.shapeDataPath = 'Country';
this.shapeSettings = {
colorValuePath: 'Membership',
colorMapping: [
{
value: 'Permanent', color: '#D84444'
},
{
value: 'Non-Permanent', color: '#316DB5'
}]
};
this.legendSettings = {
visible: true
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Legend shape
Maps supports the following types of legend shapes. The shape
property in the legendSettings
property can be used to change the type of legend shapes.
- Circle
- Rectangle
- Triangle
- Diamond
- Cross
- Star
- HorizontalLine
- VerticalLine
- Pentagon
- InvertedTriangle
The shape of legends can be customized using the shapeWidth
, shapeHeight
, shapeBorder
and shapePadding
properties.
Customization
The following properties are available in legend to customize the legend shape and legend text in Maps.
-
background
- To customize the background color of the Legend. -
border
- To customize the color, width and opacity of the border for the Legend. -
fill
- To apply the color for the Legend. -
labelDisplayMode
- To customize the display mode for the Legend text. -
labelPosition
- To customize the position of the Legend text. -
orientation
- To customize the orientation of the Legend. -
textStyle
- To customize the text style for Legend. -
title
- To apply the title for the Legend. -
titleStyle
- To customize the style of the title for the Legend. -
height
- To customize the height of the Legend. -
width
- To customize the width of the Legend. -
opacity
- To apply the opacity to the Legend.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { LegendService } from '@syncfusion/ej2-angular-maps'
import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
providers: [LegendService],
standalone: true,
selector: 'app-container',
template:
`<ejs-maps id='rn-container' [legendSettings] = 'legendSettings'>
<e-layers>
<e-layer [shapeData]= 'shapeData' [shapePropertyPath]= 'shapePropertyPath' [shapeDataPath]= 'shapeDataPath' [dataSource] = 'dataSource' [shapeSettings] = 'shapeSettings'></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public dataSource?: object[];
public shapeData?: object;
public shapePropertyPath?: string;
public shapeDataPath?: string;
public shapeSettings?: object;
public legendSettings?: object;
ngOnInit(): void {
this.dataSource = [
{ "Country": "China", "Membership": "Permanent" },
{ "Country": "France", "Membership": "Permanent" },
{ "Country": "Russia", "Membership": "Permanent" },
{ "Country": "Kazakhstan","Membership": "Non-Permanent" },
{ "Country": "Poland", "Membership": "Non-Permanent" },
{ "Country": "Sweden", "Membership": "Non-Permanent" }];
this.shapeData = world_map;
this.shapePropertyPath = 'name';
this.shapeDataPath = 'Country';
this.shapeSettings = {
colorValuePath: 'Membership',
colorMapping: [
{
value: 'Permanent', color: '#D84444'
},
{
value: 'Non-Permanent', color: '#316DB5'
}]
};
this.legendSettings = {
visible: true,
background: 'green',
border: {
color: 'blue',
width: 2
},
fill: 'orange',
labelPosition: 'Before',
orientation: 'Vertical',
textStyle: {
size: '12px',
color: 'red',
fontStyle: 'italic'
},
title: {
description: 'Legend title',
text: 'Legend'
},
titleStyle: {
size: '12px',
color: '#d6e341',
fontStyle: 'italic'
}
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Legend for items excluded from color mapping
The legend can be enabled for items excluded from the color mapping using the color
property in colorMapping
. Refer to the Population_density data which demonstrates the population density of some countries.
export let Population_density = [
https://ej2.syncfusion.com/angular/documentation.
{
'code': 'AE',
'value': 90,
'name': 'United Arab Emirates',
'population': 8264070,
'density': 99
},
{
'code': 'GB',
'value': 257,
'name': 'United Kingdom',
'population': 62041708,
'density': 255
},
{
'code': 'US',
'value': 34,
'name': 'United States',
'population': 325020000,
'density': 33
}
...
];
In the following example, color mapping is added for the ranges from 0 to 200. If there are any records in the data source that are outside of this range, the color mapping will not be applied. To apply the color for these excluded items, set the color
property alone in the colorMapping
. To enable legend for these items, set the visible
property of legendSettings
to true.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { LegendService } from '@syncfusion/ej2-angular-maps'
import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
import{ Population_Density } from './data'
@Component({
imports: [
MapsModule
],
providers: [LegendService],
standalone: true,
selector: 'app-container',
template:
`<ejs-maps id='rn-container' [legendSettings] = 'legendSettings'>
<e-layers>
<e-layer [shapeData]= 'shapeData' [shapePropertyPath]= 'shapePropertyPath' [shapeDataPath]= 'shapeDataPath' [dataSource] = 'dataSource' [shapeSettings] = 'shapeSettings'></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public dataSource?: object[];
public shapeData?: object;
public shapePropertyPath?: string;
public shapeDataPath?: string;
public shapeSettings?: object;
public legendSettings?: object;
ngOnInit(): void {
this.dataSource = Population_Density;
this.shapeData = world_map;
this.shapePropertyPath = 'name';
this.shapeDataPath = 'name';
this.shapeSettings = {
colorValuePath: 'density',
colorMapping: [
{
from: 0, to: 100, color: 'rgb(153,174,214)',
},
{
from: 101, to: 200, color: 'rgb(115,143,199)',
},
{
color: 'rgb(77,112,184)'
},
]
};
this.legendSettings = {
visible: true
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Hide desired legend items
Use the showLegend
in the colorMapping
property to show or hide the desired legend items in Maps. If the showLegend
property is set to false, the legend item will be hidden. otherwise, it will be visible.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { LegendService } from '@syncfusion/ej2-angular-maps'
import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
providers: [LegendService],
standalone: true,
selector: 'app-container',
template:
`<ejs-maps id='rn-container' [legendSettings] = 'legendSettings'>
<e-layers>
<e-layer [shapeData]= 'shapeData' [shapePropertyPath]= 'shapePropertyPath' [shapeDataPath]= 'shapeDataPath' [dataSource] = 'dataSource' [shapeSettings] = 'shapeSettings'></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public dataSource?: object[];
public shapeData?: object;
public shapePropertyPath?: string;
public shapeDataPath?: string;
public shapeSettings?: object;
public legendSettings?: object;
ngOnInit(): void {
this.dataSource = [
{ "Country": "China", "Membership": "Permanent"},
{ "Country": "France", "Membership": "Permanent" },
{ "Country": "Russia","Membership": "Permanent"},
{ "Country": "Kazakhstan", "Membership": "Both"},
{ "Country": "Poland", "Membership": "Non-Permanent"},
{ "Country": "Sweden", "Membership": "Non-Permanent"}];
this.shapeData = world_map;
this.shapePropertyPath = 'name';
this.shapeDataPath = 'Country';
this.shapeSettings = {
colorValuePath: 'Membership',
colorMapping: [
{
value: 'Permanent', color: '#D84444', showLegend : true
},
{
value: 'Non-Permanent', color: '#316DB5', showLegend : false
},
{
color: 'violet', showLegend : false
}]
};
this.legendSettings = {
visible: true
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Hide legend items based data source value
Depending on the boolean values provided in the data source, the legend items will be hidden or visible. Bind the field name that contains the visibility state in the data source to the showLegendPath
property of the legendSettings
to achieve this.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { LegendService } from '@syncfusion/ej2-angular-maps'
import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
Maps.Inject(Legend);
@Component({
imports: [
MapsModule
],
providers: [LegendService],
standalone: true,
selector: 'app-container',
template:
`<ejs-maps id='rn-container' [legendSettings] = 'legendSettings'>
<e-layers>
<e-layer [shapeData]= 'shapeData' [shapePropertyPath]= 'shapePropertyPath' [shapeDataPath]= 'shapeDataPath' [dataSource] = 'dataSource' [shapeSettings] = 'shapeSettings'></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public dataSource?: object[];
public shapeData?: object;
public shapePropertyPath?: string;
public shapeDataPath?: string;
public shapeSettings?: object;
public legendSettings?: object;
ngOnInit(): void {
this.dataSource = [
{ "Country": "China", "Membership": "Permanent", "visibility" : "true", "color" : "red"},
{ "Country": "France", "Membership": "Permanent", "visibility" : "true", "color" : "blue" },
{ "Country": "Russia", "Membership": "Permanent", "visibility" : "true", "color" : "green"},
{ "Country": "Kazakhstan", "Membership": "Both", "visibility" : "true", "color" : "orange"},
{ "Country": "Poland","Membership": "Non-Permanent", "visibility" : "true", "color" : "yellow"},
{ "Country": "Sweden", "Membership": "Non-Permanent", "visibility" : "true", "color" : "pink"}];
this.shapeData = world_map;
this.shapePropertyPath = 'name';
this.shapeDataPath = 'Country';
this.shapeSettings = {
colorValuePath: 'color',
};
this.legendSettings = {
visible: true,
showLegendPath: 'visibility'
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Binding legend item text from data source
To show the legend text based on values provided in the data source, use the valuePath
property in the legendSettings
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { LegendService } from '@syncfusion/ej2-angular-maps'
import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
providers: [LegendService],
standalone: true,
selector: 'app-container',
template:
`<ejs-maps id='rn-container' [legendSettings] = 'legendSettings'>
<e-layers>
<e-layer [shapeData]= 'shapeData' [shapePropertyPath]= 'shapePropertyPath' [shapeDataPath]= 'shapeDataPath' [dataSource] = 'dataSource' [shapeSettings] = 'shapeSettings'></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public dataSource?: object[];
public shapeData?: object;
public shapePropertyPath?: string;
public shapeDataPath?: string;
public shapeSettings?: object;
public legendSettings?: object;
ngOnInit(): void {
this.dataSource = [
{ "Country": "China", "Membership": "Permanent", "visibility" : "true", "color" : "red"},
{ "Country": "France", "Membership": "Permanent", "visibility" : "true", "color" : "blue" },
{ "Country": "Russia","Membership": "Permanent", "visibility" : "true", "color" : "green"},
{ "Country": "Kazakhstan", "Membership": "Both", "visibility" : "true", "color" : "orange"},
{ "Country": "Poland", "Membership": "Non-Permanent", "visibility" : "true", "color" : "yellow"},
{ "Country": "Sweden", "Membership": "Non-Permanent", "visibility" : "true", "color" : "pink"}];
this.shapeData = world_map;
this.shapePropertyPath = 'name';
this.shapeDataPath = 'Country';
this.shapeSettings = {
colorValuePath: 'color',
};
this.legendSettings = {
visible: true,
valuePath: 'Country'
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Hide duplicate legend items
To hide the duplicate legend items in Maps, set the removeDuplicateLegend
property to true in the legendSettings
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { LegendService } from '@syncfusion/ej2-angular-maps'
import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
providers: [LegendService],
standalone: true,
selector: 'app-container',
template:
`<ejs-maps id='rn-container' [legendSettings] = 'legendSettings'>
<e-layers>
<e-layer [shapeData]= 'shapeData' [shapePropertyPath]= 'shapePropertyPath' [shapeDataPath]= 'shapeDataPath' [dataSource] = 'dataSource' [shapeSettings] = 'shapeSettings'></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public dataSource?: object[];
public shapeData?: object;
public shapePropertyPath?: string;
public shapeDataPath?: string;
public shapeSettings?: object;
public legendSettings?: object;
ngOnInit(): void {
this.dataSource = [
{ "Country": "China", "Membership": "Permanent","visibility" : "true", "color" : "red"},
{ "Country": "France", "Membership": "Permanent", "visibility" : "true", "color" : "blue" },
{ "Country": "Russia", "Membership": "Permanent", "visibility" : "true", "color" : "green"},
{ "Country": "Kazakhstan", "Membership": "Both", "visibility" : "true", "color" : "orange"},
{ "Country": "Poland", "Membership": "Non-Permanent", "visibility" : "true", "color" : "yellow"},
{ "Country": "Sweden", "Membership": "Non-Permanent", "visibility" : "true", "color" : "pink"}];
this.shapeData = world_map;
this.shapePropertyPath = 'name';
this.shapeDataPath = 'Country';
this.shapeSettings = {
colorValuePath: 'color',
};
this.legendSettings = {
visible: true,
valuePath: 'Membership',
removeDuplicateLegend: true
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Toggle option in legend
The toggle option has been provided for legend. If the legend can be toggled, the given color will be changed to the corresponding Maps shape item. To enable the toggle options in Legend, set the enable
property of the toggleLegendSettings
to true.
The following properties are available to customize the toggle option in legend.
-
applyShapeSettings
– To apply afill
property color to the shapes when toggling the legend items. -
fill
- To apply the color to the shape of the Maps for which legend item is toggled. -
opacity
– To customize the transparency for the shapes for which legend item is toggled. -
border
– To customize the color, width and opacity of the border of the shapes in Maps.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { LegendService } from '@syncfusion/ej2-angular-maps'
import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
import{ Population_Density } from './data'
@Component({
imports: [
MapsModule
],
providers: [LegendService],
standalone: true,
selector: 'app-container',
template:
`<ejs-maps id='rn-container' [legendSettings] = 'legendSettings'>
<e-layers>
<e-layer [shapeData]= 'shapeData' [shapePropertyPath]= 'shapePropertyPath' [shapeDataPath]= 'shapeDataPath' [dataSource] = 'dataSource' [shapeSettings] = 'shapeSettings'></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public dataSource?: object[];
public shapeData?: object;
public shapePropertyPath?: string;
public shapeDataPath?: string;
public shapeSettings?: object;
public legendSettings?: object;
ngOnInit(): void {
this.dataSource = Population_Density;
this.shapeData = world_map;
this.shapePropertyPath = 'name';
this.shapeDataPath = 'name';
this.shapeSettings = {
colorValuePath: 'density',
colorMapping: [
{
from: 0, to: 100, color: 'rgb(153,174,214)',
},
{
from: 101, to: 200, color: 'rgb(115,143,199)',
},
{
color: 'rgb(77,112,184)'
}]
};
this.legendSettings = {
visible: true,
toggleLegendSettings: {
enable: true,
applyShapeSettings: false,
border: {
color: 'green',
width: 2
}
}
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Enable legend for bubbles
To enable the legend for the bubble by setting the visible
property of legendSettings
as true and type
property of legendSettings
as Bubbles.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { LegendService, BubbleService } from '@syncfusion/ej2-angular-maps'
import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
providers: [LegendService, BubbleService],
standalone: true,
selector: 'app-container',
template: `<ejs-maps id='rn-container' [legendSettings] ='legendSettings' >
<e-layers>
<e-layer [shapeData]= 'shapeData' [bubbleSettings] = 'bubbleSettings'></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public shapeData?: object;
public shapeDataPath?: object | any;
public shapePropertyPath?: object | any;
public bubbleSettings?: object;
public legendSettings?: object;
ngOnInit(): void {
this.shapeData = world_map;
this.shapeDataPath = 'name',
this.shapePropertyPath = 'name',
this.bubbleSettings = [{
visible: true,
minRadius: 20,
dataSource: [
{color: 'green', name: 'India', population: '38332521' },
{color: 'purple', name: 'New Zealand', population: '19651127' },
{color: 'blue', name: 'Pakistan', population: '3090416' }
],
maxRadius: 40,
valuePath: 'population',
colorValuePath: 'color'
}];
this.legendSettings = {
visible: true,
type: 'Bubbles'
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Enable legend for markers
To enable legend for marker by setting the visible
property of legendSettings
as true and type
property of legendSettings
as Markers. The legendText
property in the markerSettings
can be used to show the legend text based on values provided in the data source.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { LegendService, MarkerService } from '@syncfusion/ej2-angular-maps'
import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
providers: [LegendService, MarkerService],
standalone: true,
selector: 'app-container',
template:
`<ejs-maps id='rn-container' [legendSettings] ='legendSettings'>
<e-layers>
<e-layer [shapeData]= 'shapeData' [markerSettings] = 'markerSettings'></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public shapeData?: object;
public markerSettings?: object;
public legendSettings?: object;
ngOnInit(): void {
this.shapeData = world_map;
this.markerSettings = [{
visible: true,
legendText: 'city',
dataSource: [
{ latitude: 37.0000, longitude: -120.0000, city: 'California' },
{ latitude: 40.7127, longitude: -74.0059, city: 'New York' },
{ latitude: 42, longitude: -93, city: 'Iowa' }
]
}];
this.legendSettings = {
visible: true,
type: 'Markers'
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Imitate/Map marker shape to the legend shape
To imitate or map the marker shape with its legend item shape, set the useMarkerShape
property to true in the legendSettings
property.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { LegendService, MarkerService } from '@syncfusion/ej2-angular-maps'
import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
import { markerDataSource } from './markerdata';
@Component({
imports: [
MapsModule
],
providers: [LegendService, MarkerService],
standalone: true,
selector: 'app-container',
template:
`<ejs-maps
id="rn-container"
style="display:block"
[legendSettings]="legendSettings"
>
<e-layers>
<e-layer [shapeData]= 'shapeData'
[shapePropertyPath]="shapePropertyPath"
[shapeDataPath]="shapeDataPath"
[markerSettings]="markerSettings"
[shapeSettings]="shapeSettings"
></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public shapeData?: object;
public shapeDataPath?: string;
public shapePropertyPath?: string;
public shapeSettings?: object;
public markerSettings?: object;
public legendSettings?: object;
ngOnInit(): void {
this.shapeData = world_map;
this.shapeDataPath = 'name';
this.shapePropertyPath = 'name';
this.legendSettings = {
visible: true,
type: 'Markers',
useMarkerShape: true,
toggleLegendSettings: {
enable: true,
applyShapeSettings: false,
border: {
color: 'green',
width: 2,
},
},
};
this.shapeSettings = {
fill: '#E5E5E5',
};
this.markerSettings = [
{
dataSource: markerDataSource,
colorValuePath: 'color',
shapeValuePath: 'shape',
legendText: 'country',
visible: true,
},
];
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));