抓取https://geojson.cn/数据,获取全国的省市县,转换为JavaScript JSON
抓取https://geojson.cn/数据,获取全国的省市县,转换为JavaScript JSON
function convert(properties) {
return {
name: properties.name,
fullname: properties.fullname,
code: properties.code,
pinyin: properties.pinyin,
level: properties.level,
}
}
async function appendFeatrues(features, data) {
data.children = []
for (let feature of features) {
if (!feature.properties.code) continue
const d = convert(feature.properties)
data.children.push(d)
if (feature.properties.level > 2 || !feature.properties.filename) continue
// console.log(d)
let { features: f } = await fetch(`https://file.geojson.cn/china/1.6.2/${feature.properties.filename}.json`).then(i => i.json())
await appendFeatrues(f, d)
}
return data
}
let code = "100000"
let { properties, features } = await fetch(`https://file.geojson.cn/china/1.6.2/${code}.json`).then(i => i.json())
const data = convert(properties)
await appendFeatrues(features, data)
console.log(JSON.stringify(data))
浙公网安备 33010602011771号