지리적 위치를 사용한 Angular 바인딩 JSON 파일

    Ignite UI for Angular 사용하면 다양한 파일 유형에서 로드된 지리적 데이터를 플로팅할 수 있습니다. 예를 들어, JavaScript Object Notation(JSON) 파일에서 지리적 위치를 로드할 수 있습니다.

    Angular Binding JSON Files with Geographic Locations Example

    EXAMPLE
    MODULES
    TS
    HTML
    SCSS

    Like this sample? Get access to our complete Ignite UI for Angular toolkit and start building your own apps in minutes. Download it for free.

    Data Example

    다음은 JSON 파일의 데이터 예입니다.

    [
       { "name": "Sydney Island", "lat": -16.68972, "lon": 139.45917 },
       { "name": "Sydney Creek",  "lat": -16.3,     "lon": 128.95 },
       { "name": "Mount Sydney",  "lat": -21.39864, "lon": 121.193 },
     // ...
    ]
    json

    Code Snippet

    다음 코드는 지도 구성 요소의 IgxGeographicHighDensityScatterSeriesComponent 로드하고 지리적 위치가 포함된 로드된 JSON 파일에서 생성된 객체 배열에 바인딩합니다.

    <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>
                <span>{{item.city}}</span>
            </div>
    </ng-template>
    html
    import { AfterViewInit, Component, TemplateRef, ViewChild } from "@angular/core";
    import { MarkerType } from 'igniteui-angular-charts';
    import { IgxGeographicMapComponent } from 'igniteui-angular-maps';
    import { IgxGeographicSymbolSeriesComponent } from 'igniteui-angular-maps';
    
    @Component({
      selector: "app-map-binding-geographic-json-files",
      styleUrls: ["./map-binding-geographic-json-files.component.scss"],
      templateUrl: "./map-binding-geographic-json-files.component.html"
    })
    
    export class MapBindingDataJsonPointsComponent implements AfterViewInit {
    
        @ViewChild ("map")
        public map: IgxGeographicMapComponent;
        @ViewChild("template")
        public tooltip: TemplateRef<object>;
        constructor() {
        }
    
        public ngAfterViewInit(): void {
            this.componentDidMount();
        }
    
        public componentDidMount() {
            // fetching JSON data with geographic locations from public folder
            fetch("assets/Data/WorldCities.json")
                .then((response) => response.json())
                .then((data) => this.onDataLoaded(data));
        }
    
        public onDataLoaded(jsonData: any[]) {
            const geoLocations: any[] = [];
            // parsing JSON data and using only cities that are capitals
            for (const jsonItem of jsonData) {
                if (jsonItem.cap) {
                    const location = {
                        city: jsonItem.name,
                        country: jsonItem.country,
                        latitude: jsonItem.lat,
                        longitude: jsonItem.lon,
                        population: jsonItem.pop
                    };
                    geoLocations.push(location);
                }
            }
    
            // creating symbol series with loaded data
            const geoSeries = new IgxGeographicSymbolSeriesComponent();
            geoSeries.dataSource = geoLocations;
            geoSeries.markerType = MarkerType.Circle;
            geoSeries.latitudeMemberPath  = "latitude";
            geoSeries.longitudeMemberPath = "longitude";
            geoSeries.markerBrush = "LightGray";
            geoSeries.markerOutline = "Black";
            geoSeries.tooltipTemplate = this.tooltip;
    
            // adding symbol series to the geographic amp
            this.map.series.add(geoSeries);
        }
    }
    ts

    API References