지리적 위치를 사용한 React 바인딩 JSON 파일
Ignite UI for React 사용하면 다양한 파일 유형에서 로드된 지리적 데이터를 플로팅할 수 있습니다. 예를 들어, JavaScript Object Notation(JSON) 파일에서 지리적 위치를 로드할 수 있습니다.
React Binding JSON Files with Geographic Locations Example
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 },
// ...
]
Code Snippet
다음 코드는 지리적 위치가 표시된 로드된 JSON 파일에서 생성된 객체 배열에 맵 컴포넌트를 로드하고 바인딩IgrGeographicHighDensityScatterSeries 합니다:
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);
}
API References
IgrGeographicHighDensityScatterSeriesIgrGeographicSymbolSeriesGeographicMapDataSourcelatitudeMemberPathlongitudeMemberPath