Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

index.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (factory((global.WhooTS = {})));
  5. }(this, (function (exports) {
  6. /**
  7. * getURL
  8. *
  9. * @param {String} baseUrl Base url of the WMS server
  10. * @param {String} layer Layer name
  11. * @param {Number} x Tile coordinate x
  12. * @param {Number} y Tile coordinate y
  13. * @param {Number} z Tile zoom
  14. * @param {Object} [options]
  15. * @param {String} [options.format='image/png']
  16. * @param {String} [options.service='WMS']
  17. * @param {String} [options.version='1.1.1']
  18. * @param {String} [options.request='GetMap']
  19. * @param {String} [options.srs='EPSG:3857']
  20. * @param {Number} [options.width='256']
  21. * @param {Number} [options.height='256']
  22. * @returns {String} url
  23. * @example
  24. * var baseUrl = 'http://geodata.state.nj.us/imagerywms/Natural2015';
  25. * var layer = 'Natural2015';
  26. * var url = whoots.getURL(baseUrl, layer, 154308, 197167, 19);
  27. */
  28. function getURL(baseUrl, layer, x, y, z, options) {
  29. options = options || {};
  30. var url = baseUrl + '?' + [
  31. 'bbox=' + getTileBBox(x, y, z),
  32. 'format=' + (options.format || 'image/png'),
  33. 'service=' + (options.service || 'WMS'),
  34. 'version=' + (options.version || '1.1.1'),
  35. 'request=' + (options.request || 'GetMap'),
  36. 'srs=' + (options.srs || 'EPSG:3857'),
  37. 'width=' + (options.width || 256),
  38. 'height=' + (options.height || 256),
  39. 'layers=' + layer
  40. ].join('&');
  41. return url;
  42. }
  43. /**
  44. * getTileBBox
  45. *
  46. * @param {Number} x Tile coordinate x
  47. * @param {Number} y Tile coordinate y
  48. * @param {Number} z Tile zoom
  49. * @returns {String} String of the bounding box
  50. */
  51. function getTileBBox(x, y, z) {
  52. // for Google/OSM tile scheme we need to alter the y
  53. y = (Math.pow(2, z) - y - 1);
  54. var min = getMercCoords(x * 256, y * 256, z),
  55. max = getMercCoords((x + 1) * 256, (y + 1) * 256, z);
  56. return min[0] + ',' + min[1] + ',' + max[0] + ',' + max[1];
  57. }
  58. /**
  59. * getMercCoords
  60. *
  61. * @param {Number} x Pixel coordinate x
  62. * @param {Number} y Pixel coordinate y
  63. * @param {Number} z Tile zoom
  64. * @returns {Array} [x, y]
  65. */
  66. function getMercCoords(x, y, z) {
  67. var resolution = (2 * Math.PI * 6378137 / 256) / Math.pow(2, z),
  68. merc_x = (x * resolution - 2 * Math.PI * 6378137 / 2.0),
  69. merc_y = (y * resolution - 2 * Math.PI * 6378137 / 2.0);
  70. return [merc_x, merc_y];
  71. }
  72. exports.getURL = getURL;
  73. exports.getTileBBox = getTileBBox;
  74. exports.getMercCoords = getMercCoords;
  75. Object.defineProperty(exports, '__esModule', { value: true });
  76. })));