2013-07-29 02:19:42 +00:00
|
|
|
<!DOCTYPE html>
|
2013-07-27 22:30:25 +00:00
|
|
|
<html>
|
|
|
|
<head>
|
2013-07-29 02:19:42 +00:00
|
|
|
<meta charset="UTF-8">
|
2013-07-29 01:13:03 +00:00
|
|
|
<title>Printable High-Resolution Maps!</title>
|
2013-07-27 22:30:25 +00:00
|
|
|
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
|
|
|
|
<!--[if lte IE 8]>
|
|
|
|
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.ie.css" />
|
|
|
|
<![endif]-->
|
|
|
|
<style type="text/css">
|
2013-07-29 01:13:03 +00:00
|
|
|
#navigation {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
2013-07-29 02:03:09 +00:00
|
|
|
z-index: 9999;
|
2013-07-29 01:13:03 +00:00
|
|
|
background-color: white;
|
|
|
|
font-family: Arial, Helvetica, sans-serif;
|
|
|
|
padding: 1em;
|
2013-07-29 02:03:09 +00:00
|
|
|
width: 15em;
|
|
|
|
height: 612px;
|
|
|
|
overflow-y: auto;
|
|
|
|
opacity: 0.8;
|
2013-07-29 01:13:03 +00:00
|
|
|
}
|
2013-07-29 02:03:09 +00:00
|
|
|
#printbutton {
|
|
|
|
font-size: 1.5em;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
2013-07-28 06:34:38 +00:00
|
|
|
#map {
|
2013-07-29 02:03:09 +00:00
|
|
|
padding: 1em;
|
|
|
|
border: 1px solid black;
|
2013-07-28 23:34:21 +00:00
|
|
|
height: 612px; /* 8.5 inch at 72 dpi */
|
|
|
|
width: 792px; /* 11 inch at 72 dpi */
|
2013-07-28 06:34:38 +00:00
|
|
|
}
|
|
|
|
#results {
|
2013-07-29 01:13:03 +00:00
|
|
|
margin: 0 0 0 1em;
|
|
|
|
padding: 0;
|
2013-07-28 06:34:38 +00:00
|
|
|
}
|
|
|
|
#results li span {
|
|
|
|
cursor: pointer;
|
|
|
|
color: blue;
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
|
|
|
.active_result {
|
|
|
|
background-color: #eee;
|
|
|
|
}
|
2013-07-27 22:30:25 +00:00
|
|
|
</style>
|
|
|
|
|
2013-07-29 02:19:42 +00:00
|
|
|
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
|
|
|
|
|
2013-07-27 22:30:25 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
2013-07-29 01:13:03 +00:00
|
|
|
<div id="navigation">
|
|
|
|
<form method="get" action="#" id="search_form">
|
2013-07-29 03:06:51 +00:00
|
|
|
<input type="text" id="q" name="q" value="" /><input type="submit" value="Search" />
|
2013-07-29 01:13:03 +00:00
|
|
|
</form>
|
2013-07-29 02:03:09 +00:00
|
|
|
<input type="button" id="printbutton" value="Print" onclick="printMap()" />
|
|
|
|
<h2>Printable High-Resolution Maps!</h2>
|
|
|
|
<ol>
|
|
|
|
<li>Search/center/zoom this map until it covers the desired area.</li>
|
|
|
|
<li>Click the Print button above.</li>
|
|
|
|
<li>A new window will open with a high-resolution map!</li>
|
|
|
|
</ol>
|
2013-07-29 01:13:03 +00:00
|
|
|
<ul id="results"></ul>
|
|
|
|
</div>
|
2013-07-28 10:29:24 +00:00
|
|
|
|
2013-07-27 23:40:21 +00:00
|
|
|
<div id="map"></div>
|
|
|
|
|
2013-07-27 22:30:25 +00:00
|
|
|
<script type="text/javascript">
|
2013-07-28 08:07:10 +00:00
|
|
|
|
|
|
|
var query = "";
|
|
|
|
var map = L.map('map'); //.setView([51.505, -0.09], 13);
|
2013-07-27 22:30:25 +00:00
|
|
|
L.tileLayer('http://{s}.tile.cloudmade.com/4be2d4a8b7ae4a5e8ebc0558bb5d7db4/997/256/{z}/{x}/{y}.png', {
|
2013-07-29 02:03:09 +00:00
|
|
|
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>; Imagery © <a href="http://cloudmade.com">CloudMade</a>',
|
2013-07-27 22:30:25 +00:00
|
|
|
maxZoom: 18
|
|
|
|
}).addTo(map);
|
2013-07-27 23:40:21 +00:00
|
|
|
|
|
|
|
// Get url params
|
|
|
|
var prmstr = window.location.search.substr(1);
|
|
|
|
var prmarr = prmstr.split ("&");
|
|
|
|
var params = {};
|
|
|
|
for ( var i = 0; i < prmarr.length; i++) {
|
|
|
|
var tmparr = prmarr[i].split("=");
|
|
|
|
params[tmparr[0]] = tmparr[1];
|
|
|
|
}
|
|
|
|
|
2013-07-28 06:34:38 +00:00
|
|
|
// decode query param
|
2013-07-28 08:07:10 +00:00
|
|
|
if(params["q"] && params["q"].length > 0){
|
|
|
|
handleQuery(decodeURIComponent(params["q"]).replace(/\+/g, ' '));
|
|
|
|
}
|
2013-07-28 08:45:08 +00:00
|
|
|
else {
|
2013-07-28 08:07:10 +00:00
|
|
|
if (navigator.geolocation)
|
|
|
|
{
|
|
|
|
navigator.geolocation.getCurrentPosition(function(pos){
|
2013-07-28 08:45:08 +00:00
|
|
|
// Move the map over
|
|
|
|
map.setView([pos.coords.latitude,pos.coords.longitude],12);
|
|
|
|
|
2013-07-28 08:07:10 +00:00
|
|
|
// AJAX request for checking where we are
|
2013-07-28 08:45:08 +00:00
|
|
|
reverseLookup(pos.coords.latitude,pos.coords.longitude,18,function(xmlhttp) {
|
2013-07-28 08:07:10 +00:00
|
|
|
// Decode response as JSON
|
|
|
|
response = JSON.parse(xmlhttp.responseText);
|
2013-07-28 00:22:29 +00:00
|
|
|
|
2013-07-28 08:45:08 +00:00
|
|
|
if(response.address){
|
|
|
|
console.log(response.address);
|
|
|
|
var loc = "";
|
|
|
|
// Set search textbox to where we think we are
|
|
|
|
if(response.address.suburb){
|
|
|
|
loc += response.address.suburb+", ";
|
|
|
|
}
|
|
|
|
if(response.address.city){
|
|
|
|
loc += response.address.city+", ";
|
|
|
|
}
|
|
|
|
if(response.address.state){
|
|
|
|
loc += response.address.state+", ";
|
|
|
|
}
|
|
|
|
if(response.address.country){
|
|
|
|
loc += response.address.country+", ";
|
|
|
|
}
|
|
|
|
document.getElementById("q").value = loc;
|
2013-07-28 08:07:10 +00:00
|
|
|
}
|
2013-07-28 08:45:08 +00:00
|
|
|
else{
|
|
|
|
console.log("No reverse-lookup json");
|
|
|
|
}
|
2013-07-28 08:07:10 +00:00
|
|
|
});
|
|
|
|
},function(error){
|
|
|
|
console.log(error);
|
|
|
|
updateMap("Tempe, Arizona",[[33.6569,-111.6801],[33.3133,-112.3276]])
|
2013-07-28 10:29:24 +00:00
|
|
|
window.query = "Tempe, Arizona";
|
2013-07-28 08:07:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
updateMap("Tempe, Arizona",[[33.6569,-111.6801],[33.3133,-112.3276]])
|
2013-07-28 10:29:24 +00:00
|
|
|
window.query = "Tempe, Arizona";
|
2013-07-28 08:07:10 +00:00
|
|
|
}
|
2013-07-28 00:22:29 +00:00
|
|
|
}
|
2013-07-27 23:40:21 +00:00
|
|
|
|
2013-07-28 08:07:10 +00:00
|
|
|
function handleQuery(query){
|
|
|
|
window.query = query;
|
|
|
|
// AJAX request for geolocation of query
|
|
|
|
forwardLookup(query,function(xmlhttp) {
|
|
|
|
// Decode response as JSON
|
2013-07-27 23:40:21 +00:00
|
|
|
response = JSON.parse(xmlhttp.responseText);
|
|
|
|
|
2013-07-28 06:34:38 +00:00
|
|
|
if(response.length > 0){
|
|
|
|
// Display all results in sidebar
|
|
|
|
response.forEach(function(result,index){
|
|
|
|
appendToResults(index,result.display_name);
|
|
|
|
});
|
2013-07-27 23:40:21 +00:00
|
|
|
|
2013-07-28 06:34:38 +00:00
|
|
|
// Fit map to bounds of first result
|
|
|
|
showItem(0);
|
|
|
|
}
|
|
|
|
else {
|
2013-07-28 08:07:10 +00:00
|
|
|
appendToResults("No Results");
|
2013-07-28 06:34:38 +00:00
|
|
|
}
|
2013-07-28 08:07:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function forwardLookup(query,callback){
|
|
|
|
xmlhttp=new XMLHttpRequest();
|
|
|
|
xmlhttp.open("GET","http://nominatim.openstreetmap.org/search/"+encodeURIComponent(query)+"?format=json",true);
|
|
|
|
xmlhttp.send();
|
2013-07-28 08:45:08 +00:00
|
|
|
xmlhttp.onreadystatechange = function(){
|
2013-07-28 08:07:10 +00:00
|
|
|
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
|
|
|
|
callback(xmlhttp);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-07-28 08:45:08 +00:00
|
|
|
function reverseLookup(lat,lon,zoom,callback){
|
2013-07-28 08:07:10 +00:00
|
|
|
xmlhttp=new XMLHttpRequest();
|
2013-07-28 08:45:08 +00:00
|
|
|
request = "http://nominatim.openstreetmap.org/reverse?format=json&lat="+encodeURIComponent(lat)+"&lon="+encodeURIComponent(lon)+"&zoom="+encodeURIComponent(zoom);
|
|
|
|
xmlhttp.open("GET",request,true);
|
2013-07-28 08:07:10 +00:00
|
|
|
xmlhttp.send();
|
2013-07-28 08:45:08 +00:00
|
|
|
xmlhttp.onreadystatechange = function(){
|
2013-07-28 08:07:10 +00:00
|
|
|
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
|
2013-07-28 08:45:08 +00:00
|
|
|
callback(xmlhttp);
|
2013-07-28 08:07:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-07-28 06:34:38 +00:00
|
|
|
function appendToResults(index,name){
|
|
|
|
var item = document.createElement("li");
|
|
|
|
item.innerHTML = "<span onclick=\"showItem('"+index+"');\">"+name+'</span>';
|
|
|
|
item.id = "result_"+index;
|
|
|
|
document.getElementById("results").appendChild(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
function showItem(index){
|
|
|
|
// Change this item to be the active one
|
|
|
|
var results = document.getElementsByClassName("active_result")
|
|
|
|
for(var i=0; i < results.length; i++){
|
|
|
|
console.log(i);
|
|
|
|
results[i].className = "";
|
|
|
|
}
|
|
|
|
document.getElementById("result_"+index).className = "active_result";
|
|
|
|
|
2013-07-28 08:07:10 +00:00
|
|
|
// Update the map
|
|
|
|
updateMap(query,[[response[index].boundingbox[0], response[index].boundingbox[2]],
|
|
|
|
[response[index].boundingbox[1], response[index].boundingbox[3]]]);
|
2013-07-28 06:34:38 +00:00
|
|
|
}
|
|
|
|
|
2013-07-28 08:07:10 +00:00
|
|
|
function updateMap(query,bounds){
|
|
|
|
// Set search textbox to query
|
|
|
|
document.getElementById("q").value = query;
|
|
|
|
|
|
|
|
// Fit map to the GPS boundaries
|
|
|
|
map.fitBounds(bounds);
|
2013-07-28 10:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function printMap(){
|
|
|
|
var bounds = map.getBounds();
|
|
|
|
newwindow=window.open("print.html?q="+query
|
|
|
|
+"&b0="+bounds._northEast.lat
|
|
|
|
+"&b1="+bounds._northEast.lng
|
|
|
|
+"&b2="+bounds._southWest.lat
|
|
|
|
+"&b3="+bounds._southWest.lng
|
|
|
|
,'name');
|
|
|
|
if (window.focus) {newwindow.focus()}
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-28 08:07:10 +00:00
|
|
|
|
2013-07-27 22:30:25 +00:00
|
|
|
</script>
|
2013-07-27 23:40:21 +00:00
|
|
|
|
2013-07-29 03:04:08 +00:00
|
|
|
<script>
|
|
|
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
|
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
|
|
|
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
|
|
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
|
|
|
|
|
|
|
ga('create', 'UA-42790423-1', 'zyphlar.github.io');
|
|
|
|
ga('send', 'pageview');
|
|
|
|
|
|
|
|
</script>
|
2013-07-27 22:30:25 +00:00
|
|
|
</body>
|
|
|
|
</html>
|