leaflet 加载geojson 出现 Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'. 解决办法
在加载geojson文件时报错 : Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node' 如图所示:
以下是
geojson
文件格式
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": 0
},
"geometry": {
"type": "Point",
"coordinates": [
101.7581977222,
36.8348153089
]
}
},
错误原因是 "properties"的格式错误"name": 0 零应双引号括起来。
js
。代码片段
for (let i = 0; i < excelConvertArr.length; i++) {
//excel文件数据格式纬度在前而Geojson格式是经度在前这里进行转换
var x = excelConvertArr[i][0];
var y = excelConvertArr[i][1];
var coordinate = [y, x];
var properties = { name: i}
var pointToFeature = this._pointToFeature(coordinate, properties)
lnglat.push(pointToFeature);
}
错误代码为
下面展示一些 内联代码片
。
var properties = { name: i}
将var properties = { name: i}更改为
var properties = { name: `${i}` }
问题解决
修改后的 geojson代码片
。
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "0"
},
"geometry": {
"type": "Point",
"coordinates": [
101.7581977222,
36.8348153089
]
}
},