다음과 같은 구조를 제안합니다. 이 방법을 사용하면 모든 레이어에 대해 별도의 함수를 작성하지 않고이 레이어 만 별도로 작성할 수 있습니다. 여기에 'input'태그의 'id'가 KML 파일 이름으로 사용됩니다. 이 question을보고 싶을 것입니다. 찾고 있다면 앞으로 geoxml3 옵션을 사용할 수 있습니다.
var G = google.maps;
function toggle() {
if (!this.kml)
{this.kml = new G.KmlLayer('http://toptrippk.com/webgis/uploadfiles/kml/' + this.id + '.kml', {preserveViewport:true}); this.on = false};
if (this.on)
{this.kml.setMap(null); this.on = false} else {this.kml.setMap(map); this.on = true};
};
function initialize() {
var layers = document.getElementsByTagName('input');
var options = {};
map = new G.Map(document.getElementById('map_canvas'), options);
for (var i=0; i<layers.length; i++) {G.event.addDomListener(layers[i], 'click', toggle)};};
G.event.addDomListener(window, 'load', initialize);