Angular Binding Multiple Data Sources
In the Ignite UI for Angular map, you can add multiple geographic series objects to overlay custom data sources with geo-spacial data. For example, IgxGeographicSymbolSeriesComponent
for plotting geographic locations of airports, the IgxGeographicPolylineSeriesComponent
for plotting flights between airports, and 2nd IgxGeographicPolylineSeriesComponent
for plotting gridlines of major geographic coordinates.
Angular Binding Multiple Data Sources Example
This topic takes you step-by-step towards displaying multiple geographic series that will plot following geo-spatial data:
IgxGeographicSymbolSeriesComponent
– displays locations of major airportsIgxGeographicPolylineSeriesComponent
– displays flights between airportsIgxGeographicPolylineSeriesComponent
– displays gridlines of major coordinates
You can use geographic series in this or other combinations to plot desired data.
Creating Data Sources
Create data sources for all geographic series that you want to display in the Ignite UI for Angular map. For example, you can the use WorldConnections script.
<div className="sampleRoot" >
<igx-geographic-map #map
width="700px"
height="500px"
zoomable="true" >
</igx-geographic-map>
</div>
<ng-template let-series="series" let-item="item" #polylineTooltipTemplate>
<div>
<span>
Arrival: {{item.origin.country}}
</span>
<br/>
<span>
Destination: {{item.dest.country}}
</span>
<br/>
<span>
Distance: {{item.distance}} miles
</span>
</div>
</ng-template>
<ng-template let-series="series" let-item="item" #pointTooltipTemplate>
<div>
<span>
{{item?.country}}
</span>
<br />
<span>
{{item?.name}}
</span>
<br />
<span>
Population: {{item.pop}} M
</span>
<br/>
<span>
Flights: {{item.flights}}
</span>
</div>
</ng-template>
Overlaying Flights
Create first IgxGeographicPolylineSeriesComponent
object with flight connections between major airports and add it to the Series collection of the Ignite UI for Angular map.
<igx-geographic-polyline-series #polylineSeries
[tooltipTemplate]="polylineTooltipTemplate"
name="polylineSeries"
shapeMemberPath="points"
shapeStroke="rgba(147, 15, 180, 0.5)"
thickness={3.0} >
</igx-geographic-polyline-series>
Overlaying Gridlines
Create second IgxGeographicPolylineSeriesComponent
object with geographic gridlines and add it to the Series collection of the Ignite UI for Angular map.
<igx-geographic-polyline-series #polylineSeries
[tooltipTemplate]="polylineTooltipTemplate"
datasource = worldFlights
name="polylineSeries"
shapeMemberPath="points"
shapeStroke="rgba(196, 14, 14,0.05)"
thickness={3.0} >
</igx-geographic-polyline-series>
Overlaying Airports
Create IgxGeographicSymbolSeriesComponent
object with airport points and add it to the Series collection of the geographic Ignite UI for Angular map.
<igx-geographic-symbol-series #symbolSeries
name="symbolSeries"
longitudeMemberPath="longitude"
latitudeMemberPath="latitude"
markerType="Circle"
markerOutline="rgb(73, 73, 73)"
markerBrush="White" >
</igx-geographic-symbol-series>
Summary
For your convenience, all above code snippets are combined into one code block below that you can easily copy to your project.
import { AfterViewInit, Component, TemplateRef, ViewChild } from "@angular/core";
import { MarkerType } from 'igniteui-angular-charts';
import { IgxGeographicMapComponent } from 'igniteui-angular-maps';
import { IgxGeographicPolylineSeriesComponent } from "igniteui-angular-maps";
import { IgxGeographicSymbolSeriesComponent } from "igniteui-angular-maps";
import { WorldConnections } from "../../utilities/WorldConnections";
@Component({
selector: "app-map-binding-multiple-data-sources",
styleUrls: ["./map-binding-multiple-data-sources.component.scss"],
templateUrl: "./map-binding-multiple--data-sources.component.html"
})
export class MapBindingMultipleSourcesComponent implements AfterViewInit {
@ViewChild ("map")
public map: IgxGeographicMapComponent;
@ViewChild("polylineTooltipTemplate")
public polylineTooltipTemplate: TemplateRef<object>;
@ViewChild("pointTooltipTemplate")
public pointTooltipTemplate: TemplateRef<object>;
public data: any;
constructor() {
}
public ngAfterViewInit(): void {
this.map.windowRect = { left: 0.195, top: 0.1, width: 0.5, height: 0.5 };
const worldFlights = WorldConnections.getFlights();
const worldAirports = WorldConnections.getAirports();
const worldGridlines = WorldConnections.getGridlines();
this.addPolylineSeriesWith(worldFlights);
this.addGridlineSeriesWith(worldGridlines);
this.addSymbolSeriesWith(worldAirports);
}
public addGridlineSeriesWith(data: any[]) {
const gridSeries = new IgxGeographicPolylineSeriesComponent();
gridSeries.dataSource = data;
gridSeries.shapeMemberPath = "points";
gridSeries.shapeStroke = "Gray";
gridSeries.shapeStrokeThickness = 1;
this.map.series.add(gridSeries);
}
public addPolylineSeriesWith(data: any[]) {
const lineSeries = new IgxGeographicPolylineSeriesComponent ();
lineSeries.dataSource = data;
lineSeries.shapeMemberPath = "points";
lineSeries.shapeStroke = "rgba(196, 14, 14,0.05)";
lineSeries.shapeStrokeThickness = 4;
lineSeries.tooltipTemplate = this.polylineTooltipTemplate;
this.map.series.add(lineSeries);
}
public addSymbolSeriesWith(data: any[]) {
const symbolSeries = new IgxGeographicSymbolSeriesComponent ();
symbolSeries.dataSource = data;
symbolSeries.markerType = MarkerType.Circle;
symbolSeries.latitudeMemberPath = "lat";
symbolSeries.longitudeMemberPath = "lon";
symbolSeries.markerBrush = "#aad3df";
symbolSeries.markerOutline = "rgb(73, 73, 73)";
symbolSeries.thickness = 1;
symbolSeries.tooltipTemplate = this.pointTooltipTemplate;
this.map.series.add(symbolSeries);
}
}