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

Marker: zIndex

zIndexはMarkerクラスのオプションです。z-orderの値を調整できます。数値が高いほど、他のオブジェクトと重なった時に手前に表示されます。

number

z-orderの値を数値で指定する。数値が高いほど、重なった時に手前に表示される。

var opts = {
	zIndex: 5 ,
} ;

デモ

zIndexを指定したデモです。右側のマーカーのz-orderの値は1です。左側のマーカーの方が高い数値が指定されているため、手前に表示されています。z-indexを指定する際は、全てのマーカーに指定しないと表示が崩れることがあります。

var leftMarker = new google.maps.Marker( {
	map: map ,
	position: new google.maps.LatLng( 35.710068 , 139.8102 ) ,
	zIndex: 2 ,
} ) ;

var rightMarker = new google.maps.Marker( {
	map: map ,
	position: new google.maps.LatLng( 35.710063 , 139.8107 ) ,
	zIndex: 1 ,
} ) ;

サンプルコード

<!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.710068 , 139.8102 ) ,
	zoom: 15 ,
} ) ;

// Marker
var leftMarker = new google.maps.Marker( {
	map: map ,
	position: new google.maps.LatLng( 35.710068 , 139.8102 ) ,
	zIndex: 2 ,
} ) ;

var rightMarker = new google.maps.Marker( {
	map: map ,
	position: new google.maps.LatLng( 35.710063 , 139.8107 ) ,
	zIndex: 1 ,
} ) ;
	</script>
</body>
</html>

デモページを開く

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