Browse Source

updating getPrecision() to handle null/undefined/empty zoom params

pull/24/head
Harish Krishna 10 years ago
parent
commit
0abe345c1c
  1. 16
      query/suggest.js
  2. 4
      test/unit/query/suggest.js

16
query/suggest.js

@ -6,16 +6,16 @@ function generate( params ){
var getPrecision = function(zoom) { var getPrecision = function(zoom) {
switch (true) { switch (true) {
case (zoom < 4): case (zoom > 15):
return 1; // zoom: 1-3 return 5; // zoom: >= 16
case (zoom < 6): case (zoom > 9):
return 2; // zoom: 4-5
case (zoom < 10):
return 3; // zoom: 6-9
case (zoom < 16):
return 4; // zoom: 10-15 return 4; // zoom: 10-15
case (zoom > 5):
return 3; // zoom: 6-9
case (zoom > 3):
return 2; // zoom: 4-5
default: default:
return 5; // zoom: >= 16 return 1; // zoom: 1-3 or when zoom: undefined
} }
}; };

4
test/unit/query/suggest.js

@ -59,7 +59,9 @@ module.exports.tests.precision = function(test, common) {
{zoom:17, precision:5}, {zoom:17, precision:5},
{zoom:18, precision:5}, {zoom:18, precision:5},
{zoom:19, precision:5}, {zoom:19, precision:5},
{zoom:20, precision:5} {zoom:'', precision:1},
{zoom:null, precision:1},
{zoom:undefined, precision:1}
]; ];
test_cases.forEach( function( test_case ){ test_cases.forEach( function( test_case ){

Loading…
Cancel
Save