Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set zoom level for search results links based on results bounding box… #37

Merged
merged 1 commit into from
Oct 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions mbgl-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,20 @@ document.addEventListener("DOMContentLoaded", function(){
return li;
}

function BBoxToZoomLevel(bbox) {
// for now always use 13.5
return 13.5;
// This picks the largest zoom level for which one tile fits within the lon range of the bbox.
// Note: for zoom level z, one tile has width 260/2^z degrees.
// A better implementation would also look at the latitude range.
function zoomLevelForSearchResultsItem(item) {
if (!('boundingbox' in item)) {
return 13.5;
}
const lon1 = item['boundingbox'][2];
const lon2 = item['boundingbox'][3];
return 1 + Math.floor(Math.log(360/Math.abs(lon1 - lon2)) / Math.log(2));
}

function searchResultsURL(item) {
return "/#" + BBoxToZoomLevel(item) + "/" + item.lat + "/" + item.lon;
return "/#" + zoomLevelForSearchResultsItem(item) + "/" + item.lat + "/" + item.lon;
}


Expand Down