Skip to content

Commit

Permalink
Avoid bbox too small and camera too close to the ground in NominatimS…
Browse files Browse the repository at this point in the history
…earch.
  • Loading branch information
glughi committed Feb 27, 2019
1 parent 046f0ef commit 1c4cd57
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions lib/ViewModels/NominatimSearchProviderViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,41 @@ NominatimSearchProviderViewModel.prototype.search = function(searchText) {

function createZoomToFunction(viewModel, resource) {
var bbox = resource.boundingbox;
var south = bbox[0];
var west = bbox[2];
var north = bbox[1];
var east = bbox[3];

// Parse string to float
var south = parseFloat(bbox[0]);
var west = parseFloat(bbox[2]);
var north = parseFloat(bbox[1]);
var east = parseFloat(bbox[3]);

// Avoids the bbox is too small and camera too close to the ground
const delta = 0.001;
if(Math.abs(south - north) <= delta)
{
if(south > north)
{
south += delta;
north -= delta;
}
else
{
south -= delta;
north += delta;
}
}
if(Math.abs(east - west) <= delta)
{
if(east > west)
{
east += delta;
west -= delta;
}
else
{
east -= delta;
west += delta;
}
}

var rectangle = Rectangle.fromDegrees(west, south, east, north);

Expand Down

0 comments on commit 1c4cd57

Please sign in to comment.