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

Polygon: geodesic

geodesicはPolygonクラスのオプションです。ポリゴンを測地線に対応させるか否かを調整できます。測地線に対応したポリゴンは、空間を考慮した曲線になります。

boolean

trueなら測地線に対応させる、falseなら対応させない。

var opts = {
	geodesic: true ,
} ;

デモ

geodesicを指定したデモです。trueの場合、ポリゴンの各辺は空間を考慮した曲線になります。

カスタム

var polygon = new google.maps.Polygon( {
	map: map ,
	paths: [
		new google.maps.LatLng( 62.19248005776629, 35.83541993749998 ) ,
		new google.maps.LatLng( 11.719326743315053, 37.41745118749998 ) ,
		new google.maps.LatLng( 29.513509273261302, 126.71432618749998 ) ,
		new google.maps.LatLng( 66.43614855061702, 145.17135743749998 ) ,
	] ,
	geodesic: true ,
} ) ;

デフォルト

var polygon = new google.maps.Polygon( {
	map: map ,
	paths: [
		new google.maps.LatLng( 62.19248005776629, 35.83541993749998 ) ,
		new google.maps.LatLng( 11.719326743315053, 37.41745118749998 ) ,
		new google.maps.LatLng( 29.513509273261302, 126.71432618749998 ) ,
		new google.maps.LatLng( 66.43614855061702, 145.17135743749998 ) ,
	] ,
} ) ;

サンプルコード

<!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( 62.19248005776629, 35.83541993749998 ) ,
		new google.maps.LatLng( 11.719326743315053, 37.41745118749998 ) ,
		new google.maps.LatLng( 29.513509273261302, 126.71432618749998 ) ,
		new google.maps.LatLng( 66.43614855061702, 145.17135743749998 ) ,
	] ,
	geodesic: true ,
} ) ;

// 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日 (火)
コンテンツを公開しました。