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

Polyline: icons

iconsはPolylineクラスのオプションです。ポリラインに乗せるアイコンを調整できます。アイコンは、Symbolオブジェクトを利用したSVGで指定できます。

Array<IconSequence>

IconSequenceオブジェクトを配列で任意の数だけ指定する。

var opts = {
	icons: [ {
		fixedRotation: true ,
		icon: {
			fillColor: "gold" ,
			path: "M0 8h22L4 22L11 0L18 22z" ,
			scale: 3 ,
		} ,
		offset: "50%" ,
	} ] ,
} ;

デモ

iconsを指定したデモです。1つのIconSequenceオブジェクトを指定しました。

カスタム

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 ) ,
	] ,
	icons: [ {
		fixedRotation: true ,
		icon: {
			fillColor: "gold" ,
			fillOpacity: 1 ,
			path: "M0 8h22L4 22L11 0L18 22z" ,
			scale: 2 ,
			anchor: new google.maps.Point( 11, 22 ) ,
		} ,
		offset: "50%" ,
	} , ] ,
} ) ;

デフォルト

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

サンプルコード

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

// 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 ) ,
	] ,
	icons: [ {
		fixedRotation: true ,
		icon: {
			fillColor: "gold" ,
			fillOpacity: 1 ,
			path: "M0 8h22L4 22L11 0L18 22z" ,
			scale: 2 ,
			anchor: new google.maps.Point( 11, 22 ) ,
		} ,
		offset: "50%" ,
	} , ] ,
} ) ;

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

polyline.getPath().forEach( function ( LatLng ) {
	LatLngBounds.extend( LatLng ) ;
} ) ;

map.fitBounds( LatLngBounds ) ;
	</script>
</body>
</html>

デモページを開く

  • Twitterでシェア
  • Facebookでシェア
  • Google+でシェア
  • はてなブックマークでシェア
  • pocketに保存
  • LINEでシェア
更新履歴
2015年9月1日 (火)
コンテンツを公開しました。