GroundOverlay.getOpacity()
GroundOverlay.getOpacity()はGroundOverlayクラスのメソッドです。オーバーレイの不透明度を取得します。
構文
getOpacity()
パラメータ
パラメータはありません。
返り値
number
不透明度を表す数値。opacityが明示的に指定されていない場合、undefinedが返る。
デモ
メソッドを実行すると、オーバーレイの不透明度を取得します。
var groundOverlay = new google.maps.GroundOverlay(
"./overlay.svg" ,
new google.maps.LatLngBounds(
new google.maps.LatLng( 35.708194, 139.808565 ) ,
new google.maps.LatLng( 35.712280, 139.813619 )
), {
map: map ,
clickable: true ,
opacity: 0.5 ,
} ) ;
// メソッドを実行
groundOverlay.getOpacity() ;
サンプルコード
<!DOCTYPE html>
<html>
<head>
<style>
#map-canvas {
width: 600px ;
height: 600px ;
}
</style>
</head>
<body>
<div id="map-canvas"></div>
<p><button id="method">メソッドを実行</button><button id="reset">リセット</button></p>
<p><textarea id="response"></textarea></p>
<script src="//maps.googleapis.com/maps/api/js?key={APIキー}"></script>
<script>
function initialize() {
var mapDiv = document.getElementById( "map-canvas" ) ;
var responseTextarea = document.getElementById( "response" ) ;
responseTextarea.value = "" ;
// Map
var map = new google.maps.Map( mapDiv, {
center: new google.maps.LatLng( 35, 139 ) ,
zoom: 15 ,
} ) ;
// GroundOverlay
var groundOverlay = new google.maps.GroundOverlay(
"https://lab.syncer.jp/Web/API/Google_Maps/JavaScript/GroundOverlay/getBounds/overlay.svg" ,
new google.maps.LatLngBounds(
new google.maps.LatLng( 35.708194, 139.808565 ) ,
new google.maps.LatLng( 35.712280, 139.813619 )
), {
map: map ,
opacity: 0.5 ,
} ) ;
// fit bounds
map.fitBounds( groundOverlay.getBounds() ) ;
// Method
document.getElementById( "method" ).onclick = function () {
var response = groundOverlay.getOpacity( 0.5 ) ;
try{ response = typeof response == "object" ? JSON.stringify( response ) : response ; }catch(e){}
responseTextarea.value = response ;
console.log( response ) ;
}
}
// Reset
document.getElementById( "reset" ).onclick = initialize ;
initialize() ;
</script>
</body>
</html>