当我单击“ resetMap”按钮时,我的WebConsole告诉我“ t未定义”。这是resetMap函数的javascript
function resetMap() {
/* This creates a variable which groups the layers.
*/
var layerGroup = L.layerGroup([Frog1Layer, Frog2Layer, Frog3Layer, Frog4Layer, Frog5Layer, Frog6Layer, Frog7Layer, Frog8Layer]);
/* This removes the variable layerGroup from the map.
*/
map.removeLayer(layerGroup);
/* This changes the map centre & zoom level to default.
*/
map.setView(new L.LatLng(0,0), 1);
}
这是控制台中的错误
TypeError: t is undefinedleaflet.js:5:652
u https://unpkg.com/leaflet@1.5.1/dist/leaflet.js:5
getLayerId https://unpkg.com/leaflet@1.5.1/dist/leaflet.js:5
addLayer https://unpkg.com/leaflet@1.5.1/dist/leaflet.js:5
initialize https://unpkg.com/leaflet@1.5.1/dist/leaflet.js:5
i https://unpkg.com/leaflet@1.5.1/dist/leaflet.js:5
layerGroup https://unpkg.com/leaflet@1.5.1/dist/leaflet.js:5
resetMap file:///F:/GIS Assessment 1/MyScript.js:247
onclick file:///F:/GIS Assessment 1/MyHTML.html:1
我该如何解决?
答案 0 :(得分:0)
错误描述应该非常准确:您的图层之一未定义。
您可以跳过创建图层组的操作,
let layers = [Frog1Layer, Frog2Layer, Frog3Layer, Frog4Layer, Frog5Layer, Frog6Layer, Frog7Layer, Frog8Layer]
for (let layer of layers) {
if (layer) {
map.removeLayer(layer)
}
}