Azure maps in Angular Maps component
13 Jun 202412 minutes to read
Azure Maps is yet another online Maps provider, owned by Microsoft. As like OSM and Bing Maps, it provides Maps tile images based on our requests and combines those images into a single one to display Maps area.
Adding Azure Maps
The Azure Maps can be rendered using the urlTemplate property with the tile server URL provided by online map providers. In the meantime, a subscription key is required for Azure Maps. Follow the steps in this link to generate an API key, and then added the key to the URL.
Refer to Azure Maps Licensing.
import { Component, OnInit } from '@angular/core';
import { Maps } from '@syncfusion/ej2-angular-maps';
@Component({
selector: 'app-container',
template:
`<ejs-maps id='rn-container' style="display:block">
<e-layers>
<e-layer [urlTemplate]= 'urlTemplate'></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public urlTemplate: string;
ngOnInit(): void {
this.urlTemplate = 'https://atlas.microsoft.com/map/imagery/png?subscription-key=Your-Key &api-version=1.0&style=satellite&zoom=level&x=tileX&y=tileY';
}
}
Enabling zooming and panning
The Azure Maps layer can be zoomed and panned. Zooming helps to get a closer look at a particular area on a map for in-depth analysis. Panning helps to move a map around to focus the targeted area.
import { Component, OnInit, Inject } from '@angular/core';
import { Maps, Zoom } from '@syncfusion/ej2-angular-maps';
Maps.Inject(Zoom);
@Component({
selector: 'app-container',
template:
`<ejs-maps id='rn-container' style='display:block' [zoomSettings]='zoomSettings'>
<e-layers>
<e-layer [urlTemplate]= 'urlTemplate'></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public zoomSettings: object;
public urlTemplate: string;
ngOnInit(): void {
this.urlTemplate = 'https://atlas.microsoft.com/map/imagery/png?subscription-key=Your-Key &api-version=1.0&style=satellite&zoom=level&x=tileX&y=tileY';
this.zoomSettings = {
enable: true,
toolbarSettings: {
buttonSettings: {
toolbarItems: ['Zoom', 'ZoomIn', 'ZoomOut', 'Pan', 'Reset'],
}
}
}
}
}
Adding markers and navigation line
Markers can be added to the layers of Azure Maps by setting the corresponding location’s coordinates of latitude and longitude using markerSettings. Navigation lines can be added on top of the Azure Maps layer for highlighting a path among various places by setting the corresponding location’s coordinates of latitude and longitude in the navigationLineSettings.
import { Component, Inject, OnInit } from '@angular/core';
import { Maps, Zoom, Marker, NavigationLine } from '@syncfusion/ej2-angular-maps';
Maps.Inject(Zoom, Marker, NavigationLine);
@Component({
selector: 'app-container',
template:
`<ejs-maps id='rn-container' style='display:block' [zoomSettings]='zoomSettings' [centerPosition]='centerPosition'>
<e-layers>
<e-layer [urlTemplate]= 'urlTemplate' [markerSettings]='markerSettings' [navigationLineSettings]='navigationLineSettings'></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public zoomSettings: object;
public centerPosition: object;
public markerSettings: object;
public navigationLineSettings: object;
public urlTemplate: string;
ngOnInit(): void {
this.urlTemplate = 'https://atlas.microsoft.com/map/imagery/png?subscription-key=Your-Key &api-version=1.0&style=satellite&zoom=level&x=tileX&y=tileY';
this.zoomSettings = {
zoomFactor: 4
};
this.centerPosition = {
latitude: 29.394708,
longitude: -94.954653
};
this.markerSettings = [{
visible: true,
height: 25,
width: 15,
dataSource: [
{
latitude: 34.060620,
longitude: -118.330491,
name: "California"
},
{
latitude: 40.724546,
longitude: -73.850344,
name: "New York"
}
]
}];
this.navigationLineSettings = [{
visible: true,
color: "blue",
width: 5,
angle: 0.1,
latitude: [34.060620, 40.724546],
longitude: [-118.330491,-73.850344]
}];
}
}
Adding sublayer
Any GeoJSON shape can be rendered as a sublayer on top of the Azure Maps layer for highlighting a particular continent or country in Azure Maps by adding another layer and specifying the type property of Maps layer to SubLayer.
import { Component, OnInit } from '@angular/core';
import { Maps } from '@syncfusion/ej2-angular-maps';
import { africa_continent } from 'africa-continent.ts';
@Component({
selector: 'app-container',
template:
`<ejs-maps id='rn-container' style='display:block'>
<e-layers>
<e-layer [urlTemplate]= 'urlTemplate'></e-layer>
<e-layer [type] = 'type' [shapeData]='shapeData' [shapeSettings]='shapeSettings'></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public type: string;
public shapeData: object;
public shapeSettings: object;
public urlTemplate: string;
ngOnInit(): void {
this.urlTemplate = 'https://atlas.microsoft.com/map/imagery/png?subscription-key=Your-Key &api-version=1.0&style=satellite&zoom=level&x=tileX&y=tileY';
this.type = 'SubLayer';
this.shapeData = africa_continent;
this.shapeSettings = {
fill: 'blue'
};
}
}
Enabling legend
The legend can be added to the Azure Maps by setting the visible property of legendSettings to true.
import { Component, OnInit} from '@angular/core';
import { Maps } from '@syncfusion/ej2-angular-maps';
import { markerDataSource } from 'markerdata.ts';
@Component({
selector: 'app-container',
template:
`<ejs-maps
id="rn-container"
style="display:block"
[legendSettings]="legendSettings"
>
<e-layers>
<e-layer [urlTemplate]= 'urlTemplate'
[shapePropertyPath]="shapePropertyPath"
[shapeDataPath]="shapeDataPath"
[markerSettings]="markerSettings"
[shapeSettings]="shapeSettings"
></e-layer>
</e-layers>
</ejs-maps>`
})
export class AppComponent implements OnInit {
public shapeDataPath: string;
public shapePropertyPath: string;
public shapeSettings: object;
public markerSettings: object;
public legendSettings: object;
public urlTemplate: string;
ngOnInit(): void {
this.urlTemplate = 'https://atlas.microsoft.com/map/imagery/png?subscription-key=Your-Key &api-version=1.0&style=satellite&zoom=level&x=tileX&y=tileY';
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,
},
];
}
}