Google.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  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/SphericalMercator.js
  7. * @requires OpenLayers/Layer/EventPane.js
  8. * @requires OpenLayers/Layer/FixedZoomLevels.js
  9. * @requires OpenLayers/Lang.js
  10. */
  11. /**
  12. * Class: OpenLayers.Layer.Google
  13. *
  14. * Inherits from:
  15. * - <OpenLayers.Layer.SphericalMercator>
  16. * - <OpenLayers.Layer.EventPane>
  17. * - <OpenLayers.Layer.FixedZoomLevels>
  18. */
  19. OpenLayers.Layer.Google = OpenLayers.Class(
  20. OpenLayers.Layer.EventPane,
  21. OpenLayers.Layer.FixedZoomLevels, {
  22. /**
  23. * Constant: MIN_ZOOM_LEVEL
  24. * {Integer} 0
  25. */
  26. MIN_ZOOM_LEVEL: 0,
  27. /**
  28. * Constant: MAX_ZOOM_LEVEL
  29. * {Integer} 21
  30. */
  31. MAX_ZOOM_LEVEL: 21,
  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. 1.40625,
  39. 0.703125,
  40. 0.3515625,
  41. 0.17578125,
  42. 0.087890625,
  43. 0.0439453125,
  44. 0.02197265625,
  45. 0.010986328125,
  46. 0.0054931640625,
  47. 0.00274658203125,
  48. 0.001373291015625,
  49. 0.0006866455078125,
  50. 0.00034332275390625,
  51. 0.000171661376953125,
  52. 0.0000858306884765625,
  53. 0.00004291534423828125,
  54. 0.00002145767211914062,
  55. 0.00001072883605957031,
  56. 0.00000536441802978515,
  57. 0.00000268220901489257,
  58. 0.0000013411045074462891,
  59. 0.00000067055225372314453
  60. ],
  61. /**
  62. * APIProperty: type
  63. * {GMapType}
  64. */
  65. type: null,
  66. /**
  67. * APIProperty: wrapDateLine
  68. * {Boolean} Allow user to pan forever east/west. Default is true.
  69. * Setting this to false only restricts panning if
  70. * <sphericalMercator> is true.
  71. */
  72. wrapDateLine: true,
  73. /**
  74. * APIProperty: sphericalMercator
  75. * {Boolean} Should the map act as a mercator-projected map? This will
  76. * cause all interactions with the map to be in the actual map
  77. * projection, which allows support for vector drawing, overlaying
  78. * other maps, etc.
  79. */
  80. sphericalMercator: false,
  81. /**
  82. * Property: version
  83. * {Number} The version of the Google Maps API
  84. */
  85. version: null,
  86. /**
  87. * Constructor: OpenLayers.Layer.Google
  88. *
  89. * Parameters:
  90. * name - {String} A name for the layer.
  91. * options - {Object} An optional object whose properties will be set
  92. * on the layer.
  93. */
  94. initialize: function(name, options) {
  95. options = options || {};
  96. if(!options.version) {
  97. options.version = typeof GMap2 === "function" ? "2" : "3";
  98. }
  99. var mixin = OpenLayers.Layer.Google["v" +
  100. options.version.replace(/\./g, "_")];
  101. if (mixin) {
  102. OpenLayers.Util.applyDefaults(options, mixin);
  103. } else {
  104. throw "Unsupported Google Maps API version: " + options.version;
  105. }
  106. OpenLayers.Util.applyDefaults(options, mixin.DEFAULTS);
  107. if (options.maxExtent) {
  108. options.maxExtent = options.maxExtent.clone();
  109. }
  110. OpenLayers.Layer.EventPane.prototype.initialize.apply(this,
  111. [name, options]);
  112. OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this,
  113. [name, options]);
  114. if (this.sphericalMercator) {
  115. OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator);
  116. this.initMercatorParameters();
  117. }
  118. },
  119. /**
  120. * Method: clone
  121. * Create a clone of this layer
  122. *
  123. * Returns:
  124. * {<OpenLayers.Layer.Google>} An exact clone of this layer
  125. */
  126. clone: function() {
  127. /**
  128. * This method isn't intended to be called by a subclass and it
  129. * doesn't call the same method on the superclass. We don't call
  130. * the super's clone because we don't want properties that are set
  131. * on this layer after initialize (i.e. this.mapObject etc.).
  132. */
  133. return new OpenLayers.Layer.Google(
  134. this.name, this.getOptions()
  135. );
  136. },
  137. /**
  138. * APIMethod: setVisibility
  139. * Set the visibility flag for the layer and hide/show & redraw
  140. * accordingly. Fire event unless otherwise specified
  141. *
  142. * Note that visibility is no longer simply whether or not the layer's
  143. * style.display is set to "block". Now we store a 'visibility' state
  144. * property on the layer class, this allows us to remember whether or
  145. * not we *desire* for a layer to be visible. In the case where the
  146. * map's resolution is out of the layer's range, this desire may be
  147. * subverted.
  148. *
  149. * Parameters:
  150. * visible - {Boolean} Display the layer (if in range)
  151. */
  152. setVisibility: function(visible) {
  153. // sharing a map container, opacity has to be set per layer
  154. var opacity = this.opacity == null ? 1 : this.opacity;
  155. OpenLayers.Layer.EventPane.prototype.setVisibility.apply(this, arguments);
  156. this.setOpacity(opacity);
  157. },
  158. /**
  159. * APIMethod: display
  160. * Hide or show the Layer
  161. *
  162. * Parameters:
  163. * display - {Boolean}
  164. */
  165. display: function(visible) {
  166. if (!this._dragging) {
  167. this.setGMapVisibility(visible);
  168. }
  169. OpenLayers.Layer.EventPane.prototype.display.apply(this, arguments);
  170. },
  171. /**
  172. * Method: moveTo
  173. *
  174. * Parameters:
  175. * bound - {<OpenLayers.Bounds>}
  176. * zoomChanged - {Boolean} Tells when zoom has changed, as layers have to
  177. * do some init work in that case.
  178. * dragging - {Boolean}
  179. */
  180. moveTo: function(bounds, zoomChanged, dragging) {
  181. this._dragging = dragging;
  182. OpenLayers.Layer.EventPane.prototype.moveTo.apply(this, arguments);
  183. delete this._dragging;
  184. },
  185. /**
  186. * APIMethod: setOpacity
  187. * Sets the opacity for the entire layer (all images)
  188. *
  189. * Parameter:
  190. * opacity - {Float}
  191. */
  192. setOpacity: function(opacity) {
  193. if (opacity !== this.opacity) {
  194. if (this.map != null) {
  195. this.map.events.triggerEvent("changelayer", {
  196. layer: this,
  197. property: "opacity"
  198. });
  199. }
  200. this.opacity = opacity;
  201. }
  202. // Though this layer's opacity may not change, we're sharing a container
  203. // and need to update the opacity for the entire container.
  204. if (this.getVisibility()) {
  205. var container = this.getMapContainer();
  206. OpenLayers.Util.modifyDOMElement(
  207. container, null, null, null, null, null, null, opacity
  208. );
  209. }
  210. },
  211. /**
  212. * APIMethod: destroy
  213. * Clean up this layer.
  214. */
  215. destroy: function() {
  216. /**
  217. * We have to override this method because the event pane destroy
  218. * deletes the mapObject reference before removing this layer from
  219. * the map.
  220. */
  221. if (this.map) {
  222. this.setGMapVisibility(false);
  223. var cache = OpenLayers.Layer.Google.cache[this.map.id];
  224. if (cache && cache.count <= 1) {
  225. this.removeGMapElements();
  226. }
  227. }
  228. OpenLayers.Layer.EventPane.prototype.destroy.apply(this, arguments);
  229. },
  230. /**
  231. * Method: removeGMapElements
  232. * Remove all elements added to the dom. This should only be called if
  233. * this is the last of the Google layers for the given map.
  234. */
  235. removeGMapElements: function() {
  236. var cache = OpenLayers.Layer.Google.cache[this.map.id];
  237. if (cache) {
  238. // remove shared elements from dom
  239. var container = this.mapObject && this.getMapContainer();
  240. if (container && container.parentNode) {
  241. container.parentNode.removeChild(container);
  242. }
  243. var termsOfUse = cache.termsOfUse;
  244. if (termsOfUse && termsOfUse.parentNode) {
  245. termsOfUse.parentNode.removeChild(termsOfUse);
  246. }
  247. var poweredBy = cache.poweredBy;
  248. if (poweredBy && poweredBy.parentNode) {
  249. poweredBy.parentNode.removeChild(poweredBy);
  250. }
  251. }
  252. },
  253. /**
  254. * APIMethod: removeMap
  255. * On being removed from the map, also remove termsOfUse and poweredBy divs
  256. *
  257. * Parameters:
  258. * map - {<OpenLayers.Map>}
  259. */
  260. removeMap: function(map) {
  261. // hide layer before removing
  262. if (this.visibility && this.mapObject) {
  263. this.setGMapVisibility(false);
  264. }
  265. // check to see if last Google layer in this map
  266. var cache = OpenLayers.Layer.Google.cache[map.id];
  267. if (cache) {
  268. if (cache.count <= 1) {
  269. this.removeGMapElements();
  270. delete OpenLayers.Layer.Google.cache[map.id];
  271. } else {
  272. // decrement the layer count
  273. --cache.count;
  274. }
  275. }
  276. // remove references to gmap elements
  277. delete this.termsOfUse;
  278. delete this.poweredBy;
  279. delete this.mapObject;
  280. delete this.dragObject;
  281. OpenLayers.Layer.EventPane.prototype.removeMap.apply(this, arguments);
  282. },
  283. //
  284. // TRANSLATION: MapObject Bounds <-> OpenLayers.Bounds
  285. //
  286. /**
  287. * APIMethod: getOLBoundsFromMapObjectBounds
  288. *
  289. * Parameters:
  290. * moBounds - {Object}
  291. *
  292. * Returns:
  293. * {<OpenLayers.Bounds>} An <OpenLayers.Bounds>, translated from the
  294. * passed-in MapObject Bounds.
  295. * Returns null if null value is passed in.
  296. */
  297. getOLBoundsFromMapObjectBounds: function(moBounds) {
  298. var olBounds = null;
  299. if (moBounds != null) {
  300. var sw = moBounds.getSouthWest();
  301. var ne = moBounds.getNorthEast();
  302. if (this.sphericalMercator) {
  303. sw = this.forwardMercator(sw.lng(), sw.lat());
  304. ne = this.forwardMercator(ne.lng(), ne.lat());
  305. } else {
  306. sw = new OpenLayers.LonLat(sw.lng(), sw.lat());
  307. ne = new OpenLayers.LonLat(ne.lng(), ne.lat());
  308. }
  309. olBounds = new OpenLayers.Bounds(sw.lon,
  310. sw.lat,
  311. ne.lon,
  312. ne.lat );
  313. }
  314. return olBounds;
  315. },
  316. /**
  317. * APIMethod: getWarningHTML
  318. *
  319. * Returns:
  320. * {String} String with information on why layer is broken, how to get
  321. * it working.
  322. */
  323. getWarningHTML:function() {
  324. return OpenLayers.i18n("googleWarning");
  325. },
  326. /************************************
  327. * *
  328. * MapObject Interface Controls *
  329. * *
  330. ************************************/
  331. // Get&Set Center, Zoom
  332. /**
  333. * APIMethod: getMapObjectCenter
  334. *
  335. * Returns:
  336. * {Object} The mapObject's current center in Map Object format
  337. */
  338. getMapObjectCenter: function() {
  339. return this.mapObject.getCenter();
  340. },
  341. /**
  342. * APIMethod: getMapObjectZoom
  343. *
  344. * Returns:
  345. * {Integer} The mapObject's current zoom, in Map Object format
  346. */
  347. getMapObjectZoom: function() {
  348. return this.mapObject.getZoom();
  349. },
  350. /************************************
  351. * *
  352. * MapObject Primitives *
  353. * *
  354. ************************************/
  355. // LonLat
  356. /**
  357. * APIMethod: getLongitudeFromMapObjectLonLat
  358. *
  359. * Parameters:
  360. * moLonLat - {Object} MapObject LonLat format
  361. *
  362. * Returns:
  363. * {Float} Longitude of the given MapObject LonLat
  364. */
  365. getLongitudeFromMapObjectLonLat: function(moLonLat) {
  366. return this.sphericalMercator ?
  367. this.forwardMercator(moLonLat.lng(), moLonLat.lat()).lon :
  368. moLonLat.lng();
  369. },
  370. /**
  371. * APIMethod: getLatitudeFromMapObjectLonLat
  372. *
  373. * Parameters:
  374. * moLonLat - {Object} MapObject LonLat format
  375. *
  376. * Returns:
  377. * {Float} Latitude of the given MapObject LonLat
  378. */
  379. getLatitudeFromMapObjectLonLat: function(moLonLat) {
  380. var lat = this.sphericalMercator ?
  381. this.forwardMercator(moLonLat.lng(), moLonLat.lat()).lat :
  382. moLonLat.lat();
  383. return lat;
  384. },
  385. // Pixel
  386. /**
  387. * APIMethod: getXFromMapObjectPixel
  388. *
  389. * Parameters:
  390. * moPixel - {Object} MapObject Pixel format
  391. *
  392. * Returns:
  393. * {Integer} X value of the MapObject Pixel
  394. */
  395. getXFromMapObjectPixel: function(moPixel) {
  396. return moPixel.x;
  397. },
  398. /**
  399. * APIMethod: getYFromMapObjectPixel
  400. *
  401. * Parameters:
  402. * moPixel - {Object} MapObject Pixel format
  403. *
  404. * Returns:
  405. * {Integer} Y value of the MapObject Pixel
  406. */
  407. getYFromMapObjectPixel: function(moPixel) {
  408. return moPixel.y;
  409. },
  410. CLASS_NAME: "OpenLayers.Layer.Google"
  411. });
  412. /**
  413. * Property: OpenLayers.Layer.Google.cache
  414. * {Object} Cache for elements that should only be created once per map.
  415. */
  416. OpenLayers.Layer.Google.cache = {};
  417. /**
  418. * Constant: OpenLayers.Layer.Google.v2
  419. *
  420. * Mixin providing functionality specific to the Google Maps API v2.
  421. */
  422. OpenLayers.Layer.Google.v2 = {
  423. /**
  424. * Property: termsOfUse
  425. * {DOMElement} Div for Google's copyright and terms of use link
  426. */
  427. termsOfUse: null,
  428. /**
  429. * Property: poweredBy
  430. * {DOMElement} Div for Google's powered by logo and link
  431. */
  432. poweredBy: null,
  433. /**
  434. * Property: dragObject
  435. * {GDraggableObject} Since 2.93, Google has exposed the ability to get
  436. * the maps GDraggableObject. We can now use this for smooth panning
  437. */
  438. dragObject: null,
  439. /**
  440. * Method: loadMapObject
  441. * Load the GMap and register appropriate event listeners. If we can't
  442. * load GMap2, then display a warning message.
  443. */
  444. loadMapObject:function() {
  445. if (!this.type) {
  446. this.type = G_NORMAL_MAP;
  447. }
  448. var mapObject, termsOfUse, poweredBy;
  449. var cache = OpenLayers.Layer.Google.cache[this.map.id];
  450. if (cache) {
  451. // there are already Google layers added to this map
  452. mapObject = cache.mapObject;
  453. termsOfUse = cache.termsOfUse;
  454. poweredBy = cache.poweredBy;
  455. // increment the layer count
  456. ++cache.count;
  457. } else {
  458. // this is the first Google layer for this map
  459. var container = this.map.viewPortDiv;
  460. var div = document.createElement("div");
  461. div.id = this.map.id + "_GMap2Container";
  462. div.style.position = "absolute";
  463. div.style.width = "100%";
  464. div.style.height = "100%";
  465. container.appendChild(div);
  466. // create GMap and shuffle elements
  467. try {
  468. mapObject = new GMap2(div);
  469. // move the ToS and branding stuff up to the container div
  470. termsOfUse = div.lastChild;
  471. container.appendChild(termsOfUse);
  472. termsOfUse.style.zIndex = "1100";
  473. termsOfUse.style.right = "";
  474. termsOfUse.style.bottom = "";
  475. termsOfUse.className = "olLayerGoogleCopyright";
  476. poweredBy = div.lastChild;
  477. container.appendChild(poweredBy);
  478. poweredBy.style.zIndex = "1100";
  479. poweredBy.style.right = "";
  480. poweredBy.style.bottom = "";
  481. poweredBy.className = "olLayerGooglePoweredBy gmnoprint";
  482. } catch (e) {
  483. throw(e);
  484. }
  485. // cache elements for use by any other google layers added to
  486. // this same map
  487. OpenLayers.Layer.Google.cache[this.map.id] = {
  488. mapObject: mapObject,
  489. termsOfUse: termsOfUse,
  490. poweredBy: poweredBy,
  491. count: 1
  492. };
  493. }
  494. this.mapObject = mapObject;
  495. this.termsOfUse = termsOfUse;
  496. this.poweredBy = poweredBy;
  497. // ensure this layer type is one of the mapObject types
  498. if (OpenLayers.Util.indexOf(this.mapObject.getMapTypes(),
  499. this.type) === -1) {
  500. this.mapObject.addMapType(this.type);
  501. }
  502. //since v 2.93 getDragObject is now available.
  503. if(typeof mapObject.getDragObject == "function") {
  504. this.dragObject = mapObject.getDragObject();
  505. } else {
  506. this.dragPanMapObject = null;
  507. }
  508. if(this.isBaseLayer === false) {
  509. this.setGMapVisibility(this.div.style.display !== "none");
  510. }
  511. },
  512. /**
  513. * APIMethod: onMapResize
  514. */
  515. onMapResize: function() {
  516. // workaround for resizing of invisible or not yet fully loaded layers
  517. // where GMap2.checkResize() does not work. We need to load the GMap
  518. // for the old div size, then checkResize(), and then call
  519. // layer.moveTo() to trigger GMap.setCenter() (which will finish
  520. // the GMap initialization).
  521. if(this.visibility && this.mapObject.isLoaded()) {
  522. this.mapObject.checkResize();
  523. } else {
  524. if(!this._resized) {
  525. var layer = this;
  526. var handle = GEvent.addListener(this.mapObject, "load", function() {
  527. GEvent.removeListener(handle);
  528. delete layer._resized;
  529. layer.mapObject.checkResize();
  530. layer.moveTo(layer.map.getCenter(), layer.map.getZoom());
  531. });
  532. }
  533. this._resized = true;
  534. }
  535. },
  536. /**
  537. * Method: setGMapVisibility
  538. * Display the GMap container and associated elements.
  539. *
  540. * Parameters:
  541. * visible - {Boolean} Display the GMap elements.
  542. */
  543. setGMapVisibility: function(visible) {
  544. var cache = OpenLayers.Layer.Google.cache[this.map.id];
  545. if (cache) {
  546. var container = this.mapObject.getContainer();
  547. if (visible === true) {
  548. this.mapObject.setMapType(this.type);
  549. container.style.display = "";
  550. this.termsOfUse.style.left = "";
  551. this.termsOfUse.style.display = "";
  552. this.poweredBy.style.display = "";
  553. cache.displayed = this.id;
  554. } else {
  555. if (cache.displayed === this.id) {
  556. delete cache.displayed;
  557. }
  558. if (!cache.displayed) {
  559. container.style.display = "none";
  560. this.termsOfUse.style.display = "none";
  561. // move ToU far to the left in addition to setting display
  562. // to "none", because at the end of the GMap2 load
  563. // sequence, display: none will be unset and ToU would be
  564. // visible after loading a map with a google layer that is
  565. // initially hidden.
  566. this.termsOfUse.style.left = "-9999px";
  567. this.poweredBy.style.display = "none";
  568. }
  569. }
  570. }
  571. },
  572. /**
  573. * Method: getMapContainer
  574. *
  575. * Returns:
  576. * {DOMElement} the GMap container's div
  577. */
  578. getMapContainer: function() {
  579. return this.mapObject.getContainer();
  580. },
  581. //
  582. // TRANSLATION: MapObject Bounds <-> OpenLayers.Bounds
  583. //
  584. /**
  585. * APIMethod: getMapObjectBoundsFromOLBounds
  586. *
  587. * Parameters:
  588. * olBounds - {<OpenLayers.Bounds>}
  589. *
  590. * Returns:
  591. * {Object} A MapObject Bounds, translated from olBounds
  592. * Returns null if null value is passed in
  593. */
  594. getMapObjectBoundsFromOLBounds: function(olBounds) {
  595. var moBounds = null;
  596. if (olBounds != null) {
  597. var sw = this.sphericalMercator ?
  598. this.inverseMercator(olBounds.bottom, olBounds.left) :
  599. new OpenLayers.LonLat(olBounds.bottom, olBounds.left);
  600. var ne = this.sphericalMercator ?
  601. this.inverseMercator(olBounds.top, olBounds.right) :
  602. new OpenLayers.LonLat(olBounds.top, olBounds.right);
  603. moBounds = new GLatLngBounds(new GLatLng(sw.lat, sw.lon),
  604. new GLatLng(ne.lat, ne.lon));
  605. }
  606. return moBounds;
  607. },
  608. /************************************
  609. * *
  610. * MapObject Interface Controls *
  611. * *
  612. ************************************/
  613. // Get&Set Center, Zoom
  614. /**
  615. * APIMethod: setMapObjectCenter
  616. * Set the mapObject to the specified center and zoom
  617. *
  618. * Parameters:
  619. * center - {Object} MapObject LonLat format
  620. * zoom - {int} MapObject zoom format
  621. */
  622. setMapObjectCenter: function(center, zoom) {
  623. this.mapObject.setCenter(center, zoom);
  624. },
  625. /**
  626. * APIMethod: dragPanMapObject
  627. *
  628. * Parameters:
  629. * dX - {Integer}
  630. * dY - {Integer}
  631. */
  632. dragPanMapObject: function(dX, dY) {
  633. this.dragObject.moveBy(new GSize(-dX, dY));
  634. },
  635. // LonLat - Pixel Translation
  636. /**
  637. * APIMethod: getMapObjectLonLatFromMapObjectPixel
  638. *
  639. * Parameters:
  640. * moPixel - {Object} MapObject Pixel format
  641. *
  642. * Returns:
  643. * {Object} MapObject LonLat translated from MapObject Pixel
  644. */
  645. getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
  646. return this.mapObject.fromContainerPixelToLatLng(moPixel);
  647. },
  648. /**
  649. * APIMethod: getMapObjectPixelFromMapObjectLonLat
  650. *
  651. * Parameters:
  652. * moLonLat - {Object} MapObject LonLat format
  653. *
  654. * Returns:
  655. * {Object} MapObject Pixel transtlated from MapObject LonLat
  656. */
  657. getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
  658. return this.mapObject.fromLatLngToContainerPixel(moLonLat);
  659. },
  660. // Bounds
  661. /**
  662. * APIMethod: getMapObjectZoomFromMapObjectBounds
  663. *
  664. * Parameters:
  665. * moBounds - {Object} MapObject Bounds format
  666. *
  667. * Returns:
  668. * {Object} MapObject Zoom for specified MapObject Bounds
  669. */
  670. getMapObjectZoomFromMapObjectBounds: function(moBounds) {
  671. return this.mapObject.getBoundsZoomLevel(moBounds);
  672. },
  673. /************************************
  674. * *
  675. * MapObject Primitives *
  676. * *
  677. ************************************/
  678. // LonLat
  679. /**
  680. * APIMethod: getMapObjectLonLatFromLonLat
  681. *
  682. * Parameters:
  683. * lon - {Float}
  684. * lat - {Float}
  685. *
  686. * Returns:
  687. * {Object} MapObject LonLat built from lon and lat params
  688. */
  689. getMapObjectLonLatFromLonLat: function(lon, lat) {
  690. var gLatLng;
  691. if(this.sphericalMercator) {
  692. var lonlat = this.inverseMercator(lon, lat);
  693. gLatLng = new GLatLng(lonlat.lat, lonlat.lon);
  694. } else {
  695. gLatLng = new GLatLng(lat, lon);
  696. }
  697. return gLatLng;
  698. },
  699. // Pixel
  700. /**
  701. * APIMethod: getMapObjectPixelFromXY
  702. *
  703. * Parameters:
  704. * x - {Integer}
  705. * y - {Integer}
  706. *
  707. * Returns:
  708. * {Object} MapObject Pixel from x and y parameters
  709. */
  710. getMapObjectPixelFromXY: function(x, y) {
  711. return new GPoint(x, y);
  712. }
  713. };