Failed to execute ‘appendChild‘ on ‘Node‘: parameter 1 is not of type ‘Node‘.解决办法

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:insert image description here

The following is geojsonthe 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
                ]
            }
        },

"name": "0" After adding double quotes, the problem is solved.

Guess you like

Origin blog.csdn.net/weixin_43727933/article/details/128616591