Customization in Angular Maps component
27 Apr 202420 minutes to read
Setting the size for Maps
The width and height of the Maps can be set using the width
and height
properties in the Maps component. Percentage or pixel values can be used for the height and width values.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { Component, ViewEncapsulation } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the maps component
template:
`<ejs-maps id='rn-container' height='200px' width='200px'>
<e-layers>
<e-layer [shapeData]='shapeData' [shapeSettings]="shapeSettings"></e-layer>
</e-layers>
</ejs-maps>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
public shapeData = world_map;
public shapeSettings = {
autofill: true
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Maps title
The title for the Maps can be set using the titleSettings
. It can be customized using the following properties.
-
alignment
- To customize the alignment for the text in the title for the Maps. The possible values are Center, Near and Far. -
description
- To set the description of the title in Maps. -
text
- To set the text for the title in Maps. -
textStyle
- To customize the text of the title in Maps. -
subtitleSettings
- To customize the subtitle for the Maps.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { Component, ViewEncapsulation } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the maps component
template:
`<ejs-maps id='rn-container' [titleSettings]='titleSettings'>
<e-layers>
<e-layer [shapeData]='shapeData' [shapeSettings]="shapeSettings"></e-layer>
</e-layers>
</ejs-maps>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
public titleSettings: object = {
text: 'Maps Control',
textStyle: {
color: 'red',
fontStyle: 'italic',
fontWeight: 'regular',
fontFamily: 'arial',
size: '14px'
},
alignment: 'Center'
};
public shapeData = world_map;
public shapeSettings = {
autofill: true
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Setting theme
The Maps component supports following themes.
- Material
- Fabric
- Bootstrap
- Highcontrast
- MaterialDark
- FabricDark
- BootstrapDark
- Bootstrap4
- HighContrastLight
- Tailwind
By default, the Maps are rendered by the Material theme. The theme of the Maps component is changed using the theme
property.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { Component, ViewEncapsulation } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the maps component
template:
`<ejs-maps id='rn-container' theme="FabricDark">
<e-layers>
<e-layer [shapeData]='shapeData' [shapeSettings]="shapeSettings"></e-layer>
</e-layers>
</ejs-maps>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
public shapeData = world_map;
public shapeSettings = {
autofill: true
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Customizing Maps container
The following properties are available to customize the container in the Maps.
-
background
- To apply the background color to the container in the Maps. -
border
- To customize the color, width and opacity of the border of the Maps. -
margin
- To customize the margins of the Maps.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { Component, ViewEncapsulation } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the maps component
template:
`<ejs-maps id='rn-container' [background]='background' [border]='border' [margin]='margin'>
<e-layers>
<e-layer [shapeData]='shapeData' [shapeSettings]="shapeSettings"></e-layer>
</e-layers>
</ejs-maps>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
public background: string = '#CCD1D1';
public border: object = {
color: 'green',
width: 2
};
public margin: object = {
bottom: 10,
left: 20,
right: 20,
top: 10
}
public shapeData = world_map;
public shapeSettings = {
autofill: true
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Customizing Maps area
By default, the background color of the shape maps is set as white. To modify the background color of the Maps area, the background
property in the mapsArea
is used. The border of the Maps area can be customized using border
property in the mapsArea
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { Component, ViewEncapsulation } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the maps component
template:
`<ejs-maps id='rn-container' [mapsArea]='mapsArea'>
<e-layers>
<e-layer [shapeData]='shapeData' [shapeSettings]="shapeSettings"></e-layer>
</e-layers>
</ejs-maps>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
public mapsArea: object = {
background: '#CCD1D1',
border: {
width: 2,
color: 'green'
}
};
public shapeData = world_map;
public shapeSettings = {
autofill: true
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Customizing the shapes
The following properties are available in shapeSettings
to customize the shapes of the Maps.
-
fill
- To apply the fill color to the all the shapes. -
autofill
- To apply the palette colors to the shapes if it is set as true. -
palette
- To set the custom palette for the shapes. -
border
- To customize the color, width and opacity of the border of the shapes. -
dashArray
- To define the pattern of dashes and gaps that is applied to the outline of the shapes. -
opacity
- To customize the transparency for the shapes.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { Component, ViewEncapsulation } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the maps component
template:
`<ejs-maps id='rn-container'>
<e-layers>
<e-layer [shapeData]='shapeData' [shapeSettings]="shapeSettings"></e-layer>
</e-layers>
</ejs-maps>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
public shapeData = world_map;
public shapeSettings = {
autofill: true,
palette: ['#C7DE6C', '#59A076', '#88D0BC', '#FEA78C', '#FFC557'],
border: {
color: '#FEE1DD',
width: 3
},
dashArray: '1',
opacity: 0.9
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Setting color to the shapes from the data source
The color for each shape in the Maps can be set using the colorValuePath
property of shapeSettings
. The value for the colorValuePath
property is the field name from the data source of the shapeSettings
which contains the color values.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { Component, ViewEncapsulation } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the maps component
template:
`<ejs-maps id='rn-container'>
<e-layers>
<e-layer [shapeData]='shapeData' [shapePropertyPath]='shapePropertyPath' [shapeDataPath]='shapeDataPath' [dataSource]='dataSource' [shapeSettings]="shapeSettings"></e-layer>
</e-layers>
</ejs-maps>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
public shapeData = world_map;
public shapePropertyPath = 'continent';
public shapeDataPath = 'continent';
public dataSource = [
{ continent: "North America", color: '#71B081' },
{ continent: "South America", color: '#5A9A77' },
{ continent: "Africa", color: '#498770' },
{ continent: "Europe", color: '#39776C' },
{ continent: "Asia", color: '#266665' },
{ continent: "Oceania", color: '#124F5E' }
]
public shapeSettings = {
colorValuePath: 'color'
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Applying border to individual shapes
The border of each shape in the Maps can be customized using the borderColorValuePath
and borderWidthValuePath
properties to modify the color and the width of the border respectively. The field name in the data source of the layer which contains the color and the width values must be set in the borderColorValuePath
and borderWidthValuePath
properties respectively. If the values of borderWidthValuePath
and borderColorValuePath
do not match with the field name from the data source, then the color and width of the border will be applied to the shapes using the border
property in the shapeSettings
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { Component, ViewEncapsulation } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the maps component
template:
`<ejs-maps id='rn-container'>
<e-layers>
<e-layer [shapeData]='shapeData' [shapePropertyPath]='shapePropertyPath' [shapeDataPath]='shapeDataPath' [dataSource]='dataSource' [shapeSettings]="shapeSettings"></e-layer>
</e-layers>
</ejs-maps>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
public shapeData = world_map;
public shapePropertyPath = 'continent';
public shapeDataPath = 'continent';
public dataSource = [
{ continent: "North America", color: '#71B081', borderColor: '#CCFFE5', width: 2 },
{ continent: "South America", color: '#5A9A77', borderColor: 'red', width: 2 },
{ continent: "Africa", color: '#498770', borderColor: '#FFCC99', width: 2 },
{ continent: "Europe", color: '#39776C', borderColor: '#66B2FF', width: 2 },
{ continent: "Asia", color: '#266665', borderColor: '#999900', width: 2 },
{ continent: "Oceania", color: '#124F5E', borderColor: 'blue', width: 2 }
]
public shapeSettings = {
borderColorValuePath: 'borderColor',
borderWidthValuePath: 'width',
colorValuePath: 'color'
};
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Projection type
The Maps component supports the following projection types:
- Mercator
- Equirectangular
- Miller
- Eckert3
- Eckert5
- Eckert6
- Winkel3
- AitOff
By default, the Maps are rendered by the Mercator projection type in which the Maps are rendered based on the coordinates. So, the Maps is not stretched. To change the type of projection in the Maps, the projectionType
property is used.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { MapsModule } from '@syncfusion/ej2-angular-maps'
import { Component, ViewEncapsulation } from '@angular/core';
import { world_map } from './world-map';
@Component({
imports: [
MapsModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the maps component
template:
`<div>
<div>
<ejs-maps id='maps' #maps style="display:block;" projectionType="Miller">
<e-layers>
<e-layer [shapeData]='shapeData'></e-layer>
</e-layers>
</ejs-maps>
</div>
</div>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
public shapeData = world_map;
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));