richmarker.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. // ==ClosureCompiler==
  2. // @compilation_level ADVANCED_OPTIMIZATIONS
  3. // @externs_url http://closure-compiler.googlecode.com/svn/trunk/contrib/externs/maps/google_maps_api_v3.js
  4. // @output_wrapper (function() {%output%})();
  5. // ==/ClosureCompiler==
  6. /**
  7. * @license
  8. * Copyright 2013 Google Inc. All Rights Reserved.
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. */
  22. /**
  23. * A RichMarker that allows any HTML/DOM to be added to a map and be draggable.
  24. *
  25. * @param {Object.<string, *>=} opt_options Optional properties to set.
  26. * @extends {google.maps.OverlayView}
  27. * @constructor
  28. */
  29. function RichMarker(opt_options) {
  30. var options = opt_options || {};
  31. /**
  32. * @type {boolean}
  33. * @private
  34. */
  35. this.ready_ = false;
  36. /**
  37. * @type {boolean}
  38. * @private
  39. */
  40. this.dragging_ = false;
  41. if (opt_options['visible'] == undefined) {
  42. opt_options['visible'] = true;
  43. }
  44. if (opt_options['shadow'] == undefined) {
  45. // opt_options['shadow'] = '7px -3px 5px rgba(88,88,88,0.7)';
  46. }
  47. if (opt_options['anchor'] == undefined) {
  48. opt_options['anchor'] = RichMarkerPosition['BOTTOM'];
  49. }
  50. this.setValues(options);
  51. }
  52. RichMarker.prototype = new google.maps.OverlayView();
  53. window['RichMarker'] = RichMarker;
  54. /**
  55. * Returns the current visibility state of the marker.
  56. *
  57. * @return {boolean} The visiblity of the marker.
  58. */
  59. RichMarker.prototype.getVisible = function() {
  60. return /** @type {boolean} */ (this.get('visible'));
  61. };
  62. RichMarker.prototype['getVisible'] = RichMarker.prototype.getVisible;
  63. /**
  64. * Sets the visiblility state of the marker.
  65. *
  66. * @param {boolean} visible The visiblilty of the marker.
  67. */
  68. RichMarker.prototype.setVisible = function(visible) {
  69. this.set('visible', visible);
  70. };
  71. RichMarker.prototype['setVisible'] = RichMarker.prototype.setVisible;
  72. /**
  73. * The visible changed event.
  74. */
  75. RichMarker.prototype.visible_changed = function() {
  76. if (this.ready_) {
  77. this.markerWrapper_.style['display'] = this.getVisible() ? '' : 'none';
  78. this.draw();
  79. }
  80. };
  81. RichMarker.prototype['visible_changed'] = RichMarker.prototype.visible_changed;
  82. /**
  83. * Sets the marker to be flat.
  84. *
  85. * @param {boolean} flat If the marker is to be flat or not.
  86. */
  87. RichMarker.prototype.setFlat = function(flat) {
  88. this.set('flat', !!flat);
  89. };
  90. RichMarker.prototype['setFlat'] = RichMarker.prototype.setFlat;
  91. /**
  92. * If the makrer is flat or not.
  93. *
  94. * @return {boolean} True the marker is flat.
  95. */
  96. RichMarker.prototype.getFlat = function() {
  97. return /** @type {boolean} */ (this.get('flat'));
  98. };
  99. RichMarker.prototype['getFlat'] = RichMarker.prototype.getFlat;
  100. /**
  101. * Get the width of the marker.
  102. *
  103. * @return {Number} The width of the marker.
  104. */
  105. RichMarker.prototype.getWidth = function() {
  106. return /** @type {Number} */ (this.get('width'));
  107. };
  108. RichMarker.prototype['getWidth'] = RichMarker.prototype.getWidth;
  109. /**
  110. * Get the height of the marker.
  111. *
  112. * @return {Number} The height of the marker.
  113. */
  114. RichMarker.prototype.getHeight = function() {
  115. return /** @type {Number} */ (this.get('height'));
  116. };
  117. RichMarker.prototype['getHeight'] = RichMarker.prototype.getHeight;
  118. /**
  119. * Sets the marker's box shadow.
  120. *
  121. * @param {string} shadow The box shadow to set.
  122. */
  123. RichMarker.prototype.setShadow = function(shadow) {
  124. this.set('shadow', shadow);
  125. this.flat_changed();
  126. };
  127. RichMarker.prototype['setShadow'] = RichMarker.prototype.setShadow;
  128. /**
  129. * Gets the marker's box shadow.
  130. *
  131. * @return {string} The box shadow.
  132. */
  133. RichMarker.prototype.getShadow = function() {
  134. return /** @type {string} */ (this.get('shadow'));
  135. };
  136. RichMarker.prototype['getShadow'] = RichMarker.prototype.getShadow;
  137. /**
  138. * Flat changed event.
  139. */
  140. RichMarker.prototype.flat_changed = function() {
  141. if (!this.ready_) {
  142. return;
  143. }
  144. this.markerWrapper_.style['boxShadow'] =
  145. this.markerWrapper_.style['webkitBoxShadow'] =
  146. this.markerWrapper_.style['MozBoxShadow'] =
  147. this.getFlat() ? '' : this.getShadow();
  148. };
  149. RichMarker.prototype['flat_changed'] = RichMarker.prototype.flat_changed;
  150. /**
  151. * Sets the zIndex of the marker.
  152. *
  153. * @param {Number} index The index to set.
  154. */
  155. RichMarker.prototype.setZIndex = function(index) {
  156. this.set('zIndex', index);
  157. };
  158. RichMarker.prototype['setZIndex'] = RichMarker.prototype.setZIndex;
  159. /**
  160. * Gets the zIndex of the marker.
  161. *
  162. * @return {Number} The zIndex of the marker.
  163. */
  164. RichMarker.prototype.getZIndex = function() {
  165. return /** @type {Number} */ (this.get('zIndex'));
  166. };
  167. RichMarker.prototype['getZIndex'] = RichMarker.prototype.getZIndex;
  168. /**
  169. * zIndex changed event.
  170. */
  171. RichMarker.prototype.zIndex_changed = function() {
  172. if (this.getZIndex() && this.ready_) {
  173. this.markerWrapper_.style.zIndex = this.getZIndex();
  174. }
  175. };
  176. RichMarker.prototype['zIndex_changed'] = RichMarker.prototype.zIndex_changed;
  177. /**
  178. * Whether the marker is draggable or not.
  179. *
  180. * @return {boolean} True if the marker is draggable.
  181. */
  182. RichMarker.prototype.getDraggable = function() {
  183. return /** @type {boolean} */ (this.get('draggable'));
  184. };
  185. RichMarker.prototype['getDraggable'] = RichMarker.prototype.getDraggable;
  186. /**
  187. * Sets the marker to be draggable or not.
  188. *
  189. * @param {boolean} draggable If the marker is draggable or not.
  190. */
  191. RichMarker.prototype.setDraggable = function(draggable) {
  192. this.set('draggable', !!draggable);
  193. };
  194. RichMarker.prototype['setDraggable'] = RichMarker.prototype.setDraggable;
  195. /**
  196. * Draggable property changed callback.
  197. */
  198. RichMarker.prototype.draggable_changed = function() {
  199. if (this.ready_) {
  200. if (this.getDraggable()) {
  201. this.addDragging_(this.markerWrapper_);
  202. } else {
  203. this.removeDragListeners_();
  204. }
  205. }
  206. };
  207. RichMarker.prototype['draggable_changed'] =
  208. RichMarker.prototype.draggable_changed;
  209. /**
  210. * Gets the postiton of the marker.
  211. *
  212. * @return {google.maps.LatLng} The position of the marker.
  213. */
  214. RichMarker.prototype.getPosition = function() {
  215. return /** @type {google.maps.LatLng} */ (this.get('position'));
  216. };
  217. RichMarker.prototype['getPosition'] = RichMarker.prototype.getPosition;
  218. /**
  219. * Sets the position of the marker.
  220. *
  221. * @param {google.maps.LatLng} position The position to set.
  222. */
  223. RichMarker.prototype.setPosition = function(position) {
  224. this.set('position', position);
  225. };
  226. RichMarker.prototype['setPosition'] = RichMarker.prototype.setPosition;
  227. /**
  228. * Position changed event.
  229. */
  230. RichMarker.prototype.position_changed = function() {
  231. this.draw();
  232. };
  233. RichMarker.prototype['position_changed'] =
  234. RichMarker.prototype.position_changed;
  235. /**
  236. * Gets the anchor.
  237. *
  238. * @return {google.maps.Size} The position of the anchor.
  239. */
  240. RichMarker.prototype.getAnchor = function() {
  241. return /** @type {google.maps.Size} */ (this.get('anchor'));
  242. };
  243. RichMarker.prototype['getAnchor'] = RichMarker.prototype.getAnchor;
  244. /**
  245. * Sets the anchor.
  246. *
  247. * @param {RichMarkerPosition|google.maps.Size} anchor The anchor to set.
  248. */
  249. RichMarker.prototype.setAnchor = function(anchor) {
  250. this.set('anchor', anchor);
  251. };
  252. RichMarker.prototype['setAnchor'] = RichMarker.prototype.setAnchor;
  253. /**
  254. * Anchor changed event.
  255. */
  256. RichMarker.prototype.anchor_changed = function() {
  257. this.draw();
  258. };
  259. RichMarker.prototype['anchor_changed'] = RichMarker.prototype.anchor_changed;
  260. /**
  261. * Converts a HTML string to a document fragment.
  262. *
  263. * @param {string} htmlString The HTML string to convert.
  264. * @return {Node} A HTML document fragment.
  265. * @private
  266. */
  267. RichMarker.prototype.htmlToDocumentFragment_ = function(htmlString) {
  268. var tempDiv = document.createElement('DIV');
  269. tempDiv.innerHTML = htmlString;
  270. if (tempDiv.childNodes.length == 1) {
  271. return /** @type {!Node} */ (tempDiv.removeChild(tempDiv.firstChild));
  272. } else {
  273. var fragment = document.createDocumentFragment();
  274. while (tempDiv.firstChild) {
  275. fragment.appendChild(tempDiv.firstChild);
  276. }
  277. return fragment;
  278. }
  279. };
  280. /**
  281. * Removes all children from the node.
  282. *
  283. * @param {Node} node The node to remove all children from.
  284. * @private
  285. */
  286. RichMarker.prototype.removeChildren_ = function(node) {
  287. if (!node) {
  288. return;
  289. }
  290. var child;
  291. while (child = node.firstChild) {
  292. node.removeChild(child);
  293. }
  294. };
  295. /**
  296. * Sets the content of the marker.
  297. *
  298. * @param {string|Node} content The content to set.
  299. */
  300. RichMarker.prototype.setContent = function(content) {
  301. this.set('content', content);
  302. };
  303. RichMarker.prototype['setContent'] = RichMarker.prototype.setContent;
  304. /**
  305. * Get the content of the marker.
  306. *
  307. * @return {string|Node} The marker content.
  308. */
  309. RichMarker.prototype.getContent = function() {
  310. return /** @type {Node|string} */ (this.get('content'));
  311. };
  312. RichMarker.prototype['getContent'] = RichMarker.prototype.getContent;
  313. /**
  314. * Sets the marker content and adds loading events to images
  315. */
  316. RichMarker.prototype.content_changed = function() {
  317. if (!this.markerContent_) {
  318. // Marker content area doesnt exist.
  319. return;
  320. }
  321. this.removeChildren_(this.markerContent_);
  322. var content = this.getContent();
  323. if (content) {
  324. if (typeof content == 'string') {
  325. content = content.replace(/^\s*([\S\s]*)\b\s*$/, '$1');
  326. content = this.htmlToDocumentFragment_(content);
  327. }
  328. this.markerContent_.appendChild(content);
  329. var that = this;
  330. var images = this.markerContent_.getElementsByTagName('IMG');
  331. for (var i = 0, image; image = images[i]; i++) {
  332. // By default, a browser lets a image be dragged outside of the browser,
  333. // so by calling preventDefault we stop this behaviour and allow the image
  334. // to be dragged around the map and now out of the browser and onto the
  335. // desktop.
  336. google.maps.event.addDomListener(image, 'mousedown', function(e) {
  337. if (that.getDraggable()) {
  338. if (e.preventDefault) {
  339. e.preventDefault();
  340. }
  341. e.returnValue = false;
  342. }
  343. });
  344. // Because we don't know the size of an image till it loads, add a
  345. // listener to the image load so the marker can resize and reposition
  346. // itself to be the correct height.
  347. google.maps.event.addDomListener(image, 'load', function() {
  348. that.draw();
  349. });
  350. }
  351. google.maps.event.trigger(this, 'domready');
  352. }
  353. if (this.ready_) {
  354. this.draw();
  355. }
  356. };
  357. RichMarker.prototype['content_changed'] = RichMarker.prototype.content_changed;
  358. /**
  359. * Sets the cursor.
  360. *
  361. * @param {string} whichCursor What cursor to show.
  362. * @private
  363. */
  364. RichMarker.prototype.setCursor_ = function(whichCursor) {
  365. if (!this.ready_) {
  366. return;
  367. }
  368. var cursor = '';
  369. if (navigator.userAgent.indexOf('Gecko/') !== -1) {
  370. // Moz has some nice cursors :)
  371. if (whichCursor == 'dragging') {
  372. cursor = '-moz-grabbing';
  373. }
  374. if (whichCursor == 'dragready') {
  375. cursor = '-moz-grab';
  376. }
  377. if (whichCursor == 'draggable') {
  378. cursor = 'pointer';
  379. }
  380. } else {
  381. if (whichCursor == 'dragging' || whichCursor == 'dragready') {
  382. cursor = 'move';
  383. }
  384. if (whichCursor == 'draggable') {
  385. cursor = 'pointer';
  386. }
  387. }
  388. if (this.markerWrapper_.style.cursor != cursor) {
  389. this.markerWrapper_.style.cursor = cursor;
  390. }
  391. };
  392. /**
  393. * Start dragging.
  394. *
  395. * @param {Event} e The event.
  396. */
  397. RichMarker.prototype.startDrag = function(e) {
  398. if (!this.getDraggable()) {
  399. return;
  400. }
  401. if (!this.dragging_) {
  402. this.dragging_ = true;
  403. var map = this.getMap();
  404. this.mapDraggable_ = map.get('draggable');
  405. map.set('draggable', false);
  406. // Store the current mouse position
  407. this.mouseX_ = e.clientX;
  408. this.mouseY_ = e.clientY;
  409. this.setCursor_('dragready');
  410. // Stop the text from being selectable while being dragged
  411. this.markerWrapper_.style['MozUserSelect'] = 'none';
  412. this.markerWrapper_.style['KhtmlUserSelect'] = 'none';
  413. this.markerWrapper_.style['WebkitUserSelect'] = 'none';
  414. this.markerWrapper_['unselectable'] = 'on';
  415. this.markerWrapper_['onselectstart'] = function() {
  416. return false;
  417. };
  418. this.addDraggingListeners_();
  419. google.maps.event.trigger(this, 'dragstart');
  420. }
  421. };
  422. /**
  423. * Stop dragging.
  424. */
  425. RichMarker.prototype.stopDrag = function() {
  426. if (!this.getDraggable()) {
  427. return;
  428. }
  429. if (this.dragging_) {
  430. this.dragging_ = false;
  431. this.getMap().set('draggable', this.mapDraggable_);
  432. this.mouseX_ = this.mouseY_ = this.mapDraggable_ = null;
  433. // Allow the text to be selectable again
  434. this.markerWrapper_.style['MozUserSelect'] = '';
  435. this.markerWrapper_.style['KhtmlUserSelect'] = '';
  436. this.markerWrapper_.style['WebkitUserSelect'] = '';
  437. this.markerWrapper_['unselectable'] = 'off';
  438. this.markerWrapper_['onselectstart'] = function() {};
  439. this.removeDraggingListeners_();
  440. this.setCursor_('draggable');
  441. google.maps.event.trigger(this, 'dragend');
  442. this.draw();
  443. }
  444. };
  445. /**
  446. * Handles the drag event.
  447. *
  448. * @param {Event} e The event.
  449. */
  450. RichMarker.prototype.drag = function(e) {
  451. if (!this.getDraggable() || !this.dragging_) {
  452. // This object isn't draggable or we have stopped dragging
  453. this.stopDrag();
  454. return;
  455. }
  456. var dx = this.mouseX_ - e.clientX;
  457. var dy = this.mouseY_ - e.clientY;
  458. this.mouseX_ = e.clientX;
  459. this.mouseY_ = e.clientY;
  460. var left = parseInt(this.markerWrapper_.style['left'], 10) - dx;
  461. var top = parseInt(this.markerWrapper_.style['top'], 10) - dy;
  462. this.markerWrapper_.style['left'] = left + 'px';
  463. this.markerWrapper_.style['top'] = top + 'px';
  464. var offset = this.getOffset_();
  465. // Set the position property and adjust for the anchor offset
  466. var point = new google.maps.Point(left - offset.width, top - offset.height);
  467. var projection = this.getProjection();
  468. this.setPosition(projection.fromDivPixelToLatLng(point));
  469. this.setCursor_('dragging');
  470. google.maps.event.trigger(this, 'drag');
  471. };
  472. /**
  473. * Removes the drag listeners associated with the marker.
  474. *
  475. * @private
  476. */
  477. RichMarker.prototype.removeDragListeners_ = function() {
  478. if (this.draggableListener_) {
  479. google.maps.event.removeListener(this.draggableListener_);
  480. delete this.draggableListener_;
  481. }
  482. this.setCursor_('');
  483. };
  484. /**
  485. * Add dragability events to the marker.
  486. *
  487. * @param {Node} node The node to apply dragging to.
  488. * @private
  489. */
  490. RichMarker.prototype.addDragging_ = function(node) {
  491. if (!node) {
  492. return;
  493. }
  494. var that = this;
  495. this.draggableListener_ =
  496. google.maps.event.addDomListener(node, 'mousedown', function(e) {
  497. that.startDrag(e);
  498. });
  499. this.setCursor_('draggable');
  500. };
  501. /**
  502. * Add dragging listeners.
  503. *
  504. * @private
  505. */
  506. RichMarker.prototype.addDraggingListeners_ = function() {
  507. var that = this;
  508. if (this.markerWrapper_.setCapture) {
  509. this.markerWrapper_.setCapture(true);
  510. this.draggingListeners_ = [
  511. google.maps.event.addDomListener(this.markerWrapper_, 'mousemove', function(e) {
  512. that.drag(e);
  513. }, true),
  514. google.maps.event.addDomListener(this.markerWrapper_, 'mouseup', function() {
  515. that.stopDrag();
  516. that.markerWrapper_.releaseCapture();
  517. }, true)
  518. ];
  519. } else {
  520. this.draggingListeners_ = [
  521. google.maps.event.addDomListener(window, 'mousemove', function(e) {
  522. that.drag(e);
  523. }, true),
  524. google.maps.event.addDomListener(window, 'mouseup', function() {
  525. that.stopDrag();
  526. }, true)
  527. ];
  528. }
  529. };
  530. /**
  531. * Remove dragging listeners.
  532. *
  533. * @private
  534. */
  535. RichMarker.prototype.removeDraggingListeners_ = function() {
  536. if (this.draggingListeners_) {
  537. for (var i = 0, listener; listener = this.draggingListeners_[i]; i++) {
  538. google.maps.event.removeListener(listener);
  539. }
  540. this.draggingListeners_.length = 0;
  541. }
  542. };
  543. /**
  544. * Get the anchor offset.
  545. *
  546. * @return {google.maps.Size} The size offset.
  547. * @private
  548. */
  549. RichMarker.prototype.getOffset_ = function() {
  550. var anchor = this.getAnchor();
  551. if (typeof anchor == 'object') {
  552. return /** @type {google.maps.Size} */ (anchor);
  553. }
  554. var offset = new google.maps.Size(0, 0);
  555. if (!this.markerContent_) {
  556. return offset;
  557. }
  558. var width = this.markerContent_.offsetWidth;
  559. var height = this.markerContent_.offsetHeight;
  560. switch (anchor) {
  561. case RichMarkerPosition['TOP_LEFT']:
  562. break;
  563. case RichMarkerPosition['TOP']:
  564. offset.width = -width / 2;
  565. break;
  566. case RichMarkerPosition['TOP_RIGHT']:
  567. offset.width = -width;
  568. break;
  569. case RichMarkerPosition['LEFT']:
  570. offset.height = -height / 2;
  571. break;
  572. case RichMarkerPosition['MIDDLE']:
  573. offset.width = -width / 2;
  574. offset.height = -height / 2;
  575. break;
  576. case RichMarkerPosition['RIGHT']:
  577. offset.width = -width;
  578. offset.height = -height / 2;
  579. break;
  580. case RichMarkerPosition['BOTTOM_LEFT']:
  581. offset.height = -height;
  582. break;
  583. case RichMarkerPosition['BOTTOM']:
  584. offset.width = -width / 2;
  585. offset.height = -height;
  586. break;
  587. case RichMarkerPosition['BOTTOM_RIGHT']:
  588. offset.width = -width;
  589. offset.height = -height;
  590. break;
  591. }
  592. return offset;
  593. };
  594. /**
  595. * Adding the marker to a map.
  596. * Implementing the interface.
  597. */
  598. RichMarker.prototype.onAdd = function() {
  599. if (!this.markerWrapper_) {
  600. this.markerWrapper_ = document.createElement('DIV');
  601. this.markerWrapper_.style['position'] = 'absolute';
  602. }
  603. if (this.getZIndex()) {
  604. this.markerWrapper_.style['zIndex'] = this.getZIndex();
  605. }
  606. this.markerWrapper_.style['display'] = this.getVisible() ? '' : 'none';
  607. if (!this.markerContent_) {
  608. this.markerContent_ = document.createElement('DIV');
  609. this.markerWrapper_.appendChild(this.markerContent_);
  610. var that = this;
  611. google.maps.event.addDomListener(this.markerContent_, 'click', function(e) {
  612. google.maps.event.trigger(that, 'click', e);
  613. });
  614. google.maps.event.addDomListener(this.markerContent_, 'mouseover', function(e) {
  615. google.maps.event.trigger(that, 'mouseover', e);
  616. });
  617. google.maps.event.addDomListener(this.markerContent_, 'mouseout', function(e) {
  618. google.maps.event.trigger(that, 'mouseout', e);
  619. });
  620. }
  621. this.ready_ = true;
  622. this.content_changed();
  623. this.flat_changed();
  624. this.draggable_changed();
  625. var panes = this.getPanes();
  626. if (panes) {
  627. panes.overlayMouseTarget.appendChild(this.markerWrapper_);
  628. }
  629. google.maps.event.trigger(this, 'ready');
  630. };
  631. RichMarker.prototype['onAdd'] = RichMarker.prototype.onAdd;
  632. /**
  633. * Impelementing the interface.
  634. */
  635. RichMarker.prototype.draw = function() {
  636. if (!this.ready_ || this.dragging_) {
  637. return;
  638. }
  639. var projection = this.getProjection();
  640. if (!projection) {
  641. // The map projection is not ready yet so do nothing
  642. return;
  643. }
  644. var latLng = /** @type {google.maps.LatLng} */ (this.get('position'));
  645. var pos = projection.fromLatLngToDivPixel(latLng);
  646. var offset = this.getOffset_();
  647. // console.log(offset)
  648. this.markerWrapper_.style['top'] = (pos.y + -42) + 'px';
  649. this.markerWrapper_.style['left'] = (pos.x + -21) + 'px';
  650. var height = this.markerContent_.offsetHeight;
  651. var width = this.markerContent_.offsetWidth;
  652. if (width != this.get('width')) {
  653. this.set('width', width);
  654. }
  655. if (height != this.get('height')) {
  656. this.set('height', height);
  657. }
  658. };
  659. RichMarker.prototype['draw'] = RichMarker.prototype.draw;
  660. /**
  661. * Removing a marker from the map.
  662. * Implementing the interface.
  663. */
  664. RichMarker.prototype.onRemove = function() {
  665. if (this.markerWrapper_ && this.markerWrapper_.parentNode) {
  666. this.markerWrapper_.parentNode.removeChild(this.markerWrapper_);
  667. }
  668. this.removeDragListeners_();
  669. };
  670. RichMarker.prototype['onRemove'] = RichMarker.prototype.onRemove;
  671. /**
  672. * RichMarker Anchor positions
  673. * @enum {number}
  674. */
  675. var RichMarkerPosition = {
  676. 'TOP_LEFT': 1,
  677. 'TOP': 2,
  678. 'TOP_RIGHT': 3,
  679. 'LEFT': 4,
  680. 'MIDDLE': 5,
  681. 'RIGHT': 6,
  682. 'BOTTOM_LEFT': 7,
  683. 'BOTTOM': 8,
  684. 'BOTTOM_RIGHT': 9
  685. };
  686. window['RichMarkerPosition'] = RichMarkerPosition;