<?php
	require("../__common__/__define_common.php");

	if (!defined("GOOGLE_API_KEY")) {
		define("GOOGLE_API_KEY", "ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q");
	}
	if (!defined("GOOGLE_MAPS_EARTH_ADDRESS")) {
		define("GOOGLE_MAPS_EARTH_ADDRESS", "東京タワー");
	}
	if (!defined("GOOGLE_MAPS_EARTH_ZOOM")) {
		define("GOOGLE_MAPS_EARTH_ZOOM", 15);
	}
	//define("GOOGLE_MAPS_EARTH_CENTER", "35.6894875,139.6917064");

	if ($_GET['addr'] <> '') {
		$addr = $_GET['addr'];
	} else {
		$addr = GOOGLE_MAPS_EARTH_ADDRESS;
	}
	if ($_GET['zoom'] <> '') {
		$zoom = $_GET['zoom'];
	} else {
		$zoom = GOOGLE_MAPS_EARTH_ZOOM;
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Language" content="ja">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="author" content="ok.2nd">
<title>Google Maps & Earth</title>
<script src="http://www.google.com/jsapi?key=<?= GOOGLE_API_KEY ?>"></script>
<script type="text/javascript">
var map;
var ge;
var geocoder = null;
google.load("maps", "2.x");
function init() {
	map = new GMap2(document.getElementById('map3d'));
//	map.setCenter(new GLatLng(<?= GOOGLE_MAPS_EARTH_CENTER ?>), <?= $zoom ?>);
	var mapui = map.getDefaultUI();
	mapui.maptypes.physical = true;
	map.setUI(mapui);
	map.addMapType(G_SATELLITE_3D_MAP);
	GEvent.addListener(map, 'maptypechanged', function() {
		if (ge) return;
		map.getEarthInstance(function(pluginInstance) {
			ge = pluginInstance;
			doStuffWithEarth();
		});
	});
	geocoder = new GClientGeocoder();
	showAddress('<?= $addr ?>');
}
function doStuffWithEarth() {
	document.getElementById('installed-plugin-version').innerHTML = ge.getPluginVersion().toString();
}
function showAddress(address) {
	if (geocoder) {
		geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
					alert(address + " が見つかりません");
				} else {
					map.setCenter(point, <?= $zoom ?>);
				}
			}
		);
	}
}
</script>
<style type="text/css">
* { margin: 0px; padding: 0px; }
html {
	width: 100%;
	height: 100%;
	overflow: hidden;
}
body {
	margin: 5px;
	width: 100%;
	height: 100%;
	font-size: 84%;
}
#map3d {
	width: 98%;
	height: 90%;
}
input {
	font-family: "ＭＳ Ｐゴシック",arial,helvetica,clean,sans-serif;
	line-height: 1.2;
	*line-height: 1.0;
	font-size: 100%;
}
input.text {
	margin: 0px;
	padding: 1px 0 1px 0;
}
a { color: blue; }
</style>
</head>
<body onload="init()">
<form onsubmit="showAddress(this.address.value); return false">
	<input class="text" type="text" size="40" name="address" value="<?= $addr ?>">
	<input type="submit" value="地図を検索">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<a href="http://maps.google.co.jp/" target="_blank">Google マップ</a>&nbsp;&nbsp;&nbsp;&nbsp;
	<a href="http://code.google.com/intl/ja/apis/earth/" target="_blank">Google Earth API</a>
</form>
<div id="map3d"></div>
<br>
<div>Installed Plugin Version: <span id="installed-plugin-version" style="font-weight: bold;">Loading...</span></div>
</body>
</html>
