Google.js 25 KB

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