Angular 地理ポリゴン マップ
Angular マップ コンポーネントでは、IgxGeographicShapeSeriesComponent
を使用して、地理的コンテキストで形状ポリゴンを使用して地理空間データを表示できます。地理的シリーズのこのタイプは、地理的位置で定義される国々または領域の図形を描画するためにしばしば使用されます。
Angular 地理ポリゴン マップの例
IgxGeographicShapeSeriesComponent
は、地理空間データがポリラインではなくポリゴンでレンダリングされる以外、IgxGeographicPolylineSeriesComponent
とほとんど同じです。
データ要件
マップコントロールの他の種類の地理的シリーズと同様に、IgxGeographicShapeSeriesComponent
には、オブジェクトの配列にバインドできる ItemsSource
プロパティがあります。さらに、このオブジェクトの各データ項目には、地理的位置を表す x 値と y 値を持つオブジェクトの配列の配列を使用して単一または複数の形状を格納する 1 つのデータ列が必要です。このデータ列は、ShapeMemberPath
プロパティにマップされます。IgxGeographicShapeSeriesComponent
は、マップされたデータ列の点を使用してマップコントロールにポリゴンをプロットします。
コード スニペット
以下のコードは、IgxShapeDataSource
を使用してシェイプ ファイルからロードした世界の国々の図形に IgxGeographicShapeSeriesComponent
をバインドする方法を示します。
<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" #template>
<div>
<div *ngIf="item.org;then hasOrg; else notOrg" ></div>
<span [style.color]="series.brush">
{{item.name}}
</span>
<br/>
<span>
Population {{item.pop}} M
</span>
</div>
<ng-template #hasOrg>
<span>
Population {{item.pop}} M
</span>
<br />
</ng-template>
<ng-template #notOrg>
<span>
</span>
</ng-template>
</ng-template>
import { AfterViewInit, Component, TemplateRef, ViewChild } from "@angular/core";
import { IgxShapeDataSource } from 'igniteui-angular-core';
import { IgxGeographicMapComponent } from 'igniteui-angular-maps';
import { IgxGeographicShapeSeriesComponent } from 'igniteui-angular-maps';
@Component({
selector: "app-map-geographic-shape-polygon-series",
styleUrls: ["./map-geographic-shape-polygon-series.component.scss"],
templateUrl: "./map-geographic-shape-polygon-series.component.html"
})
export class MapTypeShapePolygonSeriesComponent implements AfterViewInit {
@ViewChild ("map")
public map: IgxGeographicMapComponent;
@ViewChild("template")
public tooltip: TemplateRef<object>;
public data: any;
constructor() {
}
public ngAfterViewInit(): void {
const sds = new IgxShapeDataSource();
sds.shapefileSource = "assets/Shapes/WorldCountries.shp";
sds.databaseSource = "assets/Shapes/WorldCountries.dbf";
sds.dataBind();
sds.importCompleted.subscribe(() => this.onDataLoaded(sds, ""));
}
public onDataLoaded(sds: IgxShapeDataSource, e: any) {
const shapeRecords = sds.getPointData();
console.log("loaded /Shapes/WorldCountries.shp " + shapeRecords.length);
const countriesNATO: any[] = [];
const countriesSCO: any[] = [];
const countriesARAB: any[] = [];
const countriesOther: any[] = [];
for (const record of shapeRecords) {
// using field/column names from .DBF file
const country = {
name: record.fieldValues.NAME,
org: record.fieldValues.ALLIANCE,
points: record.points,
pop: record.fieldValues.POPULATION
};
const group = record.fieldValues.ALLIANCE;
if (group === "NATO") {
countriesNATO.push(country);
} else if (group === "SCO") {
countriesSCO.push(country);
} else if (group === "ARAB LEAGUE") {
countriesARAB.push(country);
} else {
countriesOther.push(country);
}
}
this.addSeriesWith(countriesNATO, "rgb(32, 146, 252)", "NATO");
this.addSeriesWith(countriesSCO, "rgb(252, 32, 32)", "SCO");
this.addSeriesWith(countriesARAB, "rgb(14, 194, 14)", "AL");
this.addSeriesWith(countriesOther, "rgb(146, 146, 146)", "Other");
}
public addSeriesWith(shapeData: any[], shapeBrush: string, shapeTitle: string) {
const seriesName = shapeTitle + "series";
const geoSeries = new IgxGeographicShapeSeriesComponent();
geoSeries.dataSource = shapeData;
geoSeries.shapeMemberPath = "points";
geoSeries.brush = shapeBrush;
geoSeries.outline = "Black";
geoSeries.tooltipTemplate = this.tooltip;
geoSeries.thickness = 1;
geoSeries.title = shapeTitle;
this.map.series.add(geoSeries);
}
}
API リファレンス
IgxGeographicPolylineSeriesComponent
IgxGeographicShapeSeriesComponent
ItemsSource
ShapeMemberPath
IgxShapeDataSource
ページを開く:
GitHub