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

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

    지리적 위치를 사용한 React 바인딩 JSON 파일 예제

    EXAMPLE
    DATA
    TSX

    이 샘플이 마음에 드시나요? Ignite UI for React 전체에 액세스하고 몇 분 만에 나만의 앱을 빌드하기 시작하세요. 무료로 다운로드하세요.

    데이터 예시

    다음은 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
    Ignite UI for React | CTA 배너

    코드 조각

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

    import { IgrGeographicSymbolSeries } from 'igniteui-react-maps';
    import { MarkerType } from 'igniteui-react-charts';
    // ...
    
    public componentDidMount() {
        // fetching JSON data with geographic locations from public folder
        fetch(url + "/Data/WorldCities.json")
            .then((response) => response.text())
            .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 = {
                    latitude: jsonItem.lat,
                    longitude: jsonItem.lon,
                    population: jsonItem.pop,
                    city: jsonItem.name,
                    country: jsonItem.country
                };
                geoLocations.push(location);
            }
        }
        // creating symbol series with loaded data
        const geoSeries = new IgrGeographicSymbolSeries( { name: "series" });
        geoSeries.dataSource = geoLocations;
        geoSeries.markerType = MarkerType.Circle;
        geoSeries.latitudeMemberPath  = "latitude";
        geoSeries.longitudeMemberPath = "longitude";
        geoSeries.markerBrush = "LightGray";
        geoSeries.markerOutline = "Black";
        // adding symbol series to the geographic amp
        this.geoMap.series.add(geoSeries);
    }
    ts

    API 참조