목차
geometry data 들로 이루어진 object를 GeoJSON 형태로 return 해주는 library.
var data = [
{ name: 'Location A', category: 'Store', street: 'Market', lat: 39.984, lng: -75.343 },
{ name: 'Location B', category: 'House', street: 'Broad', lat: 39.284, lng: -75.833 },
{ name: 'Location C', category: 'Office', street: 'South', lat: 39.123, lng: -74.534 }
];
GeoJSON.parse(data, {Point: ['lat', 'lng']});
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [-75.343, 39.984]},
"properties": {
"name": "Location A",
"category": "Store"
}
},
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [-75.833, 39.284]},
"properties": {
"name": "Location B",
"category": "House"
}
},
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [ -75.534, 39.123]},
"properties": {
"name": "Location C",
"category": "Office"
}
}
]
}
array형태와 single obejct 모두 사용 가능하다.
단순 점좌표 뿐만 아니라 여러 geometry type을 받을 수 있다.
비슷한 여러 데이터들을 통합해 파싱하도록 설정이 가능하다.
var data1 = [{ name: 'Location A', street: 'Market', x: 34, y: -75 }];
var data2 = [{ name: 'Location B', date: '11/23/2012', x: 54, y: -98 }];
GeoJSON.defaults = {Point: ['x', 'y'], include: ['name']};
GeoJSON.parse(data1, {});
...