Annotations in Angular Maps component

23 Sep 202313 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 content property of annotations, text content or id of an element or an HTML string can be specified to render a new HTML element in Maps.

import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
@Component({
    selector: 'app-container',
    template:
    `<ejs-maps id='rn-container' style="display:block" [annotations]='annotations'>
    <e-layers>
    <e-layer  [shapeData]= 'shapeData'></e-layer>
    </e-layers>
    </ejs-maps>`
})

export class AppComponent implements OnInit {
    public annotations?: object;
    public shapeData?: object;
        ngOnInit(): void {
            this.annotations = [{
                content: '<div id="first"><h1>Maps</h1></div>',
                x: '0%', y: '50%',
                zIndex: '-1'
            }];
            this.shapeData = world_map
        }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { MapsModule } from '@syncfusion/ej2-angular-maps';
import { AnnotationsService } from '@syncfusion/ej2-angular-maps';
/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, MapsModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
     providers: [AnnotationsService]
   
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Annotation customization

Changing the z-index

The stack order of an annotation element can be changed using theĀ zIndex property in the annotations.

import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
@Component({
    selector: 'app-container',
    template:
    `<ejs-maps id='rn-container' style="display:block" [annotations]='annotations'>
    <e-layers>
    <e-layer  [shapeData]= 'shapeData'></e-layer>
    </e-layers>
    </ejs-maps>`
})

export class AppComponent implements OnInit {
    public annotations?: object;
    public shapeData?: object;
        ngOnInit(): void {
            this.annotations = [{
                content: '<div id="first"><h1>Maps</h1></div>',
                x: '0%', y: '50%',
                zIndex: '-1'
            }];
        this.shapeData = world_map;
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { MapsModule } from '@syncfusion/ej2-angular-maps';
import { AnnotationsService } from '@syncfusion/ej2-angular-maps';
/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, MapsModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
     providers: [AnnotationsService]
   
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Positioning an annotation

Annotations can be placed anywhere in the Maps by specifying pixel or percentage values to the x and y properties in the annotations.

import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
@Component({
    selector: 'app-container',
    template:
    `<ejs-maps id='rn-container' style="display:block" [annotations]='annotations'>
    <e-layers>
    <e-layer  [shapeData]= 'shapeData'></e-layer>
    </e-layers>
    </ejs-maps>`
})

export class AppComponent implements OnInit {
    public annotations?: object;
    public shapeData?: object
    ngOnInit(): void {
        this.annotations = [{
            content: '<div id="first"><h1>Maps</h1></div>',
            x: '20%', y: '50%',
            zIndex: '-1'
        }];
        this.shapeData = world_map;
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { MapsModule } from '@syncfusion/ej2-angular-maps';
import { AnnotationsService } from '@syncfusion/ej2-angular-maps';
/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, MapsModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
     providers: [AnnotationsService]
   
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Alignment of an annotation

Annotations can be aligned using the horizontalAlignment and verticalAlignment properties in the annotations. The possible values can be Center, Far, Near and None.

import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
@Component({
    selector: 'app-container',
    template:
    `<ejs-maps id='rn-container' style="display:block" [annotations]='annotations'>
    <e-layers>
    <e-layer  [shapeData]= 'shapeData'></e-layer>
    </e-layers>
    </ejs-maps>`
})

export class AppComponent implements OnInit {
    public annotations?: object;
    public shapeData?: object;
    ngOnInit(): void {
        this.annotations = [{
            content: '<div id="first"><h1>Maps</h1></div>',
            verticalAlignment: 'Center',
            horizontalAlignment: 'Center',
            x: '20%', y: '50%',
            zIndex: '-1'
        }];
        this.shapeData = world_map;
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { MapsModule } from '@syncfusion/ej2-angular-maps';
import { AnnotationsService } from '@syncfusion/ej2-angular-maps';
/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, MapsModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
     providers: [AnnotationsService]
   
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

Multiple Annotation

Multiple annotations can be added to the Maps using the annotations in which the properties of annotations are added as an array. The customization for the annotations can be done with the annotations.

import { Component, OnInit } from '@angular/core';
import { world_map } from './world-map';
@Component({
    selector: 'app-container',
    template:
    `<ejs-maps id='rn-container' style="display:block" [annotations]='annotations'>
    <e-layers>
    <e-layer  [shapeData]= 'shapeData'></e-layer>
    </e-layers>
    </ejs-maps>`
})

export class AppComponent implements OnInit {
    public annotations?: object;
    public shapeData?: object;
    ngOnInit(): void {
        this.annotations = [{
            content: '<div id="first"><h1>Maps-Annotation</h1></div>',
            x: '50%', y: '0%',
            zIndex: '-1'
        },
        {
            content: '<div id="first"><h1>Maps</h1></div>',
            x: '20%', y: '50%',
            zIndex: '-1'
        }];
        this.shapeData = world_map;
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { MapsModule } from '@syncfusion/ej2-angular-maps';
import { AnnotationsService } from '@syncfusion/ej2-angular-maps';
/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, MapsModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
     providers: [AnnotationsService]
   
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);