WorldWind.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
  2. * full list of contributors). Published under the 2-clause BSD license.
  3. * See license.txt in the OpenLayers distribution or repository for the
  4. * full text of the license. */
  5. /**
  6. * @requires OpenLayers/Layer/Grid.js
  7. */
  8. /**
  9. * Class: OpenLayers.Layer.WorldWind
  10. *
  11. * Inherits from:
  12. * - <OpenLayers.Layer.Grid>
  13. */
  14. OpenLayers.Layer.WorldWind = OpenLayers.Class(OpenLayers.Layer.Grid, {
  15. DEFAULT_PARAMS: {
  16. },
  17. /**
  18. * APIProperty: isBaseLayer
  19. * {Boolean} WorldWind layer is a base layer by default.
  20. */
  21. isBaseLayer: true,
  22. /**
  23. * APIProperty: lzd
  24. * {Float} LevelZeroTileSizeDegrees
  25. */
  26. lzd: null,
  27. /**
  28. * APIProperty: zoomLevels
  29. * {Integer} Number of zoom levels.
  30. */
  31. zoomLevels: null,
  32. /**
  33. * Constructor: OpenLayers.Layer.WorldWind
  34. *
  35. * Parameters:
  36. * name - {String} Name of Layer
  37. * url - {String} Base URL
  38. * lzd - {Float} Level zero tile size degrees
  39. * zoomLevels - {Integer} number of zoom levels
  40. * params - {Object} additional parameters
  41. * options - {Object} additional options
  42. */
  43. initialize: function(name, url, lzd, zoomLevels, params, options) {
  44. this.lzd = lzd;
  45. this.zoomLevels = zoomLevels;
  46. var newArguments = [];
  47. newArguments.push(name, url, params, options);
  48. OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
  49. this.params = OpenLayers.Util.applyDefaults(
  50. this.params, this.DEFAULT_PARAMS
  51. );
  52. },
  53. /**
  54. * Method: getZoom
  55. * Convert map zoom to WW zoom.
  56. */
  57. getZoom: function () {
  58. var zoom = this.map.getZoom();
  59. var extent = this.map.getMaxExtent();
  60. zoom = zoom - Math.log(this.maxResolution / (this.lzd/512))/Math.log(2);
  61. return zoom;
  62. },
  63. /**
  64. * Method: getURL
  65. *
  66. * Parameters:
  67. * bounds - {<OpenLayers.Bounds>}
  68. *
  69. * Returns:
  70. * {String} A string with the layer's url and parameters and also the
  71. * passed-in bounds and appropriate tile size specified as
  72. * parameters
  73. */
  74. getURL: function (bounds) {
  75. bounds = this.adjustBounds(bounds);
  76. var zoom = this.getZoom();
  77. var extent = this.map.getMaxExtent();
  78. var deg = this.lzd/Math.pow(2,this.getZoom());
  79. var x = Math.floor((bounds.left - extent.left)/deg);
  80. var y = Math.floor((bounds.bottom - extent.bottom)/deg);
  81. if (this.map.getResolution() <= (this.lzd/512)
  82. && this.getZoom() <= this.zoomLevels) {
  83. return this.getFullRequestString(
  84. { L: zoom,
  85. X: x,
  86. Y: y
  87. });
  88. } else {
  89. return OpenLayers.Util.getImageLocation("blank.gif");
  90. }
  91. },
  92. CLASS_NAME: "OpenLayers.Layer.WorldWind"
  93. });