Google.js 24 KB

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