亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

不斷得到“未定義”,但是我嘗試用 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 關注
  • 131 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號