InfoWindow: disableAutoPan
disableAutoPanはInfoWindowクラスのオプションです。情報ウィンドウが現在のビューポートの外で開くと、それを見せようと、中心の位置座標が勝手に移動してしまいます。その自動修正を拒否できます。
値
boolean
trueなら位置座標の自動修正をしない、falseならする。
var opts = {
disableAutoPan: true ,
} ;
デモ
disableAutoPanを指定したデモです。いずれも、地図の中心の位置座標は東京スカイツリーです。自動修正がある方は、情報ウィンドウを見せようと、中心の位置座標が勝手に変わってしまっています。
カスタム
var infoWindow = new google.maps.InfoWindow( {
position: new google.maps.LatLng( 35.718088, 139.816731 ) ,
content: "SYNCER" ,
disableAutoPan: true ,
} ) ;
infoWindow.open( map ) ;
デフォルト
var infoWindow = new google.maps.InfoWindow( {
position: new google.maps.LatLng( 35.718088, 139.816731 ) ,
content: "SYNCER" ,
} ) ;
infoWindow.open( map ) ;
サンプルコード
<!DOCTYPE html>
<html>
<head>
<style>
#map-canvas {
width: 600px ;
height: 600px ;
}
</style>
</head>
<body>
<div id="map-canvas"></div>
<script src="//maps.googleapis.com/maps/api/js?key={APIキー}"></script>
<script>
var mapDiv = document.getElementById( "map-canvas" ) ;
// Map
var map = new google.maps.Map( mapDiv, {
center: new google.maps.LatLng( 35.710062699999995, 139.8107004 ) ,
zoom: 16 ,
} ) ;
// InfoWindow
var infoWindow = new google.maps.InfoWindow( {
position: new google.maps.LatLng( 35.718088, 139.816731 ) ,
content: "SYNCER" ,
disableAutoPan: true ,
} ) ;
infoWindow.open( map ) ;
</script>
</body>
</html>