﻿var SetGmaps = {
	
	mark: [
		{
			latlng: [35.008587, 135.767727],
			iconsrc: './img/gmap_icon.png',
			html: '<img src="./img/footer.gif" alt="JEUGIA(ジュージヤ)三条本店" />'
		}, {
			latlng: [35.008713, 135.766342],
			iconsrc: './img/gmap_parking_icon.png',
			html: '<strong>三条パーキング</strong><br />御幸町三条・入庫は御池通からの南向き一方通行になります'
		}, {
			latlng: [35.007235, 135.764601],
			iconsrc: './img/gmap_parking_icon.png',
			html: '<strong>駐輪所</strong><br />京都市中京区六角通柳馬場東入る大黒町81'
		}
	],
	
	init: function() {
		
		var gmap = new GMap2(document.getElementById('gmaps'));
		
		// gmap.setCenter(new GLatLng(this.mark[0].latlng[0], this.mark[0].latlng[1]), 17);
		gmap.setCenter(new GLatLng(35.009058, 135.767337), 17);
		// gmap.addControl(new GMapTypeControl());
		gmap.addControl(new GSmallMapControl());
		
		for (var i = 0, l = this.mark.length; i < l; i++) {
			
			gmap.addOverlay(this.createGmarker(gmap, i));
			
		}
		
		// 住所から緯度、経度を求める
		// this.getGeoCoder(gmap, '京都市中京区六角通柳馬場東入る大黒町81');
	},

	createGmarker: function(g, i) {
		
		var m = this.mark[i];
		// Icon
		var markerOpt = { icon: this.createGIcon(m.iconsrc) };
		
		var marker = new GMarker(new GLatLng(m.latlng[0], m.latlng[1]), markerOpt);
		// infoWindow 幅の指定
		var infoWindowOpt = g.getInfoWindow();
		infoWindowOpt.maxWidth = 130;
		
		GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(m.html, infoWindowOpt); });
		
		return marker;
		
	},

	createGIcon: function(src) {
		
		var icon = new GIcon(G_DEFAULT_ICON);
		icon.image = src;
		icon.shadow = './img/gmap_shadow.png';
		icon.iconSize = new GSize(25, 32);
		icon.shadowSize = new GSize(25, 38);
		icon.iconAnchor = new GPoint(13, 32);
		
		return icon;
		
	},
	
	getGeoCoder: function(g, address) {
		
		var geocoder = new GClientGeocoder();
		geocoder.getLatLng(address, function(e) {
			if (e != null) {
				prompt(address, e);
				g.panTo(e);
			} else {
				alert('指定した住所はありません\n' + address);
			}
		});
		
	}
	
};

