When leaflet loads geojson, Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'. Solution
An error was reported when loading the geojson file: Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'
as shown in the figure:
The following is geojson
the file format
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": 0
},
"geometry": {
"type": "Point",
"coordinates": [
101.7581977222,
36.8348153089
]
}
},
The reason for the error is that "properties" is malformed "name": 0 Zeros should be enclosed in double quotes.
Some are shown below js
. code segment
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);
}
The error code is
Some are shown below 内联代码片
.
var properties = { name: i}
Change var properties = { name: i} to
var properties = {
name: `${
i}` }
Problem solved
Modified geojson代码片
.
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "0"
},
"geometry": {
"type": "Point",
"coordinates": [
101.7581977222,
36.8348153089
]
}
},