我的教授希望我在代码中纠正两件事。第一个是我需要将RU休息图层绘制在我的漫滩图层顶部,以便所有其余图层都可见。第二,我的代码中似乎有一些东西会在您切换洪泛区图层时重置地图的比例,我宁愿这样做也不会发生。这是我的代码:
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Toggle</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
#panel {
position: absolute;
top: 5px;
left: 50%;
margin-left: -180px;
z-index: 5;
background-color: #fff;
padding: 5px;
border: 1px solid #999;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn-history/r172/trunk/arcgislink/src/arcgislink.js"></script>
<script>
var overlay;
var map;
var url;
var dynamap;
function initialize() {
var mapOptions = {
zoom: 13,
center: new google.maps.LatLng(37.1276, -80.56895),
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
url = 'http://geog-grant.radford.edu/arcgiscloud/rest/services/RU/MapServer';
dynamap = new gmaps.ags.MapOverlay(url);
overlay = new google.maps.KmlLayer({
url: 'http://www.radford.edu/kblakemore/KML_Layer_Severity/KML_Floodplain_Radford/doc.kml'
});
}
function toggleFloodplain() {
overlay.setMap(overlay.getMap() ? null : map);
}
function toggleRUrest() {
dynamap.setMap(dynamap.getMap() ? null : map);
}
window.onload = initialize;
</script>
</head>
<body>
<div id ="panel">
<p> Floodplains Radford, Virginia </p>
<input id= "toggle" type="checkbox" value="toggleFloodplain" onclick="toggleFloodplain();"> Floodplains </input>
<input id= "toggle" type="checkbox" value="toggleRUrest" onclick="toggleRUrest()">Toggle RUrest</button>
</div>
<div id="map-canvas"></div>
</body>
</html>
答案 0 :(得分:0)
您必须使用另一个地图窗格作为dynamap。
地图窗格在使用过的库中进行了硬编码(第2796行):
panes.overlayLayer.appendChild(div);
使用例如markerLayer
代替overlayLayer
为了能够更改它,您必须直接更改库或覆盖MapOverlay.prototype.onAdd
(这是指定窗格的功能)