Adding reverselookup to override query
This commit is contained in:
parent
172e99629b
commit
0e53e41a0e
|
@ -71,7 +71,7 @@
|
||||||
var map = L.map('map').setView([51.505, -0.09], 2);
|
var map = L.map('map').setView([51.505, -0.09], 2);
|
||||||
L.tileLayer('http://{s}.tile.cloudmade.com/4be2d4a8b7ae4a5e8ebc0558bb5d7db4/997/256/{z}/{x}/{y}.png', {
|
L.tileLayer('http://{s}.tile.cloudmade.com/4be2d4a8b7ae4a5e8ebc0558bb5d7db4/997/256/{z}/{x}/{y}.png', {
|
||||||
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>',
|
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>',
|
||||||
maxZoom: 18
|
maxZoom: 16
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
// Get url params
|
// Get url params
|
||||||
|
|
92
print.html
92
print.html
|
@ -80,26 +80,32 @@
|
||||||
params[tmparr[0]] = tmparr[1];
|
params[tmparr[0]] = tmparr[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
var query = decodeURIComponent(params["q"]);
|
var query = "";
|
||||||
var map = L.map('map', {zoomControl: false}); //.setView([51.505, -0.09], 13);
|
var map = L.map('map', {zoomControl: false}); //.setView([51.505, -0.09], 13);
|
||||||
L.tileLayer('http://{s}.tile.cloudmade.com/4be2d4a8b7ae4a5e8ebc0558bb5d7db4/997/256/{z}/{x}/{y}.png', {
|
|
||||||
attribution: query+' map from PrintMaps.com; 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>',
|
if(params["q"]){
|
||||||
maxZoom: 18
|
window.query = decodeURIComponent(params["q"]);
|
||||||
}).addTo(map);
|
updateTitle(window.query);
|
||||||
|
}
|
||||||
|
|
||||||
// decode query param
|
// decode query param
|
||||||
if( params["b0"] && params["b1"] && params["b2"] && params["b3"]){
|
if(params["b0"] && params["b1"] && params["b2"] && params["b3"]){
|
||||||
updateMap(query,[[decodeURIComponent(params["b0"]), decodeURIComponent(params["b1"])],
|
|
||||||
|
// Update the map
|
||||||
|
updateMap([[decodeURIComponent(params["b0"]), decodeURIComponent(params["b1"])],
|
||||||
[decodeURIComponent(params["b2"]), decodeURIComponent(params["b3"])]]);
|
[decodeURIComponent(params["b2"]), decodeURIComponent(params["b3"])]]);
|
||||||
|
|
||||||
|
// Figure out what the actual name of this place is
|
||||||
|
var latavg = (parseFloat(decodeURIComponent(params["b0"]))+parseFloat(decodeURIComponent(params["b2"])))/2;
|
||||||
|
var lonavg = (parseFloat(decodeURIComponent(params["b1"]))+parseFloat(decodeURIComponent(params["b3"])))/2;
|
||||||
|
doReverseLookup(latavg, lonavg, map.getZoom());
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
alert("No boundaries given!");
|
alert("No boundaries given!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateMap(bounds){
|
||||||
function updateMap(query,bounds){
|
|
||||||
// Generate title
|
|
||||||
document.title = query + " map";
|
|
||||||
// Fit map to the GPS boundaries
|
// Fit map to the GPS boundaries
|
||||||
map.fitBounds(bounds);
|
map.fitBounds(bounds);
|
||||||
};
|
};
|
||||||
|
@ -120,6 +126,70 @@
|
||||||
},2000);
|
},2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function doReverseLookup(lat, lon, zoom){
|
||||||
|
|
||||||
|
// AJAX request for checking where we are
|
||||||
|
reverseLookup(lat,lon,zoom,function(xmlhttp) {
|
||||||
|
// Decode response as JSON
|
||||||
|
response = JSON.parse(xmlhttp.responseText);
|
||||||
|
|
||||||
|
if(response.address){
|
||||||
|
console.log(response.address);
|
||||||
|
console.log(zoom);
|
||||||
|
var loc = [];
|
||||||
|
// Set search textbox to where we think we are
|
||||||
|
if(response.address.suburb && zoom > 14){
|
||||||
|
loc.push(response.address.suburb);
|
||||||
|
}
|
||||||
|
if(response.address.city && zoom > 9){
|
||||||
|
loc.push(response.address.city);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(response.address.county && zoom > 9){
|
||||||
|
loc.push(response.address.county+" County");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(response.address.state && zoom >= 8){
|
||||||
|
loc.push(response.address.state);
|
||||||
|
}
|
||||||
|
if(response.address.country && zoom <= 8){
|
||||||
|
loc.push(response.address.country);
|
||||||
|
}
|
||||||
|
window.query = loc.join(", ");
|
||||||
|
updateTitle(window.query);
|
||||||
|
setTileLayer(window.query);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
console.log("No reverse-lookup json");
|
||||||
|
setTileLayer(window.query);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function reverseLookup(lat,lon,zoom,callback){
|
||||||
|
xmlhttp=new XMLHttpRequest();
|
||||||
|
request = "http://nominatim.openstreetmap.org/reverse?format=json&lat="+encodeURIComponent(lat)+"&lon="+encodeURIComponent(lon)+"&zoom="+encodeURIComponent(zoom);
|
||||||
|
xmlhttp.open("GET",request,true);
|
||||||
|
xmlhttp.send();
|
||||||
|
xmlhttp.onreadystatechange = function(){
|
||||||
|
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
|
||||||
|
callback(xmlhttp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateTitle(title){
|
||||||
|
// Generate title
|
||||||
|
document.title = query + " map";
|
||||||
|
}
|
||||||
|
|
||||||
|
function setTileLayer(query){
|
||||||
|
L.tileLayer('http://{s}.tile.cloudmade.com/4be2d4a8b7ae4a5e8ebc0558bb5d7db4/997/256/{z}/{x}/{y}.png', {
|
||||||
|
attribution: query+' map from PrintMaps.com; 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>',
|
||||||
|
maxZoom: 18
|
||||||
|
}).addTo(map);
|
||||||
|
}
|
||||||
|
|
||||||
function halveMap(){
|
function halveMap(){
|
||||||
|
|
||||||
resizeScale = 0.281; // magic number that seems to work best in Chrome
|
resizeScale = 0.281; // magic number that seems to work best in Chrome
|
||||||
|
|
Loading…
Reference in New Issue
Block a user