チェックボックスの選択に応じて Google マップ キャンバスを表示したいのですが、クリックしてもマップがうまく表示されず、マップが正しく表示されず、「マップ機能」も機能しません..... css リンクは map_canvas の div サイズを設定します。この show 関数を削除すると、マップは完璧に機能します。コードは次のとおりです。
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<link href="https://developers.google.com/maps/documentation/javascript/examples/default.css" rel="stylesheet">
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=drawing"> </script>
<script type="text/javascript" src="../jquery-1.2.1.pack.js"></script>
<script type="text/javascript">
function lookup(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$('#suggestions').hide();
} else {
$.post("do_search.php", {queryString: ""+inputString+""},
function(data){
if(data.length >0) {
alert(data);
$('#suggestions').show();
$('#autoSuggestionsList').html(data);
}
});
}
} // lookup
//alert(queryString);
</script>
<script>
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-35.48833, -62.97528),
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
var drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.MARKER,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: [
google.maps.drawing.OverlayType.POLYGON
]
},
markerOptions: {
icon: 'images/beachflag.png'
},
circleOptions: {
fillColor: '#ffff00',
fillOpacity: 1,
strokeWeight: 5,
clickable: false,
editable: true,
zIndex: 1
}
});
drawingManager.setMap(map);
google.maps.event.addListener(drawingManager, 'polygoncomplete', function(polygon) {
//alert('Poligono cerrado');
var coordinates = "";
var path = polygon.getPath();
for (var i = 0; i < path.getLength(); i++)
coordinates += path.getAt(i) + ",";
//alert(coordinates);
lookup(coordinates);
drawingManager.drawingControlOptions.drawingModes = [];
drawingManager.drawingControl = false;
drawingManager.setMap(map);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<script>
function fnchecked(blnchecked)
{
if(blnchecked)
{
document.getElementById("map_canvas").style.display = "";
}
else
{
document.getElementById("map_canvas").style.display = "none";
}
}
</script>
</head>
<body>
<input type="checkbox" name="fldcheckbox" id="fldcheckbox" onclick="fnchecked(this.checked);"/>mapa
<div id="map_canvas" style="display:none;">
</div>
</body>
何か案が?