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

Polygon: fillColor

fillColorはPolygonクラスのオプションです。ポリゴンの塗りつぶしの色を変更できます。

string

スタイルシートと同じ方法で、色を文字列で指定する。

var opts = {
	fillColor: "tomato" ,
} ;

デモ

fillColorを指定したデモです。

カスタム

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 ) ,
	] ,
	fillColor: "tomato" ,
} ) ;

デフォルト

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

サンプルコード

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

// 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 ) ,
	] ,
	fillColor: "tomato" ,
} ) ;

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

polygon.getPaths().forEach( function ( LatLngs ) {
	LatLngs.forEach( function ( LatLng ) {
		LatLngBounds.extend( LatLng ) ;
	} ) ;
} ) ;

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

デモページを開く

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