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

Circle.setOptions()

Circle.setOptions()はCircleクラスのメソッドです。円の各種設定をセットします。

構文

setOptions( options:CircleOptions )

パラメータ

options

CircleOptions

地図の設定をまとめたCircleOptionsオブジェクト。インスタンスを作成する時に引数に指定するのと同じ形式。

返り値

返り値はありません。

デモ

メソッドを実行すると、円の各種設定をセットします。中央の青い円のz-orderは1なので、zIndexに2以上を設定すれば重なった時に手前に表示されます。

var circle = new google.maps.Circle( {
	map: map ,
	center: new google.maps.LatLng( 35.794361,139.791421 ) ,
	radius: 800 ,
} ) ;

// メソッドを実行
var options = {
	map: map ,
	center: new google.maps.LatLng( 35.78572777,139.78867441 ) ,
	radius: 400 ,
	clickable: true ,
	draggable: true ,
	editable: true ,
	fillColor: "red" ,
	fillOpacity: 1 ,
	strokeColor: "blue" ,
	strokeOpacity: 0.25 ,
	strokePosition: google.maps.StrokePosition.INSIDE ,
	strokeWeight: 30 ,
	visible: true ,
	zIndex: 2 ,
} ;

circle.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( 35, 139 ) ,
		zoom: 15 ,
	} ) ;

	// Circle
	var circle = new google.maps.Circle( {
		map: map ,
		center: map.getCenter() ,
		radius: 800 ,
	} ) ;

	// Method
	document.getElementById( "method" ).onclick = function () {
		var options = {
//		map: map ,
//		center: new google.maps.LatLng( 35.78572777,139.78867441 ) ,
			radius: 400 ,
			clickable: true ,
			draggable: true ,
			editable: true ,
			fillColor: "red" ,
			fillOpacity: 1 ,
			strokeColor: "blue" ,
			strokeOpacity: 0.25 ,
			strokePosition: google.maps.StrokePosition.INSIDE ,
			strokeWeight: 30 ,
			visible: true ,
			zIndex: 2 ,
		} ;

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