Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="js-gmap" class="gmap" data-latitude="35.710260" data-longitude="139.757228" data-title="株式会社LIG"></div>

              
            
!

CSS

              
                * {
  box-sizing: border-box;
}
.gmap {
	margin-top: 30px;
	height: 450px;
}
.gmap-info-window {
	position: relative;
	width: 250px;
	padding: 25px 30px;
	border: 2px solid #EC492C;
	background-color: #fff;
}
.gmap-info-window:before {
		display: inline-block;
		position: absolute;
		left: 50%;
		bottom: -10px;
		width: 20px;
		height: 10px;
		transform: translate(-50%, 0);
		background: url(https://82mou.github.io/infobox/img/gmap-info-window-frame-point.png) no-repeat 0 0;
		content: '';
	}
.gmap-info-window-title {
	color: #EC492C;
	font-size: 16px;
	font-weight: bold;
	text-align: center;
}
.gmap-info-window-address {
	margin-top: 10px;
	font-size: 12px;
	font-weight: bold;
}
.infobox-marker {
  width: 30px;
  height: 30px;
  padding: 4px 0 5px;
  border-radius: 50%;
  background-color: #fff;
  border: 2px solid #F6411B;
  text-align: center;
  span {
    font-weight: bold;
    line-height: 1;
  }
}
              
            
!

JS

              
                const infobox = []; // 全てのinfoboxオブジェクトを格納する配列を用意する
const $map = document.querySelector('#js-gmap');
const latitude = $map.dataset['latitude']; // 緯度
const	longitude = $map.dataset['longitude'] // 経度
const title = $map.dataset['title']; // タイトル
const targetLatlng = new google.maps.LatLng(latitude, longitude);

const myOptions = {
  zoom: 15, // 拡大比率
  center: targetLatlng, // 表示枠内の中心点
  mapTypeId: google.maps.MapTypeId.ROADMAP // 表示タイプの指定
};

const	map = new google.maps.Map($map, myOptions);

function hiddenAll() {
  for(let i = 0; i < infobox.length; i++) {
    infobox[i].close(map);
  }
}

function makeInfobox() {
  const obj = [
    {
      name: 'ショップ1',
      discription: 'ショップ1の説明',
      position: {
        lat: 35.710260,
        lng: 139.777228
      }
    },
    {
      name: 'ショップ2',
      discription: 'ショップ2の説明',
      position: {
        lat: 35.711260,
        lng: 139.767228
      }
    },
    {
      name: 'ショップ3',
      discription: 'ショップ3の説明',
      position: {
        lat: 35.712260,
        lng: 139.757228
      }
    },
    {
      name: 'ショップ4',
      discription: 'ショップ4の説明',
      position: {
        lat: 35.713260,
        lng: 139.747228
      }
    },
    {
      name: 'ショップ5',
      discription: 'ショップ5の説明',
      position: {
        lat: 35.714260,
        lng: 139.737228
      }
    }
  ];
  
  for(let i = 0; i < obj.length; i++) {
    // markerのDOMを生成
	  let infoboxMarkerElem = `<div id="js-marker-${i + 1}" class="infobox-marker"><span>${i + 1}</span></div>`;

	  // infobox用のDOMを生成
	  let infoboxElem = `<div class="gmap-info-window-inner">
<p class="gmap-info-window-title">${obj[i].name}</p>
<p class="gmap-info-window-address">${obj[i].discription}</p>
</div>`;
    
    let markerLatlng = new google.maps.LatLng(obj[i].position);
    
    // infoboxのオプション
    let infoMarkerOptions = {
      content: infoboxMarkerElem, // 生成したDOMを割り当てる
      pixelOffset: new google.maps.Size(0, 0), // オフセット値
      alignBottom: true, // 位置の基準
      position: markerLatlng, // 位置の座標
      boxClass: "gmap-info-window-marker", // 生成したDOMをラップするdivのclass名
      closeBoxURL: ''
    };

    // infoboxのオプション
    let infoboxOptions = {
      content: infoboxElem, // 生成したDOMを割り当てる
      pixelOffset: new google.maps.Size(-110, -40), // オフセット値
      alignBottom: true, // 位置の基準
      position: markerLatlng, // 位置の座標
      boxClass: "gmap-info-window", // 生成したDOMをラップするdivのclass名
      closeBoxMargin: "-15px -20px 0px 0px", // 閉じるボタンの位置調整
      closeBoxURL: 'https://82mou.github.io/infobox/img/close.png' // 閉じるボタンの画像パス
    };
    // infoboxを生成して表示
    let infoboxMarker = new InfoBox(infoMarkerOptions);
    infobox[i] = new InfoBox(infoboxOptions);

    // infoboxを表示
    infoboxMarker.open(map);

    map.addListener('tilesloaded', () => {
      let $marker = document.querySelector(`#js-marker-${i + 1}`);
      google.maps.event.addDomListener($marker, 'click', (event) => {
        hiddenAll();
        infobox[i].open(map);
      });
    });
  }
}

$(window).on('load', function() {
  makeInfobox();
});
              
            
!
999px

Console