为了账号安全,请及时绑定邮箱和手机立即绑定

不断得到“未定义”,但是我尝试用 javascript 解析 geojson 文件

不断得到“未定义”,但是我尝试用 javascript 解析 geojson 文件

摇曳的蔷薇 2023-07-29 15:19:43
我有这个 geojson 文件:{   "type":"FeatureCollection",   "features":[      {         "type":"Feature",         "properties":{            "Adresse":"### St-Roch",            "Type":"famille"         },         "geometry":{            "type":"Point",            "coordinates":[               -73.6291292309761,               45.52982413033413            ]         }      },      {         "type":"Feature",         "properties":{            "Adresse":"### St-Roch",            "Type":"organisme"         },         "geometry":{            "type":"Point",            "coordinates":[               -73.62943768501282,               45.531770729329985            ]         }      }   ]}这是我的脚本(的一部分):        var request = new XMLHttpRequest();        request.open("GET", "photoParcEx.geojson", false);        request.send(null);        var dataJSON = JSON.parse(request.responseText);        console.log(dataJSON.features.properties.Adresse);                photoParcEx.addTo(maCarte).on('click', function () {            sidebar.toggle();            document.getElementById("sidebar").innerHTML = "Type : " + dataJSON.Adresse;        });我试图将“Adresse”键发送到内部 HTML,但始终未定义。当我尝试使用控制台日志打印该值时,情况也是如此。我究竟做错了什么 ?
查看完整描述

1 回答

?
守候你守候我

TA贡献1802条经验 获得超10个赞

这做到了这一点:


photoParcEx.on('click', function (e) {

      sidebar.show();

            console.log(e.layer.feature.properties.Type);

            var photoDesc = document.getElementById("photoDesc");

            //$("sidebar").innerHTML = "Type : " + e.layer.properties.Type;

            if (photoDesc.style.display === 'none') {

                photoDesc.style.display = "block";

              } else {

              } 

            document.getElementById("type").innerHTML = "TYPE : " + (e.layer.feature.properties.Type).toUpperCase();

            document.getElementById("desc").innerHTML = "<b>MY STORY : </b>" + e.layer.feature.properties.description;

            document.getElementById("photo").src = e.layer.feature.properties.image1;

            removeBanner();

    });


查看完整回答
反对 回复 2023-07-29
  • 1 回答
  • 0 关注
  • 70 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信