﻿//<![CDATA[

function load() {
if (GBrowserIsCompatible()) {
  var gmarkers = [];
  var gicons = [];
  gicons["Dj"] = new GIcon(); // 食事
  gicons["Dj"].image = "/gmp/icon/dj.png";
  gicons["Dj"].iconSize = new GSize(13,13);
  gicons["Dj"].iconAnchor = new GLatLng(6,6);
  gicons["Dj"].infoWindowAnchor = new GLatLng(2,10);
	
  gicons["Df"] = new GIcon(); // 食事
  gicons["Df"].image = "/gmp/icon/df.png";
  gicons["Df"].iconSize = new GSize(13,13);
  gicons["Df"].iconAnchor = new GLatLng(7,7);
  gicons["Df"].infoWindowAnchor = new GLatLng(4,9);
	
  gicons["Ds"] = new GIcon(); // 食事
  gicons["Ds"].image = "/gmp/icon/ds.png";
  gicons["Ds"].iconSize = new GSize(13,13);
  gicons["Ds"].iconAnchor = new GLatLng(7,7);
  gicons["Ds"].infoWindowAnchor = new GLatLng(4,9);
	
  gicons["Di"] = new GIcon(); // 食事
  gicons["Di"].image = "/gmp/icon/di.png";
  gicons["Di"].iconSize = new GSize(13,13);
  gicons["Di"].iconAnchor = new GLatLng(7,7);
  gicons["Di"].infoWindowAnchor = new GLatLng(4,9);
	
  gicons["Dc"] = new GIcon(); // 食事
  gicons["Dc"].image = "/gmp/icon/dc.png";
  gicons["Dc"].iconSize = new GSize(13,13);
  gicons["Dc"].iconAnchor = new GLatLng(7,7);
  gicons["Dc"].infoWindowAnchor = new GLatLng(4,9);
	
  gicons["Db"] = new GIcon(); // 食事
  gicons["Db"].image = "/gmp/icon/db.png";
  gicons["Db"].iconSize = new GSize(13,13);
  gicons["Db"].iconAnchor = new GLatLng(7,7);
  gicons["Db"].infoWindowAnchor = new GLatLng(4,9);
	
  gicons["ctp"] = new GIcon(); // CTP
  gicons["ctp"].image = "/gmp/icon/ctp.png";
  gicons["ctp"].iconSize = new GSize(1,1);
  gicons["ctp"].iconAnchor = new GLatLng(1,1);
  gicons["ctp"].infoWindowAnchor = new GLatLng(1,1);
  
  function createMarker(id, category, type, name, lat, lng, point, zoom, url, src, addr, tel) {
	var marker = new GMarker(point, gicons[category]);
	marker.mycategory = category;
	marker.myid = id;
	marker.mylat = lat;
	marker.mylng = lng;
	marker.myzoom = zoom;
	marker.myname = name;
	var html = "<div class='balloon'>"+type+"<br>"+name+"<br>"+addr+"<br>"+tel+"<\/div>";
	GEvent.addListener(marker, "click", function() {
	  marker.openInfoWindowHtml(html);
	});
	gmarkers.push(marker);
	return marker;
  }
  function show(id) {
	for (var i=0; i<gmarkers.length; i++) {
	  if (gmarkers[i].myid == id) {
		gmarkers[i].show();
		map.setCenter(new GLatLng(gmarkers[i].mylat, gmarkers[i].mylng), parseInt(gmarkers[i].myzoom)); // 中央座標を施設を中心にしリセット
	  }else{
		gmarkers[i].hide();
	  }
	}
  }
  function myclick(i) {
	GEvent.trigger(gmarkers[i],"click");
  }
  var map = new GMap2(document.getElementById("map"));
  map.addControl(new GLargeMapControl());
  map.addControl(new GScaleControl());
  map.addControl(new GMapTypeControl(true));
  map.setCenter(new GLatLng(34.98546, 135.758228), 10); // 初期表示の中央座標
	
	//var tilelayer = new GTileLayer(new GCopyrightCollection(), 0, 17);
	//tilelayer.getTileUrl = function(tile, zoom){
	//	return "/gmp/icon/white.png";
	//};
	//tilelayer.getOpacity = function () { return 0.0; };
	//map.addOverlay(new GTileLayerOverlay (tilelayer));
	
  GDownloadUrl("/gmp/data.xml", function(doc) { // XML 引っ張る
	var xmlDoc = GXml.parse(doc);
	var Institution = xmlDoc.documentElement.getElementsByTagName("marker");
	for (var i = 0; i < Institution.length; i++) {
	  var id = Institution[i].getAttribute("id"); // ID
	  var category = Institution[i].getAttribute("category"); // カテゴリー
	  var type = Institution[i].getAttribute("type"); // 業種
	  var name = Institution[i].getAttribute("name"); // 施設名
	  var lat = parseFloat(Institution[i].getAttribute("lat")); // 緯度
	  var lng = parseFloat(Institution[i].getAttribute("lng")); // 経度
	  var point = new GLatLng(lat,lng);
	  var zoom = Institution[i].getAttribute("zoom"); // 拡大率
	  var url = Institution[i].getAttribute("url"); // リンクURL
	  var src = Institution[i].getAttribute("src"); // 画像SRC
	  var addr = Institution[i].getAttribute("addr"); // 住所
	  var tel = Institution[i].getAttribute("tel"); // 電話番号
	  var marker = createMarker(id, category, type, name, lat, lng, point, zoom, url, src, addr, tel);
	  map.addOverlay(marker);
	}
	if (document.URL.substr(0,37) == "http://www.kyotokyoto.jp/dining_cafe/") {
	  diningID = document.URL.substr(37,5); //Dining専用
	}
	else if (document.URL.substr(0,33) == "http://kyotokyoto.jp/dining_cafe/") {
	  diningID = document.URL.substr(33,5); //Dining専用
	}
	else if (document.URL.substr(0,42) == "http://www.kyotokyoto.jp/test/dining_cafe/") {
	  diningID = document.URL.substr(42,5); //Dining専用
	}
	else if (document.URL.substr(0,38) == "http://kyotokyoto.jp/test/dining_cafe/") {
	  diningID = document.URL.substr(38,5); //Dining専用
	}
	show(diningID); // 初期表示で見せる。それ以外は隠す
  });
}
}

//]]>
