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

Polyline.setOptions()

Polyline.setOptions()はPolylineクラスのメソッドです。ポリラインの各種設定をまとめて指定できます。

構文

setOptions( options:PolylineOptions )

パラメータ

options

PolylineOptions

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

返り値

返り値はありません。

デモ

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

var polyline = new google.maps.Polyline( {
	map: map ,
	path: [
		new google.maps.LatLng( 35.794507 , 139.790788 ) ,
		new google.maps.LatLng( 35.794007 , 139.791788 ) ,
	] ,
} ) ;

// メソッドを実行
var options = {
	map: map ,
	path: [
		new google.maps.LatLng( 32.7294, 131.2157 ) ,
		new google.maps.LatLng( 35.7085, 139.7411 ) ,
		new google.maps.LatLng( 44.8694, 142.1581 ) ,
	] ,
	clickable: false ,
	draggable: true ,
	editable: true ,
	geodesic: true ,
	strokeColor: "red" ,
	strokeOpacity: 0.5 ,
	strokeWeight: 20 ,
	visible: false ,
} ;

polyline.setOptions( false ) ;

サンプルコード

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

	// Polyline
	var polyline = new google.maps.Polyline( {
		map: map ,
		path: [
			new google.maps.LatLng( 35.794507 , 139.790788 ) ,
			new google.maps.LatLng( 35.794007 , 139.791788 ) ,
		] ,
	} ) ;

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

	polyline.getPath().forEach( function ( latLng ) {
		latLngBounds.extend( latLng ) ;
	} ) ;

	map.fitBounds( latLngBounds ) ;

	// Method
	document.getElementById( "method" ).onclick = function () {
		var options = {
//		map: map ,
			path: [
				new google.maps.LatLng( 35.794007, 139.790788 ) ,
				new google.maps.LatLng( 35.794507, 139.791788 ) ,
			] ,
			clickable: false ,
			draggable: true ,
			editable: true ,
			geodesic: true ,
			strokeColor: "red" ,
			strokeOpacity: 0.5 ,
			strokeWeight: 20 ,
//		visible: false ,
		} ;

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