Code coverage report for osm-build-query/index.js

Statements: 100% (20 / 20)      Branches: 100% (0 / 0)      Functions: 100% (1 / 1)      Lines: 100% (20 / 20)      Ignored: none     

All files » osm-build-query/ » index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48          1 1 1 1 1 1 1 1 1   1 5 5     1 1   1 1   1       1                   1           1  
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 
var OSMBuildQuery = function(key, bounds) {
   var bbox; // (lower lat., lower lon., upper lat., upper lon.)
   var lat = [];
   var lon = [];
   var coordinates = bounds.geometry.coordinates[0];
   var lowerLat;
   var lowerLon;
   var upperLat;
   var upperLon;
 
   for (var c = 0; c < coordinates.length; c++) {
      lon.push(coordinates[c][0]);
      lat.push(coordinates[c][1]);
   }
 
   lowerLat = Math.min.apply(Math, lat);
   upperLat = Math.max.apply(Math, lat);
 
   lowerLon = Math.min.apply(Math, lon);
   upperLon = Math.max.apply(Math, lon);
 
   bbox = lowerLat + ',' + lowerLon + ',' + upperLat + ',' + upperLon;
 
   /* This query looks for nodes, ways and relations
   with the given key/value combination. */
   var query = '[out:json][timeout:90];' +
      '(' +
      'node["' + key + '"](' + bbox + ');' +
      'way["' + key + '"](' + bbox + ');' +
      'relation["' + key + '"](' + bbox + ');' +
      ');' +
      'out body;' +
      '>;' +
      'out skel qt;';
 
   return {
      data: query
   };
};
 
/** @module osm-build-query */
module.exports = OSMBuildQuery;