0
我無法找到代碼中的谷歌地圖使用複選框層 但是當我選中的複選框的錯誤爬我需要做的是這樣that但我的層使用複選框層谷歌地圖
toggleLayers(0) [setMap([object Object]] returns status: undefined
toggleLayers(0) [setMap(null] returns status: INVALID_REQUEST
toggleLayers(1) [setMap([object Object]] returns status: undefined
toggleLayers(1) [setMap(null] returns status: undefined
我所做的不正確?我出了什麼問題? P.S.對不起,我的英語
function initialize() {
var latlng = new google.maps.LatLng(59.93644, 30.152664);
var myOptions = {
zoom: 10,
center: latlng,
mapTypeIds: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
}
var layers=[];
layers[0] = new google.maps.KmlLayer('ban.kml',
{preserveViewport: true});
layers[1] = new google.maps.KmlLayer('http://wrf1.geology.um.maine.edu/bipush/kml/plot_5938.kmz',
{preserveViewport: true});
var map;
function toggleLayers(i)
{
if(layers[i].getMap()==null) {
layers[i].setMap(map);
}
else {
layers[i].setMap(null);
}
document.getElementById('status').innerHTML += "toggleLayers("+i+") [setMap("+layers[i].getMap()+"] returns status: "+layers[i].getStatus()+"<br>";
}
<body onload="initialize()">
Parish boundary line <input type="checkbox" id="layer100" onclick="toggleLayer(100)" checked><br />
Letterbox locations and results <input type="checkbox" id="layer0" onclick="toggleLayer(0)" checked><br />
Landscape challenges <input type="checkbox" id="layer1" onclick="toggleLayer(1)" checked><br />
<div id="map_canvas" style="height:500px; width:600px;"></div>
<div id="status"></div>