SYNCERのロゴ
アイキャッチ画像

GroundOverlay.setOpacity()

GroundOverlay.setOpacity()はGroundOverlayクラスのメソッドです。オーバーレイの不透明度をセットします。

構文

setOpacity( opacity:number )

パラメータ

opacity

number

不透明度を表す数値を指定する。

返り値

返り値はありません。

デモ

メソッドを実行すると、オーバーレイの不透明度をセットします。

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: 1 ,
} ) ;

// メソッドを実行
groundOverlay.setOpacity( 0.5 ) ;

サンプルコード

<!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 ,
	} ) ;

	// fit bounds
	map.fitBounds( groundOverlay.getBounds() ) ;

	// Method
	document.getElementById( "method" ).onclick = function () {
		var response = groundOverlay.setOpacity( 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>

デモページを開く

  • Twitterでシェア
  • Facebookでシェア
  • Google+でシェア
  • はてなブックマークでシェア
  • pocketに保存
  • LINEでシェア
更新履歴
2015年9月1日 (火)
コンテンツを公開しました。