Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
66 lines (60 sloc) 1.55 KB
<html>
<head>
<title>Controling Maps</title>
<script type="text/javascript" src="./socket.io/socket.io.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
// Socket.IO
var socket = io.connect('http://chocolate.local', {port:4126});
var map;
var ct = new google.maps.LatLng(35.704269,139.751973);
// Google Maps API
function initMaps(){
var mapdiv = document.getElementById("data");
mapdiv.style.width = '100%';
mapdiv.style.height = '100%';
var startOptions = {
zoom: 18,
center: ct,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(mapdiv, startOptions);
/*google.maps.event.addListner(map, 'idle', function(){
map.setCenter(ct);
});*/
}
// Socket.IO
socket.on('message', function(data){
var c = map.getCenter();
switch(data.state){
case 'X':
//console.log(c);
//console.log(c.lat());
var newCenter = google.maps.LatLng(
c.lat(),
c.lng()+data.value
);
map.panTo(newCenter);
ct = newCenter;
break;
case 'Y':
var newCenter = google.maps.LatLng(
c.lat()+data.value,
c.lng()
);
//map.setCenter(newCenter);
ct = newCenter;
break;
case 'Z':
map.setZoom(Math.round(data.value));
break;
default:
break;
}
});
</script>
</head>
<body id="back" onload="initMaps()">
<div id="data" ></div>
</body>
</html>