PolylineOptions
PolylineOptionsは、ポリラインの設定を調整するためのオブジェクトです。ポリラインを作成する時のPolylineクラスの引数などに利用できます。
プロパティ
プロパティ名 | 説明 |
---|---|
clickable | boolean trueならクリックできる、falseならクリックできない。 |
draggable | boolean trueならドラッグ操作できる、falseならドラッグ操作できない。 |
editable | boolean trueなら編集できる、falseなら編集できない。 |
geodesic | boolean trueなら測地線に対応、falseなら測地線に非対応。 |
icons | Array<IconSequence> IconSequenceオブジェクトを配列で任意の数だけ指定する。 |
map | 地図を表すMapクラスのインスタンスを指定する。 |
path | MVCArray<LatLng> / Array<LatLng|LatLngLiteral> 位置座標を配列で任意の数だけ指定する。配列はJavaScriptのネイティブな配列、またはGoogle Maps独自のMVCArrayクラスで指定できる。MVCArrayクラスの場合は、LatLngLiteralオブジェクトで指定することはできない。 |
strokeColor | string スタイルシートと同じ方法で、色を文字列で指定する。 |
strokeOpacity | number スタイルシートと同じ方法で、不透明度を数値で指定する。 |
strokeWeight | number 太さを、ピクセル単位の数値で指定する。 |
visible | boolean trueなら表示状態、falseなら非表示状態になる。 |
zIndex | number z-orderを表す数値を指定する。 |
デモ
オプションの内容を確認して下さい。ここで紹介し切れなかったプロパティは、専用のページをご参考下さい。
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 ,
} ;
var polyline = new google.maps.Polyline( options ) ;
サンプルコード
<!DOCTYPE html>
<html>
<head>
<style>
#map-canvas {
width: 600px ;
height: 600px ;
}
</style>
</head>
<body>
<div id="map-canvas"></div>
<script src="//maps.googleapis.com/maps/api/js?key={APIキー}"></script>
<script>
var mapDiv = document.getElementById( "map-canvas" ) ;
// Map
var map = new google.maps.Map( mapDiv, {
center: new google.maps.LatLng( 35, 139 ) ,
zoom: 18 ,
} ) ;
// Polyline
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 ,
} ;
var polyline = new google.maps.Polyline( options ) ;
// fit bounds
var latLngBounds = new google.maps.LatLngBounds() ;
polyline.getPath().forEach( function ( latLng ) {
latLngBounds.extend( latLng ) ;
} ) ;
map.fitBounds( latLngBounds ) ;
</script>
</body>
</html>
参考
- Google Maps JavaScript API: PolylineOptions
- Googleの公式リファレンス。