Web Components 複数のシェイプ ファイルのバインドとオーバーレイ

    Ignite UI for Web Components マップでは、複数の地理的シリーズオブジェクトを追加して、複数のシェープファイルを地理空間データでオーバーレイすることができます。たとえば、港湾の地理的位置をプロットするための IgcGeographicSymbolSeriesComponent、港湾間のルートをプロットするための IgcGeographicPolylineSeriesComponent、国の形状をプロットするための IgcGeographicShapeSeriesComponent などがあります。

    Web Components 複数のシェイプ ファイルのバインドとオーバーレイの例

    EXAMPLE
    TS
    HTML
    CSS

    このサンプルが気に入りましたか? 完全な Ignite UI for Web Componentsツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。

    このトピックでは、マップ コンポーネントに複数の地理的シリーズを表示する方法について段階的に説明します。すべての地理的シリーズは、IgcShapeDataSource クラスを使用して形状ファイルからロードされた地理空間データに従ってプロットします。IgcShapeDataSource オブジェクトの詳細については、シェープ ファイルのバインディングのトピックを参照してください。

    目的のデータをプロットするために、地理的シリーズを上記の組み合わせまたは他の組み合わせで使用できます。

    コンポーネントのインポート

    まず、必要なコンポーネントとモジュールをインポートします。

    import { IgcGeographicMapModule } from 'igniteui-webcomponents-maps';
    import { IgcDataChartInteractivityModule } from 'igniteui-webcomponents-charts';
    import { IgcGeographicMapComponent } from 'igniteui-webcomponents-maps';
    import { IgcGeographicShapeSeriesComponent } from 'igniteui-webcomponents-maps';
    import { IgcGeographicPolylineSeriesComponent } from 'igniteui-webcomponents-maps';
    import { IgcGeographicSymbolSeriesComponent } from 'igniteui-webcomponents-maps';
    import { IgcShapeDataSource } from 'igniteui-webcomponents-core';
    import { ModuleManager } from 'igniteui-webcomponents-core';
    
    ModuleManager.register(
        IgcDataChartInteractivityModule,
        IgcGeographicMapModule
    );
    ts
    Ignite UI for Web Components | CTA Banner

    シリーズの作成

    次に、後で異なるタイプのシェープ ファイルをロードする地理的シリーズでマップを作成します。

    <igc-geographic-map id="geoMap" width="100%" height="100%" >
        <igc-geographic-shape-series
            id="polygonSeries"
            shape-memberPath="points"
            shape-fill="rgb(150, 150, 150)"
            shape-stroke="Black"
            shape-stroke-thickness="1.0">
        </igc-geographic-shape-series>
        <igc-geographic-polyline-series
            id="lineSeries"
            shape-member-path="points"
            shape-stroke="rgba(147, 15, 180, 0.5)"
            thickness="3.0" >
        </igc-geographic-polyline-series>
        <igc-geographic-symbol-series
            id="symbolSeries"
            longitude-member-path="longitude"
            latitude-member-path="latitude"
            marker-type="Circle"
            marker-outline="rgb(2, 102, 196)"
            marker-brush="White">
        </igc-geographic-symbol-series>
    </igc-geographic-map>
    html

    シェープファイルの読み込み

    次に、ページのコンストラクターで、地理マップコンポーネントに表示する各シェープファイルの IgcShapeDataSource を追加します。

    const sdsPolygons = new IgcShapeDataSource();
    sdsPolygons.importCompleted = this.onPolygonsLoaded;
    sdsPolygons.shapefileSource = url + "/shapes/WorldCountries.shp";
    sdsPolygons.databaseSource  = url + "/shapes/WorldCountries.dbf";
    sdsPolygons.dataBind();
    const sdsPolylines = new IgcShapeDataSource();
    sdsPolylines.importCompleted = this.onPolylinesLoaded;
    sdsPolylines.shapefileSource = url + "/shapes/WorldConnections.shp";
    sdsPolylines.databaseSource  = url + "/shapes/WorldConnections.dbf";
    sdsPolylines.dataBind();
    const sdsLocations = new IgcShapeDataSource();
    sdsLocations.importCompleted = this.onPointsLoaded;
    sdsLocations.shapefileSource = url + "/Shapes/WorldCities.shp";
    sdsLocations.databaseSource  = url + "/Shapes/WorldCities.dbf";
    sdsLocations.dataBind();
    ts

    ポリゴンの処理

    世界の国々の IgcShapeDataSource に読み込まれた形状データを処理し、IgcGeographicShapeSeriesComponent オブジェクトに割り当てます。

    import { IgcGeographicShapeSeriesComponent } from 'igniteui-webcomponents-maps';
    import { IgcShapeDataSource } from 'igniteui-webcomponents-core';
    // ...
    public onPolygonsLoaded(sds: IgcShapeDataSource, e: any) {
        const geoPolygons: any[] = [];
        // parsing shapefile data and creating geo-polygons
        let pointData = sds.getPointData();
        for ( let i = 0; i < pointData.length; i++ ) {
            let record = pointData[i];
            // using field/column names from .DBF file
            const country = {
                points: record.points,
                name: record.fieldValues.NAME,
                gdp: record.fieldValues.GDP,
                population: record.fieldValues.POPULATION
            };
            geoPolygons.push(country);
        };
        let polygonSeries = (document.getElementById("polygonSeries") as IgcGeographicShapeSeriesComponent);
        polygonSeries.dataSource = geoPolygons;
        polygonSeries.renderSeries(false);
    }
    ts

    ポリラインの処理

    IgcShapeDataSource に読み込まれた形状データを処理し、主要都市間の通信ルートを使用して、IgcGeographicPolylineSeriesComponent オブジェクトに割り当てます。

    import { IgcGeographicPolylineSeriesComponent } from 'igniteui-webcomponents-maps';
    import { IgcShapeDataSource } from 'igniteui-webcomponents-core';
    // ...
    public onPolylinesLoaded(sds: IgcShapeDataSource, e: any) {
        const geoPolylines: any[] = [];
        // parsing shapefile data and creating geo-polygons
        let pointData = sds.getPointData();
        for ( let i = 0; i < pointData.length; i++ ) {
            let record = pointData[i];
            // using field/column names from .DBF file
            const route = {
                points: record.points,
                name: record.fieldValues.Name,
                capacity: record.fieldValues.CapacityG,
                distance: record.fieldValues.DistanceKM,
                isOverLand: record.fieldValues.OverLand === 0,
                isActive: record.fieldValues.NotLive !== 0,
                service: record.fieldValues.InService
            };
            geoPolylines.push(route);
        }
    
        let lineSeries = (document.getElementById("lineSeries") as IgcGeographicPolylineSeriesComponent);
        lineSeries.dataSource = geoPolylines;
        lineSeries.renderSeries(false);
    }
    ts

    ポイントの処理

    IgcShapeDataSource に読み込まれた世界各国の形状データを処理し、IgcGeographicSymbolSeriesComponent オブジェクトに割り当てます。

    import { IgcGeographicSymbolSeriesComponent } from 'igniteui-webcomponents-maps';
    import { IgcShapeDataSource } from 'igniteui-webcomponents-core';
    // ...
    public onPointsLoaded(sds: IgcShapeDataSource, e: any) {
        const geoLocations: any[] = [];
        // parsing shapefile data and creating geo-locations
        let pointData = sds.getPointData();
        for ( let i = 0; i < pointData.length; i++ ) {
            let record = pointData[i];
            const pop = record.fieldValues.POPULATION;
            if (pop > 0) {
                // each shapefile record has just one point
                const location = {
                    latitude: record.points[0][0].y,
                    longitude: record.points[0][0].x,
                    city: record.fieldValues.NAME,
                    population: pop
                };
                geoLocations.push(location);
            }
        }
        let symbolSeries = (document.getElementById("symbolSeries") as IgcGeographicSymbolSeriesComponent);
        symbolSeries.dataSource = geoLocations;
        symbolSeries.renderSeries(false);
    }
    ts

    マップ背景

    また形状ファイルがアプリケーションのために十分な地理的文脈 (国の形状など) を提供した際に、地図背景コンテンツで地理的画像を非表示にしたい場合があります。

    public geoMap: IgcGeographicMapComponent;
    // ...
    
    this.geoMap.backgroundContent = null;
    ts

    概要

    上記すべてのコード スニペットを以下のコード ブロックにまとめて、プロジェクトに簡単にコピーできます。

    import { SampleBase } from "../../sample-base";
    import { AssetsUtils } from "../../../utilities/AssetsUtils";
    
    import { IgcGeographicMapModule } from 'igniteui-webcomponents-maps';
    import { IgcDataChartInteractivityModule } from 'igniteui-webcomponents-charts';
    import { IgcGeographicMapComponent } from 'igniteui-webcomponents-maps';
    import { IgcGeographicShapeSeriesComponent } from 'igniteui-webcomponents-maps';
    import { IgcGeographicPolylineSeriesComponent } from 'igniteui-webcomponents-maps';
    import { IgcGeographicSymbolSeriesComponent } from 'igniteui-webcomponents-maps';
    import { IgcShapeDataSource } from 'igniteui-webcomponents-core';
    import { ModuleManager } from 'igniteui-webcomponents-core';
    
    ModuleManager.register(
        IgcDataChartInteractivityModule,
        IgcGeographicMapModule
    );
    
    let templateHTML = `
    <div class="sample-container" style="background: #aad3df;">
        <igc-geographic-map id="geoMap" width="100%" height="100%" >
            <igc-geographic-shape-series
                id="polygonSeries"
                shape-memberPath="points"
                shape-fill="rgb(150, 150, 150)"
                shape-stroke="Black"
                shape-stroke-thickness="1.0">
            </igc-geographic-shape-series>
            <igc-geographic-polyline-series
                id="lineSeries"
                shape-member-path="points"
                shape-stroke="rgba(147, 15, 180, 0.5)"
                thickness="3.0" >
            </igc-geographic-polyline-series>
            <igc-geographic-symbol-series
                id="symbolSeries"
                longitude-member-path="longitude"
                latitude-member-path="latitude"
                marker-type="Circle"
                marker-outline="rgb(2, 102, 196)"
                marker-brush="White">
            </igc-geographic-symbol-series>
        </igc-geographic-map>
    </div>
    `;
    
    export class MapBindingMultipleShapes extends SampleBase {
    
        public static htmlTagName: string = SampleBase.tag("MapBindingMultipleShapes");
        public static register(): any {
            window.customElements.define(this.htmlTagName, MapBindingMultipleShapes); return this;
        }
    
        private geoMap: IgcGeographicMapComponent;
    
        constructor() {
            super();
            this.onPointsLoaded = this.onPointsLoaded.bind(this);
            this.onPolylinesLoaded = this.onPolylinesLoaded.bind(this);
            this.onPolygonsLoaded = this.onPolygonsLoaded.bind(this);
        }
    
        connectedCallback() {
            this.innerHTML = templateHTML;
    
            this.geoMap = document.getElementById("geoMap") as IgcGeographicMapComponent;
            this.geoMap.backgroundContent = null;
            this.geoMap.windowRect = { left: 0.2, top: 0.1, width: 0.6, height: 0.6 };
    
            const url = AssetsUtils.getAssetsPath();
    
            const sdsPolygons = new IgcShapeDataSource();
            sdsPolygons.importCompleted = this.onPolygonsLoaded;
            sdsPolygons.shapefileSource = url + "/shapes/WorldCountries.shp";
            sdsPolygons.databaseSource  = url + "/shapes/WorldCountries.dbf";
            sdsPolygons.dataBind();
    
            const sdsPolylines = new IgcShapeDataSource();
            sdsPolylines.importCompleted = this.onPolylinesLoaded;
            sdsPolylines.shapefileSource = url + "/shapes/WorldCableRoutes.shp";
            sdsPolylines.databaseSource  = url + "/shapes/WorldCableRoutes.dbf";
            sdsPolylines.dataBind();
    
            // // loading a shapefile with geographic points
            const sdsPoints = new IgcShapeDataSource();
            sdsPoints.importCompleted = this.onPointsLoaded;
            sdsPoints.shapefileSource = url + "/shapes/WorldCities.shp";
            sdsPoints.databaseSource  = url + "/shapes/WorldCities.dbf";
            sdsPoints.dataBind();
        }
    
        public onPointsLoaded(sds: IgcShapeDataSource, e: any) {
            console.log("onPoints");
    
            const geoLocations: any[] = [];
            // parsing shapefile data and creating geo-locations
            let pointData = sds.getPointData();
            for ( let i = 0; i < pointData.length; i++ ) {
                let record = pointData[i];
                const pop = record.fieldValues.POPULATION;
                if (pop > 0) {
                    // each shapefile record has just one point
                    const location = {
                        latitude: record.points[0][0].y,
                        longitude: record.points[0][0].x,
                        city: record.fieldValues.NAME,
                        population: pop
                    };
                    geoLocations.push(location);
                }
            }
            let symbolSeries = (document.getElementById("symbolSeries") as IgcGeographicSymbolSeriesComponent);
            symbolSeries.dataSource = geoLocations;
            symbolSeries.renderSeries(false);
        }
    
        public onPolylinesLoaded(sds: IgcShapeDataSource, e: any) {
            console.log("onPolylines");
    
            const geoPolylines: any[] = [];
            // parsing shapefile data and creating geo-polygons
            let pointData = sds.getPointData();
            for ( let i = 0; i < pointData.length; i++ ) {
                let record = pointData[i];
                // using field/column names from .DBF file
                const route = {
                    points: record.points,
                    name: record.fieldValues.Name,
                    capacity: record.fieldValues.CapacityG,
                    distance: record.fieldValues.DistanceKM,
                    isOverLand: record.fieldValues.OverLand === 0,
                    isActive: record.fieldValues.NotLive !== 0,
                    service: record.fieldValues.InService
                };
                geoPolylines.push(route);
            }
    
            let lineSeries = (document.getElementById("lineSeries") as IgcGeographicPolylineSeriesComponent);
            lineSeries.dataSource = geoPolylines;
            lineSeries.renderSeries(false);
        }
    
        public onPolygonsLoaded(sds: IgcShapeDataSource, e: any) {
            console.log("onPolygons ");
    
            const geoPolygons: any[] = [];
            // parsing shapefile data and creating geo-polygons
            let pointData = sds.getPointData();
            for ( let i = 0; i < pointData.length; i++ ) {
                let record = pointData[i];
                // using field/column names from .DBF file
                const country = {
                    points: record.points,
                    name: record.fieldValues.NAME,
                    gdp: record.fieldValues.GDP,
                    population: record.fieldValues.POPULATION
                };
                geoPolygons.push(country);
            };
    
            let polygonSeries = (document.getElementById("polygonSeries") as IgcGeographicShapeSeriesComponent);
            polygonSeries.dataSource = geoPolygons;
            polygonSeries.renderSeries(false);
        }
    }
    ts

    API リファレンス