MultiMap.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
  2. * full list of contributors). Published under the Clear BSD license.
  3. * See http://svn.openlayers.org/trunk/openlayers/license.txt for the
  4. * full text of the license. */
  5. /**
  6. * @requires OpenLayers/Layer/EventPane.js
  7. * @requires OpenLayers/Layer/FixedZoomLevels.js
  8. * @requires OpenLayers/Lang.js
  9. */
  10. /**
  11. * Class: OpenLayers.Layer.MultiMap
  12. * Note that MultiMap does not fully support the sphericalMercator
  13. * option. See Ticket #953 for more details.
  14. * *Deprecated*. Use OpenLayers.Layer.Bing instead. See #3063
  15. *
  16. * Inherits from:
  17. * - <OpenLayers.Layer.EventPane>
  18. * - <OpenLayers.Layer.FixedZoomLevels>
  19. */
  20. OpenLayers.Layer.MultiMap = OpenLayers.Class(
  21. OpenLayers.Layer.EventPane, OpenLayers.Layer.FixedZoomLevels, {
  22. /**
  23. * Constant: MIN_ZOOM_LEVEL
  24. * {Integer} 1
  25. */
  26. MIN_ZOOM_LEVEL: 1,
  27. /**
  28. * Constant: MAX_ZOOM_LEVEL
  29. * {Integer} 17
  30. */
  31. MAX_ZOOM_LEVEL: 17,
  32. /**
  33. * Constant: RESOLUTIONS
  34. * {Array(Float)} Hardcode these resolutions so that they are more closely
  35. * tied with the standard wms projection
  36. */
  37. RESOLUTIONS: [
  38. 9,
  39. 1.40625,
  40. 0.703125,
  41. 0.3515625,
  42. 0.17578125,
  43. 0.087890625,
  44. 0.0439453125,
  45. 0.02197265625,
  46. 0.010986328125,
  47. 0.0054931640625,
  48. 0.00274658203125,
  49. 0.001373291015625,
  50. 0.0006866455078125,
  51. 0.00034332275390625,
  52. 0.000171661376953125,
  53. 0.0000858306884765625,
  54. 0.00004291534423828125
  55. ],
  56. /**
  57. * APIProperty: type
  58. * {?}
  59. */
  60. type: null,
  61. /**
  62. * Constructor: OpenLayers.Layer.MultiMap
  63. *
  64. * Parameters:
  65. * name - {String}
  66. * options - {Object}
  67. */
  68. initialize: function(name, options) {
  69. OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
  70. OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this,
  71. arguments);
  72. if (this.sphericalMercator) {
  73. OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator);
  74. this.initMercatorParameters();
  75. this.RESOLUTIONS.unshift(10);
  76. }
  77. },
  78. /**
  79. * Method: loadMapObject
  80. */
  81. loadMapObject:function() {
  82. try { //crash proofing
  83. this.mapObject = new MultimapViewer(this.div);
  84. } catch (e) { }
  85. },
  86. /**
  87. * APIMethod: getWarningHTML
  88. *
  89. * Returns:
  90. * {String} String with information on why layer is broken, how to get
  91. * it working.
  92. */
  93. getWarningHTML:function() {
  94. return OpenLayers.i18n(
  95. "getLayerWarning", {'layerType':"MM", 'layerLib':"MultiMap"}
  96. );
  97. },
  98. /************************************
  99. * *
  100. * MapObject Interface Controls *
  101. * *
  102. ************************************/
  103. // Get&Set Center, Zoom
  104. /**
  105. * APIMethod: setMapObjectCenter
  106. * Set the mapObject to the specified center and zoom
  107. *
  108. * Parameters:
  109. * center - {Object} MapObject LonLat format
  110. * zoom - {int} MapObject zoom format
  111. */
  112. setMapObjectCenter: function(center, zoom) {
  113. this.mapObject.goToPosition(center, zoom);
  114. },
  115. /**
  116. * APIMethod: getMapObjectCenter
  117. *
  118. * Returns:
  119. * {Object} The mapObject's current center in Map Object format
  120. */
  121. getMapObjectCenter: function() {
  122. return this.mapObject.getCurrentPosition();
  123. },
  124. /**
  125. * APIMethod: getMapObjectZoom
  126. *
  127. * Returns:
  128. * {Integer} The mapObject's current zoom, in Map Object format
  129. */
  130. getMapObjectZoom: function() {
  131. return this.mapObject.getZoomFactor();
  132. },
  133. // LonLat - Pixel Translation
  134. /**
  135. * APIMethod: getMapObjectLonLatFromMapObjectPixel
  136. *
  137. * Parameters:
  138. * moPixel - {Object} MapObject Pixel format
  139. *
  140. * Returns:
  141. * {Object} MapObject LonLat translated from MapObject Pixel
  142. */
  143. getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
  144. moPixel.x = moPixel.x - (this.map.getSize().w/2);
  145. moPixel.y = moPixel.y - (this.map.getSize().h/2);
  146. return this.mapObject.getMapPositionAt(moPixel);
  147. },
  148. /**
  149. * APIMethod: getMapObjectPixelFromMapObjectLonLat
  150. *
  151. * Parameters:
  152. * moLonLat - {Object} MapObject LonLat format
  153. *
  154. * Returns:
  155. * {Object} MapObject Pixel transtlated from MapObject LonLat
  156. */
  157. getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
  158. return this.mapObject.geoPosToContainerPixels(moLonLat);
  159. },
  160. /************************************
  161. * *
  162. * MapObject Primitives *
  163. * *
  164. ************************************/
  165. // LonLat
  166. /**
  167. * APIMethod: getLongitudeFromMapObjectLonLat
  168. *
  169. * Parameters:
  170. * moLonLat - {Object} MapObject LonLat format
  171. *
  172. * Returns:
  173. * {Float} Longitude of the given MapObject LonLat
  174. */
  175. getLongitudeFromMapObjectLonLat: function(moLonLat) {
  176. return this.sphericalMercator ?
  177. this.forwardMercator(moLonLat.lon, moLonLat.lat).lon :
  178. moLonLat.lon;
  179. },
  180. /**
  181. * APIMethod: getLatitudeFromMapObjectLonLat
  182. *
  183. * Parameters:
  184. * moLonLat - {Object} MapObject LonLat format
  185. *
  186. * Returns:
  187. * {Float} Latitude of the given MapObject LonLat
  188. */
  189. getLatitudeFromMapObjectLonLat: function(moLonLat) {
  190. return this.sphericalMercator ?
  191. this.forwardMercator(moLonLat.lon, moLonLat.lat).lat :
  192. moLonLat.lat;
  193. },
  194. /**
  195. * APIMethod: getMapObjectLonLatFromLonLat
  196. *
  197. * Parameters:
  198. * lon - {Float}
  199. * lat - {Float}
  200. *
  201. * Returns:
  202. * {Object} MapObject LonLat built from lon and lat params
  203. */
  204. getMapObjectLonLatFromLonLat: function(lon, lat) {
  205. var mmLatLon;
  206. if(this.sphericalMercator) {
  207. var lonlat = this.inverseMercator(lon, lat);
  208. mmLatLon = new MMLatLon(lonlat.lat, lonlat.lon);
  209. } else {
  210. mmLatLon = new MMLatLon(lat, lon);
  211. }
  212. return mmLatLon;
  213. },
  214. // Pixel
  215. /**
  216. * APIMethod: getXFromMapObjectPixel
  217. *
  218. * Parameters:
  219. * moPixel - {Object} MapObject Pixel format
  220. *
  221. * Returns:
  222. * {Integer} X value of the MapObject Pixel
  223. */
  224. getXFromMapObjectPixel: function(moPixel) {
  225. return moPixel.x;
  226. },
  227. /**
  228. * APIMethod: getYFromMapObjectPixel
  229. *
  230. * Parameters:
  231. * moPixel - {Object} MapObject Pixel format
  232. *
  233. * Returns:
  234. * {Integer} Y value of the MapObject Pixel
  235. */
  236. getYFromMapObjectPixel: function(moPixel) {
  237. return moPixel.y;
  238. },
  239. /**
  240. * APIMethod: getMapObjectPixelFromXY
  241. *
  242. * Parameters:
  243. * x - {Integer}
  244. * y - {Integer}
  245. *
  246. * Returns:
  247. * {Object} MapObject Pixel from x and y parameters
  248. */
  249. getMapObjectPixelFromXY: function(x, y) {
  250. return new MMPoint(x, y);
  251. },
  252. CLASS_NAME: "OpenLayers.Layer.MultiMap"
  253. });