我正在使用本地机器上的 geoxml3 来加载 kml。但是,一旦加载了 kml,默认视图中心就会发生变化。我确实尝试添加行“preserveViewport:true”,但在加载后我仍然可以看到 kml 的完整视图。任何阻止这种情况的建议。
这是我的代码
<html>
<head>
<title>Google Map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map {
margin: 0;
padding: 0;
height: 100%;
}
</style>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script type="text/javascript" src="geoxml3-master/polys/geoxml3.js"></script>
<script type="text/javascript" src="geoxml3-master/ProjectedOverlay.js"></script>
<script>
var myCenter=new google.maps.LatLng( 13.751768, 100.537606);
var map;
var marker;
var mapProp;
function initialize()
{
mapProp = {
center:myCenter,
zoom:17,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map=new google.maps.Map(document.getElementById("map"),mapProp);
var parser = new geoXML3.parser({
suppressInfoWindows: true,
map: map,
preserveViewport: true
});
parser.parse('test.kml');
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div style="height:100%; width:100%;">
<div id="map"></div>
</div>
</body>