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

Polygon.setOptions()

Polygon.setOptions()はPolygonクラスのメソッドです。ポリゴンの各種設定をセットします。

構文

setOptions( options:PolygonOptions )

パラメータ

options

PolygonOptions

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

返り値

返り値はありません。

デモ

メソッドを実行すると、ポリゴンの各種設定をまとめてセットします。

var polygon = new google.maps.Polygon( {
	map: map ,
	paths: [
		new google.maps.LatLng( 35.7113 , 139.8099 ) ,
		new google.maps.LatLng( 35.7106 , 139.8088 ) ,
		new google.maps.LatLng( 35.7091 , 139.8088 ) ,
		new google.maps.LatLng( 35.7088 , 139.8107 ) ,
		new google.maps.LatLng( 35.7100 , 139.8120 ) ,
		new google.maps.LatLng( 35.7093 , 139.8135 ) ,
		new google.maps.LatLng( 35.7116 , 139.8128 ) ,
		new google.maps.LatLng( 35.7109 , 139.8120 ) ,
	] ,
} ) ;

// メソッドを実行
var options = {
	map: map ,
	paths: [
		new google.maps.LatLng( 50.24627379, 120.98433848 ) ,
		new google.maps.LatLng( 46.87945962, 97.85176874 ) ,
		new google.maps.LatLng( 25.31043851, 56.94393182 ) ,
		new google.maps.LatLng( 29.07889049, 130.5270086 ) ,
		new google.maps.LatLng( 19.17339437, 159.608875 ) ,
		new google.maps.LatLng( 39.23583978, -117.29978124 ) ,
		new google.maps.LatLng( 59.61722201, 185.14739473 ) ,
		new google.maps.LatLng( 48.68442305, 138.83946581 ) ,
	] ,
	clickable: false ,
	draggable: true ,
	editable: true ,
	fillColor: "red" ,
	fillOpacity: 1 ,
	geodesic: true ,
	strokeColor: "blue" ,
	strokeOpacity: 0.5 ,
	strokePosition: google.maps.StrokePosition.INSIDE ,
	strokeWeight: 20 ,
	visible: false ,
} ;

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

	// Polygon
	var polygon = new google.maps.Polygon( {
		map: map ,
		paths: [
			new google.maps.LatLng( 35.7113 , 139.8099 ) ,
			new google.maps.LatLng( 35.7106 , 139.8088 ) ,
			new google.maps.LatLng( 35.7091 , 139.8088 ) ,
			new google.maps.LatLng( 35.7088 , 139.8107 ) ,
			new google.maps.LatLng( 35.7100 , 139.8120 ) ,
			new google.maps.LatLng( 35.7093 , 139.8135 ) ,
			new google.maps.LatLng( 35.7116 , 139.8128 ) ,
			new google.maps.LatLng( 35.7109 , 139.8120 ) ,
		] ,
		draggable: true ,
	} ) ;

	// fit bounds
	var latLngBounds = new google.maps.LatLngBounds() ;

	polygon.getPaths().forEach( function ( latLngs ) {
		latLngs.forEach( function ( latLng ) {
			latLngBounds.extend( latLng ) ;
		} ) ;
	} ) ;

	map.fitBounds( latLngBounds ) ;

	// Method
	document.getElementById( "method" ).onclick = function () {
		var options = {
			map: map ,
			paths: [
				new google.maps.LatLng( 35.7113 , 139.8099 ) ,
				new google.maps.LatLng( 35.7091 , 139.8088 ) ,
				new google.maps.LatLng( 35.7100 , 139.8120 ) ,
				new google.maps.LatLng( 35.7116 , 139.8128 ) ,
			] ,
			clickable: false ,
			draggable: true ,
			editable: true ,
			fillColor: "red" ,
			fillOpacity: 1 ,
			geodesic: false ,
			strokeColor: "blue" ,
			strokeOpacity: 0.5 ,
			strokePosition: google.maps.StrokePosition.INSIDE ,
			strokeWeight: 20 ,
//		visible: false ,
		} ;

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