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

Rectangle.setOptions()

Rectangle.setOptions()はRectangleクラスのメソッドです。レクタングルの各種設定をセットします。

構文

パラメータ

options

RectangleOptions

設定内容を表すRectangleOptionsオブジェクトを指定する。インスタンスを作成する時に引数に指定するのと同じ形式。

返り値

返り値はありません。

デモ

メソッドを実行すると、レクタングルの各種設定を更新します。

var rectangle = new google.maps.Rectangle( {
	map: map ,
	bounds: new google.maps.LatLngBounds(
		new google.maps.LatLng( 32.6868, 132.2624 ) ,
		new google.maps.LatLng( 34.4353, 134.7123 )
	) ,
} ) ;

// メソッドを実行
var options = {
	map: map ,
	bounds: new google.maps.LatLngBounds(
		new google.maps.LatLng( 31.6868, 131.2624 ) ,
		new google.maps.LatLng( 35.4353, 135.7123 )
	) ,
	clickable: false ,
	draggable: true ,
	editable: true ,
	fillColor: "red" ,
	fillOpacity: 0.5 ,
	strokeColor: "purple" ,
	strokeOpacity: 0.5 ,
	strokePosition: google.maps.StrokePosition.INSIDE ,
	strokeWeight: 20 ,
	visible: false ,
} ;

rectangle.setOptions( options ) ;

サンプルコード

<!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( 43.0611, 141.3564 ) ,
		zoom: 7 ,
	} ) ;

	// Rectangle
	var rectangle = new google.maps.Rectangle( {
		map: map ,
		bounds: new google.maps.LatLngBounds(
			new google.maps.LatLng( 32.6868, 132.2624 ) ,
			new google.maps.LatLng( 34.4353, 134.7123 )
		) ,
		draggable: true ,
		editable: true ,
	} ) ;

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

	// Method
	document.getElementById( "method" ).onclick = function () {
		var options = {
			map: map ,
			bounds: new google.maps.LatLngBounds(
				new google.maps.LatLng( 32.6868, 134.0624 ) ,
				new google.maps.LatLng( 34.4353, 134.7123 )
			) ,
			clickable: false ,
			draggable: true ,
			editable: true ,
			fillColor: "red" ,
			fillOpacity: 0.5 ,
			strokeColor: "purple" ,
			strokeOpacity: 0.5 ,
			strokePosition: google.maps.StrokePosition.INSIDE ,
			strokeWeight: 20 ,
//		visible: false ,
		} ;

		var response = rectangle.setOptions( options ) ;
		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日 (火)
コンテンツを公開しました。