Skip to content

Instantly share code, notes, and snippets.

@alexeagle
Created January 16, 2011 02:44
Show Gist options
  • Save alexeagle/781497 to your computer and use it in GitHub Desktop.
Save alexeagle/781497 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(37.7166, -122.283);
var zoom = 9;
var myOptions = {
zoom: zoom,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var move = function(data) {
// console.log("got data: " + data.x + "," + data.y + ", " + data.z);
if (data.z > 0.3 && data.z < 0.7) {
// pan mode
var zoomMultiplier = 200 * Math.exp(-.7820260166 * zoom);
var up = data.y < 0.0;
var down = data.y > 0.8;
var left = data.x < 0;
var right = data.x > 0.5;
var lat = latlng.lat();
var lng = latlng.lng();
if (up) {
lat += zoomMultiplier;
}
if (down) {
lat -= zoomMultiplier;
}
if (left) {
lng -= zoomMultiplier;
}
if (right) {
lng += zoomMultiplier;
}
latlng = new google.maps.LatLng(lat, lng);
map.panTo(latlng);
} else {
// zoom mode
if (data.z > 0.7) {
zoom -= 0.1;
} else {
zoom += 0.1;
}
if (zoom > 20) zoom = 20;
if (zoom < 4) zoom = 4;
map.setZoom(Math.round(zoom));
}
}
initDepthJs(move);
}
function initDepthJs(move) {
var $DepthJS_eventPort = $("#DepthJS_eventPort");
var eventHandler = function(callback) {
return function() {
var jsonRep = $DepthJS_eventPort.text();
var msg = JSON.parse(jsonRep);
callback(msg.data);
};
};
if ($DepthJS_eventPort.length > 0) {
console.log("Binding to eventPort");
setInterval(eventHandler(move), 100);
// $DepthJS_eventPort.bind("Move", eventHandler(move));
} else {
// This is created on document_end, so it may/may not be avail the first time
setTimeout(initDepthJs(move), 100);
}
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment