React 地理ポリライン マップ
React マップ コンポーネントでは、IgrGeographicPolylineSeries
を使用して、地理的コンテキストでポリラインを使用して地理空間データを表示できます。地理的シリーズのこのタイプは、都市または空港などの地理的位置間の道路または接続を描画するためにしばしば使用されます。
React 地理ポリライン マップの例
IgrGeographicPolylineSeries
は、IgrGeographicShapeSeries
とよく似ていますが、地理空間データがポリゴンではなくポリラインでレンダリングされる点が異なります。
データ要件
コントロール内の他の種類の地理的シリーズと同様に、IgrGeographicPolylineSeries
には、オブジェクトの配列にバインドできる ItemsSource
プロパティがあります。さらに、このオブジェクトの各データ項目には、地理的位置を表す x 値と y 値を持つオブジェクトの配列の配列を使用して単一または複数の形状を格納する 1 つのデータ列が必要です。このデータ列は、ShapeMemberPath プロパティにマップされます。IgrGeographicPolylineSeries
は、コントロールで多角形をプロットするために、このマップされたデータ列のポイントを使用します。
コード スニペット
以下のコードは、IgrShapeDataSource
を使用してシェイプ ファイルからロードした都市の場所に IgrGeographicPolylineSeries
をバインドする方法を示します。
import { IgrGeographicMapModule } from 'igniteui-react-maps';
import { IgrGeographicMap } from 'igniteui-react-maps';
import { IgrGeographicPolylineSeries } from 'igniteui-react-maps';
import { IgrDataChartInteractivityModule } from 'igniteui-react-charts';
import { IgrShapeDataSource } from 'igniteui-react-core';
IgrGeographicMapModule.register();
IgrDataChartInteractivityModule.register();
// ...
public render() {
return (
<IgrGeographicMap
ref={this.onMapReferenced}
width="600px"
height="600px"
zoomable="true" />
);
}
public onMapReferenced(map: IgrGeographicMap) {
this.geoMap = map;
const sds = new IgrShapeDataSource();
sds.importCompleted = this.onDataLoaded;
sds.shapefileSource = "/Shapes/AmericanRoads.shp";
sds.databaseSource = "/Shapes/AmericanRoads.dbf";
sds.dataBind();
}
public onDataLoaded(sds: IgrShapeDataSource, e: any) {
const roadsUSA: any[] = [];
const roadsMEX: any[] = [];
const roadsCAN: any[] = [];
// filtering records of loaded shapefile
for (const record of sds.getPointData()) {
// reading field values loaded from DBF file
const type = record.fieldValues.RoadType;
const road = {
country: record.fieldValues.Country,
length: record.fieldValues.RoadLength / 10,
points: record.points,
type: type === 1 ? "Highway" : "Road",
};
// grouping road items by country names
if (type === 1 || type === 2) {
if (road.country === "USA") {
roadsUSA.push(road);
} else if (road.country === "MEX") {
roadsMEX.push(road);
} else if (road.country === "CAN") {
roadsCAN.push(road);
}
}
}
// creating polyline series for roads of each country
this.addSeries(roadsCAN, "rgba(252, 32, 32, 0.9)");
this.addSeries(roadsUSA, "rgba(3, 121, 231, 0.9)");
this.addSeries(roadsMEX, "rgba(14, 194, 14, 0.9)");
}
public addSeries(shapeData: any[], shapeBrush: string)
{
const lineSeries = new IgrGeographicPolylineSeries ( { name: "lineSeries" });
lineSeries.dataSource = shapeData;
lineSeries.shapeMemberPath = "points";
lineSeries.shapeFilterResolution = 2.0;
lineSeries.shapeStrokeThickness = 2;
lineSeries.shapeStroke = shapeBrush;
this.geoMap.series.add(lineSeries);
}