PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/ajax/libs/openlayers/2.13.1/lib/OpenLayers/Layer/KaMap.js

https://gitlab.com/Mirros/cdnjs
JavaScript | 192 lines | 75 code | 20 blank | 97 comment | 4 complexity | b622bd1d50c2b7c1d47a2c37a4d9a030 MD5 | raw file
  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.KaMap
  10. *
  11. * Inherits from:
  12. * - <OpenLayers.Layer.Grid>
  13. */
  14. OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
  15. /**
  16. * APIProperty: isBaseLayer
  17. * {Boolean} KaMap Layer is always a base layer
  18. */
  19. isBaseLayer: true,
  20. /**
  21. * Constant: DEFAULT_PARAMS
  22. * {Object} parameters set by default. The default parameters set
  23. * the format via the 'i' parameter to 'jpeg'.
  24. */
  25. DEFAULT_PARAMS: {
  26. i: 'jpeg',
  27. map: ''
  28. },
  29. /**
  30. * Constructor: OpenLayers.Layer.KaMap
  31. *
  32. * Parameters:
  33. * name - {String}
  34. * url - {String}
  35. * params - {Object} Parameters to be sent to the HTTP server in the
  36. * query string for the tile. The format can be set via the 'i'
  37. * parameter (defaults to jpg) , and the map should be set via
  38. * the 'map' parameter. It has been reported that ka-Map may behave
  39. * inconsistently if your format parameter does not match the format
  40. * parameter configured in your config.php. (See ticket #327 for more
  41. * information.)
  42. * options - {Object} Additional options for the layer. Any of the
  43. * APIProperties listed on this layer, and any layer types it
  44. * extends, can be overridden through the options parameter.
  45. */
  46. initialize: function(name, url, params, options) {
  47. OpenLayers.Layer.Grid.prototype.initialize.apply(this, arguments);
  48. this.params = OpenLayers.Util.applyDefaults(
  49. this.params, this.DEFAULT_PARAMS
  50. );
  51. },
  52. /**
  53. * Method: getURL
  54. *
  55. * Parameters:
  56. * bounds - {<OpenLayers.Bounds>}
  57. *
  58. * Returns:
  59. * {String} A string with the layer's url and parameters and also the
  60. * passed-in bounds and appropriate tile size specified as
  61. * parameters
  62. */
  63. getURL: function (bounds) {
  64. bounds = this.adjustBounds(bounds);
  65. var mapRes = this.map.getResolution();
  66. var scale = Math.round((this.map.getScale() * 10000)) / 10000;
  67. var pX = Math.round(bounds.left / mapRes);
  68. var pY = -Math.round(bounds.top / mapRes);
  69. return this.getFullRequestString(
  70. { t: pY,
  71. l: pX,
  72. s: scale
  73. });
  74. },
  75. /**
  76. * Method: calculateGridLayout
  77. * ka-Map uses the center point of the map as an origin for
  78. * its tiles. Override calculateGridLayout to center tiles
  79. * correctly for this case.
  80. *
  81. * Parameters:
  82. * bounds - {<OpenLayers.Bound>}
  83. * origin - {<OpenLayers.LonLat>}
  84. * resolution - {Number}
  85. *
  86. * Returns:
  87. * {Object} Object containing properties tilelon, tilelat, startcol,
  88. * startrow
  89. */
  90. calculateGridLayout: function(bounds, origin, resolution) {
  91. var tilelon = resolution*this.tileSize.w;
  92. var tilelat = resolution*this.tileSize.h;
  93. var offsetlon = bounds.left;
  94. var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
  95. var offsetlat = bounds.top;
  96. var tilerow = Math.floor(offsetlat/tilelat) + this.buffer;
  97. return {
  98. tilelon: tilelon, tilelat: tilelat,
  99. startcol: tilecol, startrow: tilerow
  100. };
  101. },
  102. /**
  103. * Method: getTileBoundsForGridIndex
  104. *
  105. * Parameters:
  106. * row - {Number} The row of the grid
  107. * col - {Number} The column of the grid
  108. *
  109. * Returns:
  110. * {<OpenLayers.Bounds>} The bounds for the tile at (row, col)
  111. */
  112. getTileBoundsForGridIndex: function(row, col) {
  113. var origin = this.getTileOrigin();
  114. var tileLayout = this.gridLayout;
  115. var tilelon = tileLayout.tilelon;
  116. var tilelat = tileLayout.tilelat;
  117. var minX = (tileLayout.startcol + col) * tilelon;
  118. var minY = (tileLayout.startrow - row) * tilelat;
  119. return new OpenLayers.Bounds(
  120. minX, minY,
  121. minX + tilelon, minY + tilelat
  122. );
  123. },
  124. /**
  125. * APIMethod: clone
  126. *
  127. * Parameters:
  128. * obj - {Object}
  129. *
  130. * Returns:
  131. * {<OpenLayers.Layer.Kamap>} An exact clone of this OpenLayers.Layer.KaMap
  132. */
  133. clone: function (obj) {
  134. if (obj == null) {
  135. obj = new OpenLayers.Layer.KaMap(this.name,
  136. this.url,
  137. this.params,
  138. this.getOptions());
  139. }
  140. //get all additions from superclasses
  141. obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
  142. // copy/set any non-init, non-simple values here
  143. if (this.tileSize != null) {
  144. obj.tileSize = this.tileSize.clone();
  145. }
  146. // we do not want to copy reference to grid, so we make a new array
  147. obj.grid = [];
  148. return obj;
  149. },
  150. /**
  151. * APIMethod: getTileBounds
  152. * Returns The tile bounds for a layer given a pixel location.
  153. *
  154. * Parameters:
  155. * viewPortPx - {<OpenLayers.Pixel>} The location in the viewport.
  156. *
  157. * Returns:
  158. * {<OpenLayers.Bounds>} Bounds of the tile at the given pixel location.
  159. */
  160. getTileBounds: function(viewPortPx) {
  161. var resolution = this.getResolution();
  162. var tileMapWidth = resolution * this.tileSize.w;
  163. var tileMapHeight = resolution * this.tileSize.h;
  164. var mapPoint = this.getLonLatFromViewPortPx(viewPortPx);
  165. var tileLeft = tileMapWidth * Math.floor(mapPoint.lon / tileMapWidth);
  166. var tileBottom = tileMapHeight * Math.floor(mapPoint.lat / tileMapHeight);
  167. return new OpenLayers.Bounds(tileLeft, tileBottom,
  168. tileLeft + tileMapWidth,
  169. tileBottom + tileMapHeight);
  170. },
  171. CLASS_NAME: "OpenLayers.Layer.KaMap"
  172. });