PageRenderTime 99ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 1ms

/www/js/angular-google-maps.js

https://github.com/IBM-Bluemix/bluemix-retail
JavaScript | 8131 lines | 5539 code | 912 blank | 1680 comment | 1237 complexity | f181de0b80499e1d68469cc3f32e2b3c MD5 | raw file
Possible License(s): Apache-2.0
  1. /*! angular-google-maps 1.1.1-SNAPSHOT 2014-05-26
  2. * AngularJS directives for Google Maps
  3. * git: https://github.com/nlaplante/angular-google-maps.git
  4. */
  5. /*
  6. !
  7. The MIT License
  8. Copyright (c) 2010-2013 Google, Inc. http://angularjs.org
  9. Permission is hereby granted, free of charge, to any person obtaining a copy
  10. of this software and associated documentation files (the "Software"), to deal
  11. in the Software without restriction, including without limitation the rights
  12. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. copies of the Software, and to permit persons to whom the Software is
  14. furnished to do so, subject to the following conditions:
  15. The above copyright notice and this permission notice shall be included in
  16. all copies or substantial portions of the Software.
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. THE SOFTWARE.
  24. angular-google-maps
  25. https://github.com/nlaplante/angular-google-maps
  26. @authors
  27. Nicolas Laplante - https://plus.google.com/108189012221374960701
  28. Nicholas McCready - https://twitter.com/nmccready
  29. */
  30. (function() {
  31. angular.module("google-maps.directives.api.utils", []);
  32. angular.module("google-maps.directives.api.managers", []);
  33. angular.module("google-maps.directives.api.models.child", ["google-maps.directives.api.utils"]);
  34. angular.module("google-maps.directives.api.models.parent", ["google-maps.directives.api.managers", "google-maps.directives.api.models.child"]);
  35. angular.module("google-maps.directives.api", ["google-maps.directives.api.models.parent"]);
  36. angular.module("google-maps", ["google-maps.directives.api"]).factory("debounce", [
  37. "$timeout", function($timeout) {
  38. return function(fn) {
  39. var nthCall;
  40. nthCall = 0;
  41. return function() {
  42. var argz, later, that;
  43. that = this;
  44. argz = arguments;
  45. nthCall++;
  46. later = (function(version) {
  47. return function() {
  48. if (version === nthCall) {
  49. return fn.apply(that, argz);
  50. }
  51. };
  52. })(nthCall);
  53. return $timeout(later, 0, true);
  54. };
  55. };
  56. }
  57. ]);
  58. }).call(this);
  59. (function() {
  60. angular.element(document).ready(function() {
  61. if (!(google || (typeof google !== "undefined" && google !== null ? google.maps : void 0) || (google.maps.InfoWindow != null))) {
  62. return;
  63. }
  64. google.maps.InfoWindow.prototype._open = google.maps.InfoWindow.prototype.open;
  65. google.maps.InfoWindow.prototype._close = google.maps.InfoWindow.prototype.close;
  66. google.maps.InfoWindow.prototype._isOpen = false;
  67. google.maps.InfoWindow.prototype.open = function(map, anchor) {
  68. this._isOpen = true;
  69. this._open(map, anchor);
  70. };
  71. google.maps.InfoWindow.prototype.close = function() {
  72. this._isOpen = false;
  73. this._close();
  74. };
  75. google.maps.InfoWindow.prototype.isOpen = function(val) {
  76. if (val == null) {
  77. val = void 0;
  78. }
  79. if (val == null) {
  80. return this._isOpen;
  81. } else {
  82. return this._isOpen = val;
  83. }
  84. };
  85. /*
  86. Do the same for InfoBox
  87. TODO: Clean this up so the logic is defined once, wait until develop becomes master as this will be easier
  88. */
  89. if (!window.InfoBox) {
  90. return;
  91. }
  92. window.InfoBox.prototype._open = window.InfoBox.prototype.open;
  93. window.InfoBox.prototype._close = window.InfoBox.prototype.close;
  94. window.InfoBox.prototype._isOpen = false;
  95. window.InfoBox.prototype.open = function(map, anchor) {
  96. this._isOpen = true;
  97. this._open(map, anchor);
  98. };
  99. window.InfoBox.prototype.close = function() {
  100. this._isOpen = false;
  101. this._close();
  102. };
  103. return window.InfoBox.prototype.isOpen = function(val) {
  104. if (val == null) {
  105. val = void 0;
  106. }
  107. if (val == null) {
  108. return this._isOpen;
  109. } else {
  110. return this._isOpen = val;
  111. }
  112. };
  113. });
  114. }).call(this);
  115. /*
  116. Author Nick McCready
  117. Intersection of Objects if the arrays have something in common each intersecting object will be returned
  118. in an new array.
  119. */
  120. (function() {
  121. _.intersectionObjects = function(array1, array2, comparison) {
  122. var res,
  123. _this = this;
  124. if (comparison == null) {
  125. comparison = void 0;
  126. }
  127. res = _.map(array1, function(obj1) {
  128. return _.find(array2, function(obj2) {
  129. if (comparison != null) {
  130. return comparison(obj1, obj2);
  131. } else {
  132. return _.isEqual(obj1, obj2);
  133. }
  134. });
  135. });
  136. return _.filter(res, function(o) {
  137. return o != null;
  138. });
  139. };
  140. _.containsObject = _.includeObject = function(obj, target, comparison) {
  141. var _this = this;
  142. if (comparison == null) {
  143. comparison = void 0;
  144. }
  145. if (obj === null) {
  146. return false;
  147. }
  148. return _.any(obj, function(value) {
  149. if (comparison != null) {
  150. return comparison(value, target);
  151. } else {
  152. return _.isEqual(value, target);
  153. }
  154. });
  155. };
  156. _.differenceObjects = function(array1, array2, comparison) {
  157. if (comparison == null) {
  158. comparison = void 0;
  159. }
  160. return _.filter(array1, function(value) {
  161. return !_.containsObject(array2, value);
  162. });
  163. };
  164. _.withoutObjects = function(array, array2) {
  165. return _.differenceObjects(array, array2);
  166. };
  167. _.indexOfObject = function(array, item, comparison, isSorted) {
  168. var i, length;
  169. if (array == null) {
  170. return -1;
  171. }
  172. i = 0;
  173. length = array.length;
  174. if (isSorted) {
  175. if (typeof isSorted === "number") {
  176. i = (isSorted < 0 ? Math.max(0, length + isSorted) : isSorted);
  177. } else {
  178. i = _.sortedIndex(array, item);
  179. return (array[i] === item ? i : -1);
  180. }
  181. }
  182. while (i < length) {
  183. if (comparison != null) {
  184. if (comparison(array[i], item)) {
  185. return i;
  186. }
  187. } else {
  188. if (_.isEqual(array[i], item)) {
  189. return i;
  190. }
  191. }
  192. i++;
  193. }
  194. return -1;
  195. };
  196. _["extends"] = function(arrayOfObjectsToCombine) {
  197. return _.reduce(arrayOfObjectsToCombine, function(combined, toAdd) {
  198. return _.extend(combined, toAdd);
  199. }, {});
  200. };
  201. }).call(this);
  202. /*
  203. Author: Nicholas McCready & jfriend00
  204. _async handles things asynchronous-like :), to allow the UI to be free'd to do other things
  205. Code taken from http://stackoverflow.com/questions/10344498/best-way-to-iterate-over-an-array-without-blocking-the-ui
  206. The design of any funcitonality of _async is to be like lodash/underscore and replicate it but call things
  207. asynchronously underneath. Each should be sufficient for most things to be derrived from.
  208. TODO: Handle Object iteration like underscore and lodash as well.. not that important right now
  209. */
  210. (function() {
  211. var async;
  212. async = {
  213. each: function(array, callback, doneCallBack, pausedCallBack, chunk, index, pause) {
  214. var doChunk;
  215. if (chunk == null) {
  216. chunk = 20;
  217. }
  218. if (index == null) {
  219. index = 0;
  220. }
  221. if (pause == null) {
  222. pause = 1;
  223. }
  224. if (!pause) {
  225. throw "pause (delay) must be set from _async!";
  226. return;
  227. }
  228. if (array === void 0 || (array != null ? array.length : void 0) <= 0) {
  229. doneCallBack();
  230. return;
  231. }
  232. doChunk = function() {
  233. var cnt, i;
  234. cnt = chunk;
  235. i = index;
  236. while (cnt-- && i < (array ? array.length : i + 1)) {
  237. callback(array[i], i);
  238. ++i;
  239. }
  240. if (array) {
  241. if (i < array.length) {
  242. index = i;
  243. if (pausedCallBack != null) {
  244. pausedCallBack();
  245. }
  246. return setTimeout(doChunk, pause);
  247. } else {
  248. if (doneCallBack) {
  249. return doneCallBack();
  250. }
  251. }
  252. }
  253. };
  254. return doChunk();
  255. },
  256. map: function(objs, iterator, doneCallBack, pausedCallBack, chunk) {
  257. var results;
  258. results = [];
  259. if (objs == null) {
  260. return results;
  261. }
  262. return _async.each(objs, function(o) {
  263. return results.push(iterator(o));
  264. }, function() {
  265. return doneCallBack(results);
  266. }, pausedCallBack, chunk);
  267. }
  268. };
  269. window._async = async;
  270. angular.module("google-maps.directives.api.utils").factory("async", function() {
  271. return window._async;
  272. });
  273. }).call(this);
  274. (function() {
  275. var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
  276. angular.module("google-maps.directives.api.utils").factory("BaseObject", function() {
  277. var BaseObject, baseObjectKeywords;
  278. baseObjectKeywords = ['extended', 'included'];
  279. BaseObject = (function() {
  280. function BaseObject() {}
  281. BaseObject.extend = function(obj) {
  282. var key, value, _ref;
  283. for (key in obj) {
  284. value = obj[key];
  285. if (__indexOf.call(baseObjectKeywords, key) < 0) {
  286. this[key] = value;
  287. }
  288. }
  289. if ((_ref = obj.extended) != null) {
  290. _ref.apply(this);
  291. }
  292. return this;
  293. };
  294. BaseObject.include = function(obj) {
  295. var key, value, _ref;
  296. for (key in obj) {
  297. value = obj[key];
  298. if (__indexOf.call(baseObjectKeywords, key) < 0) {
  299. this.prototype[key] = value;
  300. }
  301. }
  302. if ((_ref = obj.included) != null) {
  303. _ref.apply(this);
  304. }
  305. return this;
  306. };
  307. return BaseObject;
  308. })();
  309. return BaseObject;
  310. });
  311. }).call(this);
  312. /*
  313. Useful function callbacks that should be defined at later time.
  314. Mainly to be used for specs to verify creation / linking.
  315. This is to lead a common design in notifying child stuff.
  316. */
  317. (function() {
  318. angular.module("google-maps.directives.api.utils").factory("ChildEvents", function() {
  319. return {
  320. onChildCreation: function(child) {}
  321. };
  322. });
  323. }).call(this);
  324. (function() {
  325. var __hasProp = {}.hasOwnProperty,
  326. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  327. angular.module("google-maps.directives.api.utils").factory("FitHelper", [
  328. "BaseObject", "Logger", function(BaseObject, $log) {
  329. var FitHelper, _ref;
  330. return FitHelper = (function(_super) {
  331. __extends(FitHelper, _super);
  332. function FitHelper() {
  333. _ref = FitHelper.__super__.constructor.apply(this, arguments);
  334. return _ref;
  335. }
  336. FitHelper.prototype.fit = function(gMarkers, gMap) {
  337. var bounds, everSet,
  338. _this = this;
  339. if (gMap && gMarkers && gMarkers.length > 0) {
  340. bounds = new google.maps.LatLngBounds();
  341. everSet = false;
  342. return _async.each(gMarkers, function(gMarker) {
  343. if (gMarker) {
  344. if (!everSet) {
  345. everSet = true;
  346. }
  347. return bounds.extend(gMarker.getPosition());
  348. }
  349. }, function() {
  350. if (everSet) {
  351. return gMap.fitBounds(bounds);
  352. }
  353. });
  354. }
  355. };
  356. return FitHelper;
  357. })(BaseObject);
  358. }
  359. ]);
  360. }).call(this);
  361. (function() {
  362. angular.module("google-maps.directives.api.utils").service("GmapUtil", [
  363. "Logger", "$compile", function(Logger, $compile) {
  364. var getCoords, validateCoords;
  365. getCoords = function(value) {
  366. if (Array.isArray(value) && value.length === 2) {
  367. return new google.maps.LatLng(value[1], value[0]);
  368. } else if (angular.isDefined(value.type) && value.type === "Point") {
  369. return new google.maps.LatLng(value.coordinates[1], value.coordinates[0]);
  370. } else {
  371. return new google.maps.LatLng(value.latitude, value.longitude);
  372. }
  373. };
  374. validateCoords = function(coords) {
  375. if (angular.isUndefined(coords)) {
  376. return false;
  377. }
  378. if (_.isArray(coords)) {
  379. if (coords.length === 2) {
  380. return true;
  381. }
  382. } else if ((coords != null) && (coords != null ? coords.type : void 0)) {
  383. if (coords.type === "Point" && _.isArray(coords.coordinates) && coords.coordinates.length === 2) {
  384. return true;
  385. }
  386. } else {
  387. if (coords && angular.isDefined((coords != null ? coords.latitude : void 0) && angular.isDefined(coords != null ? coords.longitude : void 0))) {
  388. return true;
  389. }
  390. }
  391. return false;
  392. };
  393. return {
  394. getLabelPositionPoint: function(anchor) {
  395. var xPos, yPos;
  396. if (anchor === void 0) {
  397. return void 0;
  398. }
  399. anchor = /^([-\d\.]+)\s([-\d\.]+)$/.exec(anchor);
  400. xPos = parseFloat(anchor[1]);
  401. yPos = parseFloat(anchor[2]);
  402. if ((xPos != null) && (yPos != null)) {
  403. return new google.maps.Point(xPos, yPos);
  404. }
  405. },
  406. createMarkerOptions: function(coords, icon, defaults, map) {
  407. var opts;
  408. if (map == null) {
  409. map = void 0;
  410. }
  411. if (defaults == null) {
  412. defaults = {};
  413. }
  414. opts = angular.extend({}, defaults, {
  415. position: defaults.position != null ? defaults.position : getCoords(coords),
  416. icon: defaults.icon != null ? defaults.icon : icon,
  417. visible: defaults.visible != null ? defaults.visible : validateCoords(coords)
  418. });
  419. if (map != null) {
  420. opts.map = map;
  421. }
  422. return opts;
  423. },
  424. createWindowOptions: function(gMarker, scope, content, defaults) {
  425. if ((content != null) && (defaults != null) && ($compile != null)) {
  426. return angular.extend({}, defaults, {
  427. content: this.buildContent(scope, defaults, content),
  428. position: defaults.position != null ? defaults.position : angular.isObject(gMarker) ? gMarker.getPosition() : getCoords(scope.coords)
  429. });
  430. } else {
  431. if (!defaults) {
  432. Logger.error("infoWindow defaults not defined");
  433. if (!content) {
  434. return Logger.error("infoWindow content not defined");
  435. }
  436. } else {
  437. return defaults;
  438. }
  439. }
  440. },
  441. buildContent: function(scope, defaults, content) {
  442. var parsed, ret;
  443. if (defaults.content != null) {
  444. ret = defaults.content;
  445. } else {
  446. if ($compile != null) {
  447. parsed = $compile(content)(scope);
  448. if (parsed.length > 0) {
  449. ret = parsed[0];
  450. }
  451. } else {
  452. ret = content;
  453. }
  454. }
  455. return ret;
  456. },
  457. defaultDelay: 50,
  458. isTrue: function(val) {
  459. return angular.isDefined(val) && val !== null && val === true || val === "1" || val === "y" || val === "true";
  460. },
  461. isFalse: function(value) {
  462. return ['false', 'FALSE', 0, 'n', 'N', 'no', 'NO'].indexOf(value) !== -1;
  463. },
  464. getCoords: getCoords,
  465. validateCoords: validateCoords,
  466. validatePath: function(path) {
  467. var array, i;
  468. i = 0;
  469. if (angular.isUndefined(path.type)) {
  470. if (!Array.isArray(path) || path.length < 2) {
  471. return false;
  472. }
  473. while (i < path.length) {
  474. if (!((angular.isDefined(path[i].latitude) && angular.isDefined(path[i].longitude)) || (typeof path[i].lat === "function" && typeof path[i].lng === "function"))) {
  475. return false;
  476. }
  477. i++;
  478. }
  479. return true;
  480. } else {
  481. if (angular.isUndefined(path.coordinates)) {
  482. return false;
  483. }
  484. if (path.type === "Polygon") {
  485. if (path.coordinates[0].length < 4) {
  486. return false;
  487. }
  488. array = path.coordinates[0];
  489. } else if (path.type === "LineString") {
  490. if (path.coordinates.length < 2) {
  491. return false;
  492. }
  493. array = path.coordinates;
  494. } else {
  495. return false;
  496. }
  497. while (i < array.length) {
  498. if (array[i].length !== 2) {
  499. return false;
  500. }
  501. i++;
  502. }
  503. return true;
  504. }
  505. },
  506. convertPathPoints: function(path) {
  507. var array, i, latlng, result;
  508. i = 0;
  509. result = new google.maps.MVCArray();
  510. if (angular.isUndefined(path.type)) {
  511. while (i < path.length) {
  512. latlng;
  513. if (angular.isDefined(path[i].latitude) && angular.isDefined(path[i].longitude)) {
  514. latlng = new google.maps.LatLng(path[i].latitude, path[i].longitude);
  515. } else if (typeof path[i].lat === "function" && typeof path[i].lng === "function") {
  516. latlng = path[i];
  517. }
  518. result.push(latlng);
  519. i++;
  520. }
  521. } else {
  522. array;
  523. if (path.type === "Polygon") {
  524. array = path.coordinates[0];
  525. } else if (path.type === "LineString") {
  526. array = path.coordinates;
  527. }
  528. while (i < array.length) {
  529. result.push(new google.maps.LatLng(array[i][1], array[i][0]));
  530. i++;
  531. }
  532. }
  533. return result;
  534. },
  535. extendMapBounds: function(map, points) {
  536. var bounds, i;
  537. bounds = new google.maps.LatLngBounds();
  538. i = 0;
  539. while (i < points.length) {
  540. bounds.extend(points.getAt(i));
  541. i++;
  542. }
  543. return map.fitBounds(bounds);
  544. }
  545. };
  546. }
  547. ]);
  548. }).call(this);
  549. (function() {
  550. var __hasProp = {}.hasOwnProperty,
  551. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  552. angular.module("google-maps.directives.api.utils").factory("Linked", [
  553. "BaseObject", function(BaseObject) {
  554. var Linked;
  555. Linked = (function(_super) {
  556. __extends(Linked, _super);
  557. function Linked(scope, element, attrs, ctrls) {
  558. this.scope = scope;
  559. this.element = element;
  560. this.attrs = attrs;
  561. this.ctrls = ctrls;
  562. }
  563. return Linked;
  564. })(BaseObject);
  565. return Linked;
  566. }
  567. ]);
  568. }).call(this);
  569. (function() {
  570. angular.module("google-maps.directives.api.utils").service("Logger", [
  571. "$log", function($log) {
  572. return {
  573. logger: $log,
  574. doLog: false,
  575. info: function(msg) {
  576. if (this.doLog) {
  577. if (this.logger != null) {
  578. return this.logger.info(msg);
  579. } else {
  580. return console.info(msg);
  581. }
  582. }
  583. },
  584. error: function(msg) {
  585. if (this.doLog) {
  586. if (this.logger != null) {
  587. return this.logger.error(msg);
  588. } else {
  589. return console.error(msg);
  590. }
  591. }
  592. },
  593. warn: function(msg) {
  594. if (this.doLog) {
  595. if (this.logger != null) {
  596. return this.logger.warn(msg);
  597. } else {
  598. return console.warn(msg);
  599. }
  600. }
  601. }
  602. };
  603. }
  604. ]);
  605. }).call(this);
  606. (function() {
  607. angular.module("google-maps.directives.api.utils").service("MarkerEventHelper", [
  608. "Logger", function($log) {
  609. return {
  610. setEvents: function(marker, scope, model) {
  611. if (angular.isDefined(scope.events) && (scope.events != null) && angular.isObject(scope.events)) {
  612. return _.compact(_.map(scope.events, function(eventHandler, eventName) {
  613. if (scope.events.hasOwnProperty(eventName) && angular.isFunction(scope.events[eventName])) {
  614. return google.maps.event.addListener(marker, eventName, function() {
  615. return eventHandler.apply(scope, [marker, eventName, model, arguments]);
  616. });
  617. } else {
  618. return $log.info("MarkerEventHelper: invalid event listener " + eventName);
  619. }
  620. }));
  621. }
  622. }
  623. };
  624. }
  625. ]);
  626. }).call(this);
  627. (function() {
  628. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  629. __hasProp = {}.hasOwnProperty,
  630. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  631. angular.module("google-maps.directives.api.utils").factory("ModelKey", [
  632. "BaseObject", function(BaseObject) {
  633. var ModelKey;
  634. return ModelKey = (function(_super) {
  635. __extends(ModelKey, _super);
  636. function ModelKey(scope) {
  637. this.scope = scope;
  638. this.setIdKey = __bind(this.setIdKey, this);
  639. this.modelKeyComparison = __bind(this.modelKeyComparison, this);
  640. ModelKey.__super__.constructor.call(this);
  641. this.defaultIdKey = "id";
  642. this.idKey = void 0;
  643. }
  644. ModelKey.prototype.evalModelHandle = function(model, modelKey) {
  645. if (model === void 0) {
  646. return void 0;
  647. }
  648. if (modelKey === 'self') {
  649. return model;
  650. } else {
  651. return model[modelKey];
  652. }
  653. };
  654. ModelKey.prototype.modelKeyComparison = function(model1, model2) {
  655. var scope;
  656. scope = this.scope.coords != null ? this.scope : this.parentScope;
  657. if (scope == null) {
  658. throw "No scope or parentScope set!";
  659. }
  660. return this.evalModelHandle(model1, scope.coords).latitude === this.evalModelHandle(model2, scope.coords).latitude && this.evalModelHandle(model1, scope.coords).longitude === this.evalModelHandle(model2, scope.coords).longitude;
  661. };
  662. ModelKey.prototype.setIdKey = function(scope) {
  663. return this.idKey = scope.idKey != null ? scope.idKey : this.defaultIdKey;
  664. };
  665. return ModelKey;
  666. })(BaseObject);
  667. }
  668. ]);
  669. }).call(this);
  670. (function() {
  671. angular.module("google-maps.directives.api.utils").factory("ModelsWatcher", [
  672. "Logger", function(Logger) {
  673. return {
  674. figureOutState: function(idKey, scope, childObjects, comparison, callBack) {
  675. var adds, mappedScopeModelIds, removals,
  676. _this = this;
  677. adds = [];
  678. mappedScopeModelIds = {};
  679. removals = [];
  680. return _async.each(scope.models, function(m) {
  681. var child;
  682. if (m[idKey] != null) {
  683. mappedScopeModelIds[m[idKey]] = {};
  684. if (childObjects[m[idKey]] == null) {
  685. return adds.push(m);
  686. } else {
  687. child = childObjects[m[idKey]];
  688. if (!comparison(m, child.model)) {
  689. adds.push(m);
  690. return removals.push(child.model);
  691. }
  692. }
  693. } else {
  694. return Logger.error("id missing for model " + (m.toString()) + ", can not use do comparison/insertion");
  695. }
  696. }, function() {
  697. return _async.each(childObjects.values(), function(c) {
  698. var id;
  699. if (c == null) {
  700. Logger.error("child undefined in ModelsWatcher.");
  701. return;
  702. }
  703. if (c.model == null) {
  704. Logger.error("child.model undefined in ModelsWatcher.");
  705. return;
  706. }
  707. id = c.model[idKey];
  708. if (mappedScopeModelIds[id] == null) {
  709. return removals.push(c.model[idKey]);
  710. }
  711. }, function() {
  712. return callBack({
  713. adds: adds,
  714. removals: removals
  715. });
  716. });
  717. });
  718. }
  719. };
  720. }
  721. ]);
  722. }).call(this);
  723. /*
  724. Simple Object Map with a lenght property to make it easy to track length/size
  725. */
  726. (function() {
  727. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  728. angular.module("google-maps.directives.api.utils").factory("PropMap", function() {
  729. var PropMap, propsToPop;
  730. propsToPop = ['get', 'put', 'remove', 'values', 'keys', 'length'];
  731. PropMap = (function() {
  732. function PropMap() {
  733. this.keys = __bind(this.keys, this);
  734. this.values = __bind(this.values, this);
  735. this.remove = __bind(this.remove, this);
  736. this.put = __bind(this.put, this);
  737. this.get = __bind(this.get, this);
  738. this.length = 0;
  739. }
  740. PropMap.prototype.get = function(key) {
  741. return this[key];
  742. };
  743. PropMap.prototype.put = function(key, value) {
  744. if (this[key] == null) {
  745. this.length++;
  746. }
  747. return this[key] = value;
  748. };
  749. PropMap.prototype.remove = function(key) {
  750. delete this[key];
  751. return this.length--;
  752. };
  753. PropMap.prototype.values = function() {
  754. var all, keys,
  755. _this = this;
  756. all = [];
  757. keys = _.keys(this);
  758. _.each(keys, function(value) {
  759. if (_.indexOf(propsToPop, value) === -1) {
  760. return all.push(_this[value]);
  761. }
  762. });
  763. return all;
  764. };
  765. PropMap.prototype.keys = function() {
  766. var all, keys,
  767. _this = this;
  768. keys = _.keys(this);
  769. all = [];
  770. _.each(keys, function(prop) {
  771. if (_.indexOf(propsToPop, prop) === -1) {
  772. return all.push(prop);
  773. }
  774. });
  775. return all;
  776. };
  777. return PropMap;
  778. })();
  779. return PropMap;
  780. });
  781. }).call(this);
  782. (function() {
  783. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  784. __hasProp = {}.hasOwnProperty,
  785. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  786. angular.module("google-maps.directives.api.managers").factory("ClustererMarkerManager", [
  787. "Logger", "FitHelper", function($log, FitHelper) {
  788. var ClustererMarkerManager;
  789. ClustererMarkerManager = (function(_super) {
  790. __extends(ClustererMarkerManager, _super);
  791. function ClustererMarkerManager(gMap, opt_markers, opt_options, opt_events) {
  792. var self;
  793. this.opt_events = opt_events;
  794. this.fit = __bind(this.fit, this);
  795. this.destroy = __bind(this.destroy, this);
  796. this.clear = __bind(this.clear, this);
  797. this.draw = __bind(this.draw, this);
  798. this.removeMany = __bind(this.removeMany, this);
  799. this.remove = __bind(this.remove, this);
  800. this.addMany = __bind(this.addMany, this);
  801. this.add = __bind(this.add, this);
  802. ClustererMarkerManager.__super__.constructor.call(this);
  803. self = this;
  804. this.opt_options = opt_options;
  805. if ((opt_options != null) && opt_markers === void 0) {
  806. this.clusterer = new MarkerClusterer(gMap, void 0, opt_options);
  807. } else if ((opt_options != null) && (opt_markers != null)) {
  808. this.clusterer = new MarkerClusterer(gMap, opt_markers, opt_options);
  809. } else {
  810. this.clusterer = new MarkerClusterer(gMap);
  811. }
  812. this.attachEvents(this.opt_events, "opt_events");
  813. this.clusterer.setIgnoreHidden(true);
  814. this.noDrawOnSingleAddRemoves = true;
  815. $log.info(this);
  816. }
  817. ClustererMarkerManager.prototype.add = function(gMarker) {
  818. return this.clusterer.addMarker(gMarker, this.noDrawOnSingleAddRemoves);
  819. };
  820. ClustererMarkerManager.prototype.addMany = function(gMarkers) {
  821. return this.clusterer.addMarkers(gMarkers);
  822. };
  823. ClustererMarkerManager.prototype.remove = function(gMarker) {
  824. return this.clusterer.removeMarker(gMarker, this.noDrawOnSingleAddRemoves);
  825. };
  826. ClustererMarkerManager.prototype.removeMany = function(gMarkers) {
  827. return this.clusterer.addMarkers(gMarkers);
  828. };
  829. ClustererMarkerManager.prototype.draw = function() {
  830. return this.clusterer.repaint();
  831. };
  832. ClustererMarkerManager.prototype.clear = function() {
  833. this.clusterer.clearMarkers();
  834. return this.clusterer.repaint();
  835. };
  836. ClustererMarkerManager.prototype.attachEvents = function(options, optionsName) {
  837. var eventHandler, eventName, _results;
  838. if (angular.isDefined(options) && (options != null) && angular.isObject(options)) {
  839. _results = [];
  840. for (eventName in options) {
  841. eventHandler = options[eventName];
  842. if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
  843. $log.info("" + optionsName + ": Attaching event: " + eventName + " to clusterer");
  844. _results.push(google.maps.event.addListener(this.clusterer, eventName, options[eventName]));
  845. } else {
  846. _results.push(void 0);
  847. }
  848. }
  849. return _results;
  850. }
  851. };
  852. ClustererMarkerManager.prototype.clearEvents = function(options) {
  853. var eventHandler, eventName, _results;
  854. if (angular.isDefined(options) && (options != null) && angular.isObject(options)) {
  855. _results = [];
  856. for (eventName in options) {
  857. eventHandler = options[eventName];
  858. if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
  859. $log.info("" + optionsName + ": Clearing event: " + eventName + " to clusterer");
  860. _results.push(google.maps.event.clearListeners(this.clusterer, eventName));
  861. } else {
  862. _results.push(void 0);
  863. }
  864. }
  865. return _results;
  866. }
  867. };
  868. ClustererMarkerManager.prototype.destroy = function() {
  869. this.clearEvents(this.opt_events);
  870. this.clearEvents(this.opt_internal_events);
  871. return this.clear();
  872. };
  873. ClustererMarkerManager.prototype.fit = function() {
  874. return ClustererMarkerManager.__super__.fit.call(this, this.clusterer.getMarkers(), this.clusterer.getMap());
  875. };
  876. return ClustererMarkerManager;
  877. })(FitHelper);
  878. return ClustererMarkerManager;
  879. }
  880. ]);
  881. }).call(this);
  882. (function() {
  883. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  884. __hasProp = {}.hasOwnProperty,
  885. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  886. angular.module("google-maps.directives.api.managers").factory("MarkerManager", [
  887. "Logger", "FitHelper", function(Logger, FitHelper) {
  888. var MarkerManager;
  889. MarkerManager = (function(_super) {
  890. __extends(MarkerManager, _super);
  891. MarkerManager.include(FitHelper);
  892. function MarkerManager(gMap, opt_markers, opt_options) {
  893. this.fit = __bind(this.fit, this);
  894. this.handleOptDraw = __bind(this.handleOptDraw, this);
  895. this.clear = __bind(this.clear, this);
  896. this.draw = __bind(this.draw, this);
  897. this.removeMany = __bind(this.removeMany, this);
  898. this.remove = __bind(this.remove, this);
  899. this.addMany = __bind(this.addMany, this);
  900. this.add = __bind(this.add, this);
  901. var self;
  902. MarkerManager.__super__.constructor.call(this);
  903. self = this;
  904. this.gMap = gMap;
  905. this.gMarkers = [];
  906. this.$log = Logger;
  907. this.$log.info(this);
  908. }
  909. MarkerManager.prototype.add = function(gMarker, optDraw) {
  910. this.handleOptDraw(gMarker, optDraw, true);
  911. return this.gMarkers.push(gMarker);
  912. };
  913. MarkerManager.prototype.addMany = function(gMarkers) {
  914. var gMarker, _i, _len, _results;
  915. _results = [];
  916. for (_i = 0, _len = gMarkers.length; _i < _len; _i++) {
  917. gMarker = gMarkers[_i];
  918. _results.push(this.add(gMarker));
  919. }
  920. return _results;
  921. };
  922. MarkerManager.prototype.remove = function(gMarker, optDraw) {
  923. var index, tempIndex;
  924. this.handleOptDraw(gMarker, optDraw, false);
  925. if (!optDraw) {
  926. return;
  927. }
  928. index = void 0;
  929. if (this.gMarkers.indexOf != null) {
  930. index = this.gMarkers.indexOf(gMarker);
  931. } else {
  932. tempIndex = 0;
  933. _.find(this.gMarkers, function(marker) {
  934. tempIndex += 1;
  935. if (marker === gMarker) {
  936. index = tempIndex;
  937. }
  938. });
  939. }
  940. if (index != null) {
  941. return this.gMarkers.splice(index, 1);
  942. }
  943. };
  944. MarkerManager.prototype.removeMany = function(gMarkers) {
  945. var _this = this;
  946. return this.gMarkers.forEach(function(marker) {
  947. return _this.remove(marker);
  948. });
  949. };
  950. MarkerManager.prototype.draw = function() {
  951. var deletes,
  952. _this = this;
  953. deletes = [];
  954. this.gMarkers.forEach(function(gMarker) {
  955. if (!gMarker.isDrawn) {
  956. if (gMarker.doAdd) {
  957. return gMarker.setMap(_this.gMap);
  958. } else {
  959. return deletes.push(gMarker);
  960. }
  961. }
  962. });
  963. return deletes.forEach(function(gMarker) {
  964. return _this.remove(gMarker, true);
  965. });
  966. };
  967. MarkerManager.prototype.clear = function() {
  968. var gMarker, _i, _len, _ref;
  969. _ref = this.gMarkers;
  970. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  971. gMarker = _ref[_i];
  972. gMarker.setMap(null);
  973. }
  974. delete this.gMarkers;
  975. return this.gMarkers = [];
  976. };
  977. MarkerManager.prototype.handleOptDraw = function(gMarker, optDraw, doAdd) {
  978. if (optDraw === true) {
  979. if (doAdd) {
  980. gMarker.setMap(this.gMap);
  981. } else {
  982. gMarker.setMap(null);
  983. }
  984. return gMarker.isDrawn = true;
  985. } else {
  986. gMarker.isDrawn = false;
  987. return gMarker.doAdd = doAdd;
  988. }
  989. };
  990. MarkerManager.prototype.fit = function() {
  991. return MarkerManager.__super__.fit.call(this, this.gMarkers, this.gMap);
  992. };
  993. return MarkerManager;
  994. })(FitHelper);
  995. return MarkerManager;
  996. }
  997. ]);
  998. }).call(this);
  999. (function() {
  1000. angular.module("google-maps").factory("array-sync", [
  1001. "add-events", function(mapEvents) {
  1002. return function(mapArray, scope, pathEval) {
  1003. var geojsonArray, geojsonHandlers, geojsonWatcher, isSetFromScope, legacyHandlers, legacyWatcher, mapArrayListener, scopePath, watchListener;
  1004. isSetFromScope = false;
  1005. scopePath = scope.$eval(pathEval);
  1006. if (!scope["static"]) {
  1007. legacyHandlers = {
  1008. set_at: function(index) {
  1009. var value;
  1010. if (isSetFromScope) {
  1011. return;
  1012. }
  1013. value = mapArray.getAt(index);
  1014. if (!value) {
  1015. return;
  1016. }
  1017. if (!value.lng || !value.lat) {
  1018. return scopePath[index] = value;
  1019. } else {
  1020. scopePath[index].latitude = value.lat();
  1021. return scopePath[index].longitude = value.lng();
  1022. }
  1023. },
  1024. insert_at: function(index) {
  1025. var value;
  1026. if (isSetFromScope) {
  1027. return;
  1028. }
  1029. value = mapArray.getAt(index);
  1030. if (!value) {
  1031. return;
  1032. }
  1033. if (!value.lng || !value.lat) {
  1034. return scopePath.splice(index, 0, value);
  1035. } else {
  1036. return scopePath.splice(index, 0, {
  1037. latitude: value.lat(),
  1038. longitude: value.lng()
  1039. });
  1040. }
  1041. },
  1042. remove_at: function(index) {
  1043. if (isSetFromScope) {
  1044. return;
  1045. }
  1046. return scopePath.splice(index, 1);
  1047. }
  1048. };
  1049. geojsonArray;
  1050. if (scopePath.type === "Polygon") {
  1051. geojsonArray = scopePath.coordinates[0];
  1052. } else if (scopePath.type === "LineString") {
  1053. geojsonArray = scopePath.coordinates;
  1054. }
  1055. geojsonHandlers = {
  1056. set_at: function(index) {
  1057. var value;
  1058. if (isSetFromScope) {
  1059. return;
  1060. }
  1061. value = mapArray.getAt(index);
  1062. if (!value) {
  1063. return;
  1064. }
  1065. if (!value.lng || !value.lat) {
  1066. return;
  1067. }
  1068. geojsonArray[index][1] = value.lat();
  1069. return geojsonArray[index][0] = value.lng();
  1070. },
  1071. insert_at: function(index) {
  1072. var value;
  1073. if (isSetFromScope) {
  1074. return;
  1075. }
  1076. value = mapArray.getAt(index);
  1077. if (!value) {
  1078. return;
  1079. }
  1080. if (!value.lng || !value.lat) {
  1081. return;
  1082. }
  1083. return geojsonArray.splice(index, 0, [value.lng(), value.lat()]);
  1084. },
  1085. remove_at: function(index) {
  1086. if (isSetFromScope) {
  1087. return;
  1088. }
  1089. return geojsonArray.splice(index, 1);
  1090. }
  1091. };
  1092. mapArrayListener = mapEvents(mapArray, angular.isUndefined(scopePath.type) ? legacyHandlers : geojsonHandlers);
  1093. }
  1094. legacyWatcher = function(newPath) {
  1095. var i, l, newLength, newValue, oldArray, oldLength, oldValue;
  1096. isSetFromScope = true;
  1097. oldArray = mapArray;
  1098. if (newPath) {
  1099. i = 0;
  1100. oldLength = oldArray.getLength();
  1101. newLength = newPath.length;
  1102. l = Math.min(oldLength, newLength);
  1103. newValue = void 0;
  1104. while (i < l) {
  1105. oldValue = oldArray.getAt(i);
  1106. newValue = newPath[i];
  1107. if (typeof newValue.equals === "function") {
  1108. if (!newValue.equals(oldValue)) {
  1109. oldArray.setAt(i, newValue);
  1110. }
  1111. } else {
  1112. if ((oldValue.lat() !== newValue.latitude) || (oldValue.lng() !== newValue.longitude)) {
  1113. oldArray.setAt(i, new google.maps.LatLng(newValue.latitude, newValue.longitude));
  1114. }
  1115. }
  1116. i++;
  1117. }
  1118. while (i < newLength) {
  1119. newValue = newPath[i];
  1120. if (typeof newValue.lat === "function" && typeof newValue.lng === "function") {
  1121. oldArray.push(newValue);
  1122. } else {
  1123. oldArray.push(new google.maps.LatLng(newValue.latitude, newValue.longitude));
  1124. }
  1125. i++;
  1126. }
  1127. while (i < oldLength) {
  1128. oldArray.pop();
  1129. i++;
  1130. }
  1131. }
  1132. return isSetFromScope = false;
  1133. };
  1134. geojsonWatcher = function(newPath) {
  1135. var array, i, l, newLength, newValue, oldArray, oldLength, oldValue;
  1136. isSetFromScope = true;
  1137. oldArray = mapArray;
  1138. if (newPath) {
  1139. array;
  1140. if (scopePath.type === "Polygon") {
  1141. array = newPath.coordinates[0];
  1142. } else if (scopePath.type === "LineString") {
  1143. array = newPath.coordinates;
  1144. }
  1145. i = 0;
  1146. oldLength = oldArray.getLength();
  1147. newLength = array.length;
  1148. l = Math.min(oldLength, newLength);
  1149. newValue = void 0;
  1150. while (i < l) {
  1151. oldValue = oldArray.getAt(i);
  1152. newValue = array[i];
  1153. if ((oldValue.lat() !== newValue[1]) || (oldValue.lng() !== newValue[0])) {
  1154. oldArray.setAt(i, new google.maps.LatLng(newValue[1], newValue[0]));
  1155. }
  1156. i++;
  1157. }
  1158. while (i < newLength) {
  1159. newValue = array[i];
  1160. oldArray.push(new google.maps.LatLng(newValue[1], newValue[0]));
  1161. i++;
  1162. }
  1163. while (i < oldLength) {
  1164. oldArray.pop();
  1165. i++;
  1166. }
  1167. }
  1168. return isSetFromScope = false;
  1169. };
  1170. watchListener;
  1171. if (!scope["static"]) {
  1172. if (angular.isUndefined(scopePath.type)) {
  1173. watchListener = scope.$watchCollection(pathEval, legacyWatcher);
  1174. } else {
  1175. watchListener = scope.$watch(pathEval, geojsonWatcher);
  1176. }
  1177. }
  1178. return function() {
  1179. if (mapArrayListener) {
  1180. mapArrayListener();
  1181. mapArrayListener = null;
  1182. }
  1183. if (watchListener) {
  1184. watchListener();
  1185. return watchListener = null;
  1186. }
  1187. };
  1188. };
  1189. }
  1190. ]);
  1191. }).call(this);
  1192. (function() {
  1193. angular.module("google-maps").factory("add-events", [
  1194. "$timeout", function($timeout) {
  1195. var addEvent, addEvents;
  1196. addEvent = function(target, eventName, handler) {
  1197. return google.maps.event.addListener(target, eventName, function() {
  1198. handler.apply(this, arguments);
  1199. return $timeout((function() {}), true);
  1200. });
  1201. };
  1202. addEvents = function(target, eventName, handler) {
  1203. var remove;
  1204. if (handler) {
  1205. return addEvent(target, eventName, handler);
  1206. }
  1207. remove = [];
  1208. angular.forEach(eventName, function(_handler, key) {
  1209. return remove.push(addEvent(target, key, _handler));
  1210. });
  1211. return function() {
  1212. angular.forEach(remove, function(listener) {
  1213. return google.maps.event.removeListener(listener);
  1214. });
  1215. return remove = null;
  1216. };
  1217. };
  1218. return addEvents;
  1219. }
  1220. ]);
  1221. }).call(this);
  1222. (function() {
  1223. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  1224. __hasProp = {}.hasOwnProperty,
  1225. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  1226. angular.module("google-maps.directives.api.models.child").factory("MarkerLabelChildModel", [
  1227. "BaseObject", "GmapUtil", function(BaseObject, GmapUtil) {
  1228. var MarkerLabelChildModel;
  1229. MarkerLabelChildModel = (function(_super) {
  1230. __extends(MarkerLabelChildModel, _super);
  1231. MarkerLabelChildModel.include(GmapUtil);
  1232. function MarkerLabelChildModel(gMarker, opt_options) {
  1233. this.destroy = __bind(this.destroy, this);
  1234. this.draw = __bind(this.draw, this);
  1235. this.setPosition = __bind(this.setPosition, this);
  1236. this.setZIndex = __bind(this.setZIndex, this);
  1237. this.setVisible = __bind(this.setVisible, this);
  1238. this.setAnchor = __bind(this.setAnchor, this);
  1239. this.setMandatoryStyles = __bind(this.setMandatoryStyles, this);
  1240. this.setStyles = __bind(this.setStyles, this);
  1241. this.setContent = __bind(this.setContent, this);
  1242. this.setTitle = __bind(this.setTitle, this);
  1243. this.getSharedCross = __bind(this.getSharedCross, this);
  1244. var self, _ref, _ref1;
  1245. MarkerLabelChildModel.__super__.constructor.call(this);
  1246. self = this;
  1247. this.marker = gMarker;
  1248. this.marker.set("labelContent", opt_options.labelContent);
  1249. this.marker.set("labelAnchor", this.getLabelPositionPoint(opt_options.labelAnchor));
  1250. this.marker.set("labelClass", opt_options.labelClass || 'labels');
  1251. this.marker.set("labelStyle", opt_options.labelStyle || {
  1252. opacity: 100
  1253. });
  1254. this.marker.set("labelInBackground", opt_options.labelInBackground || false);
  1255. if (!opt_options.labelVisible) {
  1256. this.marker.set("labelVisible", true);
  1257. }
  1258. if (!opt_options.raiseOnDrag) {
  1259. this.marker.set("raiseOnDrag", true);
  1260. }
  1261. if (!opt_options.clickable) {
  1262. this.marker.set("clickable", true);
  1263. }
  1264. if (!opt_options.draggable) {
  1265. this.marker.set("draggable", false);
  1266. }
  1267. if (!opt_options.optimized) {
  1268. this.marker.set("optimized", false);
  1269. }
  1270. opt_options.crossImage = (_ref = opt_options.crossImage) != null ? _ref : document.location.protocol + "//maps.gstatic.com/intl/en_us/mapfiles/drag_cross_67_16.png";
  1271. opt_options.handCursor = (_ref1 = opt_options.handCursor) != null ? _ref1 : document.location.protocol + "//maps.gstatic.com/intl/en_us/mapfiles/closedhand_8_8.cur";
  1272. this.markerLabel = new MarkerLabel_(this.marker, opt_options.crossImage, opt_options.handCursor);
  1273. this.marker.set("setMap", function(theMap) {
  1274. google.maps.Marker.prototype.setMap.apply(this, arguments);
  1275. return self.markerLabel.setMap(theMap);
  1276. });
  1277. this.marker.setMap(this.marker.getMap());
  1278. }
  1279. MarkerLabelChildModel.prototype.getSharedCross = function(crossUrl) {
  1280. return this.markerLabel.getSharedCross(crossUrl);
  1281. };
  1282. MarkerLabelChildModel.prototype.setTitle = function() {
  1283. return this.markerLabel.setTitle();
  1284. };
  1285. MarkerLabelChildModel.prototype.setContent = function() {
  1286. return this.markerLabel.setContent();
  1287. };
  1288. MarkerLabelChildModel.prototype.setStyles = function() {
  1289. return this.markerLabel.setStyles();
  1290. };
  1291. MarkerLabelChildModel.prototype.setMandatoryStyles = function() {
  1292. return this.markerLabel.setMandatoryStyles();
  1293. };
  1294. MarkerLabelChildModel.prototype.setAnchor = function() {
  1295. return this.markerLabel.setAnchor();
  1296. };
  1297. MarkerLabelChildModel.prototype.setVisible = function() {
  1298. return this.markerLabel.setVisible();
  1299. };
  1300. MarkerLabelChildModel.prototype.setZIndex = function() {
  1301. return this.markerLabel.setZIndex();
  1302. };
  1303. MarkerLabelChildModel.prototype.setPosition = function() {
  1304. return this.markerLabel.setPosition();
  1305. };
  1306. MarkerLabelChildModel.prototype.draw = function() {
  1307. return this.markerLabel.draw();
  1308. };
  1309. MarkerLabelChildModel.prototype.destroy = function() {
  1310. if ((this.markerLabel.labelDiv_.parentNode != null) && (this.markerLabel.eventDiv_.parentNode != null)) {
  1311. return this.markerLabel.onRemove();
  1312. }
  1313. };
  1314. return MarkerLabelChildModel;
  1315. })(BaseObject);
  1316. return MarkerLabelChildModel;
  1317. }
  1318. ]);
  1319. }).call(this);
  1320. (function() {
  1321. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  1322. __hasProp = {}.hasOwnProperty,
  1323. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  1324. angular.module("google-maps.directives.api.models.child").factory("MarkerChildModel", [
  1325. "ModelKey", "GmapUtil", "Logger", "$injector", "MarkerEventHelper", function(ModelKey, GmapUtil, Logger, $injector, MarkerEventHelper) {
  1326. var MarkerChildModel;
  1327. MarkerChildModel = (function(_super) {
  1328. __extends(MarkerChildModel, _super);
  1329. MarkerChildModel.include(GmapUtil);
  1330. MarkerChildModel.include(MarkerEventHelper);
  1331. function MarkerChildModel(model, parentScope, gMap, $timeout, defaults, doClick, gMarkerManager, idKey) {
  1332. var self,
  1333. _this = this;
  1334. this.model = model;
  1335. this.parentScope = parentScope;
  1336. this.gMap = gMap;
  1337. this.$timeout = $timeout;
  1338. this.defaults = defaults;
  1339. this.doClick = doClick;
  1340. this.gMarkerManager = gMarkerManager;
  1341. this.idKey = idKey;
  1342. this.watchDestroy = __bind(this.watchDestroy, this);
  1343. this.setLabelOptions = __bind(this.setLabelOptions, this);
  1344. this.isLabelDefined = __bind(this.isLabelDefined, this);
  1345. this.setOptions = __bind(this.setOptions, this);
  1346. this.setIcon = __bind(this.setIcon, this);
  1347. this.setCoords = __bind(this.setCoords, this);
  1348. this.destroy = __bind(this.destroy, this);
  1349. this.maybeSetScopeValue = __bind(this.maybeSetScopeValue, this);
  1350. this.createMarker = __bind(this.createMarker, this);
  1351. this.setMyScope = __bind(this.setMyScope, this);
  1352. self = this;
  1353. if (this.model[this.idKey]) {
  1354. this.id = this.model[this.idKey];
  1355. }
  1356. this.iconKey = this.parentScope.icon;
  1357. this.coordsKey = this.parentScope.coords;
  1358. this.clickKey = this.parentScope.click();
  1359. this.labelContentKey = this.parentScope.labelContent;
  1360. this.optionsKey = this.parentScope.options;
  1361. this.labelOptionsKey = this.parentScope.labelOptions;
  1362. MarkerChildModel.__super__.constructor.call(this, this.parentScope.$new(false));
  1363. this.scope.model = this.model;
  1364. this.setMyScope(this.model, void 0, true);
  1365. this.createMarker(this.model);
  1366. this.scope.$watch('model', function(newValue, oldValue) {
  1367. if (newValue !== oldValue) {
  1368. return _this.setMyScope(newValue, oldValue);
  1369. }
  1370. }, true);
  1371. this.$log = Logger;
  1372. this.$log.info(self);
  1373. this.watchDestroy(this.scope);
  1374. }
  1375. MarkerChildModel.prototype.setMyScope = function(model, oldModel, isInit) {
  1376. var _this = this;
  1377. if (oldModel == null) {
  1378. oldModel = void 0;
  1379. }
  1380. if (isInit == null) {
  1381. isInit = false;
  1382. }
  1383. this.maybeSetScopeValue('icon', model, oldModel, this.iconKey, this.evalModelHandle, isInit, this.setIcon);
  1384. this.maybeSetScopeValue('coords', model, oldModel, this.coordsKey, this.evalModelHandle, isInit, this.setCoords);
  1385. this.maybeSetScopeValue('labelContent', model, oldModel, this.labelContentKey, this.evalModelHandle, isInit);
  1386. if (_.isFunction(this.clickKey) && $injector) {
  1387. return this.scope.click = function() {
  1388. return $injector.invoke(_this.clickKey, void 0, {
  1389. "$markerModel": model
  1390. });
  1391. };
  1392. } else {
  1393. this.maybeSetScopeValue('click', model, oldModel, this.clickKey, this.evalModelHandle, isInit);
  1394. return this.createMarker(model, oldModel, isInit);
  1395. }
  1396. };
  1397. MarkerChildModel.prototype.createMarker = function(model, oldModel, isInit) {
  1398. var _this = this;
  1399. if (oldModel == null) {
  1400. oldModel = void 0;
  1401. }
  1402. if (isInit == null) {
  1403. isInit = false;
  1404. }
  1405. return this.maybeSetScopeValue('options', model, oldModel, this.optionsKey, function(lModel, lModelKey) {
  1406. var value;
  1407. if (lModel === void 0) {
  1408. return void 0;
  1409. }
  1410. value = lModelKey === 'self' ? lModel : lModel[lModelKey];
  1411. if (value === void 0) {
  1412. return value = lModelKey === void 0 ? _this.defaults : _this.scope.options;
  1413. } else {
  1414. return value;
  1415. }
  1416. }, isInit, this.setOptions);
  1417. };
  1418. MarkerChildModel.prototype.maybeSetScopeValue = function(scopePropName, model, oldModel, modelKey, evaluate, isInit, gSetter) {
  1419. var newValue, oldVal;
  1420. if (gSetter == null) {
  1421. gSetter = void 0;
  1422. }
  1423. if (oldModel === void 0) {
  1424. this.scope[scopePropName] = evaluate(model, modelKey);
  1425. if (!isInit) {
  1426. if (gSetter != null) {
  1427. gSetter(this.scope);
  1428. }
  1429. }
  1430. return;
  1431. }
  1432. oldVal = evaluate(oldModel, modelKey);
  1433. newValue = evaluate(model, modelKey);
  1434. if (newValue !== oldVal && this.scope[scopePropName] !== newValue) {
  1435. this.scope[scopePropName] = newValue;
  1436. if (!isInit) {
  1437. if (gSetter != null) {
  1438. gSetter(this.scope);
  1439. }
  1440. return this.gMarkerManager.draw();
  1441. }
  1442. }
  1443. };
  1444. MarkerChildModel.prototype.destroy = function() {
  1445. return this.scope.$destroy();
  1446. };
  1447. MarkerChildModel.prototype.setCoords = function(scope) {
  1448. if (scope.$id !== this.scope.$id || this.gMarker === void 0) {
  1449. return;
  1450. }
  1451. if ((scope.coords != null)) {
  1452. if (!this.validateCoords(this.scope.coords)) {
  1453. this.$log.error("MarkerChildMarker cannot render marker as scope.coords as no position on marker: " + (JSON.stringify(this.model)));
  1454. return;
  1455. }
  1456. this.gMarker.setPosition(this.getCoords(scope.coords));
  1457. this.gMarker.setVisible(this.validateCoords(scope.coords));
  1458. this.gMarkerManager.remove(this.gMarker);
  1459. return this.gMarkerManager.add(this.gMarker);
  1460. } else {
  1461. return this.gMarkerManager.remove(this.gMarker);
  1462. }
  1463. };
  1464. MarkerChildModel.prototype.setIcon = function(scope) {
  1465. if (scope.$id !== this.scope.$id || this.gMarker === void 0) {
  1466. return;
  1467. }
  1468. this.gMarkerManager.remove(this.gMarker);
  1469. this.gMarker.setIcon(scope.icon);
  1470. this.gMarkerManager.add(this.gMarker);
  1471. this.gMarker.setPosition(this.getCoords(scope.coords));
  1472. return this.gMarker.setVisible(this.validateCoords(scope.coords));
  1473. };
  1474. MarkerChildModel.prototype.setOptions = function(scope) {
  1475. var _ref,
  1476. _this = this;
  1477. if (scope.$id !== this.scope.$id) {
  1478. return;
  1479. }
  1480. if (this.gMarker != null) {
  1481. this.gMarkerManager.remove(this.gMarker);
  1482. delete this.gMarker;
  1483. }
  1484. if (!((_ref = scope.coords) != null ? _ref : typeof scope.icon === "function" ? scope.icon(scope.options != null) : void 0)) {
  1485. return;
  1486. }
  1487. this.opts = this.createMarkerOptions(scope.coords, scope.icon, scope.options);
  1488. delete this.gMarker;
  1489. if (this.isLabelDefined(scope)) {
  1490. this.gMarker = new MarkerWithLabel(this.setLabelOptions(this.opts, scope));
  1491. } else {
  1492. this.gMarker = new google.maps.Marker(this.opts);
  1493. }
  1494. this.setEvents(this.gMarker, this.parentScope, this.model);
  1495. if (this.id) {
  1496. this.gMarker.key = this.id;
  1497. }
  1498. this.gMarkerManager.add(this.gMarker);
  1499. return google.maps.event.addListener(this.gMarker, 'click', function() {
  1500. if (_this.doClick && (_this.scope.click != null)) {
  1501. return _this.scope.click();
  1502. }
  1503. });
  1504. };
  1505. MarkerChildModel.prototype.isLabelDefined = function(scope) {
  1506. return scope.labelContent != null;
  1507. };
  1508. MarkerChildModel.prototype.setLabelOptions = function(opts, scope) {
  1509. opts.labelAnchor = this.getLabelPositionPoint(scope.labelAnchor);
  1510. opts.labelClass = scope.labelClass;
  1511. opts.labelContent = scope.labelContent;
  1512. return opts;
  1513. };
  1514. MarkerChildModel.prototype.watchDestroy = function(scope) {
  1515. var _this = this;
  1516. return scope.$on("$destroy", function() {
  1517. var self, _ref;
  1518. if (_this.gMarker != null) {
  1519. google.maps.event.clearListeners(_this.gMarker, 'click');
  1520. if (((_ref = _this.parentScope) != null ? _ref.events : void 0) && _.isArray(_this.parentScope.events)) {
  1521. _this.parentScope.events.forEach(function(event, eventName) {
  1522. return google.maps.event.clearListeners(this.gMarker, eventName);
  1523. });
  1524. }
  1525. _this.gMarkerManager.remove(_this.gMarker, true);
  1526. delete _this.gMarker;
  1527. }
  1528. return self = void 0;
  1529. });
  1530. };
  1531. return MarkerChildModel;
  1532. })(ModelKey);
  1533. return MarkerChildModel;
  1534. }
  1535. ]);
  1536. }).call(this);
  1537. (function() {
  1538. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  1539. __hasProp = {}.hasOwnProperty,
  1540. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  1541. angular.module("google-maps.directives.api").factory("PolylineChildModel", [
  1542. "BaseObject", "Logger", "$timeout", "array-sync", "GmapUtil", function(BaseObject, Logger, $timeout, arraySync, GmapUtil) {
  1543. var $log, PolylineChildModel;
  1544. $log = Logger;
  1545. return PolylineChildModel = (function(_super) {
  1546. __extends(PolylineChildModel, _super);
  1547. PolylineChildModel.include(GmapUtil);
  1548. function PolylineChildModel(scope, attrs, map, defaults, model) {
  1549. var arraySyncer, pathPoints, self,
  1550. _this = this;
  1551. this.scope = scope;
  1552. this.attrs = attrs;
  1553. this.map = map;
  1554. this.defaults = defaults;
  1555. this.model = model;
  1556. this.buildOpts = __bind(this.buildOpts, this);
  1557. self = this;
  1558. pathPoints = this.convertPathPoints(this.scope.path);
  1559. this.polyline = new google.maps.Polyline(this.buildOpts(pathPoints));
  1560. if (this.isTrue(this.attrs.fit)) {
  1561. extendMapBounds(map, pathPoints);
  1562. }
  1563. if (!scope["static"] && angular.isDefined(scope.editable)) {
  1564. scope.$watch("editable", function(newValue, oldValue) {
  1565. if (newValue !== oldValue) {
  1566. return this.polyline.setEditable(newValue);
  1567. }
  1568. });
  1569. }
  1570. if (angular.isDefined(scope.draggable)) {
  1571. scope.$watch("draggable", function(newValue, oldValue) {
  1572. if (newValue !== oldValue) {
  1573. return this.polyline.setDraggable(newValue);
  1574. }
  1575. });
  1576. }
  1577. if (angular.isDefined(scope.visible)) {
  1578. scope.$watch("visible", function(newValue, oldValue) {
  1579. if (newValue !== oldValue) {
  1580. return this.polyline.setVisible(newValue);
  1581. }
  1582. });
  1583. }
  1584. if (angular.isDefined(scope.geodesic)) {
  1585. scope.$watch("geodesic", function(newValue, oldValue) {
  1586. if (newValue !== oldValue) {
  1587. return this.polyline.setOptions(this.buildOpts(this.polyline.getPath()));
  1588. }
  1589. });
  1590. }
  1591. if (angular.isDefined(scope.stroke) && angular.isDefined(scope.stroke.weight)) {
  1592. scope.$watch("stroke.weight", function(newValue, oldValue) {
  1593. if (newValue !== oldValue) {
  1594. return this.polyline.setOptions(this.buildOpts(this.polyline.getPath()));
  1595. }
  1596. });
  1597. }
  1598. if (angular.isDefined(scope.stroke) && angular.isDefined(scope.stroke.color)) {
  1599. scope.$watch("stroke.color", function(newValue, oldValue) {
  1600. if (newValue !== oldValue) {
  1601. return this.polyline.setOptions(this.buildOpts(this.polyline.getPath()));
  1602. }
  1603. });
  1604. }
  1605. if (angular.isDefined(scope.icons)) {
  1606. scope.$watch("icons", function(newValue, oldValue) {
  1607. if (newValue !== oldValue) {
  1608. return this.polyline.setOptions(this.buildOpts(this.polyline.getPath()));
  1609. }
  1610. });
  1611. }
  1612. arraySyncer = arraySync(this.polyline.getPath(), scope, "path");
  1613. scope.$on("$destroy", function() {
  1614. _this.polyline.setMap(null);
  1615. _this.polyline = null;
  1616. _this.scope = null;
  1617. if (arraySyncer) {
  1618. arraySyncer();
  1619. return arraySyncer = null;
  1620. }
  1621. });
  1622. $log.info(this);
  1623. }
  1624. PolylineChildModel.prototype.buildOpts = function(pathPoints) {
  1625. var opts,
  1626. _this = this;
  1627. opts = angular.extend({}, this.defaults, {
  1628. map: this.map,
  1629. path: pathPoints,
  1630. icons: this.scope.icons,
  1631. strokeColor: this.scope.stroke && this.scope.stroke.color,
  1632. strokeOpacity: this.scope.stroke && this.scope.stroke.opacity,
  1633. strokeWeight: this.scope.stroke && this.scope.stroke.weight
  1634. });
  1635. angular.forEach({
  1636. clickable: true,
  1637. draggable: false,
  1638. editable: false,
  1639. geodesic: false,
  1640. visible: true,
  1641. "static": false
  1642. }, function(defaultValue, key) {
  1643. if (angular.isUndefined(_this.scope[key]) || _this.scope[key] === null) {
  1644. return opts[key] = defaultValue;
  1645. } else {
  1646. return opts[key] = _this.scope[key];
  1647. }
  1648. });
  1649. if (opts["static"]) {
  1650. opts.editable = false;
  1651. }
  1652. return opts;
  1653. };
  1654. PolylineChildModel.prototype.destroy = function() {
  1655. return this.scope.$destroy();
  1656. };
  1657. return PolylineChildModel;
  1658. })(BaseObject);
  1659. }
  1660. ]);
  1661. }).call(this);
  1662. (function() {
  1663. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  1664. __hasProp = {}.hasOwnProperty,
  1665. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  1666. angular.module("google-maps.directives.api.models.child").factory("WindowChildModel", [
  1667. "BaseObject", "GmapUtil", "Logger", "$compile", "$http", "$templateCache", function(BaseObject, GmapUtil, Logger, $compile, $http, $templateCache) {
  1668. var WindowChildModel;
  1669. WindowChildModel = (function(_super) {
  1670. __extends(WindowChildModel, _super);
  1671. WindowChildModel.include(GmapUtil);
  1672. function WindowChildModel(model, scope, opts, isIconVisibleOnClick, mapCtrl, markerCtrl, element, needToManualDestroy, markerIsVisibleAfterWindowClose) {
  1673. this.model = model;
  1674. this.scope = scope;
  1675. this.opts = opts;
  1676. this.isIconVisibleOnClick = isIconVisibleOnClick;
  1677. this.mapCtrl = mapCtrl;
  1678. this.markerCtrl = markerCtrl;
  1679. this.element = element;
  1680. this.needToManualDestroy = needToManualDestroy != null ? needToManualDestroy : false;
  1681. this.markerIsVisibleAfterWindowClose = markerIsVisibleAfterWindowClose != null ? markerIsVisibleAfterWindowClose : true;
  1682. this.destroy = __bind(this.destroy, this);
  1683. this.remove = __bind(this.remove, this);
  1684. this.hideWindow = __bind(this.hideWindow, this);
  1685. this.getLatestPosition = __bind(this.getLatestPosition, this);
  1686. this.showWindow = __bind(this.showWindow, this);
  1687. this.handleClick = __bind(this.handleClick, this);
  1688. this.watchCoords = __bind(this.watchCoords, this);
  1689. this.watchShow = __bind(this.watchShow, this);
  1690. this.createGWin = __bind(this.createGWin, this);
  1691. this.watchElement = __bind(this.watchElement, this);
  1692. this.googleMapsHandles = [];
  1693. this.$log = Logger;
  1694. this.createGWin();
  1695. if (this.markerCtrl != null) {
  1696. this.markerCtrl.setClickable(true);
  1697. }
  1698. this.handleClick();
  1699. this.watchElement();
  1700. this.watchShow();
  1701. this.watchCoords();
  1702. this.$log.info(this);
  1703. }
  1704. WindowChildModel.prototype.watchElement = function() {
  1705. var _this = this;
  1706. return this.scope.$watch(function() {
  1707. var _ref;
  1708. if (!_this.element || !_this.html) {
  1709. return;
  1710. }
  1711. if (_this.html !== _this.element.html()) {
  1712. if (_this.gWin) {
  1713. if ((_ref = _this.opts) != null) {
  1714. _ref.content = void 0;
  1715. }
  1716. _this.remove();
  1717. _this.createGWin();
  1718. return _this.showHide();
  1719. }
  1720. }
  1721. });
  1722. };
  1723. WindowChildModel.prototype.createGWin = function() {
  1724. var defaults,
  1725. _this = this;
  1726. if (this.gWin == null) {
  1727. defaults = {};
  1728. if (this.opts != null) {
  1729. if (this.scope.coords) {
  1730. this.opts.position = this.getCoords(this.scope.coords);
  1731. }
  1732. defaults = this.opts;
  1733. }
  1734. if (this.element) {
  1735. this.html = _.isObject(this.element) ? this.element.html() : this.element;
  1736. }
  1737. this.opts = this.createWindowOptions(this.markerCtrl, this.scope, this.html, defaults);
  1738. }
  1739. if ((this.opts != null) && !this.gWin) {
  1740. if (this.opts.boxClass && (window.InfoBox && typeof window.InfoBox === 'function')) {
  1741. this.gWin = new window.InfoBox(this.opts);
  1742. } else {
  1743. this.gWin = new google.maps.InfoWindow(this.opts);
  1744. }
  1745. return this.googleMapsHandles.push(google.maps.event.addListener(this.gWin, 'closeclick', function() {
  1746. var _ref;
  1747. if ((_ref = _this.markerCtrl) != null) {
  1748. _ref.setVisible(_this.markerIsVisibleAfterWindowClose);
  1749. }
  1750. _this.gWin.isOpen(false);
  1751. if (_this.scope.closeClick != null) {
  1752. return _this.scope.closeClick();
  1753. }
  1754. }));
  1755. }
  1756. };
  1757. WindowChildModel.prototype.watchShow = function() {
  1758. var _this = this;
  1759. return this.scope.$watch('show', function(newValue, oldValue) {
  1760. if (newValue !== oldValue) {
  1761. if (newValue) {
  1762. return _this.showWindow();
  1763. } else {
  1764. return _this.hideWindow();
  1765. }
  1766. } else {
  1767. if (_this.gWin != null) {
  1768. if (newValue && !_this.gWin.getMap()) {
  1769. return _this.showWindow();
  1770. }
  1771. }
  1772. }
  1773. }, true);
  1774. };
  1775. WindowChildModel.prototype.watchCoords = function() {
  1776. var scope,
  1777. _this = this;
  1778. scope = this.markerCtrl != null ? this.scope.$parent : this.scope;
  1779. return scope.$watch('coords', function(newValue, oldValue) {
  1780. var pos;
  1781. if (newValue !== oldValue) {
  1782. if (newValue == null) {
  1783. return _this.hideWindow();
  1784. } else {
  1785. if (!_this.validateCoords(newValue)) {
  1786. _this.$log.error("WindowChildMarker cannot render marker as scope.coords as no position on marker: " + (JSON.stringify(_this.model)));
  1787. return;
  1788. }
  1789. pos = _this.getCoords(newValue);
  1790. _this.gWin.setPosition(pos);
  1791. if (_this.opts) {
  1792. return _this.opts.position = pos;
  1793. }
  1794. }
  1795. }
  1796. }, true);
  1797. };
  1798. WindowChildModel.prototype.handleClick = function() {
  1799. var _this = this;
  1800. if (this.markerCtrl != null) {
  1801. return this.googleMapsHandles.push(google.maps.event.addListener(this.markerCtrl, 'click', function() {
  1802. var pos;
  1803. if (_this.gWin == null) {
  1804. _this.createGWin();
  1805. }
  1806. pos = _this.markerCtrl.getPosition();
  1807. if (_this.gWin != null) {
  1808. _this.gWin.setPosition(pos);
  1809. if (_this.opts) {
  1810. _this.opts.position = pos;
  1811. }
  1812. _this.showWindow();
  1813. }
  1814. _this.initialMarkerVisibility = _this.markerCtrl.getVisible();
  1815. return _this.markerCtrl.setVisible(_this.isIconVisibleOnClick);
  1816. }));
  1817. }
  1818. };
  1819. WindowChildModel.prototype.showWindow = function() {
  1820. var show,
  1821. _this = this;
  1822. show = function() {
  1823. if (_this.gWin) {
  1824. if ((_this.scope.show || (_this.scope.show == null)) && !_this.gWin.isOpen()) {
  1825. return _this.gWin.open(_this.mapCtrl);
  1826. }
  1827. }
  1828. };
  1829. if (this.scope.templateUrl) {
  1830. if (this.gWin) {
  1831. $http.get(this.scope.templateUrl, {
  1832. cache: $templateCache
  1833. }).then(function(content) {
  1834. var compiled, templateScope;
  1835. templateScope = _this.scope.$new();
  1836. if (angular.isDefined(_this.scope.templateParameter)) {
  1837. templateScope.parameter = _this.scope.templateParameter;
  1838. }
  1839. compiled = $compile(content.data)(templateScope);
  1840. return _this.gWin.setContent(compiled[0]);
  1841. });
  1842. }
  1843. return show();
  1844. } else {
  1845. return show();
  1846. }
  1847. };
  1848. WindowChildModel.prototype.showHide = function() {
  1849. if (this.scope.show) {
  1850. return this.showWindow();
  1851. } else {
  1852. return this.hideWindow();
  1853. }
  1854. };
  1855. WindowChildModel.prototype.getLatestPosition = function() {
  1856. if ((this.gWin != null) && (this.markerCtrl != null)) {
  1857. return this.gWin.setPosition(this.markerCtrl.getPosition());
  1858. }
  1859. };
  1860. WindowChildModel.prototype.hideWindow = function() {
  1861. if ((this.gWin != null) && this.gWin.isOpen()) {
  1862. return this.gWin.close();
  1863. }
  1864. };
  1865. WindowChildModel.prototype.remove = function() {
  1866. this.hideWindow();
  1867. _.each(this.googleMapsHandles, function(h) {
  1868. return google.maps.event.removeListener(h);
  1869. });
  1870. this.googleMapsHandles.length = 0;
  1871. return delete this.gWin;
  1872. };
  1873. WindowChildModel.prototype.destroy = function(manualOverride) {
  1874. var self;
  1875. if (manualOverride == null) {
  1876. manualOverride = false;
  1877. }
  1878. this.remove();
  1879. if ((this.scope != null) && (this.needToManualDestroy || manualOverride)) {
  1880. this.scope.$destroy();
  1881. }
  1882. return self = void 0;
  1883. };
  1884. return WindowChildModel;
  1885. })(BaseObject);
  1886. return WindowChildModel;
  1887. }
  1888. ]);
  1889. }).call(this);
  1890. /*
  1891. - interface for all markers to derrive from
  1892. - to enforce a minimum set of requirements
  1893. - attributes
  1894. - coords
  1895. - icon
  1896. - implementation needed on watches
  1897. */
  1898. (function() {
  1899. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  1900. __hasProp = {}.hasOwnProperty,
  1901. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  1902. angular.module("google-maps.directives.api.models.parent").factory("IMarkerParentModel", [
  1903. "ModelKey", "Logger", function(ModelKey, Logger) {
  1904. var IMarkerParentModel;
  1905. IMarkerParentModel = (function(_super) {
  1906. __extends(IMarkerParentModel, _super);
  1907. IMarkerParentModel.prototype.DEFAULTS = {};
  1908. function IMarkerParentModel(scope, element, attrs, mapCtrl, $timeout) {
  1909. var self,
  1910. _this = this;
  1911. this.scope = scope;
  1912. this.element = element;
  1913. this.attrs = attrs;
  1914. this.mapCtrl = mapCtrl;
  1915. this.$timeout = $timeout;
  1916. this.linkInit = __bind(this.linkInit, this);
  1917. this.onDestroy = __bind(this.onDestroy, this);
  1918. this.onWatch = __bind(this.onWatch, this);
  1919. this.watch = __bind(this.watch, this);
  1920. this.validateScope = __bind(this.validateScope, this);
  1921. this.onTimeOut = __bind(this.onTimeOut, this);
  1922. IMarkerParentModel.__super__.constructor.call(this, this.scope);
  1923. self = this;
  1924. this.$log = Logger;
  1925. if (!this.validateScope(scope)) {
  1926. throw new String("Unable to construct IMarkerParentModel due to invalid scope");
  1927. }
  1928. this.doClick = angular.isDefined(attrs.click);
  1929. if (scope.options != null) {
  1930. this.DEFAULTS = scope.options;
  1931. }
  1932. this.$timeout(function() {
  1933. _this.onTimeOut(scope);
  1934. _this.watch('coords', _this.scope);
  1935. _this.watch('icon', _this.scope);
  1936. _this.watch('options', _this.scope);
  1937. return scope.$on("$destroy", function() {
  1938. return _this.onDestroy(scope);
  1939. });
  1940. });
  1941. }
  1942. IMarkerParentModel.prototype.onTimeOut = function(scope) {};
  1943. IMarkerParentModel.prototype.validateScope = function(scope) {
  1944. var ret;
  1945. if (scope == null) {
  1946. this.$log.error(this.constructor.name + ": invalid scope used");
  1947. return false;
  1948. }
  1949. ret = scope.coords != null;
  1950. if (!ret) {
  1951. this.$log.error(this.constructor.name + ": no valid coords attribute found");
  1952. return false;
  1953. }
  1954. return ret;
  1955. };
  1956. IMarkerParentModel.prototype.watch = function(propNameToWatch, scope) {
  1957. var watchFunc,
  1958. _this = this;
  1959. watchFunc = function(newValue, oldValue) {
  1960. if (newValue !== oldValue) {
  1961. return _this.onWatch(propNameToWatch, scope, newValue, oldValue);
  1962. }
  1963. };
  1964. return scope.$watch(propNameToWatch, watchFunc, true);
  1965. };
  1966. IMarkerParentModel.prototype.onWatch = function(propNameToWatch, scope, newValue, oldValue) {
  1967. throw new String("OnWatch Not Implemented!!");
  1968. };
  1969. IMarkerParentModel.prototype.onDestroy = function(scope) {
  1970. throw new String("OnDestroy Not Implemented!!");
  1971. };
  1972. IMarkerParentModel.prototype.linkInit = function(element, mapCtrl, scope, animate) {
  1973. throw new String("LinkInit Not Implemented!!");
  1974. };
  1975. return IMarkerParentModel;
  1976. })(ModelKey);
  1977. return IMarkerParentModel;
  1978. }
  1979. ]);
  1980. }).call(this);
  1981. /*
  1982. - interface directive for all window(s) to derrive from
  1983. */
  1984. (function() {
  1985. var __hasProp = {}.hasOwnProperty,
  1986. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  1987. angular.module("google-maps.directives.api.models.parent").factory("IWindowParentModel", [
  1988. "ModelKey", "GmapUtil", "Logger", function(ModelKey, GmapUtil, Logger) {
  1989. var IWindowParentModel;
  1990. IWindowParentModel = (function(_super) {
  1991. __extends(IWindowParentModel, _super);
  1992. IWindowParentModel.include(GmapUtil);
  1993. IWindowParentModel.prototype.DEFAULTS = {};
  1994. function IWindowParentModel(scope, element, attrs, ctrls, $timeout, $compile, $http, $templateCache) {
  1995. var self;
  1996. IWindowParentModel.__super__.constructor.call(this, scope);
  1997. self = this;
  1998. this.$log = Logger;
  1999. this.$timeout = $timeout;
  2000. this.$compile = $compile;
  2001. this.$http = $http;
  2002. this.$templateCache = $templateCache;
  2003. if (scope.options != null) {
  2004. this.DEFAULTS = scope.options;
  2005. }
  2006. }
  2007. return IWindowParentModel;
  2008. })(ModelKey);
  2009. return IWindowParentModel;
  2010. }
  2011. ]);
  2012. }).call(this);
  2013. (function() {
  2014. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  2015. __hasProp = {}.hasOwnProperty,
  2016. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  2017. angular.module("google-maps.directives.api.models.parent").factory("LayerParentModel", [
  2018. "BaseObject", "Logger", function(BaseObject, Logger) {
  2019. var LayerParentModel;
  2020. LayerParentModel = (function(_super) {
  2021. __extends(LayerParentModel, _super);
  2022. function LayerParentModel(scope, element, attrs, mapCtrl, $timeout, onLayerCreated, $log) {
  2023. var _this = this;
  2024. this.scope = scope;
  2025. this.element = element;
  2026. this.attrs = attrs;
  2027. this.mapCtrl = mapCtrl;
  2028. this.$timeout = $timeout;
  2029. this.onLayerCreated = onLayerCreated != null ? onLayerCreated : void 0;
  2030. this.$log = $log != null ? $log : Logger;
  2031. this.createGoogleLayer = __bind(this.createGoogleLayer, this);
  2032. if (this.attrs.type == null) {
  2033. this.$log.info("type attribute for the layer directive is mandatory. Layer creation aborted!!");
  2034. return;
  2035. }
  2036. this.createGoogleLayer();
  2037. this.gMap = void 0;
  2038. this.doShow = true;
  2039. this.$timeout(function() {
  2040. _this.gMap = mapCtrl.getMap();
  2041. if (angular.isDefined(_this.attrs.show)) {
  2042. _this.doShow = _this.scope.show;
  2043. }
  2044. if (_this.doShow && (_this.gMap != null)) {
  2045. _this.layer.setMap(_this.gMap);
  2046. }
  2047. _this.scope.$watch("show", function(newValue, oldValue) {
  2048. if (newValue !== oldValue) {
  2049. _this.doShow = newValue;
  2050. if (newValue) {
  2051. return _this.layer.setMap(_this.gMap);
  2052. } else {
  2053. return _this.layer.setMap(null);
  2054. }
  2055. }
  2056. }, true);
  2057. _this.scope.$watch("options", function(newValue, oldValue) {
  2058. if (newValue !== oldValue) {
  2059. _this.layer.setMap(null);
  2060. _this.layer = null;
  2061. return _this.createGoogleLayer();
  2062. }
  2063. }, true);
  2064. return _this.scope.$on("$destroy", function() {
  2065. return _this.layer.setMap(null);
  2066. });
  2067. });
  2068. }
  2069. LayerParentModel.prototype.createGoogleLayer = function() {
  2070. var _this = this;
  2071. if (this.attrs.options == null) {
  2072. this.layer = this.attrs.namespace === void 0 ? new google.maps[this.attrs.type]() : new google.maps[this.attrs.namespace][this.attrs.type]();
  2073. } else {
  2074. this.layer = this.attrs.namespace === void 0 ? new google.maps[this.attrs.type](this.scope.options) : new google.maps[this.attrs.namespace][this.attrs.type](this.scope.options);
  2075. }
  2076. return this.$timeout(function() {
  2077. var fn;
  2078. if ((_this.layer != null) && (_this.onLayerCreated != null)) {
  2079. fn = _this.onLayerCreated(_this.scope, _this.layer);
  2080. if (fn) {
  2081. return fn(_this.layer);
  2082. }
  2083. }
  2084. });
  2085. };
  2086. return LayerParentModel;
  2087. })(BaseObject);
  2088. return LayerParentModel;
  2089. }
  2090. ]);
  2091. }).call(this);
  2092. /*
  2093. Basic Directive api for a marker. Basic in the sense that this directive contains 1:1 on scope and model.
  2094. Thus there will be one html element per marker within the directive.
  2095. */
  2096. (function() {
  2097. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  2098. __hasProp = {}.hasOwnProperty,
  2099. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  2100. angular.module("google-maps.directives.api.models.parent").factory("MarkerParentModel", [
  2101. "IMarkerParentModel", "GmapUtil", "MarkerEventHelper", function(IMarkerParentModel, GmapUtil, MarkerEventHelper) {
  2102. var MarkerParentModel;
  2103. MarkerParentModel = (function(_super) {
  2104. __extends(MarkerParentModel, _super);
  2105. MarkerParentModel.include(GmapUtil);
  2106. MarkerParentModel.include(MarkerEventHelper);
  2107. function MarkerParentModel(scope, element, attrs, mapCtrl, $timeout, gMarkerManager, doFit) {
  2108. var self;
  2109. this.gMarkerManager = gMarkerManager;
  2110. this.doFit = doFit;
  2111. this.onDestroy = __bind(this.onDestroy, this);
  2112. this.setGMarker = __bind(this.setGMarker, this);
  2113. this.onWatch = __bind(this.onWatch, this);
  2114. this.onTimeOut = __bind(this.onTimeOut, this);
  2115. MarkerParentModel.__super__.constructor.call(this, scope, element, attrs, mapCtrl, $timeout);
  2116. self = this;
  2117. }
  2118. MarkerParentModel.prototype.onTimeOut = function(scope) {
  2119. var opts,
  2120. _this = this;
  2121. opts = this.createMarkerOptions(scope.coords, scope.icon, scope.options, this.mapCtrl.getMap());
  2122. this.setGMarker(new google.maps.Marker(opts));
  2123. google.maps.event.addListener(this.scope.gMarker, 'click', function() {
  2124. if (_this.doClick && (scope.click != null)) {
  2125. return _this.$timeout(function() {
  2126. return _this.scope.click();
  2127. });
  2128. }
  2129. });
  2130. this.setEvents(this.scope.gMarker, scope, scope);
  2131. return this.$log.info(this);
  2132. };
  2133. MarkerParentModel.prototype.onWatch = function(propNameToWatch, scope) {
  2134. switch (propNameToWatch) {
  2135. case 'coords':
  2136. if (this.validateCoords(scope.coords) && (this.scope.gMarker != null)) {
  2137. this.scope.gMarker.setMap(this.mapCtrl.getMap());
  2138. this.scope.gMarker.setPosition(this.getCoords(scope.coords));
  2139. this.scope.gMarker.setVisible(this.validateCoords(scope.coords));
  2140. return this.scope.gMarker.setOptions(scope.options);
  2141. } else {
  2142. return this.scope.gMarker.setMap(null);
  2143. }
  2144. break;
  2145. case 'icon':
  2146. if ((scope.icon != null) && this.validateCoords(scope.coords) && (this.scope.gMarker != null)) {
  2147. this.scope.gMarker.setOptions(scope.options);
  2148. this.scope.gMarker.setIcon(scope.icon);
  2149. this.scope.gMarker.setMap(null);
  2150. this.scope.gMarker.setMap(this.mapCtrl.getMap());
  2151. this.scope.gMarker.setPosition(this.getCoords(scope.coords));
  2152. return this.scope.gMarker.setVisible(this.validateCoords(scope.coords));
  2153. }
  2154. break;
  2155. case 'options':
  2156. if (this.validateCoords(scope.coords) && (scope.icon != null) && scope.options) {
  2157. if (this.scope.gMarker != null) {
  2158. this.scope.gMarker.setMap(null);
  2159. }
  2160. return this.setGMarker(new google.maps.Marker(this.createMarkerOptions(scope.coords, scope.icon, scope.options, this.mapCtrl.getMap())));
  2161. }
  2162. }
  2163. };
  2164. MarkerParentModel.prototype.setGMarker = function(gMarker) {
  2165. if (this.scope.gMarker) {
  2166. delete this.scope.gMarker;
  2167. this.gMarkerManager.remove(this.scope.gMarker, false);
  2168. }
  2169. this.scope.gMarker = gMarker;
  2170. if (this.scope.gMarker) {
  2171. this.gMarkerManager.add(this.scope.gMarker, false);
  2172. if (this.doFit) {
  2173. return this.gMarkerManager.fit();
  2174. }
  2175. }
  2176. };
  2177. MarkerParentModel.prototype.onDestroy = function(scope) {
  2178. var self;
  2179. if (!this.scope.gMarker) {
  2180. self = void 0;
  2181. return;
  2182. }
  2183. this.scope.gMarker.setMap(null);
  2184. this.gMarkerManager.remove(this.scope.gMarker, false);
  2185. delete this.scope.gMarker;
  2186. return self = void 0;
  2187. };
  2188. return MarkerParentModel;
  2189. })(IMarkerParentModel);
  2190. return MarkerParentModel;
  2191. }
  2192. ]);
  2193. }).call(this);
  2194. (function() {
  2195. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  2196. __hasProp = {}.hasOwnProperty,
  2197. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  2198. angular.module("google-maps.directives.api.models.parent").factory("MarkersParentModel", [
  2199. "IMarkerParentModel", "ModelsWatcher", "PropMap", "MarkerChildModel", "ClustererMarkerManager", "MarkerManager", function(IMarkerParentModel, ModelsWatcher, PropMap, MarkerChildModel, ClustererMarkerManager, MarkerManager) {
  2200. var MarkersParentModel;
  2201. MarkersParentModel = (function(_super) {
  2202. __extends(MarkersParentModel, _super);
  2203. MarkersParentModel.include(ModelsWatcher);
  2204. function MarkersParentModel(scope, element, attrs, mapCtrl, $timeout) {
  2205. this.onDestroy = __bind(this.onDestroy, this);
  2206. this.newChildMarker = __bind(this.newChildMarker, this);
  2207. this.pieceMealMarkers = __bind(this.pieceMealMarkers, this);
  2208. this.reBuildMarkers = __bind(this.reBuildMarkers, this);
  2209. this.createMarkersFromScratch = __bind(this.createMarkersFromScratch, this);
  2210. this.validateScope = __bind(this.validateScope, this);
  2211. this.onWatch = __bind(this.onWatch, this);
  2212. this.onTimeOut = __bind(this.onTimeOut, this);
  2213. var self,
  2214. _this = this;
  2215. MarkersParentModel.__super__.constructor.call(this, scope, element, attrs, mapCtrl, $timeout);
  2216. self = this;
  2217. this.scope.markerModels = new PropMap();
  2218. this.$timeout = $timeout;
  2219. this.$log.info(this);
  2220. this.doRebuildAll = this.scope.doRebuildAll != null ? this.scope.doRebuildAll : true;
  2221. this.setIdKey(scope);
  2222. this.scope.$watch('doRebuildAll', function(newValue, oldValue) {
  2223. if (newValue !== oldValue) {
  2224. return _this.doRebuildAll = newValue;
  2225. }
  2226. });
  2227. }
  2228. MarkersParentModel.prototype.onTimeOut = function(scope) {
  2229. this.watch('models', scope);
  2230. this.watch('doCluster', scope);
  2231. this.watch('clusterOptions', scope);
  2232. this.watch('clusterEvents', scope);
  2233. this.watch('fit', scope);
  2234. this.watch('idKey', scope);
  2235. this.gMarkerManager = void 0;
  2236. return this.createMarkersFromScratch(scope);
  2237. };
  2238. MarkersParentModel.prototype.onWatch = function(propNameToWatch, scope, newValue, oldValue) {
  2239. if (propNameToWatch === "idKey" && newValue !== oldValue) {
  2240. this.idKey = newValue;
  2241. }
  2242. if (this.doRebuildAll) {
  2243. return this.reBuildMarkers(scope);
  2244. } else {
  2245. return this.pieceMealMarkers(scope);
  2246. }
  2247. };
  2248. MarkersParentModel.prototype.validateScope = function(scope) {
  2249. var modelsNotDefined;
  2250. modelsNotDefined = angular.isUndefined(scope.models) || scope.models === void 0;
  2251. if (modelsNotDefined) {
  2252. this.$log.error(this.constructor.name + ": no valid models attribute found");
  2253. }
  2254. return MarkersParentModel.__super__.validateScope.call(this, scope) || modelsNotDefined;
  2255. };
  2256. MarkersParentModel.prototype.createMarkersFromScratch = function(scope) {
  2257. var _this = this;
  2258. if (scope.doCluster) {
  2259. if (scope.clusterEvents) {
  2260. this.clusterInternalOptions = _.once(function() {
  2261. var self, _ref, _ref1, _ref2;
  2262. self = _this;
  2263. if (!_this.origClusterEvents) {
  2264. _this.origClusterEvents = {
  2265. click: (_ref = scope.clusterEvents) != null ? _ref.click : void 0,
  2266. mouseout: (_ref1 = scope.clusterEvents) != null ? _ref1.mouseout : void 0,
  2267. mouseover: (_ref2 = scope.clusterEvents) != null ? _ref2.mouseover : void 0
  2268. };
  2269. return _.extend(scope.clusterEvents, {
  2270. click: function(cluster) {
  2271. return self.maybeExecMappedEvent(cluster, "click");
  2272. },
  2273. mouseout: function(cluster) {
  2274. return self.maybeExecMappedEvent(cluster, "mouseout");
  2275. },
  2276. mouseover: function(cluster) {
  2277. return self.maybeExecMappedEvent(cluster, "mouseover");
  2278. }
  2279. });
  2280. }
  2281. })();
  2282. }
  2283. if (scope.clusterOptions || scope.clusterEvents) {
  2284. if (this.gMarkerManager === void 0) {
  2285. this.gMarkerManager = new ClustererMarkerManager(this.mapCtrl.getMap(), void 0, scope.clusterOptions, this.clusterInternalOptions);
  2286. } else {
  2287. if (this.gMarkerManager.opt_options !== scope.clusterOptions) {
  2288. this.gMarkerManager = new ClustererMarkerManager(this.mapCtrl.getMap(), void 0, scope.clusterOptions, this.clusterInternalOptions);
  2289. }
  2290. }
  2291. } else {
  2292. this.gMarkerManager = new ClustererMarkerManager(this.mapCtrl.getMap());
  2293. }
  2294. } else {
  2295. this.gMarkerManager = new MarkerManager(this.mapCtrl.getMap());
  2296. }
  2297. return _async.each(scope.models, function(model) {
  2298. return _this.newChildMarker(model, scope);
  2299. }, function() {
  2300. _this.gMarkerManager.draw();
  2301. if (scope.fit) {
  2302. return _this.gMarkerManager.fit();
  2303. }
  2304. });
  2305. };
  2306. MarkersParentModel.prototype.reBuildMarkers = function(scope) {
  2307. if (!scope.doRebuild && scope.doRebuild !== void 0) {
  2308. return;
  2309. }
  2310. this.onDestroy(scope);
  2311. return this.createMarkersFromScratch(scope);
  2312. };
  2313. MarkersParentModel.prototype.pieceMealMarkers = function(scope) {
  2314. var _this = this;
  2315. if ((this.scope.models != null) && this.scope.models.length > 0 && this.scope.markerModels.length > 0) {
  2316. return this.figureOutState(this.idKey, scope, this.scope.markerModels, this.modelKeyComparison, function(state) {
  2317. var payload;
  2318. payload = state;
  2319. return _async.each(payload.removals, function(child) {
  2320. if (child != null) {
  2321. child.destroy();
  2322. return _this.scope.markerModels.remove(child.id);
  2323. }
  2324. }, function() {
  2325. return _async.each(payload.adds, function(modelToAdd) {
  2326. return _this.newChildMarker(modelToAdd, scope);
  2327. }, function() {
  2328. _this.gMarkerManager.draw();
  2329. return scope.markerModels = _this.scope.markerModels;
  2330. });
  2331. });
  2332. });
  2333. } else {
  2334. return this.reBuildMarkers(scope);
  2335. }
  2336. };
  2337. MarkersParentModel.prototype.newChildMarker = function(model, scope) {
  2338. var child;
  2339. if (model[this.idKey] == null) {
  2340. this.$log.error("Marker model has no id to assign a child to. This is required for performance. Please assign id, or redirect id to a different key.");
  2341. return;
  2342. }
  2343. this.$log.info('child', child, 'markers', this.scope.markerModels);
  2344. child = new MarkerChildModel(model, scope, this.mapCtrl, this.$timeout, this.DEFAULTS, this.doClick, this.gMarkerManager, this.idKey);
  2345. this.scope.markerModels.put(model[this.idKey], child);
  2346. return child;
  2347. };
  2348. MarkersParentModel.prototype.onDestroy = function(scope) {
  2349. _.each(this.scope.markerModels.values(), function(model) {
  2350. if (model != null) {
  2351. return model.destroy();
  2352. }
  2353. });
  2354. delete this.scope.markerModels;
  2355. this.scope.markerModels = new PropMap();
  2356. if (this.gMarkerManager != null) {
  2357. return this.gMarkerManager.clear();
  2358. }
  2359. };
  2360. MarkersParentModel.prototype.maybeExecMappedEvent = function(cluster, fnName) {
  2361. var pair, _ref;
  2362. if (_.isFunction((_ref = this.scope.clusterEvents) != null ? _ref[fnName] : void 0)) {
  2363. pair = this.mapClusterToMarkerModels(cluster);
  2364. if (this.origClusterEvents[fnName]) {
  2365. return this.origClusterEvents[fnName](pair.cluster, pair.mapped);
  2366. }
  2367. }
  2368. };
  2369. MarkersParentModel.prototype.mapClusterToMarkerModels = function(cluster) {
  2370. var gMarkers, mapped,
  2371. _this = this;
  2372. gMarkers = cluster.getMarkers();
  2373. mapped = gMarkers.map(function(g) {
  2374. return _this.scope.markerModels[g.key].model;
  2375. });
  2376. return {
  2377. cluster: cluster,
  2378. mapped: mapped
  2379. };
  2380. };
  2381. return MarkersParentModel;
  2382. })(IMarkerParentModel);
  2383. return MarkersParentModel;
  2384. }
  2385. ]);
  2386. }).call(this);
  2387. /*
  2388. Windows directive where many windows map to the models property
  2389. */
  2390. (function() {
  2391. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  2392. __hasProp = {}.hasOwnProperty,
  2393. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  2394. angular.module("google-maps.directives.api.models.parent").factory("PolylinesParentModel", [
  2395. "$timeout", "Logger", "ModelKey", "ModelsWatcher", "PropMap", "PolylineChildModel", function($timeout, Logger, ModelKey, ModelsWatcher, PropMap, PolylineChildModel) {
  2396. var PolylinesParentModel;
  2397. return PolylinesParentModel = (function(_super) {
  2398. __extends(PolylinesParentModel, _super);
  2399. PolylinesParentModel.include(ModelsWatcher);
  2400. function PolylinesParentModel(scope, element, attrs, gMap, defaults) {
  2401. var self,
  2402. _this = this;
  2403. this.scope = scope;
  2404. this.element = element;
  2405. this.attrs = attrs;
  2406. this.gMap = gMap;
  2407. this.defaults = defaults;
  2408. this.modelKeyComparison = __bind(this.modelKeyComparison, this);
  2409. this.setChildScope = __bind(this.setChildScope, this);
  2410. this.createChild = __bind(this.createChild, this);
  2411. this.pieceMeal = __bind(this.pieceMeal, this);
  2412. this.createAllNew = __bind(this.createAllNew, this);
  2413. this.watchIdKey = __bind(this.watchIdKey, this);
  2414. this.createChildScopes = __bind(this.createChildScopes, this);
  2415. this.watchOurScope = __bind(this.watchOurScope, this);
  2416. this.watchDestroy = __bind(this.watchDestroy, this);
  2417. this.rebuildAll = __bind(this.rebuildAll, this);
  2418. this.doINeedToWipe = __bind(this.doINeedToWipe, this);
  2419. this.watchModels = __bind(this.watchModels, this);
  2420. this.watch = __bind(this.watch, this);
  2421. PolylinesParentModel.__super__.constructor.call(this, scope);
  2422. self = this;
  2423. this.$log = Logger;
  2424. this.plurals = new PropMap();
  2425. this.scopePropNames = ['path', 'stroke', 'clickable', 'draggable', 'editable', 'geodesic', 'icons', 'visible'];
  2426. _.each(this.scopePropNames, function(name) {
  2427. return this[name + 'Key'] = void 0;
  2428. });
  2429. this.models = void 0;
  2430. this.firstTime = true;
  2431. this.$log.info(this);
  2432. $timeout(function() {
  2433. _this.watchOurScope(scope);
  2434. return _this.createChildScopes();
  2435. });
  2436. }
  2437. PolylinesParentModel.prototype.watch = function(scope, name, nameKey) {
  2438. var _this = this;
  2439. return scope.$watch(name, function(newValue, oldValue) {
  2440. if (newValue !== oldValue) {
  2441. _this[nameKey] = typeof newValue === 'function' ? newValue() : newValue;
  2442. return _async.each(_.values(_this.plurals), function(model) {
  2443. return model.scope[name] = _this[nameKey] === 'self' ? model : model[_this[nameKey]];
  2444. }, function() {});
  2445. }
  2446. });
  2447. };
  2448. PolylinesParentModel.prototype.watchModels = function(scope) {
  2449. var _this = this;
  2450. return scope.$watch('models', function(newValue, oldValue) {
  2451. if (!_.isEqual(newValue, oldValue)) {
  2452. if (_this.doINeedToWipe(newValue)) {
  2453. return _this.rebuildAll(scope, true, true);
  2454. } else {
  2455. return _this.createChildScopes(false);
  2456. }
  2457. }
  2458. }, true);
  2459. };
  2460. PolylinesParentModel.prototype.doINeedToWipe = function(newValue) {
  2461. var newValueIsEmpty;
  2462. newValueIsEmpty = newValue != null ? newValue.length === 0 : true;
  2463. return this.plurals.length > 0 && newValueIsEmpty;
  2464. };
  2465. PolylinesParentModel.prototype.rebuildAll = function(scope, doCreate, doDelete) {
  2466. var _this = this;
  2467. return _async.each(this.plurals.values(), function(model) {
  2468. return model.destroy();
  2469. }, function() {
  2470. if (doDelete) {
  2471. delete _this.plurals;
  2472. }
  2473. _this.plurals = new PropMap();
  2474. if (doCreate) {
  2475. return _this.createChildScopes();
  2476. }
  2477. });
  2478. };
  2479. PolylinesParentModel.prototype.watchDestroy = function(scope) {
  2480. var _this = this;
  2481. return scope.$on("$destroy", function() {
  2482. return _this.rebuildAll(scope, false, true);
  2483. });
  2484. };
  2485. PolylinesParentModel.prototype.watchOurScope = function(scope) {
  2486. var _this = this;
  2487. return _.each(this.scopePropNames, function(name) {
  2488. var nameKey;
  2489. nameKey = name + 'Key';
  2490. _this[nameKey] = typeof scope[name] === 'function' ? scope[name]() : scope[name];
  2491. return _this.watch(scope, name, nameKey);
  2492. });
  2493. };
  2494. PolylinesParentModel.prototype.createChildScopes = function(isCreatingFromScratch) {
  2495. if (isCreatingFromScratch == null) {
  2496. isCreatingFromScratch = true;
  2497. }
  2498. if (angular.isUndefined(this.scope.models)) {
  2499. this.$log.error("No models to create polylines from! I Need direct models!");
  2500. return;
  2501. }
  2502. if (this.gMap != null) {
  2503. if (this.scope.models != null) {
  2504. this.watchIdKey(this.scope);
  2505. if (isCreatingFromScratch) {
  2506. return this.createAllNew(this.scope, false);
  2507. } else {
  2508. return this.pieceMeal(this.scope, false);
  2509. }
  2510. }
  2511. }
  2512. };
  2513. PolylinesParentModel.prototype.watchIdKey = function(scope) {
  2514. var _this = this;
  2515. this.setIdKey(scope);
  2516. return scope.$watch('idKey', function(newValue, oldValue) {
  2517. if (newValue !== oldValue && (newValue == null)) {
  2518. _this.idKey = newValue;
  2519. return _this.rebuildAll(scope, true, true);
  2520. }
  2521. });
  2522. };
  2523. PolylinesParentModel.prototype.createAllNew = function(scope, isArray) {
  2524. var _this = this;
  2525. if (isArray == null) {
  2526. isArray = false;
  2527. }
  2528. this.models = scope.models;
  2529. if (this.firstTime) {
  2530. this.watchModels(scope);
  2531. this.watchDestroy(scope);
  2532. }
  2533. return _async.each(scope.models, function(model) {
  2534. return _this.createChild(model, _this.gMap);
  2535. }, function() {
  2536. return _this.firstTime = false;
  2537. });
  2538. };
  2539. PolylinesParentModel.prototype.pieceMeal = function(scope, isArray) {
  2540. var _this = this;
  2541. if (isArray == null) {
  2542. isArray = true;
  2543. }
  2544. this.models = scope.models;
  2545. if ((scope != null) && (scope.models != null) && scope.models.length > 0 && this.plurals.length > 0) {
  2546. return this.figureOutState(this.idKey, scope, this.plurals, this.modelKeyComparison, function(state) {
  2547. var payload;
  2548. payload = state;
  2549. return _async.each(payload.removals, function(id) {
  2550. var child;
  2551. child = _this.plurals[id];
  2552. if (child != null) {
  2553. child.destroy();
  2554. return _this.plurals.remove(id);
  2555. }
  2556. }, function() {
  2557. return _async.each(payload.adds, function(modelToAdd) {
  2558. return _this.createChild(modelToAdd, _this.gMap);
  2559. }, function() {});
  2560. });
  2561. });
  2562. } else {
  2563. return this.rebuildAll(this.scope, true, true);
  2564. }
  2565. };
  2566. PolylinesParentModel.prototype.createChild = function(model, gMap) {
  2567. var child, childScope,
  2568. _this = this;
  2569. childScope = this.scope.$new(false);
  2570. this.setChildScope(childScope, model);
  2571. childScope.$watch('model', function(newValue, oldValue) {
  2572. if (newValue !== oldValue) {
  2573. return _this.setChildScope(childScope, newValue);
  2574. }
  2575. }, true);
  2576. childScope["static"] = this.scope["static"];
  2577. child = new PolylineChildModel(childScope, this.attrs, gMap, this.defaults, model);
  2578. if (model[this.idKey] == null) {
  2579. this.$log.error("Polyline model has no id to assign a child to. This is required for performance. Please assign id, or redirect id to a different key.");
  2580. return;
  2581. }
  2582. this.plurals.put(model[this.idKey], child);
  2583. return child;
  2584. };
  2585. PolylinesParentModel.prototype.setChildScope = function(childScope, model) {
  2586. var _this = this;
  2587. _.each(this.scopePropNames, function(name) {
  2588. var nameKey, newValue;
  2589. nameKey = name + 'Key';
  2590. newValue = _this[nameKey] === 'self' ? model : model[_this[nameKey]];
  2591. if (newValue !== childScope[name]) {
  2592. return childScope[name] = newValue;
  2593. }
  2594. });
  2595. return childScope.model = model;
  2596. };
  2597. PolylinesParentModel.prototype.modelKeyComparison = function(model1, model2) {
  2598. return _.isEqual(this.evalModelHandle(model1, this.scope.path), this.evalModelHandle(model2, this.scope.path));
  2599. };
  2600. return PolylinesParentModel;
  2601. })(ModelKey);
  2602. }
  2603. ]);
  2604. }).call(this);
  2605. /*
  2606. Windows directive where many windows map to the models property
  2607. */
  2608. (function() {
  2609. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  2610. __hasProp = {}.hasOwnProperty,
  2611. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  2612. angular.module("google-maps.directives.api.models.parent").factory("WindowsParentModel", [
  2613. "IWindowParentModel", "ModelsWatcher", "PropMap", "WindowChildModel", "Linked", function(IWindowParentModel, ModelsWatcher, PropMap, WindowChildModel, Linked) {
  2614. var WindowsParentModel;
  2615. WindowsParentModel = (function(_super) {
  2616. __extends(WindowsParentModel, _super);
  2617. WindowsParentModel.include(ModelsWatcher);
  2618. function WindowsParentModel(scope, element, attrs, ctrls, $timeout, $compile, $http, $templateCache, $interpolate) {
  2619. var self,
  2620. _this = this;
  2621. this.$interpolate = $interpolate;
  2622. this.interpolateContent = __bind(this.interpolateContent, this);
  2623. this.setChildScope = __bind(this.setChildScope, this);
  2624. this.createWindow = __bind(this.createWindow, this);
  2625. this.setContentKeys = __bind(this.setContentKeys, this);
  2626. this.pieceMealWindows = __bind(this.pieceMealWindows, this);
  2627. this.createAllNewWindows = __bind(this.createAllNewWindows, this);
  2628. this.watchIdKey = __bind(this.watchIdKey, this);
  2629. this.createChildScopesWindows = __bind(this.createChildScopesWindows, this);
  2630. this.watchOurScope = __bind(this.watchOurScope, this);
  2631. this.watchDestroy = __bind(this.watchDestroy, this);
  2632. this.rebuildAll = __bind(this.rebuildAll, this);
  2633. this.doINeedToWipe = __bind(this.doINeedToWipe, this);
  2634. this.watchModels = __bind(this.watchModels, this);
  2635. this.watch = __bind(this.watch, this);
  2636. WindowsParentModel.__super__.constructor.call(this, scope, element, attrs, ctrls, $timeout, $compile, $http, $templateCache);
  2637. self = this;
  2638. this.windows = new PropMap();
  2639. this.scopePropNames = ['show', 'coords', 'templateUrl', 'templateParameter', 'isIconVisibleOnClick', 'closeClick'];
  2640. _.each(this.scopePropNames, function(name) {
  2641. return this[name + 'Key'] = void 0;
  2642. });
  2643. this.linked = new Linked(scope, element, attrs, ctrls);
  2644. this.models = void 0;
  2645. this.contentKeys = void 0;
  2646. this.isIconVisibleOnClick = void 0;
  2647. this.firstTime = true;
  2648. this.$log.info(self);
  2649. this.parentScope = void 0;
  2650. this.$timeout(function() {
  2651. _this.watchOurScope(scope);
  2652. _this.doRebuildAll = _this.scope.doRebuildAll != null ? _this.scope.doRebuildAll : true;
  2653. scope.$watch('doRebuildAll', function(newValue, oldValue) {
  2654. if (newValue !== oldValue) {
  2655. return _this.doRebuildAll = newValue;
  2656. }
  2657. });
  2658. return _this.createChildScopesWindows();
  2659. }, 50);
  2660. }
  2661. WindowsParentModel.prototype.watch = function(scope, name, nameKey) {
  2662. var _this = this;
  2663. return scope.$watch(name, function(newValue, oldValue) {
  2664. if (newValue !== oldValue) {
  2665. _this[nameKey] = typeof newValue === 'function' ? newValue() : newValue;
  2666. return _async.each(_.values(_this.windows), function(model) {
  2667. return model.scope[name] = _this[nameKey] === 'self' ? model : model[_this[nameKey]];
  2668. }, function() {});
  2669. }
  2670. });
  2671. };
  2672. WindowsParentModel.prototype.watchModels = function(scope) {
  2673. var _this = this;
  2674. return scope.$watch('models', function(newValue, oldValue) {
  2675. if (!_.isEqual(newValue, oldValue)) {
  2676. if (_this.doRebuildAll || _this.doINeedToWipe(newValue)) {
  2677. return _this.rebuildAll(scope, true, true);
  2678. } else {
  2679. return _this.createChildScopesWindows(false);
  2680. }
  2681. }
  2682. });
  2683. };
  2684. WindowsParentModel.prototype.doINeedToWipe = function(newValue) {
  2685. var newValueIsEmpty;
  2686. newValueIsEmpty = newValue != null ? newValue.length === 0 : true;
  2687. return this.windows.length > 0 && newValueIsEmpty;
  2688. };
  2689. WindowsParentModel.prototype.rebuildAll = function(scope, doCreate, doDelete) {
  2690. var _this = this;
  2691. return _async.each(this.windows.values(), function(model) {
  2692. return model.destroy();
  2693. }, function() {
  2694. if (doDelete) {
  2695. delete _this.windows;
  2696. }
  2697. _this.windows = new PropMap();
  2698. if (doCreate) {
  2699. return _this.createChildScopesWindows();
  2700. }
  2701. });
  2702. };
  2703. WindowsParentModel.prototype.watchDestroy = function(scope) {
  2704. var _this = this;
  2705. return scope.$on("$destroy", function() {
  2706. return _this.rebuildAll(scope, false, true);
  2707. });
  2708. };
  2709. WindowsParentModel.prototype.watchOurScope = function(scope) {
  2710. var _this = this;
  2711. return _.each(this.scopePropNames, function(name) {
  2712. var nameKey;
  2713. nameKey = name + 'Key';
  2714. _this[nameKey] = typeof scope[name] === 'function' ? scope[name]() : scope[name];
  2715. return _this.watch(scope, name, nameKey);
  2716. });
  2717. };
  2718. WindowsParentModel.prototype.createChildScopesWindows = function(isCreatingFromScratch) {
  2719. var markersScope, modelsNotDefined;
  2720. if (isCreatingFromScratch == null) {
  2721. isCreatingFromScratch = true;
  2722. }
  2723. /*
  2724. being that we cannot tell the difference in Key String vs. a normal value string (TemplateUrl)
  2725. we will assume that all scope values are string expressions either pointing to a key (propName) or using
  2726. 'self' to point the model as container/object of interest.
  2727. This may force redundant information into the model, but this appears to be the most flexible approach.
  2728. */
  2729. this.isIconVisibleOnClick = true;
  2730. if (angular.isDefined(this.linked.attrs.isiconvisibleonclick)) {
  2731. this.isIconVisibleOnClick = this.linked.scope.isIconVisibleOnClick;
  2732. }
  2733. this.gMap = this.linked.ctrls[0].getMap();
  2734. if (this.linked.ctrls[1] != null) {
  2735. markersScope = this.linked.ctrls.length > 1 ? this.linked.ctrls[1].getMarkersScope() : void 0;
  2736. }
  2737. modelsNotDefined = angular.isUndefined(this.linked.scope.models);
  2738. if (modelsNotDefined && (markersScope === void 0 || (markersScope.markerModels === void 0 || markersScope.models === void 0))) {
  2739. this.$log.error("No models to create windows from! Need direct models or models derrived from markers!");
  2740. return;
  2741. }
  2742. if (this.gMap != null) {
  2743. if (this.linked.scope.models != null) {
  2744. this.watchIdKey(this.linked.scope);
  2745. if (isCreatingFromScratch) {
  2746. return this.createAllNewWindows(this.linked.scope, false);
  2747. } else {
  2748. return this.pieceMealWindows(this.linked.scope, false);
  2749. }
  2750. } else {
  2751. this.parentScope = markersScope;
  2752. this.watchIdKey(this.parentScope);
  2753. if (isCreatingFromScratch) {
  2754. return this.createAllNewWindows(markersScope, true, 'markerModels', false);
  2755. } else {
  2756. return this.pieceMealWindows(markersScope, true, 'markerModels', false);
  2757. }
  2758. }
  2759. }
  2760. };
  2761. WindowsParentModel.prototype.watchIdKey = function(scope) {
  2762. var _this = this;
  2763. this.setIdKey(scope);
  2764. return scope.$watch('idKey', function(newValue, oldValue) {
  2765. if (newValue !== oldValue && (newValue == null)) {
  2766. _this.idKey = newValue;
  2767. return _this.rebuildAll(scope, true, true);
  2768. }
  2769. });
  2770. };
  2771. WindowsParentModel.prototype.createAllNewWindows = function(scope, hasGMarker, modelsPropToIterate, isArray) {
  2772. var _this = this;
  2773. if (modelsPropToIterate == null) {
  2774. modelsPropToIterate = 'models';
  2775. }
  2776. if (isArray == null) {
  2777. isArray = false;
  2778. }
  2779. this.models = scope.models;
  2780. if (this.firstTime) {
  2781. this.watchModels(scope);
  2782. this.watchDestroy(scope);
  2783. }
  2784. this.setContentKeys(scope.models);
  2785. return _async.each(scope.models, function(model) {
  2786. var gMarker;
  2787. gMarker = hasGMarker ? scope[modelsPropToIterate][[model[_this.idKey]]].gMarker : void 0;
  2788. return _this.createWindow(model, gMarker, _this.gMap);
  2789. }, function() {
  2790. return _this.firstTime = false;
  2791. });
  2792. };
  2793. WindowsParentModel.prototype.pieceMealWindows = function(scope, hasGMarker, modelsPropToIterate, isArray) {
  2794. var _this = this;
  2795. if (modelsPropToIterate == null) {
  2796. modelsPropToIterate = 'models';
  2797. }
  2798. if (isArray == null) {
  2799. isArray = true;
  2800. }
  2801. this.models = scope.models;
  2802. if ((scope != null) && (scope.models != null) && scope.models.length > 0 && this.windows.length > 0) {
  2803. return this.figureOutState(this.idKey, scope, this.windows, this.modelKeyComparison, function(state) {
  2804. var payload;
  2805. payload = state;
  2806. return _async.each(payload.removals, function(child) {
  2807. if (child != null) {
  2808. child.destroy();
  2809. return _this.windows.remove(child.id);
  2810. }
  2811. }, function() {
  2812. return _async.each(payload.adds, function(modelToAdd) {
  2813. var gMarker;
  2814. gMarker = scope[modelsPropToIterate][modelToAdd[_this.idKey]].gMarker;
  2815. return _this.createWindow(modelToAdd, gMarker, _this.gMap);
  2816. }, function() {});
  2817. });
  2818. });
  2819. } else {
  2820. return this.rebuildAll(this.scope, true, true);
  2821. }
  2822. };
  2823. WindowsParentModel.prototype.setContentKeys = function(models) {
  2824. if (models.length > 0) {
  2825. return this.contentKeys = Object.keys(models[0]);
  2826. }
  2827. };
  2828. WindowsParentModel.prototype.createWindow = function(model, gMarker, gMap) {
  2829. var child, childScope, fakeElement, opts,
  2830. _this = this;
  2831. childScope = this.linked.scope.$new(false);
  2832. this.setChildScope(childScope, model);
  2833. childScope.$watch('model', function(newValue, oldValue) {
  2834. if (newValue !== oldValue) {
  2835. return _this.setChildScope(childScope, newValue);
  2836. }
  2837. }, true);
  2838. fakeElement = {
  2839. html: function() {
  2840. return _this.interpolateContent(_this.linked.element.html(), model);
  2841. }
  2842. };
  2843. opts = this.createWindowOptions(gMarker, childScope, fakeElement.html(), this.DEFAULTS);
  2844. child = new WindowChildModel(model, childScope, opts, this.isIconVisibleOnClick, gMap, gMarker, fakeElement, true, true);
  2845. if (model[this.idKey] == null) {
  2846. this.$log.error("Window model has no id to assign a child to. This is required for performance. Please assign id, or redirect id to a different key.");
  2847. return;
  2848. }
  2849. this.windows.put(model[this.idKey], child);
  2850. return child;
  2851. };
  2852. WindowsParentModel.prototype.setChildScope = function(childScope, model) {
  2853. var _this = this;
  2854. _.each(this.scopePropNames, function(name) {
  2855. var nameKey, newValue;
  2856. nameKey = name + 'Key';
  2857. newValue = _this[nameKey] === 'self' ? model : model[_this[nameKey]];
  2858. if (newValue !== childScope[name]) {
  2859. return childScope[name] = newValue;
  2860. }
  2861. });
  2862. return childScope.model = model;
  2863. };
  2864. WindowsParentModel.prototype.interpolateContent = function(content, model) {
  2865. var exp, interpModel, key, _i, _len, _ref;
  2866. if (this.contentKeys === void 0 || this.contentKeys.length === 0) {
  2867. return;
  2868. }
  2869. exp = this.$interpolate(content);
  2870. interpModel = {};
  2871. _ref = this.contentKeys;
  2872. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  2873. key = _ref[_i];
  2874. interpModel[key] = model[key];
  2875. }
  2876. return exp(interpModel);
  2877. };
  2878. return WindowsParentModel;
  2879. })(IWindowParentModel);
  2880. return WindowsParentModel;
  2881. }
  2882. ]);
  2883. }).call(this);
  2884. /*
  2885. - interface for all labels to derrive from
  2886. - to enforce a minimum set of requirements
  2887. - attributes
  2888. - content
  2889. - anchor
  2890. - implementation needed on watches
  2891. */
  2892. (function() {
  2893. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  2894. __hasProp = {}.hasOwnProperty,
  2895. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  2896. angular.module("google-maps.directives.api").factory("ILabel", [
  2897. "BaseObject", "Logger", function(BaseObject, Logger) {
  2898. var ILabel;
  2899. return ILabel = (function(_super) {
  2900. __extends(ILabel, _super);
  2901. function ILabel($timeout) {
  2902. this.link = __bind(this.link, this);
  2903. var self;
  2904. self = this;
  2905. this.restrict = 'ECMA';
  2906. this.replace = true;
  2907. this.template = void 0;
  2908. this.require = void 0;
  2909. this.transclude = true;
  2910. this.priority = -100;
  2911. this.scope = {
  2912. labelContent: '=content',
  2913. labelAnchor: '@anchor',
  2914. labelClass: '@class',
  2915. labelStyle: '=style'
  2916. };
  2917. this.$log = Logger;
  2918. this.$timeout = $timeout;
  2919. }
  2920. ILabel.prototype.link = function(scope, element, attrs, ctrl) {
  2921. throw new Exception("Not Implemented!!");
  2922. };
  2923. return ILabel;
  2924. })(BaseObject);
  2925. }
  2926. ]);
  2927. }).call(this);
  2928. /*
  2929. - interface for all markers to derrive from
  2930. - to enforce a minimum set of requirements
  2931. - attributes
  2932. - coords
  2933. - icon
  2934. - implementation needed on watches
  2935. */
  2936. (function() {
  2937. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  2938. __hasProp = {}.hasOwnProperty,
  2939. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  2940. angular.module("google-maps.directives.api").factory("IMarker", [
  2941. "Logger", "BaseObject", function(Logger, BaseObject) {
  2942. var IMarker;
  2943. return IMarker = (function(_super) {
  2944. __extends(IMarker, _super);
  2945. function IMarker($timeout) {
  2946. this.link = __bind(this.link, this);
  2947. var self;
  2948. self = this;
  2949. this.$log = Logger;
  2950. this.$timeout = $timeout;
  2951. this.restrict = 'ECMA';
  2952. this.require = '^googleMap';
  2953. this.priority = -1;
  2954. this.transclude = true;
  2955. this.replace = true;
  2956. this.scope = {
  2957. coords: '=coords',
  2958. icon: '=icon',
  2959. click: '&click',
  2960. options: '=options',
  2961. events: '=events',
  2962. fit: '=fit'
  2963. };
  2964. }
  2965. IMarker.prototype.controller = [
  2966. '$scope', '$element', function($scope, $element) {
  2967. throw new Exception("Not Implemented!!");
  2968. }
  2969. ];
  2970. IMarker.prototype.link = function(scope, element, attrs, ctrl) {
  2971. throw new Exception("Not implemented!!");
  2972. };
  2973. return IMarker;
  2974. })(BaseObject);
  2975. }
  2976. ]);
  2977. }).call(this);
  2978. (function() {
  2979. var __hasProp = {}.hasOwnProperty,
  2980. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  2981. angular.module("google-maps.directives.api").factory("IPolyline", [
  2982. "GmapUtil", "BaseObject", "Logger", function(GmapUtil, BaseObject, Logger) {
  2983. var IPolyline;
  2984. return IPolyline = (function(_super) {
  2985. __extends(IPolyline, _super);
  2986. IPolyline.include(GmapUtil);
  2987. function IPolyline() {
  2988. var self;
  2989. self = this;
  2990. }
  2991. IPolyline.prototype.restrict = "ECA";
  2992. IPolyline.prototype.replace = true;
  2993. IPolyline.prototype.require = "^googleMap";
  2994. IPolyline.prototype.scope = {
  2995. path: "=",
  2996. stroke: "=",
  2997. clickable: "=",
  2998. draggable: "=",
  2999. editable: "=",
  3000. geodesic: "=",
  3001. icons: "=",
  3002. visible: "=",
  3003. "static": "="
  3004. };
  3005. IPolyline.prototype.DEFAULTS = {};
  3006. IPolyline.prototype.$log = Logger;
  3007. return IPolyline;
  3008. })(BaseObject);
  3009. }
  3010. ]);
  3011. }).call(this);
  3012. /*
  3013. - interface directive for all window(s) to derrive from
  3014. */
  3015. (function() {
  3016. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  3017. __hasProp = {}.hasOwnProperty,
  3018. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  3019. angular.module("google-maps.directives.api").factory("IWindow", [
  3020. "BaseObject", "ChildEvents", "Logger", function(BaseObject, ChildEvents, Logger) {
  3021. var IWindow;
  3022. return IWindow = (function(_super) {
  3023. __extends(IWindow, _super);
  3024. IWindow.include(ChildEvents);
  3025. function IWindow($timeout, $compile, $http, $templateCache) {
  3026. var self;
  3027. this.$timeout = $timeout;
  3028. this.$compile = $compile;
  3029. this.$http = $http;
  3030. this.$templateCache = $templateCache;
  3031. this.link = __bind(this.link, this);
  3032. self = this;
  3033. this.restrict = 'ECMA';
  3034. this.template = void 0;
  3035. this.transclude = true;
  3036. this.priority = -100;
  3037. this.require = void 0;
  3038. this.replace = true;
  3039. this.scope = {
  3040. coords: '=coords',
  3041. show: '=show',
  3042. templateUrl: '=templateurl',
  3043. templateParameter: '=templateparameter',
  3044. isIconVisibleOnClick: '=isiconvisibleonclick',
  3045. closeClick: '&closeclick',
  3046. options: '=options'
  3047. };
  3048. this.$log = Logger;
  3049. }
  3050. IWindow.prototype.link = function(scope, element, attrs, ctrls) {
  3051. throw new Exception("Not Implemented!!");
  3052. };
  3053. return IWindow;
  3054. })(BaseObject);
  3055. }
  3056. ]);
  3057. }).call(this);
  3058. (function() {
  3059. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  3060. __hasProp = {}.hasOwnProperty,
  3061. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  3062. angular.module("google-maps.directives.api").factory("Map", [
  3063. "$timeout", "Logger", "GmapUtil", "BaseObject", function($timeout, Logger, GmapUtil, BaseObject) {
  3064. "use strict";
  3065. var $log, DEFAULTS, Map;
  3066. $log = Logger;
  3067. DEFAULTS = {
  3068. mapTypeId: google.maps.MapTypeId.ROADMAP
  3069. };
  3070. return Map = (function(_super) {
  3071. __extends(Map, _super);
  3072. Map.include(GmapUtil);
  3073. function Map() {
  3074. this.link = __bind(this.link, this);
  3075. var self;
  3076. self = this;
  3077. }
  3078. Map.prototype.restrict = "ECMA";
  3079. Map.prototype.transclude = true;
  3080. Map.prototype.replace = false;
  3081. Map.prototype.template = "<div class=\"angular-google-map\"><div class=\"angular-google-map-container\"></div><div ng-transclude style=\"display: none\"></div></div>";
  3082. Map.prototype.scope = {
  3083. center: "=center",
  3084. zoom: "=zoom",
  3085. dragging: "=dragging",
  3086. control: "=",
  3087. windows: "=windows",
  3088. options: "=options",
  3089. events: "=events",
  3090. styles: "=styles",
  3091. bounds: "=bounds"
  3092. };
  3093. Map.prototype.controller = [
  3094. "$scope", function($scope) {
  3095. return {
  3096. getMap: function() {
  3097. return $scope.map;
  3098. }
  3099. };
  3100. }
  3101. ];
  3102. /*
  3103. @param scope
  3104. @param element
  3105. @param attrs
  3106. */
  3107. Map.prototype.link = function(scope, element, attrs) {
  3108. var dragging, el, eventName, getEventHandler, opts, settingCenterFromScope, type, _m,
  3109. _this = this;
  3110. if (!this.validateCoords(scope.center)) {
  3111. $log.error("angular-google-maps: could not find a valid center property");
  3112. return;
  3113. }
  3114. if (!angular.isDefined(scope.zoom)) {
  3115. $log.error("angular-google-maps: map zoom property not set");
  3116. return;
  3117. }
  3118. el = angular.element(element);
  3119. el.addClass("angular-google-map");
  3120. opts = {
  3121. options: {}
  3122. };
  3123. if (attrs.options) {
  3124. opts.options = scope.options;
  3125. }
  3126. if (attrs.styles) {
  3127. opts.styles = scope.styles;
  3128. }
  3129. if (attrs.type) {
  3130. type = attrs.type.toUpperCase();
  3131. if (google.maps.MapTypeId.hasOwnProperty(type)) {
  3132. opts.mapTypeId = google.maps.MapTypeId[attrs.type.toUpperCase()];
  3133. } else {
  3134. $log.error("angular-google-maps: invalid map type \"" + attrs.type + "\"");
  3135. }
  3136. }
  3137. _m = new google.maps.Map(el.find("div")[1], angular.extend({}, DEFAULTS, opts, {
  3138. center: this.getCoords(scope.center),
  3139. draggable: this.isTrue(attrs.draggable),
  3140. zoom: scope.zoom,
  3141. bounds: scope.bounds
  3142. }));
  3143. dragging = false;
  3144. google.maps.event.addListener(_m, "dragstart", function() {
  3145. dragging = true;
  3146. return _.defer(function() {
  3147. return scope.$apply(function(s) {
  3148. if (s.dragging != null) {
  3149. return s.dragging = dragging;
  3150. }
  3151. });
  3152. });
  3153. });
  3154. google.maps.event.addListener(_m, "dragend", function() {
  3155. dragging = false;
  3156. return _.defer(function() {
  3157. return scope.$apply(function(s) {
  3158. if (s.dragging != null) {
  3159. return s.dragging = dragging;
  3160. }
  3161. });
  3162. });
  3163. });
  3164. google.maps.event.addListener(_m, "drag", function() {
  3165. var c;
  3166. c = _m.center;
  3167. return _.defer(function() {
  3168. return scope.$apply(function(s) {
  3169. if (angular.isDefined(s.center.type)) {
  3170. s.center.coordinates[1] = c.lat();
  3171. return s.center.coordinates[0] = c.lng();
  3172. } else {
  3173. s.center.latitude = c.lat();
  3174. return s.center.longitude = c.lng();
  3175. }
  3176. });
  3177. });
  3178. });
  3179. google.maps.event.addListener(_m, "zoom_changed", function() {
  3180. if (scope.zoom !== _m.zoom) {
  3181. return _.defer(function() {
  3182. return scope.$apply(function(s) {
  3183. return s.zoom = _m.zoom;
  3184. });
  3185. });
  3186. }
  3187. });
  3188. settingCenterFromScope = false;
  3189. google.maps.event.addListener(_m, "center_changed", function() {
  3190. var c;
  3191. c = _m.center;
  3192. if (settingCenterFromScope) {
  3193. return;
  3194. }
  3195. return _.defer(function() {
  3196. return scope.$apply(function(s) {
  3197. if (!_m.dragging) {
  3198. if (angular.isDefined(s.center.type)) {
  3199. if (s.center.coordinates[1] !== c.lat()) {
  3200. s.center.coordinates[1] = c.lat();
  3201. }
  3202. if (s.center.coordinates[0] !== c.lng()) {
  3203. return s.center.coordinates[0] = c.lng();
  3204. }
  3205. } else {
  3206. if (s.center.latitude !== c.lat()) {
  3207. s.center.latitude = c.lat();
  3208. }
  3209. if (s.center.longitude !== c.lng()) {
  3210. return s.center.longitude = c.lng();
  3211. }
  3212. }
  3213. }
  3214. });
  3215. });
  3216. });
  3217. google.maps.event.addListener(_m, "idle", function() {
  3218. var b, ne, sw;
  3219. b = _m.getBounds();
  3220. ne = b.getNorthEast();
  3221. sw = b.getSouthWest();
  3222. return _.defer(function() {
  3223. return scope.$apply(function(s) {
  3224. if (s.bounds !== null && s.bounds !== undefined && s.bounds !== void 0) {
  3225. s.bounds.northeast = {
  3226. latitude: ne.lat(),
  3227. longitude: ne.lng()
  3228. };
  3229. return s.bounds.southwest = {
  3230. latitude: sw.lat(),
  3231. longitude: sw.lng()
  3232. };
  3233. }
  3234. });
  3235. });
  3236. });
  3237. if (angular.isDefined(scope.events) && scope.events !== null && angular.isObject(scope.events)) {
  3238. getEventHandler = function(eventName) {
  3239. return function() {
  3240. return scope.events[eventName].apply(scope, [_m, eventName, arguments]);
  3241. };
  3242. };
  3243. for (eventName in scope.events) {
  3244. if (scope.events.hasOwnProperty(eventName) && angular.isFunction(scope.events[eventName])) {
  3245. google.maps.event.addListener(_m, eventName, getEventHandler(eventName));
  3246. }
  3247. }
  3248. }
  3249. scope.map = _m;
  3250. if ((attrs.control != null) && (scope.control != null)) {
  3251. scope.control.refresh = function(maybeCoords) {
  3252. var coords;
  3253. if (_m == null) {
  3254. return;
  3255. }
  3256. google.maps.event.trigger(_m, "resize");
  3257. if (((maybeCoords != null ? maybeCoords.latitude : void 0) != null) && ((maybeCoords != null ? maybeCoords.latitude : void 0) != null)) {
  3258. coords = _this.getCoords(maybeCoords);
  3259. if (_this.isTrue(attrs.pan)) {
  3260. return _m.panTo(coords);
  3261. } else {
  3262. return _m.setCenter(coords);
  3263. }
  3264. }
  3265. };
  3266. /*
  3267. I am sure you all will love this. You want the instance here you go.. BOOM!
  3268. */
  3269. scope.control.getGMap = function() {
  3270. return _m;
  3271. };
  3272. }
  3273. scope.$watch("center", (function(newValue, oldValue) {
  3274. var coords;
  3275. coords = _this.getCoords(newValue);
  3276. if (newValue === oldValue || (coords.lat() === _m.center.lat() && coords.lng() === _m.center.lng())) {
  3277. return;
  3278. }
  3279. settingCenterFromScope = true;
  3280. if (!dragging) {
  3281. if (!_this.validateCoords(newValue)) {
  3282. $log.error("Invalid center for newValue: " + (JSON.stringify(newValue)));
  3283. }
  3284. if (_this.isTrue(attrs.pan) && scope.zoom === _m.zoom) {
  3285. _m.panTo(coords);
  3286. } else {
  3287. _m.setCenter(coords);
  3288. }
  3289. }
  3290. return settingCenterFromScope = false;
  3291. }), true);
  3292. scope.$watch("zoom", function(newValue, oldValue) {
  3293. if (newValue === oldValue || newValue === _m.zoom) {
  3294. return;
  3295. }
  3296. return _.defer(function() {
  3297. return _m.setZoom(newValue);
  3298. });
  3299. });
  3300. scope.$watch("bounds", function(newValue, oldValue) {
  3301. var bounds, ne, sw;
  3302. if (newValue === oldValue) {
  3303. return;
  3304. }
  3305. if ((newValue.northeast.latitude == null) || (newValue.northeast.longitude == null) || (newValue.southwest.latitude == null) || (newValue.southwest.longitude == null)) {
  3306. $log.error("Invalid map bounds for new value: " + (JSON.stringify(newValue)));
  3307. return;
  3308. }
  3309. ne = new google.maps.LatLng(newValue.northeast.latitude, newValue.northeast.longitude);
  3310. sw = new google.maps.LatLng(newValue.southwest.latitude, newValue.southwest.longitude);
  3311. bounds = new google.maps.LatLngBounds(sw, ne);
  3312. return _m.fitBounds(bounds);
  3313. });
  3314. scope.$watch("options", function(newValue, oldValue) {
  3315. if (!_.isEqual(newValue, oldValue)) {
  3316. opts.options = newValue;
  3317. if (_m != null) {
  3318. return _m.setOptions(opts);
  3319. }
  3320. }
  3321. }, true);
  3322. return scope.$watch("styles", function(newValue, oldValue) {
  3323. if (!_.isEqual(newValue, oldValue)) {
  3324. opts.styles = newValue;
  3325. if (_m != null) {
  3326. return _m.setOptions(opts);
  3327. }
  3328. }
  3329. }, true);
  3330. };
  3331. return Map;
  3332. })(BaseObject);
  3333. }
  3334. ]);
  3335. }).call(this);
  3336. (function() {
  3337. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  3338. __hasProp = {}.hasOwnProperty,
  3339. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  3340. angular.module("google-maps.directives.api").factory("Marker", [
  3341. "IMarker", "MarkerParentModel", "MarkerManager", function(IMarker, MarkerParentModel, MarkerManager) {
  3342. var Marker;
  3343. return Marker = (function(_super) {
  3344. __extends(Marker, _super);
  3345. function Marker($timeout) {
  3346. this.link = __bind(this.link, this);
  3347. var self;
  3348. Marker.__super__.constructor.call(this, $timeout);
  3349. self = this;
  3350. this.template = '<span class="angular-google-map-marker" ng-transclude></span>';
  3351. this.$log.info(this);
  3352. }
  3353. Marker.prototype.controller = [
  3354. '$scope', '$element', function($scope, $element) {
  3355. return {
  3356. getMarkerScope: function() {
  3357. return $scope;
  3358. }
  3359. };
  3360. }
  3361. ];
  3362. Marker.prototype.link = function(scope, element, attrs, ctrl) {
  3363. var doFit;
  3364. if (scope.fit) {
  3365. doFit = true;
  3366. }
  3367. if (!this.gMarkerManager) {
  3368. this.gMarkerManager = new MarkerManager(ctrl.getMap());
  3369. }
  3370. return new MarkerParentModel(scope, element, attrs, ctrl, this.$timeout, this.gMarkerManager, doFit);
  3371. };
  3372. return Marker;
  3373. })(IMarker);
  3374. }
  3375. ]);
  3376. }).call(this);
  3377. (function() {
  3378. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  3379. __hasProp = {}.hasOwnProperty,
  3380. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  3381. angular.module("google-maps.directives.api").factory("Markers", [
  3382. "IMarker", "MarkersParentModel", function(IMarker, MarkersParentModel) {
  3383. var Markers;
  3384. return Markers = (function(_super) {
  3385. __extends(Markers, _super);
  3386. function Markers($timeout) {
  3387. this.link = __bind(this.link, this);
  3388. var self;
  3389. Markers.__super__.constructor.call(this, $timeout);
  3390. this.template = '<span class="angular-google-map-markers" ng-transclude></span>';
  3391. this.scope.idKey = '=idkey';
  3392. this.scope.doRebuildAll = '=dorebuildall';
  3393. this.scope.models = '=models';
  3394. this.scope.doCluster = '=docluster';
  3395. this.scope.clusterOptions = '=clusteroptions';
  3396. this.scope.clusterEvents = '=clusterevents';
  3397. this.scope.labelContent = '=labelcontent';
  3398. this.scope.labelAnchor = '@labelanchor';
  3399. this.scope.labelClass = '@labelclass';
  3400. this.$timeout = $timeout;
  3401. self = this;
  3402. this.$log.info(this);
  3403. }
  3404. Markers.prototype.controller = [
  3405. '$scope', '$element', function($scope, $element) {
  3406. return {
  3407. getMarkersScope: function() {
  3408. return $scope;
  3409. }
  3410. };
  3411. }
  3412. ];
  3413. Markers.prototype.link = function(scope, element, attrs, ctrl) {
  3414. return new MarkersParentModel(scope, element, attrs, ctrl, this.$timeout);
  3415. };
  3416. return Markers;
  3417. })(IMarker);
  3418. }
  3419. ]);
  3420. }).call(this);
  3421. (function() {
  3422. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  3423. __hasProp = {}.hasOwnProperty,
  3424. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  3425. angular.module("google-maps.directives.api").factory("Polyline", [
  3426. "IPolyline", "$timeout", "array-sync", "PolylineChildModel", function(IPolyline, $timeout, arraySync, PolylineChildModel) {
  3427. var Polyline, _ref;
  3428. return Polyline = (function(_super) {
  3429. __extends(Polyline, _super);
  3430. function Polyline() {
  3431. this.link = __bind(this.link, this);
  3432. _ref = Polyline.__super__.constructor.apply(this, arguments);
  3433. return _ref;
  3434. }
  3435. Polyline.prototype.link = function(scope, element, attrs, mapCtrl) {
  3436. var _this = this;
  3437. if (angular.isUndefined(scope.path) || scope.path === null || !this.validatePath(scope.path)) {
  3438. this.$log.error("polyline: no valid path attribute found");
  3439. return;
  3440. }
  3441. return $timeout(function() {
  3442. return new PolylineChildModel(scope, attrs, mapCtrl.getMap(), _this.DEFAULTS);
  3443. });
  3444. };
  3445. return Polyline;
  3446. })(IPolyline);
  3447. }
  3448. ]);
  3449. }).call(this);
  3450. (function() {
  3451. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  3452. __hasProp = {}.hasOwnProperty,
  3453. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  3454. angular.module("google-maps.directives.api").factory("Polylines", [
  3455. "IPolyline", "$timeout", "array-sync", "PolylinesParentModel", function(IPolyline, $timeout, arraySync, PolylinesParentModel) {
  3456. var Polylines;
  3457. return Polylines = (function(_super) {
  3458. __extends(Polylines, _super);
  3459. function Polylines() {
  3460. this.link = __bind(this.link, this);
  3461. Polylines.__super__.constructor.call(this);
  3462. this.scope.idKey = '=idkey';
  3463. this.scope.models = '=models';
  3464. this.$log.info(this);
  3465. }
  3466. Polylines.prototype.link = function(scope, element, attrs, mapCtrl) {
  3467. var _this = this;
  3468. if (angular.isUndefined(scope.path) || scope.path === null) {
  3469. this.$log.error("polylines: no valid path attribute found");
  3470. return;
  3471. }
  3472. if (!scope.models) {
  3473. this.$log.error("polylines: no models found to create from");
  3474. return;
  3475. }
  3476. return $timeout(function() {
  3477. return new PolylinesParentModel(scope, element, attrs, mapCtrl.getMap(), _this.DEFAULTS);
  3478. });
  3479. };
  3480. return Polylines;
  3481. })(IPolyline);
  3482. }
  3483. ]);
  3484. }).call(this);
  3485. (function() {
  3486. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  3487. __hasProp = {}.hasOwnProperty,
  3488. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  3489. angular.module("google-maps.directives.api").factory("Window", [
  3490. "IWindow", "GmapUtil", "WindowChildModel", function(IWindow, GmapUtil, WindowChildModel) {
  3491. var Window;
  3492. return Window = (function(_super) {
  3493. __extends(Window, _super);
  3494. Window.include(GmapUtil);
  3495. function Window($timeout, $compile, $http, $templateCache) {
  3496. this.link = __bind(this.link, this);
  3497. var self;
  3498. Window.__super__.constructor.call(this, $timeout, $compile, $http, $templateCache);
  3499. self = this;
  3500. this.require = ['^googleMap', '^?marker'];
  3501. this.template = '<span class="angular-google-maps-window" ng-transclude></span>';
  3502. this.$log.info(self);
  3503. }
  3504. Window.prototype.link = function(scope, element, attrs, ctrls) {
  3505. var _this = this;
  3506. return this.$timeout(function() {
  3507. var defaults, hasScopeCoords, isIconVisibleOnClick, mapCtrl, markerCtrl, markerScope, opts, window;
  3508. isIconVisibleOnClick = true;
  3509. if (angular.isDefined(attrs.isiconvisibleonclick)) {
  3510. isIconVisibleOnClick = scope.isIconVisibleOnClick;
  3511. }
  3512. mapCtrl = ctrls[0].getMap();
  3513. markerCtrl = ctrls.length > 1 && (ctrls[1] != null) ? ctrls[1].getMarkerScope().gMarker : void 0;
  3514. defaults = scope.options != null ? scope.options : {};
  3515. hasScopeCoords = (scope != null) && _this.validateCoords(scope.coords);
  3516. opts = hasScopeCoords ? _this.createWindowOptions(markerCtrl, scope, element.html(), defaults) : defaults;
  3517. if (mapCtrl != null) {
  3518. window = new WindowChildModel({}, scope, opts, isIconVisibleOnClick, mapCtrl, markerCtrl, element);
  3519. }
  3520. scope.$on("$destroy", function() {
  3521. return window.destroy();
  3522. });
  3523. if (ctrls[1] != null) {
  3524. markerScope = ctrls[1].getMarkerScope();
  3525. markerScope.$watch('coords', function(newValue, oldValue) {
  3526. if (!_this.validateCoords(newValue)) {
  3527. return window.hideWindow();
  3528. }
  3529. if (!angular.equals(newValue, oldValue)) {
  3530. return window.getLatestPosition();
  3531. }
  3532. }, true);
  3533. }
  3534. if ((_this.onChildCreation != null) && (window != null)) {
  3535. return _this.onChildCreation(window);
  3536. }
  3537. }, GmapUtil.defaultDelay + 25);
  3538. };
  3539. return Window;
  3540. })(IWindow);
  3541. }
  3542. ]);
  3543. }).call(this);
  3544. (function() {
  3545. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  3546. __hasProp = {}.hasOwnProperty,
  3547. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  3548. angular.module("google-maps.directives.api").factory("Windows", [
  3549. "IWindow", "WindowsParentModel", function(IWindow, WindowsParentModel) {
  3550. /*
  3551. Windows directive where many windows map to the models property
  3552. */
  3553. var Windows;
  3554. return Windows = (function(_super) {
  3555. __extends(Windows, _super);
  3556. function Windows($timeout, $compile, $http, $templateCache, $interpolate) {
  3557. this.link = __bind(this.link, this);
  3558. var self;
  3559. Windows.__super__.constructor.call(this, $timeout, $compile, $http, $templateCache);
  3560. self = this;
  3561. this.$interpolate = $interpolate;
  3562. this.require = ['^googleMap', '^?markers'];
  3563. this.template = '<span class="angular-google-maps-windows" ng-transclude></span>';
  3564. this.scope.idKey = '=idkey';
  3565. this.scope.doRebuildAll = '=dorebuildall';
  3566. this.scope.models = '=models';
  3567. this.$log.info(this);
  3568. }
  3569. Windows.prototype.link = function(scope, element, attrs, ctrls) {
  3570. return new WindowsParentModel(scope, element, attrs, ctrls, this.$timeout, this.$compile, this.$http, this.$templateCache, this.$interpolate);
  3571. };
  3572. return Windows;
  3573. })(IWindow);
  3574. }
  3575. ]);
  3576. }).call(this);
  3577. /*
  3578. !
  3579. The MIT License
  3580. Copyright (c) 2010-2013 Google, Inc. http://angularjs.org
  3581. Permission is hereby granted, free of charge, to any person obtaining a copy
  3582. of this software and associated documentation files (the "Software"), to deal
  3583. in the Software without restriction, including without limitation the rights
  3584. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3585. copies of the Software, and to permit persons to whom the Software is
  3586. furnished to do so, subject to the following conditions:
  3587. The above copyright notice and this permission notice shall be included in
  3588. all copies or substantial portions of the Software.
  3589. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3590. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3591. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3592. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3593. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3594. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3595. THE SOFTWARE.
  3596. angular-google-maps
  3597. https://github.com/nlaplante/angular-google-maps
  3598. @authors
  3599. Nicolas Laplante - https://plus.google.com/108189012221374960701
  3600. Nicholas McCready - https://twitter.com/nmccready
  3601. Nick Baugh - https://github.com/niftylettuce
  3602. */
  3603. (function() {
  3604. angular.module("google-maps").directive("googleMap", [
  3605. "Map", function(Map) {
  3606. return new Map();
  3607. }
  3608. ]);
  3609. }).call(this);
  3610. /*
  3611. !
  3612. The MIT License
  3613. Copyright (c) 2010-2013 Google, Inc. http://angularjs.org
  3614. Permission is hereby granted, free of charge, to any person obtaining a copy
  3615. of this software and associated documentation files (the "Software"), to deal
  3616. in the Software without restriction, including without limitation the rights
  3617. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3618. copies of the Software, and to permit persons to whom the Software is
  3619. furnished to do so, subject to the following conditions:
  3620. The above copyright notice and this permission notice shall be included in
  3621. all copies or substantial portions of the Software.
  3622. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3623. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3624. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3625. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3626. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3627. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3628. THE SOFTWARE.
  3629. angular-google-maps
  3630. https://github.com/nlaplante/angular-google-maps
  3631. @authors
  3632. Nicolas Laplante - https://plus.google.com/108189012221374960701
  3633. Nicholas McCready - https://twitter.com/nmccready
  3634. */
  3635. /*
  3636. Map marker directive
  3637. This directive is used to create a marker on an existing map.
  3638. This directive creates a new scope.
  3639. {attribute coords required} object containing latitude and longitude properties
  3640. {attribute icon optional} string url to image used for marker icon
  3641. {attribute animate optional} if set to false, the marker won't be animated (on by default)
  3642. */
  3643. (function() {
  3644. angular.module("google-maps").directive("marker", [
  3645. "$timeout", "Marker", function($timeout, Marker) {
  3646. return new Marker($timeout);
  3647. }
  3648. ]);
  3649. }).call(this);
  3650. /*
  3651. !
  3652. The MIT License
  3653. Copyright (c) 2010-2013 Google, Inc. http://angularjs.org
  3654. Permission is hereby granted, free of charge, to any person obtaining a copy
  3655. of this software and associated documentation files (the "Software"), to deal
  3656. in the Software without restriction, including without limitation the rights
  3657. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3658. copies of the Software, and to permit persons to whom the Software is
  3659. furnished to do so, subject to the following conditions:
  3660. The above copyright notice and this permission notice shall be included in
  3661. all copies or substantial portions of the Software.
  3662. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3663. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3664. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3665. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3666. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3667. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3668. THE SOFTWARE.
  3669. angular-google-maps
  3670. https://github.com/nlaplante/angular-google-maps
  3671. @authors
  3672. Nicolas Laplante - https://plus.google.com/108189012221374960701
  3673. Nicholas McCready - https://twitter.com/nmccready
  3674. */
  3675. /*
  3676. Map marker directive
  3677. This directive is used to create a marker on an existing map.
  3678. This directive creates a new scope.
  3679. {attribute coords required} object containing latitude and longitude properties
  3680. {attribute icon optional} string url to image used for marker icon
  3681. {attribute animate optional} if set to false, the marker won't be animated (on by default)
  3682. */
  3683. (function() {
  3684. angular.module("google-maps").directive("markers", [
  3685. "$timeout", "Markers", function($timeout, Markers) {
  3686. return new Markers($timeout);
  3687. }
  3688. ]);
  3689. }).call(this);
  3690. /*
  3691. !
  3692. The MIT License
  3693. Copyright (c) 2010-2013 Google, Inc. http://angularjs.org
  3694. Permission is hereby granted, free of charge, to any person obtaining a copy
  3695. of this software and associated documentation files (the "Software"), to deal
  3696. in the Software without restriction, including without limitation the rights
  3697. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3698. copies of the Software, and to permit persons to whom the Software is
  3699. furnished to do so, subject to the following conditions:
  3700. The above copyright notice and this permission notice shall be included in
  3701. all copies or substantial portions of the Software.
  3702. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3703. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3704. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3705. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3706. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3707. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3708. THE SOFTWARE.
  3709. angular-google-maps
  3710. https://github.com/nlaplante/angular-google-maps
  3711. @authors Bruno Queiroz, creativelikeadog@gmail.com
  3712. */
  3713. /*
  3714. Marker label directive
  3715. This directive is used to create a marker label on an existing map.
  3716. {attribute content required} content of the label
  3717. {attribute anchor required} string that contains the x and y point position of the label
  3718. {attribute class optional} class to DOM object
  3719. {attribute style optional} style for the label
  3720. */
  3721. /*
  3722. Basic Directive api for a label. Basic in the sense that this directive contains 1:1 on scope and model.
  3723. Thus there will be one html element per marker within the directive.
  3724. */
  3725. (function() {
  3726. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
  3727. __hasProp = {}.hasOwnProperty,
  3728. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  3729. angular.module("google-maps").directive("markerLabel", [
  3730. "$timeout", "ILabel", "MarkerLabelChildModel", "GmapUtil", function($timeout, ILabel, MarkerLabelChildModel, GmapUtil) {
  3731. var Label;
  3732. Label = (function(_super) {
  3733. __extends(Label, _super);
  3734. function Label($timeout) {
  3735. this.link = __bind(this.link, this);
  3736. var self;
  3737. Label.__super__.constructor.call(this, $timeout);
  3738. self = this;
  3739. this.require = '^marker';
  3740. this.template = '<span class="angular-google-maps-marker-label" ng-transclude></span>';
  3741. this.$log.info(this);
  3742. }
  3743. Label.prototype.link = function(scope, element, attrs, ctrl) {
  3744. var _this = this;
  3745. return this.$timeout(function() {
  3746. var label, markerCtrl;
  3747. markerCtrl = ctrl.getMarkerScope().gMarker;
  3748. if (markerCtrl != null) {
  3749. label = new MarkerLabelChildModel(markerCtrl, scope);
  3750. }
  3751. return scope.$on("$destroy", function() {
  3752. return label.destroy();
  3753. });
  3754. }, GmapUtil.defaultDelay + 25);
  3755. };
  3756. return Label;
  3757. })(ILabel);
  3758. return new Label($timeout);
  3759. }
  3760. ]);
  3761. }).call(this);
  3762. /*
  3763. !
  3764. The MIT License
  3765. Copyright (c) 2010-2013 Google, Inc. http://angularjs.org
  3766. Permission is hereby granted, free of charge, to any person obtaining a copy
  3767. of this software and associated documentation files (the "Software"), to deal
  3768. in the Software without restriction, including without limitation the rights
  3769. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3770. copies of the Software, and to permit persons to whom the Software is
  3771. furnished to do so, subject to the following conditions:
  3772. The above copyright notice and this permission notice shall be included in
  3773. all copies or substantial portions of the Software.
  3774. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3775. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3776. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3777. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3778. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3779. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3780. THE SOFTWARE.
  3781. angular-google-maps
  3782. https://github.com/nlaplante/angular-google-maps
  3783. @authors
  3784. Nicolas Laplante - https://plus.google.com/108189012221374960701
  3785. Nicholas McCready - https://twitter.com/nmccready
  3786. Rick Huizinga - https://plus.google.com/+RickHuizinga
  3787. */
  3788. (function() {
  3789. angular.module("google-maps").directive("polygon", [
  3790. "$log", "$timeout", "array-sync", "GmapUtil", function($log, $timeout, arraySync, GmapUtil) {
  3791. /*
  3792. Check if a value is true
  3793. */
  3794. var DEFAULTS, isTrue;
  3795. isTrue = function(val) {
  3796. return angular.isDefined(val) && val !== null && val === true || val === "1" || val === "y" || val === "true";
  3797. };
  3798. "use strict";
  3799. DEFAULTS = {};
  3800. return {
  3801. restrict: "ECA",
  3802. replace: true,
  3803. require: "^googleMap",
  3804. scope: {
  3805. path: "=path",
  3806. stroke: "=stroke",
  3807. clickable: "=",
  3808. draggable: "=",
  3809. editable: "=",
  3810. geodesic: "=",
  3811. fill: "=",
  3812. icons: "=icons",
  3813. visible: "=",
  3814. "static": "=",
  3815. events: "=",
  3816. zIndex: "=zindex"
  3817. },
  3818. link: function(scope, element, attrs, mapCtrl) {
  3819. if (angular.isUndefined(scope.path) || scope.path === null || !GmapUtil.validatePath(scope.path)) {
  3820. $log.error("polygon: no valid path attribute found");
  3821. return;
  3822. }
  3823. return $timeout(function() {
  3824. var arraySyncer, buildOpts, eventName, getEventHandler, map, polygon;
  3825. buildOpts = function(pathPoints) {
  3826. var opts;
  3827. opts = angular.extend({}, DEFAULTS, {
  3828. map: map,
  3829. path: pathPoints,
  3830. strokeColor: scope.stroke && scope.stroke.color,
  3831. strokeOpacity: scope.stroke && scope.stroke.opacity,
  3832. strokeWeight: scope.stroke && scope.stroke.weight,
  3833. fillColor: scope.fill && scope.fill.color,
  3834. fillOpacity: scope.fill && scope.fill.opacity
  3835. });
  3836. angular.forEach({
  3837. clickable: true,
  3838. draggable: false,
  3839. editable: false,
  3840. geodesic: false,
  3841. visible: true,
  3842. "static": false,
  3843. zIndex: 0
  3844. }, function(defaultValue, key) {
  3845. if (angular.isUndefined(scope[key]) || scope[key] === null) {
  3846. return opts[key] = defaultValue;
  3847. } else {
  3848. return opts[key] = scope[key];
  3849. }
  3850. });
  3851. if (opts["static"]) {
  3852. opts.editable = false;
  3853. }
  3854. return opts;
  3855. };
  3856. map = mapCtrl.getMap();
  3857. polygon = new google.maps.Polygon(buildOpts(GmapUtil.convertPathPoints(scope.path)));
  3858. if (isTrue(attrs.fit)) {
  3859. GmapUtil.extendMapBounds(map, pathPoints);
  3860. }
  3861. if (!scope["static"] && angular.isDefined(scope.editable)) {
  3862. scope.$watch("editable", function(newValue, oldValue) {
  3863. if (newValue !== oldValue) {
  3864. return polygon.setEditable(newValue);
  3865. }
  3866. });
  3867. }
  3868. if (angular.isDefined(scope.draggable)) {
  3869. scope.$watch("draggable", function(newValue, oldValue) {
  3870. if (newValue !== oldValue) {
  3871. return polygon.setDraggable(newValue);
  3872. }
  3873. });
  3874. }
  3875. if (angular.isDefined(scope.visible)) {
  3876. scope.$watch("visible", function(newValue, oldValue) {
  3877. if (newValue !== oldValue) {
  3878. return polygon.setVisible(newValue);
  3879. }
  3880. });
  3881. }
  3882. if (angular.isDefined(scope.geodesic)) {
  3883. scope.$watch("geodesic", function(newValue, oldValue) {
  3884. if (newValue !== oldValue) {
  3885. return polygon.setOptions(buildOpts(polygon.getPath()));
  3886. }
  3887. });
  3888. }
  3889. if (angular.isDefined(scope.stroke) && angular.isDefined(scope.stroke.opacity)) {
  3890. scope.$watch("stroke.opacity", function(newValue, oldValue) {
  3891. return polygon.setOptions(buildOpts(polygon.getPath()));
  3892. });
  3893. }
  3894. if (angular.isDefined(scope.stroke) && angular.isDefined(scope.stroke.weight)) {
  3895. scope.$watch("stroke.weight", function(newValue, oldValue) {
  3896. if (newValue !== oldValue) {
  3897. return polygon.setOptions(buildOpts(polygon.getPath()));
  3898. }
  3899. });
  3900. }
  3901. if (angular.isDefined(scope.stroke) && angular.isDefined(scope.stroke.color)) {
  3902. scope.$watch("stroke.color", function(newValue, oldValue) {
  3903. if (newValue !== oldValue) {
  3904. return polygon.setOptions(buildOpts(polygon.getPath()));
  3905. }
  3906. });
  3907. }
  3908. if (angular.isDefined(scope.fill) && angular.isDefined(scope.fill.color)) {
  3909. scope.$watch("fill.color", function(newValue, oldValue) {
  3910. if (newValue !== oldValue) {
  3911. return polygon.setOptions(buildOpts(polygon.getPath()));
  3912. }
  3913. });
  3914. }
  3915. if (angular.isDefined(scope.fill) && angular.isDefined(scope.fill.opacity)) {
  3916. scope.$watch("fill.opacity", function(newValue, oldValue) {
  3917. if (newValue !== oldValue) {
  3918. return polygon.setOptions(buildOpts(polygon.getPath()));
  3919. }
  3920. });
  3921. }
  3922. if (angular.isDefined(scope.zIndex)) {
  3923. scope.$watch("zIndex", function(newValue, oldValue) {
  3924. if (newValue !== oldValue) {
  3925. return polygon.setOptions(buildOpts(polygon.getPath()));
  3926. }
  3927. });
  3928. }
  3929. if (angular.isDefined(scope.events) && scope.events !== null && angular.isObject(scope.events)) {
  3930. getEventHandler = function(eventName) {
  3931. return function() {
  3932. return scope.events[eventName].apply(scope, [polygon, eventName, arguments]);
  3933. };
  3934. };
  3935. for (eventName in scope.events) {
  3936. if (scope.events.hasOwnProperty(eventName) && angular.isFunction(scope.events[eventName])) {
  3937. polygon.addListener(eventName, getEventHandler(eventName));
  3938. }
  3939. }
  3940. }
  3941. arraySyncer = arraySync(polygon.getPath(), scope, "path");
  3942. return scope.$on("$destroy", function() {
  3943. polygon.setMap(null);
  3944. if (arraySyncer) {
  3945. arraySyncer();
  3946. return arraySyncer = null;
  3947. }
  3948. });
  3949. });
  3950. }
  3951. };
  3952. }
  3953. ]);
  3954. }).call(this);
  3955. /*
  3956. !
  3957. The MIT License
  3958. Copyright (c) 2010-2013 Google, Inc. http://angularjs.org
  3959. Permission is hereby granted, free of charge, to any person obtaining a copy
  3960. of this software and associated documentation files (the "Software"), to deal
  3961. in the Software without restriction, including without limitation the rights
  3962. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  3963. copies of the Software, and to permit persons to whom the Software is
  3964. furnished to do so, subject to the following conditions:
  3965. The above copyright notice and this permission notice shall be included in
  3966. all copies or substantial portions of the Software.
  3967. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3968. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3969. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  3970. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  3971. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  3972. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  3973. THE SOFTWARE.
  3974. @authors
  3975. Julian Popescu - https://github.com/jpopesculian
  3976. Rick Huizinga - https://plus.google.com/+RickHuizinga
  3977. */
  3978. (function() {
  3979. angular.module("google-maps").directive("circle", [
  3980. "$log", "$timeout", "GmapUtil", function($log, $timeout, GmapUtil) {
  3981. "use strict";
  3982. var DEFAULTS;
  3983. DEFAULTS = {};
  3984. return {
  3985. restrict: "ECA",
  3986. replace: true,
  3987. require: "^googleMap",
  3988. scope: {
  3989. center: "=center",
  3990. radius: "=radius",
  3991. stroke: "=stroke",
  3992. fill: "=fill",
  3993. clickable: "=",
  3994. draggable: "=",
  3995. editable: "=",
  3996. geodesic: "=",
  3997. icons: "=icons",
  3998. visible: "="
  3999. },
  4000. link: function(scope, element, attrs, mapCtrl) {
  4001. return $timeout(function() {
  4002. var buildOpts, circle, map;
  4003. buildOpts = function() {
  4004. var opts;
  4005. if (!GmapUtil.validateCoords(scope.center)) {
  4006. $log.error("circle: no valid center attribute found");
  4007. return;
  4008. }
  4009. opts = angular.extend({}, DEFAULTS, {
  4010. map: map,
  4011. center: GmapUtil.getCoords(scope.center),
  4012. radius: scope.radius,
  4013. strokeColor: scope.stroke && scope.stroke.color,
  4014. strokeOpacity: scope.stroke && scope.stroke.opacity,
  4015. strokeWeight: scope.stroke && scope.stroke.weight,
  4016. fillColor: scope.fill && scope.fill.color,
  4017. fillOpacity: scope.fill && scope.fill.opacity
  4018. });
  4019. angular.forEach({
  4020. clickable: true,
  4021. draggable: false,
  4022. editable: false,
  4023. geodesic: false,
  4024. visible: true
  4025. }, function(defaultValue, key) {
  4026. if (angular.isUndefined(scope[key]) || scope[key] === null) {
  4027. return opts[key] = defaultValue;
  4028. } else {
  4029. return opts[key] = scope[key];
  4030. }
  4031. });
  4032. return opts;
  4033. };
  4034. map = mapCtrl.getMap();
  4035. circle = new google.maps.Circle(buildOpts());
  4036. scope.$watchCollection('center', function(newVals, oldVals) {
  4037. if (newVals !== oldVals) {
  4038. return circle.setOptions(buildOpts());
  4039. }
  4040. });
  4041. scope.$watchCollection('stroke', function(newVals, oldVals) {
  4042. if (newVals !== oldVals) {
  4043. return circle.setOptions(buildOpts());
  4044. }
  4045. });
  4046. scope.$watchCollection('fill', function(newVals, oldVals) {
  4047. if (newVals !== oldVals) {
  4048. return circle.setOptions(buildOpts());
  4049. }
  4050. });
  4051. scope.$watch('radius', function(newVal, oldVal) {
  4052. if (newVal !== oldVal) {
  4053. return circle.setOptions(buildOpts());
  4054. }
  4055. });
  4056. scope.$watch('clickable', function(newVal, oldVal) {
  4057. if (newVal !== oldVal) {
  4058. return circle.setOptions(buildOpts());
  4059. }
  4060. });
  4061. scope.$watch('editable', function(newVal, oldVal) {
  4062. if (newVal !== oldVal) {
  4063. return circle.setOptions(buildOpts());
  4064. }
  4065. });
  4066. scope.$watch('draggable', function(newVal, oldVal) {
  4067. if (newVal !== oldVal) {
  4068. return circle.setOptions(buildOpts());
  4069. }
  4070. });
  4071. scope.$watch('visible', function(newVal, oldVal) {
  4072. if (newVal !== oldVal) {
  4073. return circle.setOptions(buildOpts());
  4074. }
  4075. });
  4076. scope.$watch('geodesic', function(newVal, oldVal) {
  4077. if (newVal !== oldVal) {
  4078. return circle.setOptions(buildOpts());
  4079. }
  4080. });
  4081. google.maps.event.addListener(circle, 'radius_changed', function() {
  4082. scope.radius = circle.getRadius();
  4083. return $timeout(function() {
  4084. return scope.$apply();
  4085. });
  4086. });
  4087. google.maps.event.addListener(circle, 'center_changed', function() {
  4088. if (angular.isDefined(scope.center.type)) {
  4089. scope.center.coordinates[1] = circle.getCenter().lat();
  4090. scope.center.coordinates[0] = circle.getCenter().lng();
  4091. } else {
  4092. scope.center.latitude = circle.getCenter().lat();
  4093. scope.center.longitude = circle.getCenter().lng();
  4094. }
  4095. return $timeout(function() {
  4096. return scope.$apply();
  4097. });
  4098. });
  4099. return scope.$on("$destroy", function() {
  4100. return circle.setMap(null);
  4101. });
  4102. });
  4103. }
  4104. };
  4105. }
  4106. ]);
  4107. }).call(this);
  4108. /*
  4109. !
  4110. The MIT License
  4111. Copyright (c) 2010-2013 Google, Inc. http://angularjs.org
  4112. Permission is hereby granted, free of charge, to any person obtaining a copy
  4113. of this software and associated documentation files (the "Software"), to deal
  4114. in the Software without restriction, including without limitation the rights
  4115. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4116. copies of the Software, and to permit persons to whom the Software is
  4117. furnished to do so, subject to the following conditions:
  4118. The above copyright notice and this permission notice shall be included in
  4119. all copies or substantial portions of the Software.
  4120. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4121. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4122. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4123. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4124. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4125. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4126. THE SOFTWARE.
  4127. angular-google-maps
  4128. https://github.com/nlaplante/angular-google-maps
  4129. @authors
  4130. Nicolas Laplante - https://plus.google.com/108189012221374960701
  4131. Nicholas McCready - https://twitter.com/nmccready
  4132. */
  4133. (function() {
  4134. angular.module("google-maps").directive("polyline", [
  4135. "Polyline", function(Polyline) {
  4136. return new Polyline();
  4137. }
  4138. ]);
  4139. }).call(this);
  4140. /*
  4141. !
  4142. The MIT License
  4143. Copyright (c) 2010-2013 Google, Inc. http://angularjs.org
  4144. Permission is hereby granted, free of charge, to any person obtaining a copy
  4145. of this software and associated documentation files (the "Software"), to deal
  4146. in the Software without restriction, including without limitation the rights
  4147. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4148. copies of the Software, and to permit persons to whom the Software is
  4149. furnished to do so, subject to the following conditions:
  4150. The above copyright notice and this permission notice shall be included in
  4151. all copies or substantial portions of the Software.
  4152. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4153. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4154. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4155. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4156. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4157. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4158. THE SOFTWARE.
  4159. angular-google-maps
  4160. https://github.com/nlaplante/angular-google-maps
  4161. @authors
  4162. Nicolas Laplante - https://plus.google.com/108189012221374960701
  4163. Nicholas McCready - https://twitter.com/nmccready
  4164. */
  4165. (function() {
  4166. angular.module("google-maps").directive("polylines", [
  4167. "Polylines", function(Polylines) {
  4168. return new Polylines();
  4169. }
  4170. ]);
  4171. }).call(this);
  4172. /*
  4173. !
  4174. The MIT License
  4175. Copyright (c) 2010-2013 Google, Inc. http://angularjs.org
  4176. Permission is hereby granted, free of charge, to any person obtaining a copy
  4177. of this software and associated documentation files (the "Software"), to deal
  4178. in the Software without restriction, including without limitation the rights
  4179. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4180. copies of the Software, and to permit persons to whom the Software is
  4181. furnished to do so, subject to the following conditions:
  4182. The above copyright notice and this permission notice shall be included in
  4183. all copies or substantial portions of the Software.
  4184. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4185. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4186. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4187. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4188. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4189. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4190. THE SOFTWARE.
  4191. angular-google-maps
  4192. https://github.com/nlaplante/angular-google-maps
  4193. @authors
  4194. Nicolas Laplante - https://plus.google.com/108189012221374960701
  4195. Nicholas McCready - https://twitter.com/nmccready
  4196. Chentsu Lin - https://github.com/ChenTsuLin
  4197. */
  4198. (function() {
  4199. angular.module("google-maps").directive("rectangle", [
  4200. "$log", "$timeout", function($log, $timeout) {
  4201. var DEFAULTS, convertBoundPoints, fitMapBounds, isTrue, validateBoundPoints;
  4202. validateBoundPoints = function(bounds) {
  4203. if (angular.isUndefined(bounds.sw.latitude) || angular.isUndefined(bounds.sw.longitude) || angular.isUndefined(bounds.ne.latitude) || angular.isUndefined(bounds.ne.longitude)) {
  4204. return false;
  4205. }
  4206. return true;
  4207. };
  4208. convertBoundPoints = function(bounds) {
  4209. var result;
  4210. result = new google.maps.LatLngBounds(new google.maps.LatLng(bounds.sw.latitude, bounds.sw.longitude), new google.maps.LatLng(bounds.ne.latitude, bounds.ne.longitude));
  4211. return result;
  4212. };
  4213. fitMapBounds = function(map, bounds) {
  4214. return map.fitBounds(bounds);
  4215. };
  4216. /*
  4217. Check if a value is true
  4218. */
  4219. isTrue = function(val) {
  4220. return angular.isDefined(val) && val !== null && val === true || val === "1" || val === "y" || val === "true";
  4221. };
  4222. "use strict";
  4223. DEFAULTS = {};
  4224. return {
  4225. restrict: "ECA",
  4226. require: "^googleMap",
  4227. replace: true,
  4228. scope: {
  4229. bounds: "=",
  4230. stroke: "=",
  4231. clickable: "=",
  4232. draggable: "=",
  4233. editable: "=",
  4234. fill: "=",
  4235. visible: "="
  4236. },
  4237. link: function(scope, element, attrs, mapCtrl) {
  4238. if (angular.isUndefined(scope.bounds) || scope.bounds === null || angular.isUndefined(scope.bounds.sw) || scope.bounds.sw === null || angular.isUndefined(scope.bounds.ne) || scope.bounds.ne === null || !validateBoundPoints(scope.bounds)) {
  4239. $log.error("rectangle: no valid bound attribute found");
  4240. return;
  4241. }
  4242. return $timeout(function() {
  4243. var buildOpts, dragging, map, rectangle, settingBoundsFromScope;
  4244. buildOpts = function(bounds) {
  4245. var opts;
  4246. opts = angular.extend({}, DEFAULTS, {
  4247. map: map,
  4248. bounds: bounds,
  4249. strokeColor: scope.stroke && scope.stroke.color,
  4250. strokeOpacity: scope.stroke && scope.stroke.opacity,
  4251. strokeWeight: scope.stroke && scope.stroke.weight,
  4252. fillColor: scope.fill && scope.fill.color,
  4253. fillOpacity: scope.fill && scope.fill.opacity
  4254. });
  4255. angular.forEach({
  4256. clickable: true,
  4257. draggable: false,
  4258. editable: false,
  4259. visible: true
  4260. }, function(defaultValue, key) {
  4261. if (angular.isUndefined(scope[key]) || scope[key] === null) {
  4262. return opts[key] = defaultValue;
  4263. } else {
  4264. return opts[key] = scope[key];
  4265. }
  4266. });
  4267. return opts;
  4268. };
  4269. map = mapCtrl.getMap();
  4270. rectangle = new google.maps.Rectangle(buildOpts(convertBoundPoints(scope.bounds)));
  4271. if (isTrue(attrs.fit)) {
  4272. fitMapBounds(map, bounds);
  4273. }
  4274. dragging = false;
  4275. google.maps.event.addListener(rectangle, "mousedown", function() {
  4276. google.maps.event.addListener(rectangle, "mousemove", function() {
  4277. dragging = true;
  4278. return _.defer(function() {
  4279. return scope.$apply(function(s) {
  4280. if (s.dragging != null) {
  4281. return s.dragging = dragging;
  4282. }
  4283. });
  4284. });
  4285. });
  4286. google.maps.event.addListener(rectangle, "mouseup", function() {
  4287. google.maps.event.clearListeners(rectangle, 'mousemove');
  4288. google.maps.event.clearListeners(rectangle, 'mouseup');
  4289. dragging = false;
  4290. return _.defer(function() {
  4291. return scope.$apply(function(s) {
  4292. if (s.dragging != null) {
  4293. return s.dragging = dragging;
  4294. }
  4295. });
  4296. });
  4297. });
  4298. });
  4299. settingBoundsFromScope = false;
  4300. google.maps.event.addListener(rectangle, "bounds_changed", function() {
  4301. var b, ne, sw;
  4302. b = rectangle.getBounds();
  4303. ne = b.getNorthEast();
  4304. sw = b.getSouthWest();
  4305. if (settingBoundsFromScope) {
  4306. return;
  4307. }
  4308. return _.defer(function() {
  4309. return scope.$apply(function(s) {
  4310. if (!rectangle.dragging) {
  4311. if (s.bounds !== null && s.bounds !== undefined && s.bounds !== void 0) {
  4312. s.bounds.ne = {
  4313. latitude: ne.lat(),
  4314. longitude: ne.lng()
  4315. };
  4316. s.bounds.sw = {
  4317. latitude: sw.lat(),
  4318. longitude: sw.lng()
  4319. };
  4320. }
  4321. }
  4322. });
  4323. });
  4324. });
  4325. scope.$watch("bounds", (function(newValue, oldValue) {
  4326. var bounds;
  4327. if (_.isEqual(newValue, oldValue)) {
  4328. return;
  4329. }
  4330. settingBoundsFromScope = true;
  4331. if (!dragging) {
  4332. if ((newValue.sw.latitude == null) || (newValue.sw.longitude == null) || (newValue.ne.latitude == null) || (newValue.ne.longitude == null)) {
  4333. $log.error("Invalid bounds for newValue: " + (JSON.stringify(newValue)));
  4334. }
  4335. bounds = new google.maps.LatLngBounds(new google.maps.LatLng(newValue.sw.latitude, newValue.sw.longitude), new google.maps.LatLng(newValue.ne.latitude, newValue.ne.longitude));
  4336. rectangle.setBounds(bounds);
  4337. }
  4338. return settingBoundsFromScope = false;
  4339. }), true);
  4340. if (angular.isDefined(scope.editable)) {
  4341. scope.$watch("editable", function(newValue, oldValue) {
  4342. return rectangle.setEditable(newValue);
  4343. });
  4344. }
  4345. if (angular.isDefined(scope.draggable)) {
  4346. scope.$watch("draggable", function(newValue, oldValue) {
  4347. return rectangle.setDraggable(newValue);
  4348. });
  4349. }
  4350. if (angular.isDefined(scope.visible)) {
  4351. scope.$watch("visible", function(newValue, oldValue) {
  4352. return rectangle.setVisible(newValue);
  4353. });
  4354. }
  4355. if (angular.isDefined(scope.stroke)) {
  4356. if (angular.isDefined(scope.stroke.color)) {
  4357. scope.$watch("stroke.color", function(newValue, oldValue) {
  4358. return rectangle.setOptions(buildOpts(rectangle.getBounds()));
  4359. });
  4360. }
  4361. if (angular.isDefined(scope.stroke.weight)) {
  4362. scope.$watch("stroke.weight", function(newValue, oldValue) {
  4363. return rectangle.setOptions(buildOpts(rectangle.getBounds()));
  4364. });
  4365. }
  4366. if (angular.isDefined(scope.stroke.opacity)) {
  4367. scope.$watch("stroke.opacity", function(newValue, oldValue) {
  4368. return rectangle.setOptions(buildOpts(rectangle.getBounds()));
  4369. });
  4370. }
  4371. }
  4372. if (angular.isDefined(scope.fill)) {
  4373. if (angular.isDefined(scope.fill.color)) {
  4374. scope.$watch("fill.color", function(newValue, oldValue) {
  4375. return rectangle.setOptions(buildOpts(rectangle.getBounds()));
  4376. });
  4377. }
  4378. if (angular.isDefined(scope.fill.opacity)) {
  4379. scope.$watch("fill.opacity", function(newValue, oldValue) {
  4380. return rectangle.setOptions(buildOpts(rectangle.getBounds()));
  4381. });
  4382. }
  4383. }
  4384. return scope.$on("$destroy", function() {
  4385. return rectangle.setMap(null);
  4386. });
  4387. });
  4388. }
  4389. };
  4390. }
  4391. ]);
  4392. }).call(this);
  4393. /*
  4394. !
  4395. The MIT License
  4396. Copyright (c) 2010-2013 Google, Inc. http://angularjs.org
  4397. Permission is hereby granted, free of charge, to any person obtaining a copy
  4398. of this software and associated documentation files (the "Software"), to deal
  4399. in the Software without restriction, including without limitation the rights
  4400. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4401. copies of the Software, and to permit persons to whom the Software is
  4402. furnished to do so, subject to the following conditions:
  4403. The above copyright notice and this permission notice shall be included in
  4404. all copies or substantial portions of the Software.
  4405. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4406. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4407. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4408. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4409. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4410. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4411. THE SOFTWARE.
  4412. angular-google-maps
  4413. https://github.com/nlaplante/angular-google-maps
  4414. @authors
  4415. Nicolas Laplante - https://plus.google.com/108189012221374960701
  4416. Nicholas McCready - https://twitter.com/nmccready
  4417. */
  4418. /*
  4419. Map info window directive
  4420. This directive is used to create an info window on an existing map.
  4421. This directive creates a new scope.
  4422. {attribute coords required} object containing latitude and longitude properties
  4423. {attribute show optional} map will show when this expression returns true
  4424. */
  4425. (function() {
  4426. angular.module("google-maps").directive("window", [
  4427. "$timeout", "$compile", "$http", "$templateCache", "Window", function($timeout, $compile, $http, $templateCache, Window) {
  4428. return new Window($timeout, $compile, $http, $templateCache);
  4429. }
  4430. ]);
  4431. }).call(this);
  4432. /*
  4433. !
  4434. The MIT License
  4435. Copyright (c) 2010-2013 Google, Inc. http://angularjs.org
  4436. Permission is hereby granted, free of charge, to any person obtaining a copy
  4437. of this software and associated documentation files (the "Software"), to deal
  4438. in the Software without restriction, including without limitation the rights
  4439. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4440. copies of the Software, and to permit persons to whom the Software is
  4441. furnished to do so, subject to the following conditions:
  4442. The above copyright notice and this permission notice shall be included in
  4443. all copies or substantial portions of the Software.
  4444. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4445. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4446. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4447. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4448. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4449. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4450. THE SOFTWARE.
  4451. angular-google-maps
  4452. https://github.com/nlaplante/angular-google-maps
  4453. @authors
  4454. Nicolas Laplante - https://plus.google.com/108189012221374960701
  4455. Nicholas McCready - https://twitter.com/nmccready
  4456. */
  4457. /*
  4458. Map info window directive
  4459. This directive is used to create an info window on an existing map.
  4460. This directive creates a new scope.
  4461. {attribute coords required} object containing latitude and longitude properties
  4462. {attribute show optional} map will show when this expression returns true
  4463. */
  4464. (function() {
  4465. angular.module("google-maps").directive("windows", [
  4466. "$timeout", "$compile", "$http", "$templateCache", "$interpolate", "Windows", function($timeout, $compile, $http, $templateCache, $interpolate, Windows) {
  4467. return new Windows($timeout, $compile, $http, $templateCache, $interpolate);
  4468. }
  4469. ]);
  4470. }).call(this);
  4471. /*
  4472. !
  4473. The MIT License
  4474. Copyright (c) 2010-2013 Google, Inc. http://angularjs.org
  4475. Permission is hereby granted, free of charge, to any person obtaining a copy
  4476. of this software and associated documentation files (the "Software"), to deal
  4477. in the Software without restriction, including without limitation the rights
  4478. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  4479. copies of the Software, and to permit persons to whom the Software is
  4480. furnished to do so, subject to the following conditions:
  4481. The above copyright notice and this permission notice shall be included in
  4482. all copies or substantial portions of the Software.
  4483. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4484. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4485. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4486. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4487. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4488. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4489. THE SOFTWARE.
  4490. angular-google-maps
  4491. https://github.com/nlaplante/angular-google-maps
  4492. @authors:
  4493. - Nicolas Laplante https://plus.google.com/108189012221374960701
  4494. - Nicholas McCready - https://twitter.com/nmccready
  4495. */
  4496. /*
  4497. Map Layer directive
  4498. This directive is used to create any type of Layer from the google maps sdk.
  4499. This directive creates a new scope.
  4500. {attribute show optional} true (default) shows the trafficlayer otherwise it is hidden
  4501. */
  4502. (function() {
  4503. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  4504. angular.module("google-maps").directive("layer", [
  4505. "$timeout", "Logger", "LayerParentModel", function($timeout, Logger, LayerParentModel) {
  4506. var Layer;
  4507. Layer = (function() {
  4508. function Layer($timeout) {
  4509. this.$timeout = $timeout;
  4510. this.link = __bind(this.link, this);
  4511. this.$log = Logger;
  4512. this.restrict = "ECMA";
  4513. this.require = "^googleMap";
  4514. this.priority = -1;
  4515. this.transclude = true;
  4516. this.template = '<span class=\"angular-google-map-layer\" ng-transclude></span>';
  4517. this.replace = true;
  4518. this.scope = {
  4519. show: "=show",
  4520. type: "=type",
  4521. namespace: "=namespace",
  4522. options: '=options',
  4523. onCreated: '&oncreated'
  4524. };
  4525. }
  4526. Layer.prototype.link = function(scope, element, attrs, mapCtrl) {
  4527. if (attrs.oncreated != null) {
  4528. return new LayerParentModel(scope, element, attrs, mapCtrl, this.$timeout, scope.onCreated);
  4529. } else {
  4530. return new LayerParentModel(scope, element, attrs, mapCtrl, this.$timeout);
  4531. }
  4532. };
  4533. return Layer;
  4534. })();
  4535. return new Layer($timeout);
  4536. }
  4537. ]);
  4538. }).call(this);
  4539. ;/**
  4540. * @name InfoBox
  4541. * @version 1.1.12 [December 11, 2012]
  4542. * @author Gary Little (inspired by proof-of-concept code from Pamela Fox of Google)
  4543. * @copyright Copyright 2010 Gary Little [gary at luxcentral.com]
  4544. * @fileoverview InfoBox extends the Google Maps JavaScript API V3 <tt>OverlayView</tt> class.
  4545. * <p>
  4546. * An InfoBox behaves like a <tt>google.maps.InfoWindow</tt>, but it supports several
  4547. * additional properties for advanced styling. An InfoBox can also be used as a map label.
  4548. * <p>
  4549. * An InfoBox also fires the same events as a <tt>google.maps.InfoWindow</tt>.
  4550. */
  4551. /*!
  4552. *
  4553. * Licensed under the Apache License, Version 2.0 (the "License");
  4554. * you may not use this file except in compliance with the License.
  4555. * You may obtain a copy of the License at
  4556. *
  4557. * http://www.apache.org/licenses/LICENSE-2.0
  4558. *
  4559. * Unless required by applicable law or agreed to in writing, software
  4560. * distributed under the License is distributed on an "AS IS" BASIS,
  4561. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4562. * See the License for the specific language governing permissions and
  4563. * limitations under the License.
  4564. */
  4565. /*jslint browser:true */
  4566. /*global google */
  4567. /**
  4568. * @name InfoBoxOptions
  4569. * @class This class represents the optional parameter passed to the {@link InfoBox} constructor.
  4570. * @property {string|Node} content The content of the InfoBox (plain text or an HTML DOM node).
  4571. * @property {boolean} [disableAutoPan=false] Disable auto-pan on <tt>open</tt>.
  4572. * @property {number} maxWidth The maximum width (in pixels) of the InfoBox. Set to 0 if no maximum.
  4573. * @property {Size} pixelOffset The offset (in pixels) from the top left corner of the InfoBox
  4574. * (or the bottom left corner if the <code>alignBottom</code> property is <code>true</code>)
  4575. * to the map pixel corresponding to <tt>position</tt>.
  4576. * @property {LatLng} position The geographic location at which to display the InfoBox.
  4577. * @property {number} zIndex The CSS z-index style value for the InfoBox.
  4578. * Note: This value overrides a zIndex setting specified in the <tt>boxStyle</tt> property.
  4579. * @property {string} [boxClass="infoBox"] The name of the CSS class defining the styles for the InfoBox container.
  4580. * @property {Object} [boxStyle] An object literal whose properties define specific CSS
  4581. * style values to be applied to the InfoBox. Style values defined here override those that may
  4582. * be defined in the <code>boxClass</code> style sheet. If this property is changed after the
  4583. * InfoBox has been created, all previously set styles (except those defined in the style sheet)
  4584. * are removed from the InfoBox before the new style values are applied.
  4585. * @property {string} closeBoxMargin The CSS margin style value for the close box.
  4586. * The default is "2px" (a 2-pixel margin on all sides).
  4587. * @property {string} closeBoxURL The URL of the image representing the close box.
  4588. * Note: The default is the URL for Google's standard close box.
  4589. * Set this property to "" if no close box is required.
  4590. * @property {Size} infoBoxClearance Minimum offset (in pixels) from the InfoBox to the
  4591. * map edge after an auto-pan.
  4592. * @property {boolean} [isHidden=false] Hide the InfoBox on <tt>open</tt>.
  4593. * [Deprecated in favor of the <tt>visible</tt> property.]
  4594. * @property {boolean} [visible=true] Show the InfoBox on <tt>open</tt>.
  4595. * @property {boolean} alignBottom Align the bottom left corner of the InfoBox to the <code>position</code>
  4596. * location (default is <tt>false</tt> which means that the top left corner of the InfoBox is aligned).
  4597. * @property {string} pane The pane where the InfoBox is to appear (default is "floatPane").
  4598. * Set the pane to "mapPane" if the InfoBox is being used as a map label.
  4599. * Valid pane names are the property names for the <tt>google.maps.MapPanes</tt> object.
  4600. * @property {boolean} enableEventPropagation Propagate mousedown, mousemove, mouseover, mouseout,
  4601. * mouseup, click, dblclick, touchstart, touchend, touchmove, and contextmenu events in the InfoBox
  4602. * (default is <tt>false</tt> to mimic the behavior of a <tt>google.maps.InfoWindow</tt>). Set
  4603. * this property to <tt>true</tt> if the InfoBox is being used as a map label.
  4604. */
  4605. /**
  4606. * Creates an InfoBox with the options specified in {@link InfoBoxOptions}.
  4607. * Call <tt>InfoBox.open</tt> to add the box to the map.
  4608. * @constructor
  4609. * @param {InfoBoxOptions} [opt_opts]
  4610. */
  4611. function InfoBox(opt_opts) {
  4612. opt_opts = opt_opts || {};
  4613. google.maps.OverlayView.apply(this, arguments);
  4614. // Standard options (in common with google.maps.InfoWindow):
  4615. //
  4616. this.content_ = opt_opts.content || "";
  4617. this.disableAutoPan_ = opt_opts.disableAutoPan || false;
  4618. this.maxWidth_ = opt_opts.maxWidth || 0;
  4619. this.pixelOffset_ = opt_opts.pixelOffset || new google.maps.Size(0, 0);
  4620. this.position_ = opt_opts.position || new google.maps.LatLng(0, 0);
  4621. this.zIndex_ = opt_opts.zIndex || null;
  4622. // Additional options (unique to InfoBox):
  4623. //
  4624. this.boxClass_ = opt_opts.boxClass || "infoBox";
  4625. this.boxStyle_ = opt_opts.boxStyle || {};
  4626. this.closeBoxMargin_ = opt_opts.closeBoxMargin || "2px";
  4627. this.closeBoxURL_ = opt_opts.closeBoxURL || "http://www.google.com/intl/en_us/mapfiles/close.gif";
  4628. if (opt_opts.closeBoxURL === "") {
  4629. this.closeBoxURL_ = "";
  4630. }
  4631. this.infoBoxClearance_ = opt_opts.infoBoxClearance || new google.maps.Size(1, 1);
  4632. if (typeof opt_opts.visible === "undefined") {
  4633. if (typeof opt_opts.isHidden === "undefined") {
  4634. opt_opts.visible = true;
  4635. } else {
  4636. opt_opts.visible = !opt_opts.isHidden;
  4637. }
  4638. }
  4639. this.isHidden_ = !opt_opts.visible;
  4640. this.alignBottom_ = opt_opts.alignBottom || false;
  4641. this.pane_ = opt_opts.pane || "floatPane";
  4642. this.enableEventPropagation_ = opt_opts.enableEventPropagation || false;
  4643. this.div_ = null;
  4644. this.closeListener_ = null;
  4645. this.moveListener_ = null;
  4646. this.contextListener_ = null;
  4647. this.eventListeners_ = null;
  4648. this.fixedWidthSet_ = null;
  4649. }
  4650. /* InfoBox extends OverlayView in the Google Maps API v3.
  4651. */
  4652. InfoBox.prototype = new google.maps.OverlayView();
  4653. /**
  4654. * Creates the DIV representing the InfoBox.
  4655. * @private
  4656. */
  4657. InfoBox.prototype.createInfoBoxDiv_ = function () {
  4658. var i;
  4659. var events;
  4660. var bw;
  4661. var me = this;
  4662. // This handler prevents an event in the InfoBox from being passed on to the map.
  4663. //
  4664. var cancelHandler = function (e) {
  4665. e.cancelBubble = true;
  4666. if (e.stopPropagation) {
  4667. e.stopPropagation();
  4668. }
  4669. };
  4670. // This handler ignores the current event in the InfoBox and conditionally prevents
  4671. // the event from being passed on to the map. It is used for the contextmenu event.
  4672. //
  4673. var ignoreHandler = function (e) {
  4674. e.returnValue = false;
  4675. if (e.preventDefault) {
  4676. e.preventDefault();
  4677. }
  4678. if (!me.enableEventPropagation_) {
  4679. cancelHandler(e);
  4680. }
  4681. };
  4682. if (!this.div_) {
  4683. this.div_ = document.createElement("div");
  4684. this.setBoxStyle_();
  4685. if (typeof this.content_.nodeType === "undefined") {
  4686. this.div_.innerHTML = this.getCloseBoxImg_() + this.content_;
  4687. } else {
  4688. this.div_.innerHTML = this.getCloseBoxImg_();
  4689. this.div_.appendChild(this.content_);
  4690. }
  4691. // Add the InfoBox DIV to the DOM
  4692. this.getPanes()[this.pane_].appendChild(this.div_);
  4693. this.addClickHandler_();
  4694. if (this.div_.style.width) {
  4695. this.fixedWidthSet_ = true;
  4696. } else {
  4697. if (this.maxWidth_ !== 0 && this.div_.offsetWidth > this.maxWidth_) {
  4698. this.div_.style.width = this.maxWidth_;
  4699. this.div_.style.overflow = "auto";
  4700. this.fixedWidthSet_ = true;
  4701. } else { // The following code is needed to overcome problems with MSIE
  4702. bw = this.getBoxWidths_();
  4703. this.div_.style.width = (this.div_.offsetWidth - bw.left - bw.right) + "px";
  4704. this.fixedWidthSet_ = false;
  4705. }
  4706. }
  4707. this.panBox_(this.disableAutoPan_);
  4708. if (!this.enableEventPropagation_) {
  4709. this.eventListeners_ = [];
  4710. // Cancel event propagation.
  4711. //
  4712. // Note: mousemove not included (to resolve Issue 152)
  4713. events = ["mousedown", "mouseover", "mouseout", "mouseup",
  4714. "click", "dblclick", "touchstart", "touchend", "touchmove"];
  4715. for (i = 0; i < events.length; i++) {
  4716. this.eventListeners_.push(google.maps.event.addDomListener(this.div_, events[i], cancelHandler));
  4717. }
  4718. // Workaround for Google bug that causes the cursor to change to a pointer
  4719. // when the mouse moves over a marker underneath InfoBox.
  4720. this.eventListeners_.push(google.maps.event.addDomListener(this.div_, "mouseover", function (e) {
  4721. this.style.cursor = "default";
  4722. }));
  4723. }
  4724. this.contextListener_ = google.maps.event.addDomListener(this.div_, "contextmenu", ignoreHandler);
  4725. /**
  4726. * This event is fired when the DIV containing the InfoBox's content is attached to the DOM.
  4727. * @name InfoBox#domready
  4728. * @event
  4729. */
  4730. google.maps.event.trigger(this, "domready");
  4731. }
  4732. };
  4733. /**
  4734. * Returns the HTML <IMG> tag for the close box.
  4735. * @private
  4736. */
  4737. InfoBox.prototype.getCloseBoxImg_ = function () {
  4738. var img = "";
  4739. if (this.closeBoxURL_ !== "") {
  4740. img = "<img";
  4741. img += " src='" + this.closeBoxURL_ + "'";
  4742. img += " align=right"; // Do this because Opera chokes on style='float: right;'
  4743. img += " style='";
  4744. img += " position: relative;"; // Required by MSIE
  4745. img += " cursor: pointer;";
  4746. img += " margin: " + this.closeBoxMargin_ + ";";
  4747. img += "'>";
  4748. }
  4749. return img;
  4750. };
  4751. /**
  4752. * Adds the click handler to the InfoBox close box.
  4753. * @private
  4754. */
  4755. InfoBox.prototype.addClickHandler_ = function () {
  4756. var closeBox;
  4757. if (this.closeBoxURL_ !== "") {
  4758. closeBox = this.div_.firstChild;
  4759. this.closeListener_ = google.maps.event.addDomListener(closeBox, "click", this.getCloseClickHandler_());
  4760. } else {
  4761. this.closeListener_ = null;
  4762. }
  4763. };
  4764. /**
  4765. * Returns the function to call when the user clicks the close box of an InfoBox.
  4766. * @private
  4767. */
  4768. InfoBox.prototype.getCloseClickHandler_ = function () {
  4769. var me = this;
  4770. return function (e) {
  4771. // 1.0.3 fix: Always prevent propagation of a close box click to the map:
  4772. e.cancelBubble = true;
  4773. if (e.stopPropagation) {
  4774. e.stopPropagation();
  4775. }
  4776. /**
  4777. * This event is fired when the InfoBox's close box is clicked.
  4778. * @name InfoBox#closeclick
  4779. * @event
  4780. */
  4781. google.maps.event.trigger(me, "closeclick");
  4782. me.close();
  4783. };
  4784. };
  4785. /**
  4786. * Pans the map so that the InfoBox appears entirely within the map's visible area.
  4787. * @private
  4788. */
  4789. InfoBox.prototype.panBox_ = function (disablePan) {
  4790. var map;
  4791. var bounds;
  4792. var xOffset = 0, yOffset = 0;
  4793. if (!disablePan) {
  4794. map = this.getMap();
  4795. if (map instanceof google.maps.Map) { // Only pan if attached to map, not panorama
  4796. if (!map.getBounds().contains(this.position_)) {
  4797. // Marker not in visible area of map, so set center
  4798. // of map to the marker position first.
  4799. map.setCenter(this.position_);
  4800. }
  4801. bounds = map.getBounds();
  4802. var mapDiv = map.getDiv();
  4803. var mapWidth = mapDiv.offsetWidth;
  4804. var mapHeight = mapDiv.offsetHeight;
  4805. var iwOffsetX = this.pixelOffset_.width;
  4806. var iwOffsetY = this.pixelOffset_.height;
  4807. var iwWidth = this.div_.offsetWidth;
  4808. var iwHeight = this.div_.offsetHeight;
  4809. var padX = this.infoBoxClearance_.width;
  4810. var padY = this.infoBoxClearance_.height;
  4811. var pixPosition = this.getProjection().fromLatLngToContainerPixel(this.position_);
  4812. if (pixPosition.x < (-iwOffsetX + padX)) {
  4813. xOffset = pixPosition.x + iwOffsetX - padX;
  4814. } else if ((pixPosition.x + iwWidth + iwOffsetX + padX) > mapWidth) {
  4815. xOffset = pixPosition.x + iwWidth + iwOffsetX + padX - mapWidth;
  4816. }
  4817. if (this.alignBottom_) {
  4818. if (pixPosition.y < (-iwOffsetY + padY + iwHeight)) {
  4819. yOffset = pixPosition.y + iwOffsetY - padY - iwHeight;
  4820. } else if ((pixPosition.y + iwOffsetY + padY) > mapHeight) {
  4821. yOffset = pixPosition.y + iwOffsetY + padY - mapHeight;
  4822. }
  4823. } else {
  4824. if (pixPosition.y < (-iwOffsetY + padY)) {
  4825. yOffset = pixPosition.y + iwOffsetY - padY;
  4826. } else if ((pixPosition.y + iwHeight + iwOffsetY + padY) > mapHeight) {
  4827. yOffset = pixPosition.y + iwHeight + iwOffsetY + padY - mapHeight;
  4828. }
  4829. }
  4830. if (!(xOffset === 0 && yOffset === 0)) {
  4831. // Move the map to the shifted center.
  4832. //
  4833. var c = map.getCenter();
  4834. map.panBy(xOffset, yOffset);
  4835. }
  4836. }
  4837. }
  4838. };
  4839. /**
  4840. * Sets the style of the InfoBox by setting the style sheet and applying
  4841. * other specific styles requested.
  4842. * @private
  4843. */
  4844. InfoBox.prototype.setBoxStyle_ = function () {
  4845. var i, boxStyle;
  4846. if (this.div_) {
  4847. // Apply style values from the style sheet defined in the boxClass parameter:
  4848. this.div_.className = this.boxClass_;
  4849. // Clear existing inline style values:
  4850. this.div_.style.cssText = "";
  4851. // Apply style values defined in the boxStyle parameter:
  4852. boxStyle = this.boxStyle_;
  4853. for (i in boxStyle) {
  4854. if (boxStyle.hasOwnProperty(i)) {
  4855. this.div_.style[i] = boxStyle[i];
  4856. }
  4857. }
  4858. // Fix up opacity style for benefit of MSIE:
  4859. //
  4860. if (typeof this.div_.style.opacity !== "undefined" && this.div_.style.opacity !== "") {
  4861. this.div_.style.filter = "alpha(opacity=" + (this.div_.style.opacity * 100) + ")";
  4862. }
  4863. // Apply required styles:
  4864. //
  4865. this.div_.style.position = "absolute";
  4866. this.div_.style.visibility = 'hidden';
  4867. if (this.zIndex_ !== null) {
  4868. this.div_.style.zIndex = this.zIndex_;
  4869. }
  4870. }
  4871. };
  4872. /**
  4873. * Get the widths of the borders of the InfoBox.
  4874. * @private
  4875. * @return {Object} widths object (top, bottom left, right)
  4876. */
  4877. InfoBox.prototype.getBoxWidths_ = function () {
  4878. var computedStyle;
  4879. var bw = {top: 0, bottom: 0, left: 0, right: 0};
  4880. var box = this.div_;
  4881. if (document.defaultView && document.defaultView.getComputedStyle) {
  4882. computedStyle = box.ownerDocument.defaultView.getComputedStyle(box, "");
  4883. if (computedStyle) {
  4884. // The computed styles are always in pixel units (good!)
  4885. bw.top = parseInt(computedStyle.borderTopWidth, 10) || 0;
  4886. bw.bottom = parseInt(computedStyle.borderBottomWidth, 10) || 0;
  4887. bw.left = parseInt(computedStyle.borderLeftWidth, 10) || 0;
  4888. bw.right = parseInt(computedStyle.borderRightWidth, 10) || 0;
  4889. }
  4890. } else if (document.documentElement.currentStyle) { // MSIE
  4891. if (box.currentStyle) {
  4892. // The current styles may not be in pixel units, but assume they are (bad!)
  4893. bw.top = parseInt(box.currentStyle.borderTopWidth, 10) || 0;
  4894. bw.bottom = parseInt(box.currentStyle.borderBottomWidth, 10) || 0;
  4895. bw.left = parseInt(box.currentStyle.borderLeftWidth, 10) || 0;
  4896. bw.right = parseInt(box.currentStyle.borderRightWidth, 10) || 0;
  4897. }
  4898. }
  4899. return bw;
  4900. };
  4901. /**
  4902. * Invoked when <tt>close</tt> is called. Do not call it directly.
  4903. */
  4904. InfoBox.prototype.onRemove = function () {
  4905. if (this.div_) {
  4906. this.div_.parentNode.removeChild(this.div_);
  4907. this.div_ = null;
  4908. }
  4909. };
  4910. /**
  4911. * Draws the InfoBox based on the current map projection and zoom level.
  4912. */
  4913. InfoBox.prototype.draw = function () {
  4914. this.createInfoBoxDiv_();
  4915. var pixPosition = this.getProjection().fromLatLngToDivPixel(this.position_);
  4916. this.div_.style.left = (pixPosition.x + this.pixelOffset_.width) + "px";
  4917. if (this.alignBottom_) {
  4918. this.div_.style.bottom = -(pixPosition.y + this.pixelOffset_.height) + "px";
  4919. } else {
  4920. this.div_.style.top = (pixPosition.y + this.pixelOffset_.height) + "px";
  4921. }
  4922. if (this.isHidden_) {
  4923. this.div_.style.visibility = 'hidden';
  4924. } else {
  4925. this.div_.style.visibility = "visible";
  4926. }
  4927. };
  4928. /**
  4929. * Sets the options for the InfoBox. Note that changes to the <tt>maxWidth</tt>,
  4930. * <tt>closeBoxMargin</tt>, <tt>closeBoxURL</tt>, and <tt>enableEventPropagation</tt>
  4931. * properties have no affect until the current InfoBox is <tt>close</tt>d and a new one
  4932. * is <tt>open</tt>ed.
  4933. * @param {InfoBoxOptions} opt_opts
  4934. */
  4935. InfoBox.prototype.setOptions = function (opt_opts) {
  4936. if (typeof opt_opts.boxClass !== "undefined") { // Must be first
  4937. this.boxClass_ = opt_opts.boxClass;
  4938. this.setBoxStyle_();
  4939. }
  4940. if (typeof opt_opts.boxStyle !== "undefined") { // Must be second
  4941. this.boxStyle_ = opt_opts.boxStyle;
  4942. this.setBoxStyle_();
  4943. }
  4944. if (typeof opt_opts.content !== "undefined") {
  4945. this.setContent(opt_opts.content);
  4946. }
  4947. if (typeof opt_opts.disableAutoPan !== "undefined") {
  4948. this.disableAutoPan_ = opt_opts.disableAutoPan;
  4949. }
  4950. if (typeof opt_opts.maxWidth !== "undefined") {
  4951. this.maxWidth_ = opt_opts.maxWidth;
  4952. }
  4953. if (typeof opt_opts.pixelOffset !== "undefined") {
  4954. this.pixelOffset_ = opt_opts.pixelOffset;
  4955. }
  4956. if (typeof opt_opts.alignBottom !== "undefined") {
  4957. this.alignBottom_ = opt_opts.alignBottom;
  4958. }
  4959. if (typeof opt_opts.position !== "undefined") {
  4960. this.setPosition(opt_opts.position);
  4961. }
  4962. if (typeof opt_opts.zIndex !== "undefined") {
  4963. this.setZIndex(opt_opts.zIndex);
  4964. }
  4965. if (typeof opt_opts.closeBoxMargin !== "undefined") {
  4966. this.closeBoxMargin_ = opt_opts.closeBoxMargin;
  4967. }
  4968. if (typeof opt_opts.closeBoxURL !== "undefined") {
  4969. this.closeBoxURL_ = opt_opts.closeBoxURL;
  4970. }
  4971. if (typeof opt_opts.infoBoxClearance !== "undefined") {
  4972. this.infoBoxClearance_ = opt_opts.infoBoxClearance;
  4973. }
  4974. if (typeof opt_opts.isHidden !== "undefined") {
  4975. this.isHidden_ = opt_opts.isHidden;
  4976. }
  4977. if (typeof opt_opts.visible !== "undefined") {
  4978. this.isHidden_ = !opt_opts.visible;
  4979. }
  4980. if (typeof opt_opts.enableEventPropagation !== "undefined") {
  4981. this.enableEventPropagation_ = opt_opts.enableEventPropagation;
  4982. }
  4983. if (this.div_) {
  4984. this.draw();
  4985. }
  4986. };
  4987. /**
  4988. * Sets the content of the InfoBox.
  4989. * The content can be plain text or an HTML DOM node.
  4990. * @param {string|Node} content
  4991. */
  4992. InfoBox.prototype.setContent = function (content) {
  4993. this.content_ = content;
  4994. if (this.div_) {
  4995. if (this.closeListener_) {
  4996. google.maps.event.removeListener(this.closeListener_);
  4997. this.closeListener_ = null;
  4998. }
  4999. // Odd code required to make things work with MSIE.
  5000. //
  5001. if (!this.fixedWidthSet_) {
  5002. this.div_.style.width = "";
  5003. }
  5004. if (typeof content.nodeType === "undefined") {
  5005. this.div_.innerHTML = this.getCloseBoxImg_() + content;
  5006. } else {
  5007. this.div_.innerHTML = this.getCloseBoxImg_();
  5008. this.div_.appendChild(content);
  5009. }
  5010. // Perverse code required to make things work with MSIE.
  5011. // (Ensures the close box does, in fact, float to the right.)
  5012. //
  5013. if (!this.fixedWidthSet_) {
  5014. this.div_.style.width = this.div_.offsetWidth + "px";
  5015. if (typeof content.nodeType === "undefined") {
  5016. this.div_.innerHTML = this.getCloseBoxImg_() + content;
  5017. } else {
  5018. this.div_.innerHTML = this.getCloseBoxImg_();
  5019. this.div_.appendChild(content);
  5020. }
  5021. }
  5022. this.addClickHandler_();
  5023. }
  5024. /**
  5025. * This event is fired when the content of the InfoBox changes.
  5026. * @name InfoBox#content_changed
  5027. * @event
  5028. */
  5029. google.maps.event.trigger(this, "content_changed");
  5030. };
  5031. /**
  5032. * Sets the geographic location of the InfoBox.
  5033. * @param {LatLng} latlng
  5034. */
  5035. InfoBox.prototype.setPosition = function (latlng) {
  5036. this.position_ = latlng;
  5037. if (this.div_) {
  5038. this.draw();
  5039. }
  5040. /**
  5041. * This event is fired when the position of the InfoBox changes.
  5042. * @name InfoBox#position_changed
  5043. * @event
  5044. */
  5045. google.maps.event.trigger(this, "position_changed");
  5046. };
  5047. /**
  5048. * Sets the zIndex style for the InfoBox.
  5049. * @param {number} index
  5050. */
  5051. InfoBox.prototype.setZIndex = function (index) {
  5052. this.zIndex_ = index;
  5053. if (this.div_) {
  5054. this.div_.style.zIndex = index;
  5055. }
  5056. /**
  5057. * This event is fired when the zIndex of the InfoBox changes.
  5058. * @name InfoBox#zindex_changed
  5059. * @event
  5060. */
  5061. google.maps.event.trigger(this, "zindex_changed");
  5062. };
  5063. /**
  5064. * Sets the visibility of the InfoBox.
  5065. * @param {boolean} isVisible
  5066. */
  5067. InfoBox.prototype.setVisible = function (isVisible) {
  5068. this.isHidden_ = !isVisible;
  5069. if (this.div_) {
  5070. this.div_.style.visibility = (this.isHidden_ ? "hidden" : "visible");
  5071. }
  5072. };
  5073. /**
  5074. * Returns the content of the InfoBox.
  5075. * @returns {string}
  5076. */
  5077. InfoBox.prototype.getContent = function () {
  5078. return this.content_;
  5079. };
  5080. /**
  5081. * Returns the geographic location of the InfoBox.
  5082. * @returns {LatLng}
  5083. */
  5084. InfoBox.prototype.getPosition = function () {
  5085. return this.position_;
  5086. };
  5087. /**
  5088. * Returns the zIndex for the InfoBox.
  5089. * @returns {number}
  5090. */
  5091. InfoBox.prototype.getZIndex = function () {
  5092. return this.zIndex_;
  5093. };
  5094. /**
  5095. * Returns a flag indicating whether the InfoBox is visible.
  5096. * @returns {boolean}
  5097. */
  5098. InfoBox.prototype.getVisible = function () {
  5099. var isVisible;
  5100. if ((typeof this.getMap() === "undefined") || (this.getMap() === null)) {
  5101. isVisible = false;
  5102. } else {
  5103. isVisible = !this.isHidden_;
  5104. }
  5105. return isVisible;
  5106. };
  5107. /**
  5108. * Shows the InfoBox. [Deprecated; use <tt>setVisible</tt> instead.]
  5109. */
  5110. InfoBox.prototype.show = function () {
  5111. this.isHidden_ = false;
  5112. if (this.div_) {
  5113. this.div_.style.visibility = "visible";
  5114. }
  5115. };
  5116. /**
  5117. * Hides the InfoBox. [Deprecated; use <tt>setVisible</tt> instead.]
  5118. */
  5119. InfoBox.prototype.hide = function () {
  5120. this.isHidden_ = true;
  5121. if (this.div_) {
  5122. this.div_.style.visibility = "hidden";
  5123. }
  5124. };
  5125. /**
  5126. * Adds the InfoBox to the specified map or Street View panorama. If <tt>anchor</tt>
  5127. * (usually a <tt>google.maps.Marker</tt>) is specified, the position
  5128. * of the InfoBox is set to the position of the <tt>anchor</tt>. If the
  5129. * anchor is dragged to a new location, the InfoBox moves as well.
  5130. * @param {Map|StreetViewPanorama} map
  5131. * @param {MVCObject} [anchor]
  5132. */
  5133. InfoBox.prototype.open = function (map, anchor) {
  5134. var me = this;
  5135. if (anchor) {
  5136. this.position_ = anchor.getPosition();
  5137. this.moveListener_ = google.maps.event.addListener(anchor, "position_changed", function () {
  5138. me.setPosition(this.getPosition());
  5139. });
  5140. }
  5141. this.setMap(map);
  5142. if (this.div_) {
  5143. this.panBox_();
  5144. }
  5145. };
  5146. /**
  5147. * Removes the InfoBox from the map.
  5148. */
  5149. InfoBox.prototype.close = function () {
  5150. var i;
  5151. if (this.closeListener_) {
  5152. google.maps.event.removeListener(this.closeListener_);
  5153. this.closeListener_ = null;
  5154. }
  5155. if (this.eventListeners_) {
  5156. for (i = 0; i < this.eventListeners_.length; i++) {
  5157. google.maps.event.removeListener(this.eventListeners_[i]);
  5158. }
  5159. this.eventListeners_ = null;
  5160. }
  5161. if (this.moveListener_) {
  5162. google.maps.event.removeListener(this.moveListener_);
  5163. this.moveListener_ = null;
  5164. }
  5165. if (this.contextListener_) {
  5166. google.maps.event.removeListener(this.contextListener_);
  5167. this.contextListener_ = null;
  5168. }
  5169. this.setMap(null);
  5170. };;/**
  5171. * @name MarkerClustererPlus for Google Maps V3
  5172. * @version 2.1.1 [November 4, 2013]
  5173. * @author Gary Little
  5174. * @fileoverview
  5175. * The library creates and manages per-zoom-level clusters for large amounts of markers.
  5176. * <p>
  5177. * This is an enhanced V3 implementation of the
  5178. * <a href="http://gmaps-utility-library-dev.googlecode.com/svn/tags/markerclusterer/"
  5179. * >V2 MarkerClusterer</a> by Xiaoxi Wu. It is based on the
  5180. * <a href="http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/"
  5181. * >V3 MarkerClusterer</a> port by Luke Mahe. MarkerClustererPlus was created by Gary Little.
  5182. * <p>
  5183. * v2.0 release: MarkerClustererPlus v2.0 is backward compatible with MarkerClusterer v1.0. It
  5184. * adds support for the <code>ignoreHidden</code>, <code>title</code>, <code>batchSizeIE</code>,
  5185. * and <code>calculator</code> properties as well as support for four more events. It also allows
  5186. * greater control over the styling of the text that appears on the cluster marker. The
  5187. * documentation has been significantly improved and the overall code has been simplified and
  5188. * polished. Very large numbers of markers can now be managed without causing Javascript timeout
  5189. * errors on Internet Explorer. Note that the name of the <code>clusterclick</code> event has been
  5190. * deprecated. The new name is <code>click</code>, so please change your application code now.
  5191. */
  5192. /**
  5193. * Licensed under the Apache License, Version 2.0 (the "License");
  5194. * you may not use this file except in compliance with the License.
  5195. * You may obtain a copy of the License at
  5196. *
  5197. * http://www.apache.org/licenses/LICENSE-2.0
  5198. *
  5199. * Unless required by applicable law or agreed to in writing, software
  5200. * distributed under the License is distributed on an "AS IS" BASIS,
  5201. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5202. * See the License for the specific language governing permissions and
  5203. * limitations under the License.
  5204. */
  5205. /**
  5206. * @name ClusterIconStyle
  5207. * @class This class represents the object for values in the <code>styles</code> array passed
  5208. * to the {@link MarkerClusterer} constructor. The element in this array that is used to
  5209. * style the cluster icon is determined by calling the <code>calculator</code> function.
  5210. *
  5211. * @property {string} url The URL of the cluster icon image file. Required.
  5212. * @property {number} height The display height (in pixels) of the cluster icon. Required.
  5213. * @property {number} width The display width (in pixels) of the cluster icon. Required.
  5214. * @property {Array} [anchorText] The position (in pixels) from the center of the cluster icon to
  5215. * where the text label is to be centered and drawn. The format is <code>[yoffset, xoffset]</code>
  5216. * where <code>yoffset</code> increases as you go down from center and <code>xoffset</code>
  5217. * increases to the right of center. The default is <code>[0, 0]</code>.
  5218. * @property {Array} [anchorIcon] The anchor position (in pixels) of the cluster icon. This is the
  5219. * spot on the cluster icon that is to be aligned with the cluster position. The format is
  5220. * <code>[yoffset, xoffset]</code> where <code>yoffset</code> increases as you go down and
  5221. * <code>xoffset</code> increases to the right of the top-left corner of the icon. The default
  5222. * anchor position is the center of the cluster icon.
  5223. * @property {string} [textColor="black"] The color of the label text shown on the
  5224. * cluster icon.
  5225. * @property {number} [textSize=11] The size (in pixels) of the label text shown on the
  5226. * cluster icon.
  5227. * @property {string} [textDecoration="none"] The value of the CSS <code>text-decoration</code>
  5228. * property for the label text shown on the cluster icon.
  5229. * @property {string} [fontWeight="bold"] The value of the CSS <code>font-weight</code>
  5230. * property for the label text shown on the cluster icon.
  5231. * @property {string} [fontStyle="normal"] The value of the CSS <code>font-style</code>
  5232. * property for the label text shown on the cluster icon.
  5233. * @property {string} [fontFamily="Arial,sans-serif"] The value of the CSS <code>font-family</code>
  5234. * property for the label text shown on the cluster icon.
  5235. * @property {string} [backgroundPosition="0 0"] The position of the cluster icon image
  5236. * within the image defined by <code>url</code>. The format is <code>"xpos ypos"</code>
  5237. * (the same format as for the CSS <code>background-position</code> property). You must set
  5238. * this property appropriately when the image defined by <code>url</code> represents a sprite
  5239. * containing multiple images. Note that the position <i>must</i> be specified in px units.
  5240. */
  5241. /**
  5242. * @name ClusterIconInfo
  5243. * @class This class is an object containing general information about a cluster icon. This is
  5244. * the object that a <code>calculator</code> function returns.
  5245. *
  5246. * @property {string} text The text of the label to be shown on the cluster icon.
  5247. * @property {number} index The index plus 1 of the element in the <code>styles</code>
  5248. * array to be used to style the cluster icon.
  5249. * @property {string} title The tooltip to display when the mouse moves over the cluster icon.
  5250. * If this value is <code>undefined</code> or <code>""</code>, <code>title</code> is set to the
  5251. * value of the <code>title</code> property passed to the MarkerClusterer.
  5252. */
  5253. /**
  5254. * A cluster icon.
  5255. *
  5256. * @constructor
  5257. * @extends google.maps.OverlayView
  5258. * @param {Cluster} cluster The cluster with which the icon is to be associated.
  5259. * @param {Array} [styles] An array of {@link ClusterIconStyle} defining the cluster icons
  5260. * to use for various cluster sizes.
  5261. * @private
  5262. */
  5263. function ClusterIcon(cluster, styles) {
  5264. cluster.getMarkerClusterer().extend(ClusterIcon, google.maps.OverlayView);
  5265. this.cluster_ = cluster;
  5266. this.className_ = cluster.getMarkerClusterer().getClusterClass();
  5267. this.styles_ = styles;
  5268. this.center_ = null;
  5269. this.div_ = null;
  5270. this.sums_ = null;
  5271. this.visible_ = false;
  5272. this.setMap(cluster.getMap()); // Note: this causes onAdd to be called
  5273. }
  5274. /**
  5275. * Adds the icon to the DOM.
  5276. */
  5277. ClusterIcon.prototype.onAdd = function () {
  5278. var cClusterIcon = this;
  5279. var cMouseDownInCluster;
  5280. var cDraggingMapByCluster;
  5281. this.div_ = document.createElement("div");
  5282. this.div_.className = this.className_;
  5283. if (this.visible_) {
  5284. this.show();
  5285. }
  5286. this.getPanes().overlayMouseTarget.appendChild(this.div_);
  5287. // Fix for Issue 157
  5288. this.boundsChangedListener_ = google.maps.event.addListener(this.getMap(), "bounds_changed", function () {
  5289. cDraggingMapByCluster = cMouseDownInCluster;
  5290. });
  5291. google.maps.event.addDomListener(this.div_, "mousedown", function () {
  5292. cMouseDownInCluster = true;
  5293. cDraggingMapByCluster = false;
  5294. });
  5295. google.maps.event.addDomListener(this.div_, "click", function (e) {
  5296. cMouseDownInCluster = false;
  5297. if (!cDraggingMapByCluster) {
  5298. var theBounds;
  5299. var mz;
  5300. var mc = cClusterIcon.cluster_.getMarkerClusterer();
  5301. /**
  5302. * This event is fired when a cluster marker is clicked.
  5303. * @name MarkerClusterer#click
  5304. * @param {Cluster} c The cluster that was clicked.
  5305. * @event
  5306. */
  5307. google.maps.event.trigger(mc, "click", cClusterIcon.cluster_);
  5308. google.maps.event.trigger(mc, "clusterclick", cClusterIcon.cluster_); // deprecated name
  5309. // The default click handler follows. Disable it by setting
  5310. // the zoomOnClick property to false.
  5311. if (mc.getZoomOnClick()) {
  5312. // Zoom into the cluster.
  5313. mz = mc.getMaxZoom();
  5314. theBounds = cClusterIcon.cluster_.getBounds();
  5315. mc.getMap().fitBounds(theBounds);
  5316. // There is a fix for Issue 170 here:
  5317. setTimeout(function () {
  5318. mc.getMap().fitBounds(theBounds);
  5319. // Don't zoom beyond the max zoom level
  5320. if (mz !== null && (mc.getMap().getZoom() > mz)) {
  5321. mc.getMap().setZoom(mz + 1);
  5322. }
  5323. }, 100);
  5324. }
  5325. // Prevent event propagation to the map:
  5326. e.cancelBubble = true;
  5327. if (e.stopPropagation) {
  5328. e.stopPropagation();
  5329. }
  5330. }
  5331. });
  5332. google.maps.event.addDomListener(this.div_, "mouseover", function () {
  5333. var mc = cClusterIcon.cluster_.getMarkerClusterer();
  5334. /**
  5335. * This event is fired when the mouse moves over a cluster marker.
  5336. * @name MarkerClusterer#mouseover
  5337. * @param {Cluster} c The cluster that the mouse moved over.
  5338. * @event
  5339. */
  5340. google.maps.event.trigger(mc, "mouseover", cClusterIcon.cluster_);
  5341. });
  5342. google.maps.event.addDomListener(this.div_, "mouseout", function () {
  5343. var mc = cClusterIcon.cluster_.getMarkerClusterer();
  5344. /**
  5345. * This event is fired when the mouse moves out of a cluster marker.
  5346. * @name MarkerClusterer#mouseout
  5347. * @param {Cluster} c The cluster that the mouse moved out of.
  5348. * @event
  5349. */
  5350. google.maps.event.trigger(mc, "mouseout", cClusterIcon.cluster_);
  5351. });
  5352. };
  5353. /**
  5354. * Removes the icon from the DOM.
  5355. */
  5356. ClusterIcon.prototype.onRemove = function () {
  5357. if (this.div_ && this.div_.parentNode) {
  5358. this.hide();
  5359. google.maps.event.removeListener(this.boundsChangedListener_);
  5360. google.maps.event.clearInstanceListeners(this.div_);
  5361. this.div_.parentNode.removeChild(this.div_);
  5362. this.div_ = null;
  5363. }
  5364. };
  5365. /**
  5366. * Draws the icon.
  5367. */
  5368. ClusterIcon.prototype.draw = function () {
  5369. if (this.visible_) {
  5370. var pos = this.getPosFromLatLng_(this.center_);
  5371. this.div_.style.top = pos.y + "px";
  5372. this.div_.style.left = pos.x + "px";
  5373. }
  5374. };
  5375. /**
  5376. * Hides the icon.
  5377. */
  5378. ClusterIcon.prototype.hide = function () {
  5379. if (this.div_) {
  5380. this.div_.style.display = "none";
  5381. }
  5382. this.visible_ = false;
  5383. };
  5384. /**
  5385. * Positions and shows the icon.
  5386. */
  5387. ClusterIcon.prototype.show = function () {
  5388. if (this.div_) {
  5389. var img = "";
  5390. // NOTE: values must be specified in px units
  5391. var bp = this.backgroundPosition_.split(" ");
  5392. var spriteH = parseInt(bp[0].trim(), 10);
  5393. var spriteV = parseInt(bp[1].trim(), 10);
  5394. var pos = this.getPosFromLatLng_(this.center_);
  5395. this.div_.style.cssText = this.createCss(pos);
  5396. img = "<img src='" + this.url_ + "' style='position: absolute; top: " + spriteV + "px; left: " + spriteH + "px; ";
  5397. if (!this.cluster_.getMarkerClusterer().enableRetinaIcons_) {
  5398. img += "clip: rect(" + (-1 * spriteV) + "px, " + ((-1 * spriteH) + this.width_) + "px, " +
  5399. ((-1 * spriteV) + this.height_) + "px, " + (-1 * spriteH) + "px);";
  5400. }
  5401. img += "'>";
  5402. this.div_.innerHTML = img + "<div style='" +
  5403. "position: absolute;" +
  5404. "top: " + this.anchorText_[0] + "px;" +
  5405. "left: " + this.anchorText_[1] + "px;" +
  5406. "color: " + this.textColor_ + ";" +
  5407. "font-size: " + this.textSize_ + "px;" +
  5408. "font-family: " + this.fontFamily_ + ";" +
  5409. "font-weight: " + this.fontWeight_ + ";" +
  5410. "font-style: " + this.fontStyle_ + ";" +
  5411. "text-decoration: " + this.textDecoration_ + ";" +
  5412. "text-align: center;" +
  5413. "width: " + this.width_ + "px;" +
  5414. "line-height:" + this.height_ + "px;" +
  5415. "'>" + this.sums_.text + "</div>";
  5416. if (typeof this.sums_.title === "undefined" || this.sums_.title === "") {
  5417. this.div_.title = this.cluster_.getMarkerClusterer().getTitle();
  5418. } else {
  5419. this.div_.title = this.sums_.title;
  5420. }
  5421. this.div_.style.display = "";
  5422. }
  5423. this.visible_ = true;
  5424. };
  5425. /**
  5426. * Sets the icon styles to the appropriate element in the styles array.
  5427. *
  5428. * @param {ClusterIconInfo} sums The icon label text and styles index.
  5429. */
  5430. ClusterIcon.prototype.useStyle = function (sums) {
  5431. this.sums_ = sums;
  5432. var index = Math.max(0, sums.index - 1);
  5433. index = Math.min(this.styles_.length - 1, index);
  5434. var style = this.styles_[index];
  5435. this.url_ = style.url;
  5436. this.height_ = style.height;
  5437. this.width_ = style.width;
  5438. this.anchorText_ = style.anchorText || [0, 0];
  5439. this.anchorIcon_ = style.anchorIcon || [parseInt(this.height_ / 2, 10), parseInt(this.width_ / 2, 10)];
  5440. this.textColor_ = style.textColor || "black";
  5441. this.textSize_ = style.textSize || 11;
  5442. this.textDecoration_ = style.textDecoration || "none";
  5443. this.fontWeight_ = style.fontWeight || "bold";
  5444. this.fontStyle_ = style.fontStyle || "normal";
  5445. this.fontFamily_ = style.fontFamily || "Arial,sans-serif";
  5446. this.backgroundPosition_ = style.backgroundPosition || "0 0";
  5447. };
  5448. /**
  5449. * Sets the position at which to center the icon.
  5450. *
  5451. * @param {google.maps.LatLng} center The latlng to set as the center.
  5452. */
  5453. ClusterIcon.prototype.setCenter = function (center) {
  5454. this.center_ = center;
  5455. };
  5456. /**
  5457. * Creates the cssText style parameter based on the position of the icon.
  5458. *
  5459. * @param {google.maps.Point} pos The position of the icon.
  5460. * @return {string} The CSS style text.
  5461. */
  5462. ClusterIcon.prototype.createCss = function (pos) {
  5463. var style = [];
  5464. style.push("cursor: pointer;");
  5465. style.push("position: absolute; top: " + pos.y + "px; left: " + pos.x + "px;");
  5466. style.push("width: " + this.width_ + "px; height: " + this.height_ + "px;");
  5467. return style.join("");
  5468. };
  5469. /**
  5470. * Returns the position at which to place the DIV depending on the latlng.
  5471. *
  5472. * @param {google.maps.LatLng} latlng The position in latlng.
  5473. * @return {google.maps.Point} The position in pixels.
  5474. */
  5475. ClusterIcon.prototype.getPosFromLatLng_ = function (latlng) {
  5476. var pos = this.getProjection().fromLatLngToDivPixel(latlng);
  5477. pos.x -= this.anchorIcon_[1];
  5478. pos.y -= this.anchorIcon_[0];
  5479. pos.x = parseInt(pos.x, 10);
  5480. pos.y = parseInt(pos.y, 10);
  5481. return pos;
  5482. };
  5483. /**
  5484. * Creates a single cluster that manages a group of proximate markers.
  5485. * Used internally, do not call this constructor directly.
  5486. * @constructor
  5487. * @param {MarkerClusterer} mc The <code>MarkerClusterer</code> object with which this
  5488. * cluster is associated.
  5489. */
  5490. function Cluster(mc) {
  5491. this.markerClusterer_ = mc;
  5492. this.map_ = mc.getMap();
  5493. this.gridSize_ = mc.getGridSize();
  5494. this.minClusterSize_ = mc.getMinimumClusterSize();
  5495. this.averageCenter_ = mc.getAverageCenter();
  5496. this.markers_ = [];
  5497. this.center_ = null;
  5498. this.bounds_ = null;
  5499. this.clusterIcon_ = new ClusterIcon(this, mc.getStyles());
  5500. }
  5501. /**
  5502. * Returns the number of markers managed by the cluster. You can call this from
  5503. * a <code>click</code>, <code>mouseover</code>, or <code>mouseout</code> event handler
  5504. * for the <code>MarkerClusterer</code> object.
  5505. *
  5506. * @return {number} The number of markers in the cluster.
  5507. */
  5508. Cluster.prototype.getSize = function () {
  5509. return this.markers_.length;
  5510. };
  5511. /**
  5512. * Returns the array of markers managed by the cluster. You can call this from
  5513. * a <code>click</code>, <code>mouseover</code>, or <code>mouseout</code> event handler
  5514. * for the <code>MarkerClusterer</code> object.
  5515. *
  5516. * @return {Array} The array of markers in the cluster.
  5517. */
  5518. Cluster.prototype.getMarkers = function () {
  5519. return this.markers_;
  5520. };
  5521. /**
  5522. * Returns the center of the cluster. You can call this from
  5523. * a <code>click</code>, <code>mouseover</code>, or <code>mouseout</code> event handler
  5524. * for the <code>MarkerClusterer</code> object.
  5525. *
  5526. * @return {google.maps.LatLng} The center of the cluster.
  5527. */
  5528. Cluster.prototype.getCenter = function () {
  5529. return this.center_;
  5530. };
  5531. /**
  5532. * Returns the map with which the cluster is associated.
  5533. *
  5534. * @return {google.maps.Map} The map.
  5535. * @ignore
  5536. */
  5537. Cluster.prototype.getMap = function () {
  5538. return this.map_;
  5539. };
  5540. /**
  5541. * Returns the <code>MarkerClusterer</code> object with which the cluster is associated.
  5542. *
  5543. * @return {MarkerClusterer} The associated marker clusterer.
  5544. * @ignore
  5545. */
  5546. Cluster.prototype.getMarkerClusterer = function () {
  5547. return this.markerClusterer_;
  5548. };
  5549. /**
  5550. * Returns the bounds of the cluster.
  5551. *
  5552. * @return {google.maps.LatLngBounds} the cluster bounds.
  5553. * @ignore
  5554. */
  5555. Cluster.prototype.getBounds = function () {
  5556. var i;
  5557. var bounds = new google.maps.LatLngBounds(this.center_, this.center_);
  5558. var markers = this.getMarkers();
  5559. for (i = 0; i < markers.length; i++) {
  5560. bounds.extend(markers[i].getPosition());
  5561. }
  5562. return bounds;
  5563. };
  5564. /**
  5565. * Removes the cluster from the map.
  5566. *
  5567. * @ignore
  5568. */
  5569. Cluster.prototype.remove = function () {
  5570. this.clusterIcon_.setMap(null);
  5571. this.markers_ = [];
  5572. delete this.markers_;
  5573. };
  5574. /**
  5575. * Adds a marker to the cluster.
  5576. *
  5577. * @param {google.maps.Marker} marker The marker to be added.
  5578. * @return {boolean} True if the marker was added.
  5579. * @ignore
  5580. */
  5581. Cluster.prototype.addMarker = function (marker) {
  5582. var i;
  5583. var mCount;
  5584. var mz;
  5585. if (this.isMarkerAlreadyAdded_(marker)) {
  5586. return false;
  5587. }
  5588. if (!this.center_) {
  5589. this.center_ = marker.getPosition();
  5590. this.calculateBounds_();
  5591. } else {
  5592. if (this.averageCenter_) {
  5593. var l = this.markers_.length + 1;
  5594. var lat = (this.center_.lat() * (l - 1) + marker.getPosition().lat()) / l;
  5595. var lng = (this.center_.lng() * (l - 1) + marker.getPosition().lng()) / l;
  5596. this.center_ = new google.maps.LatLng(lat, lng);
  5597. this.calculateBounds_();
  5598. }
  5599. }
  5600. marker.isAdded = true;
  5601. this.markers_.push(marker);
  5602. mCount = this.markers_.length;
  5603. mz = this.markerClusterer_.getMaxZoom();
  5604. if (mz !== null && this.map_.getZoom() > mz) {
  5605. // Zoomed in past max zoom, so show the marker.
  5606. if (marker.getMap() !== this.map_) {
  5607. marker.setMap(this.map_);
  5608. }
  5609. } else if (mCount < this.minClusterSize_) {
  5610. // Min cluster size not reached so show the marker.
  5611. if (marker.getMap() !== this.map_) {
  5612. marker.setMap(this.map_);
  5613. }
  5614. } else if (mCount === this.minClusterSize_) {
  5615. // Hide the markers that were showing.
  5616. for (i = 0; i < mCount; i++) {
  5617. this.markers_[i].setMap(null);
  5618. }
  5619. } else {
  5620. marker.setMap(null);
  5621. }
  5622. this.updateIcon_();
  5623. return true;
  5624. };
  5625. /**
  5626. * Determines if a marker lies within the cluster's bounds.
  5627. *
  5628. * @param {google.maps.Marker} marker The marker to check.
  5629. * @return {boolean} True if the marker lies in the bounds.
  5630. * @ignore
  5631. */
  5632. Cluster.prototype.isMarkerInClusterBounds = function (marker) {
  5633. return this.bounds_.contains(marker.getPosition());
  5634. };
  5635. /**
  5636. * Calculates the extended bounds of the cluster with the grid.
  5637. */
  5638. Cluster.prototype.calculateBounds_ = function () {
  5639. var bounds = new google.maps.LatLngBounds(this.center_, this.center_);
  5640. this.bounds_ = this.markerClusterer_.getExtendedBounds(bounds);
  5641. };
  5642. /**
  5643. * Updates the cluster icon.
  5644. */
  5645. Cluster.prototype.updateIcon_ = function () {
  5646. var mCount = this.markers_.length;
  5647. var mz = this.markerClusterer_.getMaxZoom();
  5648. if (mz !== null && this.map_.getZoom() > mz) {
  5649. this.clusterIcon_.hide();
  5650. return;
  5651. }
  5652. if (mCount < this.minClusterSize_) {
  5653. // Min cluster size not yet reached.
  5654. this.clusterIcon_.hide();
  5655. return;
  5656. }
  5657. var numStyles = this.markerClusterer_.getStyles().length;
  5658. var sums = this.markerClusterer_.getCalculator()(this.markers_, numStyles);
  5659. this.clusterIcon_.setCenter(this.center_);
  5660. this.clusterIcon_.useStyle(sums);
  5661. this.clusterIcon_.show();
  5662. };
  5663. /**
  5664. * Determines if a marker has already been added to the cluster.
  5665. *
  5666. * @param {google.maps.Marker} marker The marker to check.
  5667. * @return {boolean} True if the marker has already been added.
  5668. */
  5669. Cluster.prototype.isMarkerAlreadyAdded_ = function (marker) {
  5670. var i;
  5671. if (this.markers_.indexOf) {
  5672. return this.markers_.indexOf(marker) !== -1;
  5673. } else {
  5674. for (i = 0; i < this.markers_.length; i++) {
  5675. if (marker === this.markers_[i]) {
  5676. return true;
  5677. }
  5678. }
  5679. }
  5680. return false;
  5681. };
  5682. /**
  5683. * @name MarkerClustererOptions
  5684. * @class This class represents the optional parameter passed to
  5685. * the {@link MarkerClusterer} constructor.
  5686. * @property {number} [gridSize=60] The grid size of a cluster in pixels. The grid is a square.
  5687. * @property {number} [maxZoom=null] The maximum zoom level at which clustering is enabled or
  5688. * <code>null</code> if clustering is to be enabled at all zoom levels.
  5689. * @property {boolean} [zoomOnClick=true] Whether to zoom the map when a cluster marker is
  5690. * clicked. You may want to set this to <code>false</code> if you have installed a handler
  5691. * for the <code>click</code> event and it deals with zooming on its own.
  5692. * @property {boolean} [averageCenter=false] Whether the position of a cluster marker should be
  5693. * the average position of all markers in the cluster. If set to <code>false</code>, the
  5694. * cluster marker is positioned at the location of the first marker added to the cluster.
  5695. * @property {number} [minimumClusterSize=2] The minimum number of markers needed in a cluster
  5696. * before the markers are hidden and a cluster marker appears.
  5697. * @property {boolean} [ignoreHidden=false] Whether to ignore hidden markers in clusters. You
  5698. * may want to set this to <code>true</code> to ensure that hidden markers are not included
  5699. * in the marker count that appears on a cluster marker (this count is the value of the
  5700. * <code>text</code> property of the result returned by the default <code>calculator</code>).
  5701. * If set to <code>true</code> and you change the visibility of a marker being clustered, be
  5702. * sure to also call <code>MarkerClusterer.repaint()</code>.
  5703. * @property {string} [title=""] The tooltip to display when the mouse moves over a cluster
  5704. * marker. (Alternatively, you can use a custom <code>calculator</code> function to specify a
  5705. * different tooltip for each cluster marker.)
  5706. * @property {function} [calculator=MarkerClusterer.CALCULATOR] The function used to determine
  5707. * the text to be displayed on a cluster marker and the index indicating which style to use
  5708. * for the cluster marker. The input parameters for the function are (1) the array of markers
  5709. * represented by a cluster marker and (2) the number of cluster icon styles. It returns a
  5710. * {@link ClusterIconInfo} object. The default <code>calculator</code> returns a
  5711. * <code>text</code> property which is the number of markers in the cluster and an
  5712. * <code>index</code> property which is one higher than the lowest integer such that
  5713. * <code>10^i</code> exceeds the number of markers in the cluster, or the size of the styles
  5714. * array, whichever is less. The <code>styles</code> array element used has an index of
  5715. * <code>index</code> minus 1. For example, the default <code>calculator</code> returns a
  5716. * <code>text</code> value of <code>"125"</code> and an <code>index</code> of <code>3</code>
  5717. * for a cluster icon representing 125 markers so the element used in the <code>styles</code>
  5718. * array is <code>2</code>. A <code>calculator</code> may also return a <code>title</code>
  5719. * property that contains the text of the tooltip to be used for the cluster marker. If
  5720. * <code>title</code> is not defined, the tooltip is set to the value of the <code>title</code>
  5721. * property for the MarkerClusterer.
  5722. * @property {string} [clusterClass="cluster"] The name of the CSS class defining general styles
  5723. * for the cluster markers. Use this class to define CSS styles that are not set up by the code
  5724. * that processes the <code>styles</code> array.
  5725. * @property {Array} [styles] An array of {@link ClusterIconStyle} elements defining the styles
  5726. * of the cluster markers to be used. The element to be used to style a given cluster marker
  5727. * is determined by the function defined by the <code>calculator</code> property.
  5728. * The default is an array of {@link ClusterIconStyle} elements whose properties are derived
  5729. * from the values for <code>imagePath</code>, <code>imageExtension</code>, and
  5730. * <code>imageSizes</code>.
  5731. * @property {boolean} [enableRetinaIcons=false] Whether to allow the use of cluster icons that
  5732. * have sizes that are some multiple (typically double) of their actual display size. Icons such
  5733. * as these look better when viewed on high-resolution monitors such as Apple's Retina displays.
  5734. * Note: if this property is <code>true</code>, sprites cannot be used as cluster icons.
  5735. * @property {number} [batchSize=MarkerClusterer.BATCH_SIZE] Set this property to the
  5736. * number of markers to be processed in a single batch when using a browser other than
  5737. * Internet Explorer (for Internet Explorer, use the batchSizeIE property instead).
  5738. * @property {number} [batchSizeIE=MarkerClusterer.BATCH_SIZE_IE] When Internet Explorer is
  5739. * being used, markers are processed in several batches with a small delay inserted between
  5740. * each batch in an attempt to avoid Javascript timeout errors. Set this property to the
  5741. * number of markers to be processed in a single batch; select as high a number as you can
  5742. * without causing a timeout error in the browser. This number might need to be as low as 100
  5743. * if 15,000 markers are being managed, for example.
  5744. * @property {string} [imagePath=MarkerClusterer.IMAGE_PATH]
  5745. * The full URL of the root name of the group of image files to use for cluster icons.
  5746. * The complete file name is of the form <code>imagePath</code>n.<code>imageExtension</code>
  5747. * where n is the image file number (1, 2, etc.).
  5748. * @property {string} [imageExtension=MarkerClusterer.IMAGE_EXTENSION]
  5749. * The extension name for the cluster icon image files (e.g., <code>"png"</code> or
  5750. * <code>"jpg"</code>).
  5751. * @property {Array} [imageSizes=MarkerClusterer.IMAGE_SIZES]
  5752. * An array of numbers containing the widths of the group of
  5753. * <code>imagePath</code>n.<code>imageExtension</code> image files.
  5754. * (The images are assumed to be square.)
  5755. */
  5756. /**
  5757. * Creates a MarkerClusterer object with the options specified in {@link MarkerClustererOptions}.
  5758. * @constructor
  5759. * @extends google.maps.OverlayView
  5760. * @param {google.maps.Map} map The Google map to attach to.
  5761. * @param {Array.<google.maps.Marker>} [opt_markers] The markers to be added to the cluster.
  5762. * @param {MarkerClustererOptions} [opt_options] The optional parameters.
  5763. */
  5764. function MarkerClusterer(map, opt_markers, opt_options) {
  5765. // MarkerClusterer implements google.maps.OverlayView interface. We use the
  5766. // extend function to extend MarkerClusterer with google.maps.OverlayView
  5767. // because it might not always be available when the code is defined so we
  5768. // look for it at the last possible moment. If it doesn't exist now then
  5769. // there is no point going ahead :)
  5770. this.extend(MarkerClusterer, google.maps.OverlayView);
  5771. opt_markers = opt_markers || [];
  5772. opt_options = opt_options || {};
  5773. this.markers_ = [];
  5774. this.clusters_ = [];
  5775. this.listeners_ = [];
  5776. this.activeMap_ = null;
  5777. this.ready_ = false;
  5778. this.gridSize_ = opt_options.gridSize || 60;
  5779. this.minClusterSize_ = opt_options.minimumClusterSize || 2;
  5780. this.maxZoom_ = opt_options.maxZoom || null;
  5781. this.styles_ = opt_options.styles || [];
  5782. this.title_ = opt_options.title || "";
  5783. this.zoomOnClick_ = true;
  5784. if (opt_options.zoomOnClick !== undefined) {
  5785. this.zoomOnClick_ = opt_options.zoomOnClick;
  5786. }
  5787. this.averageCenter_ = false;
  5788. if (opt_options.averageCenter !== undefined) {
  5789. this.averageCenter_ = opt_options.averageCenter;
  5790. }
  5791. this.ignoreHidden_ = false;
  5792. if (opt_options.ignoreHidden !== undefined) {
  5793. this.ignoreHidden_ = opt_options.ignoreHidden;
  5794. }
  5795. this.enableRetinaIcons_ = false;
  5796. if (opt_options.enableRetinaIcons !== undefined) {
  5797. this.enableRetinaIcons_ = opt_options.enableRetinaIcons;
  5798. }
  5799. this.imagePath_ = opt_options.imagePath || MarkerClusterer.IMAGE_PATH;
  5800. this.imageExtension_ = opt_options.imageExtension || MarkerClusterer.IMAGE_EXTENSION;
  5801. this.imageSizes_ = opt_options.imageSizes || MarkerClusterer.IMAGE_SIZES;
  5802. this.calculator_ = opt_options.calculator || MarkerClusterer.CALCULATOR;
  5803. this.batchSize_ = opt_options.batchSize || MarkerClusterer.BATCH_SIZE;
  5804. this.batchSizeIE_ = opt_options.batchSizeIE || MarkerClusterer.BATCH_SIZE_IE;
  5805. this.clusterClass_ = opt_options.clusterClass || "cluster";
  5806. if (navigator.userAgent.toLowerCase().indexOf("msie") !== -1) {
  5807. // Try to avoid IE timeout when processing a huge number of markers:
  5808. this.batchSize_ = this.batchSizeIE_;
  5809. }
  5810. this.setupStyles_();
  5811. this.addMarkers(opt_markers, true);
  5812. this.setMap(map); // Note: this causes onAdd to be called
  5813. }
  5814. /**
  5815. * Implementation of the onAdd interface method.
  5816. * @ignore
  5817. */
  5818. MarkerClusterer.prototype.onAdd = function () {
  5819. var cMarkerClusterer = this;
  5820. this.activeMap_ = this.getMap();
  5821. this.ready_ = true;
  5822. this.repaint();
  5823. // Add the map event listeners
  5824. this.listeners_ = [
  5825. google.maps.event.addListener(this.getMap(), "zoom_changed", function () {
  5826. cMarkerClusterer.resetViewport_(false);
  5827. // Workaround for this Google bug: when map is at level 0 and "-" of
  5828. // zoom slider is clicked, a "zoom_changed" event is fired even though
  5829. // the map doesn't zoom out any further. In this situation, no "idle"
  5830. // event is triggered so the cluster markers that have been removed
  5831. // do not get redrawn. Same goes for a zoom in at maxZoom.
  5832. if (this.getZoom() === (this.get("minZoom") || 0) || this.getZoom() === this.get("maxZoom")) {
  5833. google.maps.event.trigger(this, "idle");
  5834. }
  5835. }),
  5836. google.maps.event.addListener(this.getMap(), "idle", function () {
  5837. cMarkerClusterer.redraw_();
  5838. })
  5839. ];
  5840. };
  5841. /**
  5842. * Implementation of the onRemove interface method.
  5843. * Removes map event listeners and all cluster icons from the DOM.
  5844. * All managed markers are also put back on the map.
  5845. * @ignore
  5846. */
  5847. MarkerClusterer.prototype.onRemove = function () {
  5848. var i;
  5849. // Put all the managed markers back on the map:
  5850. for (i = 0; i < this.markers_.length; i++) {
  5851. if (this.markers_[i].getMap() !== this.activeMap_) {
  5852. this.markers_[i].setMap(this.activeMap_);
  5853. }
  5854. }
  5855. // Remove all clusters:
  5856. for (i = 0; i < this.clusters_.length; i++) {
  5857. this.clusters_[i].remove();
  5858. }
  5859. this.clusters_ = [];
  5860. // Remove map event listeners:
  5861. for (i = 0; i < this.listeners_.length; i++) {
  5862. google.maps.event.removeListener(this.listeners_[i]);
  5863. }
  5864. this.listeners_ = [];
  5865. this.activeMap_ = null;
  5866. this.ready_ = false;
  5867. };
  5868. /**
  5869. * Implementation of the draw interface method.
  5870. * @ignore
  5871. */
  5872. MarkerClusterer.prototype.draw = function () {};
  5873. /**
  5874. * Sets up the styles object.
  5875. */
  5876. MarkerClusterer.prototype.setupStyles_ = function () {
  5877. var i, size;
  5878. if (this.styles_.length > 0) {
  5879. return;
  5880. }
  5881. for (i = 0; i < this.imageSizes_.length; i++) {
  5882. size = this.imageSizes_[i];
  5883. this.styles_.push({
  5884. url: this.imagePath_ + (i + 1) + "." + this.imageExtension_,
  5885. height: size,
  5886. width: size
  5887. });
  5888. }
  5889. };
  5890. /**
  5891. * Fits the map to the bounds of the markers managed by the clusterer.
  5892. */
  5893. MarkerClusterer.prototype.fitMapToMarkers = function () {
  5894. var i;
  5895. var markers = this.getMarkers();
  5896. var bounds = new google.maps.LatLngBounds();
  5897. for (i = 0; i < markers.length; i++) {
  5898. bounds.extend(markers[i].getPosition());
  5899. }
  5900. this.getMap().fitBounds(bounds);
  5901. };
  5902. /**
  5903. * Returns the value of the <code>gridSize</code> property.
  5904. *
  5905. * @return {number} The grid size.
  5906. */
  5907. MarkerClusterer.prototype.getGridSize = function () {
  5908. return this.gridSize_;
  5909. };
  5910. /**
  5911. * Sets the value of the <code>gridSize</code> property.
  5912. *
  5913. * @param {number} gridSize The grid size.
  5914. */
  5915. MarkerClusterer.prototype.setGridSize = function (gridSize) {
  5916. this.gridSize_ = gridSize;
  5917. };
  5918. /**
  5919. * Returns the value of the <code>minimumClusterSize</code> property.
  5920. *
  5921. * @return {number} The minimum cluster size.
  5922. */
  5923. MarkerClusterer.prototype.getMinimumClusterSize = function () {
  5924. return this.minClusterSize_;
  5925. };
  5926. /**
  5927. * Sets the value of the <code>minimumClusterSize</code> property.
  5928. *
  5929. * @param {number} minimumClusterSize The minimum cluster size.
  5930. */
  5931. MarkerClusterer.prototype.setMinimumClusterSize = function (minimumClusterSize) {
  5932. this.minClusterSize_ = minimumClusterSize;
  5933. };
  5934. /**
  5935. * Returns the value of the <code>maxZoom</code> property.
  5936. *
  5937. * @return {number} The maximum zoom level.
  5938. */
  5939. MarkerClusterer.prototype.getMaxZoom = function () {
  5940. return this.maxZoom_;
  5941. };
  5942. /**
  5943. * Sets the value of the <code>maxZoom</code> property.
  5944. *
  5945. * @param {number} maxZoom The maximum zoom level.
  5946. */
  5947. MarkerClusterer.prototype.setMaxZoom = function (maxZoom) {
  5948. this.maxZoom_ = maxZoom;
  5949. };
  5950. /**
  5951. * Returns the value of the <code>styles</code> property.
  5952. *
  5953. * @return {Array} The array of styles defining the cluster markers to be used.
  5954. */
  5955. MarkerClusterer.prototype.getStyles = function () {
  5956. return this.styles_;
  5957. };
  5958. /**
  5959. * Sets the value of the <code>styles</code> property.
  5960. *
  5961. * @param {Array.<ClusterIconStyle>} styles The array of styles to use.
  5962. */
  5963. MarkerClusterer.prototype.setStyles = function (styles) {
  5964. this.styles_ = styles;
  5965. };
  5966. /**
  5967. * Returns the value of the <code>title</code> property.
  5968. *
  5969. * @return {string} The content of the title text.
  5970. */
  5971. MarkerClusterer.prototype.getTitle = function () {
  5972. return this.title_;
  5973. };
  5974. /**
  5975. * Sets the value of the <code>title</code> property.
  5976. *
  5977. * @param {string} title The value of the title property.
  5978. */
  5979. MarkerClusterer.prototype.setTitle = function (title) {
  5980. this.title_ = title;
  5981. };
  5982. /**
  5983. * Returns the value of the <code>zoomOnClick</code> property.
  5984. *
  5985. * @return {boolean} True if zoomOnClick property is set.
  5986. */
  5987. MarkerClusterer.prototype.getZoomOnClick = function () {
  5988. return this.zoomOnClick_;
  5989. };
  5990. /**
  5991. * Sets the value of the <code>zoomOnClick</code> property.
  5992. *
  5993. * @param {boolean} zoomOnClick The value of the zoomOnClick property.
  5994. */
  5995. MarkerClusterer.prototype.setZoomOnClick = function (zoomOnClick) {
  5996. this.zoomOnClick_ = zoomOnClick;
  5997. };
  5998. /**
  5999. * Returns the value of the <code>averageCenter</code> property.
  6000. *
  6001. * @return {boolean} True if averageCenter property is set.
  6002. */
  6003. MarkerClusterer.prototype.getAverageCenter = function () {
  6004. return this.averageCenter_;
  6005. };
  6006. /**
  6007. * Sets the value of the <code>averageCenter</code> property.
  6008. *
  6009. * @param {boolean} averageCenter The value of the averageCenter property.
  6010. */
  6011. MarkerClusterer.prototype.setAverageCenter = function (averageCenter) {
  6012. this.averageCenter_ = averageCenter;
  6013. };
  6014. /**
  6015. * Returns the value of the <code>ignoreHidden</code> property.
  6016. *
  6017. * @return {boolean} True if ignoreHidden property is set.
  6018. */
  6019. MarkerClusterer.prototype.getIgnoreHidden = function () {
  6020. return this.ignoreHidden_;
  6021. };
  6022. /**
  6023. * Sets the value of the <code>ignoreHidden</code> property.
  6024. *
  6025. * @param {boolean} ignoreHidden The value of the ignoreHidden property.
  6026. */
  6027. MarkerClusterer.prototype.setIgnoreHidden = function (ignoreHidden) {
  6028. this.ignoreHidden_ = ignoreHidden;
  6029. };
  6030. /**
  6031. * Returns the value of the <code>enableRetinaIcons</code> property.
  6032. *
  6033. * @return {boolean} True if enableRetinaIcons property is set.
  6034. */
  6035. MarkerClusterer.prototype.getEnableRetinaIcons = function () {
  6036. return this.enableRetinaIcons_;
  6037. };
  6038. /**
  6039. * Sets the value of the <code>enableRetinaIcons</code> property.
  6040. *
  6041. * @param {boolean} enableRetinaIcons The value of the enableRetinaIcons property.
  6042. */
  6043. MarkerClusterer.prototype.setEnableRetinaIcons = function (enableRetinaIcons) {
  6044. this.enableRetinaIcons_ = enableRetinaIcons;
  6045. };
  6046. /**
  6047. * Returns the value of the <code>imageExtension</code> property.
  6048. *
  6049. * @return {string} The value of the imageExtension property.
  6050. */
  6051. MarkerClusterer.prototype.getImageExtension = function () {
  6052. return this.imageExtension_;
  6053. };
  6054. /**
  6055. * Sets the value of the <code>imageExtension</code> property.
  6056. *
  6057. * @param {string} imageExtension The value of the imageExtension property.
  6058. */
  6059. MarkerClusterer.prototype.setImageExtension = function (imageExtension) {
  6060. this.imageExtension_ = imageExtension;
  6061. };
  6062. /**
  6063. * Returns the value of the <code>imagePath</code> property.
  6064. *
  6065. * @return {string} The value of the imagePath property.
  6066. */
  6067. MarkerClusterer.prototype.getImagePath = function () {
  6068. return this.imagePath_;
  6069. };
  6070. /**
  6071. * Sets the value of the <code>imagePath</code> property.
  6072. *
  6073. * @param {string} imagePath The value of the imagePath property.
  6074. */
  6075. MarkerClusterer.prototype.setImagePath = function (imagePath) {
  6076. this.imagePath_ = imagePath;
  6077. };
  6078. /**
  6079. * Returns the value of the <code>imageSizes</code> property.
  6080. *
  6081. * @return {Array} The value of the imageSizes property.
  6082. */
  6083. MarkerClusterer.prototype.getImageSizes = function () {
  6084. return this.imageSizes_;
  6085. };
  6086. /**
  6087. * Sets the value of the <code>imageSizes</code> property.
  6088. *
  6089. * @param {Array} imageSizes The value of the imageSizes property.
  6090. */
  6091. MarkerClusterer.prototype.setImageSizes = function (imageSizes) {
  6092. this.imageSizes_ = imageSizes;
  6093. };
  6094. /**
  6095. * Returns the value of the <code>calculator</code> property.
  6096. *
  6097. * @return {function} the value of the calculator property.
  6098. */
  6099. MarkerClusterer.prototype.getCalculator = function () {
  6100. return this.calculator_;
  6101. };
  6102. /**
  6103. * Sets the value of the <code>calculator</code> property.
  6104. *
  6105. * @param {function(Array.<google.maps.Marker>, number)} calculator The value
  6106. * of the calculator property.
  6107. */
  6108. MarkerClusterer.prototype.setCalculator = function (calculator) {
  6109. this.calculator_ = calculator;
  6110. };
  6111. /**
  6112. * Returns the value of the <code>batchSizeIE</code> property.
  6113. *
  6114. * @return {number} the value of the batchSizeIE property.
  6115. */
  6116. MarkerClusterer.prototype.getBatchSizeIE = function () {
  6117. return this.batchSizeIE_;
  6118. };
  6119. /**
  6120. * Sets the value of the <code>batchSizeIE</code> property.
  6121. *
  6122. * @param {number} batchSizeIE The value of the batchSizeIE property.
  6123. */
  6124. MarkerClusterer.prototype.setBatchSizeIE = function (batchSizeIE) {
  6125. this.batchSizeIE_ = batchSizeIE;
  6126. };
  6127. /**
  6128. * Returns the value of the <code>clusterClass</code> property.
  6129. *
  6130. * @return {string} the value of the clusterClass property.
  6131. */
  6132. MarkerClusterer.prototype.getClusterClass = function () {
  6133. return this.clusterClass_;
  6134. };
  6135. /**
  6136. * Sets the value of the <code>clusterClass</code> property.
  6137. *
  6138. * @param {string} clusterClass The value of the clusterClass property.
  6139. */
  6140. MarkerClusterer.prototype.setClusterClass = function (clusterClass) {
  6141. this.clusterClass_ = clusterClass;
  6142. };
  6143. /**
  6144. * Returns the array of markers managed by the clusterer.
  6145. *
  6146. * @return {Array} The array of markers managed by the clusterer.
  6147. */
  6148. MarkerClusterer.prototype.getMarkers = function () {
  6149. return this.markers_;
  6150. };
  6151. /**
  6152. * Returns the number of markers managed by the clusterer.
  6153. *
  6154. * @return {number} The number of markers.
  6155. */
  6156. MarkerClusterer.prototype.getTotalMarkers = function () {
  6157. return this.markers_.length;
  6158. };
  6159. /**
  6160. * Returns the current array of clusters formed by the clusterer.
  6161. *
  6162. * @return {Array} The array of clusters formed by the clusterer.
  6163. */
  6164. MarkerClusterer.prototype.getClusters = function () {
  6165. return this.clusters_;
  6166. };
  6167. /**
  6168. * Returns the number of clusters formed by the clusterer.
  6169. *
  6170. * @return {number} The number of clusters formed by the clusterer.
  6171. */
  6172. MarkerClusterer.prototype.getTotalClusters = function () {
  6173. return this.clusters_.length;
  6174. };
  6175. /**
  6176. * Adds a marker to the clusterer. The clusters are redrawn unless
  6177. * <code>opt_nodraw</code> is set to <code>true</code>.
  6178. *
  6179. * @param {google.maps.Marker} marker The marker to add.
  6180. * @param {boolean} [opt_nodraw] Set to <code>true</code> to prevent redrawing.
  6181. */
  6182. MarkerClusterer.prototype.addMarker = function (marker, opt_nodraw) {
  6183. this.pushMarkerTo_(marker);
  6184. if (!opt_nodraw) {
  6185. this.redraw_();
  6186. }
  6187. };
  6188. /**
  6189. * Adds an array of markers to the clusterer. The clusters are redrawn unless
  6190. * <code>opt_nodraw</code> is set to <code>true</code>.
  6191. *
  6192. * @param {Array.<google.maps.Marker>} markers The markers to add.
  6193. * @param {boolean} [opt_nodraw] Set to <code>true</code> to prevent redrawing.
  6194. */
  6195. MarkerClusterer.prototype.addMarkers = function (markers, opt_nodraw) {
  6196. var key;
  6197. for (key in markers) {
  6198. if (markers.hasOwnProperty(key)) {
  6199. this.pushMarkerTo_(markers[key]);
  6200. }
  6201. }
  6202. if (!opt_nodraw) {
  6203. this.redraw_();
  6204. }
  6205. };
  6206. /**
  6207. * Pushes a marker to the clusterer.
  6208. *
  6209. * @param {google.maps.Marker} marker The marker to add.
  6210. */
  6211. MarkerClusterer.prototype.pushMarkerTo_ = function (marker) {
  6212. // If the marker is draggable add a listener so we can update the clusters on the dragend:
  6213. if (marker.getDraggable()) {
  6214. var cMarkerClusterer = this;
  6215. google.maps.event.addListener(marker, "dragend", function () {
  6216. if (cMarkerClusterer.ready_) {
  6217. this.isAdded = false;
  6218. cMarkerClusterer.repaint();
  6219. }
  6220. });
  6221. }
  6222. marker.isAdded = false;
  6223. this.markers_.push(marker);
  6224. };
  6225. /**
  6226. * Removes a marker from the cluster. The clusters are redrawn unless
  6227. * <code>opt_nodraw</code> is set to <code>true</code>. Returns <code>true</code> if the
  6228. * marker was removed from the clusterer.
  6229. *
  6230. * @param {google.maps.Marker} marker The marker to remove.
  6231. * @param {boolean} [opt_nodraw] Set to <code>true</code> to prevent redrawing.
  6232. * @return {boolean} True if the marker was removed from the clusterer.
  6233. */
  6234. MarkerClusterer.prototype.removeMarker = function (marker, opt_nodraw) {
  6235. var removed = this.removeMarker_(marker);
  6236. if (!opt_nodraw && removed) {
  6237. this.repaint();
  6238. }
  6239. return removed;
  6240. };
  6241. /**
  6242. * Removes an array of markers from the cluster. The clusters are redrawn unless
  6243. * <code>opt_nodraw</code> is set to <code>true</code>. Returns <code>true</code> if markers
  6244. * were removed from the clusterer.
  6245. *
  6246. * @param {Array.<google.maps.Marker>} markers The markers to remove.
  6247. * @param {boolean} [opt_nodraw] Set to <code>true</code> to prevent redrawing.
  6248. * @return {boolean} True if markers were removed from the clusterer.
  6249. */
  6250. MarkerClusterer.prototype.removeMarkers = function (markers, opt_nodraw) {
  6251. var i, r;
  6252. var removed = false;
  6253. for (i = 0; i < markers.length; i++) {
  6254. r = this.removeMarker_(markers[i]);
  6255. removed = removed || r;
  6256. }
  6257. if (!opt_nodraw && removed) {
  6258. this.repaint();
  6259. }
  6260. return removed;
  6261. };
  6262. /**
  6263. * Removes a marker and returns true if removed, false if not.
  6264. *
  6265. * @param {google.maps.Marker} marker The marker to remove
  6266. * @return {boolean} Whether the marker was removed or not
  6267. */
  6268. MarkerClusterer.prototype.removeMarker_ = function (marker) {
  6269. var i;
  6270. var index = -1;
  6271. if (this.markers_.indexOf) {
  6272. index = this.markers_.indexOf(marker);
  6273. } else {
  6274. for (i = 0; i < this.markers_.length; i++) {
  6275. if (marker === this.markers_[i]) {
  6276. index = i;
  6277. break;
  6278. }
  6279. }
  6280. }
  6281. if (index === -1) {
  6282. // Marker is not in our list of markers, so do nothing:
  6283. return false;
  6284. }
  6285. marker.setMap(null);
  6286. this.markers_.splice(index, 1); // Remove the marker from the list of managed markers
  6287. return true;
  6288. };
  6289. /**
  6290. * Removes all clusters and markers from the map and also removes all markers
  6291. * managed by the clusterer.
  6292. */
  6293. MarkerClusterer.prototype.clearMarkers = function () {
  6294. this.resetViewport_(true);
  6295. this.markers_ = [];
  6296. };
  6297. /**
  6298. * Recalculates and redraws all the marker clusters from scratch.
  6299. * Call this after changing any properties.
  6300. */
  6301. MarkerClusterer.prototype.repaint = function () {
  6302. var oldClusters = this.clusters_.slice();
  6303. this.clusters_ = [];
  6304. this.resetViewport_(false);
  6305. this.redraw_();
  6306. // Remove the old clusters.
  6307. // Do it in a timeout to prevent blinking effect.
  6308. setTimeout(function () {
  6309. var i;
  6310. for (i = 0; i < oldClusters.length; i++) {
  6311. oldClusters[i].remove();
  6312. }
  6313. }, 0);
  6314. };
  6315. /**
  6316. * Returns the current bounds extended by the grid size.
  6317. *
  6318. * @param {google.maps.LatLngBounds} bounds The bounds to extend.
  6319. * @return {google.maps.LatLngBounds} The extended bounds.
  6320. * @ignore
  6321. */
  6322. MarkerClusterer.prototype.getExtendedBounds = function (bounds) {
  6323. var projection = this.getProjection();
  6324. // Turn the bounds into latlng.
  6325. var tr = new google.maps.LatLng(bounds.getNorthEast().lat(),
  6326. bounds.getNorthEast().lng());
  6327. var bl = new google.maps.LatLng(bounds.getSouthWest().lat(),
  6328. bounds.getSouthWest().lng());
  6329. // Convert the points to pixels and the extend out by the grid size.
  6330. var trPix = projection.fromLatLngToDivPixel(tr);
  6331. trPix.x += this.gridSize_;
  6332. trPix.y -= this.gridSize_;
  6333. var blPix = projection.fromLatLngToDivPixel(bl);
  6334. blPix.x -= this.gridSize_;
  6335. blPix.y += this.gridSize_;
  6336. // Convert the pixel points back to LatLng
  6337. var ne = projection.fromDivPixelToLatLng(trPix);
  6338. var sw = projection.fromDivPixelToLatLng(blPix);
  6339. // Extend the bounds to contain the new bounds.
  6340. bounds.extend(ne);
  6341. bounds.extend(sw);
  6342. return bounds;
  6343. };
  6344. /**
  6345. * Redraws all the clusters.
  6346. */
  6347. MarkerClusterer.prototype.redraw_ = function () {
  6348. this.createClusters_(0);
  6349. };
  6350. /**
  6351. * Removes all clusters from the map. The markers are also removed from the map
  6352. * if <code>opt_hide</code> is set to <code>true</code>.
  6353. *
  6354. * @param {boolean} [opt_hide] Set to <code>true</code> to also remove the markers
  6355. * from the map.
  6356. */
  6357. MarkerClusterer.prototype.resetViewport_ = function (opt_hide) {
  6358. var i, marker;
  6359. // Remove all the clusters
  6360. for (i = 0; i < this.clusters_.length; i++) {
  6361. this.clusters_[i].remove();
  6362. }
  6363. this.clusters_ = [];
  6364. // Reset the markers to not be added and to be removed from the map.
  6365. for (i = 0; i < this.markers_.length; i++) {
  6366. marker = this.markers_[i];
  6367. marker.isAdded = false;
  6368. if (opt_hide) {
  6369. marker.setMap(null);
  6370. }
  6371. }
  6372. };
  6373. /**
  6374. * Calculates the distance between two latlng locations in km.
  6375. *
  6376. * @param {google.maps.LatLng} p1 The first lat lng point.
  6377. * @param {google.maps.LatLng} p2 The second lat lng point.
  6378. * @return {number} The distance between the two points in km.
  6379. * @see http://www.movable-type.co.uk/scripts/latlong.html
  6380. */
  6381. MarkerClusterer.prototype.distanceBetweenPoints_ = function (p1, p2) {
  6382. var R = 6371; // Radius of the Earth in km
  6383. var dLat = (p2.lat() - p1.lat()) * Math.PI / 180;
  6384. var dLon = (p2.lng() - p1.lng()) * Math.PI / 180;
  6385. var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
  6386. Math.cos(p1.lat() * Math.PI / 180) * Math.cos(p2.lat() * Math.PI / 180) *
  6387. Math.sin(dLon / 2) * Math.sin(dLon / 2);
  6388. var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  6389. var d = R * c;
  6390. return d;
  6391. };
  6392. /**
  6393. * Determines if a marker is contained in a bounds.
  6394. *
  6395. * @param {google.maps.Marker} marker The marker to check.
  6396. * @param {google.maps.LatLngBounds} bounds The bounds to check against.
  6397. * @return {boolean} True if the marker is in the bounds.
  6398. */
  6399. MarkerClusterer.prototype.isMarkerInBounds_ = function (marker, bounds) {
  6400. return bounds.contains(marker.getPosition());
  6401. };
  6402. /**
  6403. * Adds a marker to a cluster, or creates a new cluster.
  6404. *
  6405. * @param {google.maps.Marker} marker The marker to add.
  6406. */
  6407. MarkerClusterer.prototype.addToClosestCluster_ = function (marker) {
  6408. var i, d, cluster, center;
  6409. var distance = 40000; // Some large number
  6410. var clusterToAddTo = null;
  6411. for (i = 0; i < this.clusters_.length; i++) {
  6412. cluster = this.clusters_[i];
  6413. center = cluster.getCenter();
  6414. if (center) {
  6415. d = this.distanceBetweenPoints_(center, marker.getPosition());
  6416. if (d < distance) {
  6417. distance = d;
  6418. clusterToAddTo = cluster;
  6419. }
  6420. }
  6421. }
  6422. if (clusterToAddTo && clusterToAddTo.isMarkerInClusterBounds(marker)) {
  6423. clusterToAddTo.addMarker(marker);
  6424. } else {
  6425. cluster = new Cluster(this);
  6426. cluster.addMarker(marker);
  6427. this.clusters_.push(cluster);
  6428. }
  6429. };
  6430. /**
  6431. * Creates the clusters. This is done in batches to avoid timeout errors
  6432. * in some browsers when there is a huge number of markers.
  6433. *
  6434. * @param {number} iFirst The index of the first marker in the batch of
  6435. * markers to be added to clusters.
  6436. */
  6437. MarkerClusterer.prototype.createClusters_ = function (iFirst) {
  6438. var i, marker;
  6439. var mapBounds;
  6440. var cMarkerClusterer = this;
  6441. if (!this.ready_) {
  6442. return;
  6443. }
  6444. // Cancel previous batch processing if we're working on the first batch:
  6445. if (iFirst === 0) {
  6446. /**
  6447. * This event is fired when the <code>MarkerClusterer</code> begins
  6448. * clustering markers.
  6449. * @name MarkerClusterer#clusteringbegin
  6450. * @param {MarkerClusterer} mc The MarkerClusterer whose markers are being clustered.
  6451. * @event
  6452. */
  6453. google.maps.event.trigger(this, "clusteringbegin", this);
  6454. if (typeof this.timerRefStatic !== "undefined") {
  6455. clearTimeout(this.timerRefStatic);
  6456. delete this.timerRefStatic;
  6457. }
  6458. }
  6459. // Get our current map view bounds.
  6460. // Create a new bounds object so we don't affect the map.
  6461. //
  6462. // See Comments 9 & 11 on Issue 3651 relating to this workaround for a Google Maps bug:
  6463. if (this.getMap().getZoom() > 3) {
  6464. mapBounds = new google.maps.LatLngBounds(this.getMap().getBounds().getSouthWest(),
  6465. this.getMap().getBounds().getNorthEast());
  6466. } else {
  6467. mapBounds = new google.maps.LatLngBounds(new google.maps.LatLng(85.02070771743472, -178.48388434375), new google.maps.LatLng(-85.08136444384544, 178.00048865625));
  6468. }
  6469. var bounds = this.getExtendedBounds(mapBounds);
  6470. var iLast = Math.min(iFirst + this.batchSize_, this.markers_.length);
  6471. for (i = iFirst; i < iLast; i++) {
  6472. marker = this.markers_[i];
  6473. if (!marker.isAdded && this.isMarkerInBounds_(marker, bounds)) {
  6474. if (!this.ignoreHidden_ || (this.ignoreHidden_ && marker.getVisible())) {
  6475. this.addToClosestCluster_(marker);
  6476. }
  6477. }
  6478. }
  6479. if (iLast < this.markers_.length) {
  6480. this.timerRefStatic = setTimeout(function () {
  6481. cMarkerClusterer.createClusters_(iLast);
  6482. }, 0);
  6483. } else {
  6484. delete this.timerRefStatic;
  6485. /**
  6486. * This event is fired when the <code>MarkerClusterer</code> stops
  6487. * clustering markers.
  6488. * @name MarkerClusterer#clusteringend
  6489. * @param {MarkerClusterer} mc The MarkerClusterer whose markers are being clustered.
  6490. * @event
  6491. */
  6492. google.maps.event.trigger(this, "clusteringend", this);
  6493. }
  6494. };
  6495. /**
  6496. * Extends an object's prototype by another's.
  6497. *
  6498. * @param {Object} obj1 The object to be extended.
  6499. * @param {Object} obj2 The object to extend with.
  6500. * @return {Object} The new extended object.
  6501. * @ignore
  6502. */
  6503. MarkerClusterer.prototype.extend = function (obj1, obj2) {
  6504. return (function (object) {
  6505. var property;
  6506. for (property in object.prototype) {
  6507. this.prototype[property] = object.prototype[property];
  6508. }
  6509. return this;
  6510. }).apply(obj1, [obj2]);
  6511. };
  6512. /**
  6513. * The default function for determining the label text and style
  6514. * for a cluster icon.
  6515. *
  6516. * @param {Array.<google.maps.Marker>} markers The array of markers represented by the cluster.
  6517. * @param {number} numStyles The number of marker styles available.
  6518. * @return {ClusterIconInfo} The information resource for the cluster.
  6519. * @constant
  6520. * @ignore
  6521. */
  6522. MarkerClusterer.CALCULATOR = function (markers, numStyles) {
  6523. var index = 0;
  6524. var title = "";
  6525. var count = markers.length.toString();
  6526. var dv = count;
  6527. while (dv !== 0) {
  6528. dv = parseInt(dv / 10, 10);
  6529. index++;
  6530. }
  6531. index = Math.min(index, numStyles);
  6532. return {
  6533. text: count,
  6534. index: index,
  6535. title: title
  6536. };
  6537. };
  6538. /**
  6539. * The number of markers to process in one batch.
  6540. *
  6541. * @type {number}
  6542. * @constant
  6543. */
  6544. MarkerClusterer.BATCH_SIZE = 2000;
  6545. /**
  6546. * The number of markers to process in one batch (IE only).
  6547. *
  6548. * @type {number}
  6549. * @constant
  6550. */
  6551. MarkerClusterer.BATCH_SIZE_IE = 500;
  6552. /**
  6553. * The default root name for the marker cluster images.
  6554. *
  6555. * @type {string}
  6556. * @constant
  6557. */
  6558. MarkerClusterer.IMAGE_PATH = "http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclustererplus/images/m";
  6559. /**
  6560. * The default extension name for the marker cluster images.
  6561. *
  6562. * @type {string}
  6563. * @constant
  6564. */
  6565. MarkerClusterer.IMAGE_EXTENSION = "png";
  6566. /**
  6567. * The default array of sizes for the marker cluster images.
  6568. *
  6569. * @type {Array.<number>}
  6570. * @constant
  6571. */
  6572. MarkerClusterer.IMAGE_SIZES = [53, 56, 66, 78, 90];
  6573. if (typeof String.prototype.trim !== 'function') {
  6574. /**
  6575. * IE hack since trim() doesn't exist in all browsers
  6576. * @return {string} The string with removed whitespace
  6577. */
  6578. String.prototype.trim = function() {
  6579. return this.replace(/^\s+|\s+$/g, '');
  6580. }
  6581. }
  6582. ;/**
  6583. * 1.1.9-patched
  6584. * @name MarkerWithLabel for V3
  6585. * @version 1.1.8 [February 26, 2013]
  6586. * @author Gary Little (inspired by code from Marc Ridey of Google).
  6587. * @copyright Copyright 2012 Gary Little [gary at luxcentral.com]
  6588. * @fileoverview MarkerWithLabel extends the Google Maps JavaScript API V3
  6589. * <code>google.maps.Marker</code> class.
  6590. * <p>
  6591. * MarkerWithLabel allows you to define markers with associated labels. As you would expect,
  6592. * if the marker is draggable, so too will be the label. In addition, a marker with a label
  6593. * responds to all mouse events in the same manner as a regular marker. It also fires mouse
  6594. * events and "property changed" events just as a regular marker would. Version 1.1 adds
  6595. * support for the raiseOnDrag feature introduced in API V3.3.
  6596. * <p>
  6597. * If you drag a marker by its label, you can cancel the drag and return the marker to its
  6598. * original position by pressing the <code>Esc</code> key. This doesn't work if you drag the marker
  6599. * itself because this feature is not (yet) supported in the <code>google.maps.Marker</code> class.
  6600. */
  6601. /*!
  6602. *
  6603. * Licensed under the Apache License, Version 2.0 (the "License");
  6604. * you may not use this file except in compliance with the License.
  6605. * You may obtain a copy of the License at
  6606. *
  6607. * http://www.apache.org/licenses/LICENSE-2.0
  6608. *
  6609. * Unless required by applicable law or agreed to in writing, software
  6610. * distributed under the License is distributed on an "AS IS" BASIS,
  6611. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6612. * See the License for the specific language governing permissions and
  6613. * limitations under the License.
  6614. */
  6615. /*jslint browser:true */
  6616. /*global document,google */
  6617. /**
  6618. * @param {Function} childCtor Child class.
  6619. * @param {Function} parentCtor Parent class.
  6620. */
  6621. function inherits(childCtor, parentCtor) {
  6622. /** @constructor */
  6623. function tempCtor() {}
  6624. tempCtor.prototype = parentCtor.prototype;
  6625. childCtor.superClass_ = parentCtor.prototype;
  6626. childCtor.prototype = new tempCtor();
  6627. /** @override */
  6628. childCtor.prototype.constructor = childCtor;
  6629. }
  6630. /**
  6631. * This constructor creates a label and associates it with a marker.
  6632. * It is for the private use of the MarkerWithLabel class.
  6633. * @constructor
  6634. * @param {Marker} marker The marker with which the label is to be associated.
  6635. * @param {string} crossURL The URL of the cross image =.
  6636. * @param {string} handCursor The URL of the hand cursor.
  6637. * @private
  6638. */
  6639. function MarkerLabel_(marker, crossURL, handCursorURL) {
  6640. this.marker_ = marker;
  6641. this.handCursorURL_ = marker.handCursorURL;
  6642. this.labelDiv_ = document.createElement("div");
  6643. this.labelDiv_.style.cssText = "position: absolute; overflow: hidden;";
  6644. // Set up the DIV for handling mouse events in the label. This DIV forms a transparent veil
  6645. // in the "overlayMouseTarget" pane, a veil that covers just the label. This is done so that
  6646. // events can be captured even if the label is in the shadow of a google.maps.InfoWindow.
  6647. // Code is included here to ensure the veil is always exactly the same size as the label.
  6648. this.eventDiv_ = document.createElement("div");
  6649. this.eventDiv_.style.cssText = this.labelDiv_.style.cssText;
  6650. // This is needed for proper behavior on MSIE:
  6651. this.eventDiv_.setAttribute("onselectstart", "return false;");
  6652. this.eventDiv_.setAttribute("ondragstart", "return false;");
  6653. // Get the DIV for the "X" to be displayed when the marker is raised.
  6654. this.crossDiv_ = MarkerLabel_.getSharedCross(crossURL);
  6655. }
  6656. inherits(MarkerLabel_, google.maps.OverlayView);
  6657. /**
  6658. * Returns the DIV for the cross used when dragging a marker when the
  6659. * raiseOnDrag parameter set to true. One cross is shared with all markers.
  6660. * @param {string} crossURL The URL of the cross image =.
  6661. * @private
  6662. */
  6663. MarkerLabel_.getSharedCross = function (crossURL) {
  6664. var div;
  6665. if (typeof MarkerLabel_.getSharedCross.crossDiv === "undefined") {
  6666. div = document.createElement("img");
  6667. div.style.cssText = "position: absolute; z-index: 1000002; display: none;";
  6668. // Hopefully Google never changes the standard "X" attributes:
  6669. div.style.marginLeft = "-8px";
  6670. div.style.marginTop = "-9px";
  6671. div.src = crossURL;
  6672. MarkerLabel_.getSharedCross.crossDiv = div;
  6673. }
  6674. return MarkerLabel_.getSharedCross.crossDiv;
  6675. };
  6676. /**
  6677. * Adds the DIV representing the label to the DOM. This method is called
  6678. * automatically when the marker's <code>setMap</code> method is called.
  6679. * @private
  6680. */
  6681. MarkerLabel_.prototype.onAdd = function () {
  6682. var me = this;
  6683. var cMouseIsDown = false;
  6684. var cDraggingLabel = false;
  6685. var cSavedZIndex;
  6686. var cLatOffset, cLngOffset;
  6687. var cIgnoreClick;
  6688. var cRaiseEnabled;
  6689. var cStartPosition;
  6690. var cStartCenter;
  6691. // Constants:
  6692. var cRaiseOffset = 20;
  6693. var cDraggingCursor = "url(" + this.handCursorURL_ + ")";
  6694. // Stops all processing of an event.
  6695. //
  6696. var cAbortEvent = function (e) {
  6697. if (e.preventDefault) {
  6698. e.preventDefault();
  6699. }
  6700. e.cancelBubble = true;
  6701. if (e.stopPropagation) {
  6702. e.stopPropagation();
  6703. }
  6704. };
  6705. var cStopBounce = function () {
  6706. me.marker_.setAnimation(null);
  6707. };
  6708. this.getPanes().overlayImage.appendChild(this.labelDiv_);
  6709. this.getPanes().overlayMouseTarget.appendChild(this.eventDiv_);
  6710. // One cross is shared with all markers, so only add it once:
  6711. if (typeof MarkerLabel_.getSharedCross.processed === "undefined") {
  6712. this.getPanes().overlayImage.appendChild(this.crossDiv_);
  6713. MarkerLabel_.getSharedCross.processed = true;
  6714. }
  6715. this.listeners_ = [
  6716. google.maps.event.addDomListener(this.eventDiv_, "mouseover", function (e) {
  6717. if (me.marker_.getDraggable() || me.marker_.getClickable()) {
  6718. this.style.cursor = "pointer";
  6719. google.maps.event.trigger(me.marker_, "mouseover", e);
  6720. }
  6721. }),
  6722. google.maps.event.addDomListener(this.eventDiv_, "mouseout", function (e) {
  6723. if ((me.marker_.getDraggable() || me.marker_.getClickable()) && !cDraggingLabel) {
  6724. this.style.cursor = me.marker_.getCursor();
  6725. google.maps.event.trigger(me.marker_, "mouseout", e);
  6726. }
  6727. }),
  6728. google.maps.event.addDomListener(this.eventDiv_, "mousedown", function (e) {
  6729. cDraggingLabel = false;
  6730. if (me.marker_.getDraggable()) {
  6731. cMouseIsDown = true;
  6732. this.style.cursor = cDraggingCursor;
  6733. }
  6734. if (me.marker_.getDraggable() || me.marker_.getClickable()) {
  6735. google.maps.event.trigger(me.marker_, "mousedown", e);
  6736. cAbortEvent(e); // Prevent map pan when starting a drag on a label
  6737. }
  6738. }),
  6739. google.maps.event.addDomListener(document, "mouseup", function (mEvent) {
  6740. var position;
  6741. if (cMouseIsDown) {
  6742. cMouseIsDown = false;
  6743. me.eventDiv_.style.cursor = "pointer";
  6744. google.maps.event.trigger(me.marker_, "mouseup", mEvent);
  6745. }
  6746. if (cDraggingLabel) {
  6747. if (cRaiseEnabled) { // Lower the marker & label
  6748. position = me.getProjection().fromLatLngToDivPixel(me.marker_.getPosition());
  6749. position.y += cRaiseOffset;
  6750. me.marker_.setPosition(me.getProjection().fromDivPixelToLatLng(position));
  6751. // This is not the same bouncing style as when the marker portion is dragged,
  6752. // but it will have to do:
  6753. try { // Will fail if running Google Maps API earlier than V3.3
  6754. me.marker_.setAnimation(google.maps.Animation.BOUNCE);
  6755. setTimeout(cStopBounce, 1406);
  6756. } catch (e) {}
  6757. }
  6758. me.crossDiv_.style.display = "none";
  6759. me.marker_.setZIndex(cSavedZIndex);
  6760. cIgnoreClick = true; // Set flag to ignore the click event reported after a label drag
  6761. cDraggingLabel = false;
  6762. mEvent.latLng = me.marker_.getPosition();
  6763. google.maps.event.trigger(me.marker_, "dragend", mEvent);
  6764. }
  6765. }),
  6766. google.maps.event.addListener(me.marker_.getMap(), "mousemove", function (mEvent) {
  6767. var position;
  6768. if (cMouseIsDown) {
  6769. if (cDraggingLabel) {
  6770. // Change the reported location from the mouse position to the marker position:
  6771. mEvent.latLng = new google.maps.LatLng(mEvent.latLng.lat() - cLatOffset, mEvent.latLng.lng() - cLngOffset);
  6772. position = me.getProjection().fromLatLngToDivPixel(mEvent.latLng);
  6773. if (cRaiseEnabled) {
  6774. me.crossDiv_.style.left = position.x + "px";
  6775. me.crossDiv_.style.top = position.y + "px";
  6776. me.crossDiv_.style.display = "";
  6777. position.y -= cRaiseOffset;
  6778. }
  6779. me.marker_.setPosition(me.getProjection().fromDivPixelToLatLng(position));
  6780. if (cRaiseEnabled) { // Don't raise the veil; this hack needed to make MSIE act properly
  6781. me.eventDiv_.style.top = (position.y + cRaiseOffset) + "px";
  6782. }
  6783. google.maps.event.trigger(me.marker_, "drag", mEvent);
  6784. } else {
  6785. // Calculate offsets from the click point to the marker position:
  6786. cLatOffset = mEvent.latLng.lat() - me.marker_.getPosition().lat();
  6787. cLngOffset = mEvent.latLng.lng() - me.marker_.getPosition().lng();
  6788. cSavedZIndex = me.marker_.getZIndex();
  6789. cStartPosition = me.marker_.getPosition();
  6790. cStartCenter = me.marker_.getMap().getCenter();
  6791. cRaiseEnabled = me.marker_.get("raiseOnDrag");
  6792. cDraggingLabel = true;
  6793. me.marker_.setZIndex(1000000); // Moves the marker & label to the foreground during a drag
  6794. mEvent.latLng = me.marker_.getPosition();
  6795. google.maps.event.trigger(me.marker_, "dragstart", mEvent);
  6796. }
  6797. }
  6798. }),
  6799. google.maps.event.addDomListener(document, "keydown", function (e) {
  6800. if (cDraggingLabel) {
  6801. if (e.keyCode === 27) { // Esc key
  6802. cRaiseEnabled = false;
  6803. me.marker_.setPosition(cStartPosition);
  6804. me.marker_.getMap().setCenter(cStartCenter);
  6805. google.maps.event.trigger(document, "mouseup", e);
  6806. }
  6807. }
  6808. }),
  6809. google.maps.event.addDomListener(this.eventDiv_, "click", function (e) {
  6810. if (me.marker_.getDraggable() || me.marker_.getClickable()) {
  6811. if (cIgnoreClick) { // Ignore the click reported when a label drag ends
  6812. cIgnoreClick = false;
  6813. } else {
  6814. google.maps.event.trigger(me.marker_, "click", e);
  6815. cAbortEvent(e); // Prevent click from being passed on to map
  6816. }
  6817. }
  6818. }),
  6819. google.maps.event.addDomListener(this.eventDiv_, "dblclick", function (e) {
  6820. if (me.marker_.getDraggable() || me.marker_.getClickable()) {
  6821. google.maps.event.trigger(me.marker_, "dblclick", e);
  6822. cAbortEvent(e); // Prevent map zoom when double-clicking on a label
  6823. }
  6824. }),
  6825. google.maps.event.addListener(this.marker_, "dragstart", function (mEvent) {
  6826. if (!cDraggingLabel) {
  6827. cRaiseEnabled = this.get("raiseOnDrag");
  6828. }
  6829. }),
  6830. google.maps.event.addListener(this.marker_, "drag", function (mEvent) {
  6831. if (!cDraggingLabel) {
  6832. if (cRaiseEnabled) {
  6833. me.setPosition(cRaiseOffset);
  6834. // During a drag, the marker's z-index is temporarily set to 1000000 to
  6835. // ensure it appears above all other markers. Also set the label's z-index
  6836. // to 1000000 (plus or minus 1 depending on whether the label is supposed
  6837. // to be above or below the marker).
  6838. me.labelDiv_.style.zIndex = 1000000 + (this.get("labelInBackground") ? -1 : +1);
  6839. }
  6840. }
  6841. }),
  6842. google.maps.event.addListener(this.marker_, "dragend", function (mEvent) {
  6843. if (!cDraggingLabel) {
  6844. if (cRaiseEnabled) {
  6845. me.setPosition(0); // Also restores z-index of label
  6846. }
  6847. }
  6848. }),
  6849. google.maps.event.addListener(this.marker_, "position_changed", function () {
  6850. me.setPosition();
  6851. }),
  6852. google.maps.event.addListener(this.marker_, "zindex_changed", function () {
  6853. me.setZIndex();
  6854. }),
  6855. google.maps.event.addListener(this.marker_, "visible_changed", function () {
  6856. me.setVisible();
  6857. }),
  6858. google.maps.event.addListener(this.marker_, "labelvisible_changed", function () {
  6859. me.setVisible();
  6860. }),
  6861. google.maps.event.addListener(this.marker_, "title_changed", function () {
  6862. me.setTitle();
  6863. }),
  6864. google.maps.event.addListener(this.marker_, "labelcontent_changed", function () {
  6865. me.setContent();
  6866. }),
  6867. google.maps.event.addListener(this.marker_, "labelanchor_changed", function () {
  6868. me.setAnchor();
  6869. }),
  6870. google.maps.event.addListener(this.marker_, "labelclass_changed", function () {
  6871. me.setStyles();
  6872. }),
  6873. google.maps.event.addListener(this.marker_, "labelstyle_changed", function () {
  6874. me.setStyles();
  6875. })
  6876. ];
  6877. };
  6878. /**
  6879. * Removes the DIV for the label from the DOM. It also removes all event handlers.
  6880. * This method is called automatically when the marker's <code>setMap(null)</code>
  6881. * method is called.
  6882. * @private
  6883. */
  6884. MarkerLabel_.prototype.onRemove = function () {
  6885. var i;
  6886. if (this.labelDiv_.parentNode !== null)
  6887. this.labelDiv_.parentNode.removeChild(this.labelDiv_);
  6888. if (this.eventDiv_.parentNode !== null)
  6889. this.eventDiv_.parentNode.removeChild(this.eventDiv_);
  6890. // Remove event listeners:
  6891. for (i = 0; i < this.listeners_.length; i++) {
  6892. google.maps.event.removeListener(this.listeners_[i]);
  6893. }
  6894. };
  6895. /**
  6896. * Draws the label on the map.
  6897. * @private
  6898. */
  6899. MarkerLabel_.prototype.draw = function () {
  6900. this.setContent();
  6901. this.setTitle();
  6902. this.setStyles();
  6903. };
  6904. /**
  6905. * Sets the content of the label.
  6906. * The content can be plain text or an HTML DOM node.
  6907. * @private
  6908. */
  6909. MarkerLabel_.prototype.setContent = function () {
  6910. var content = this.marker_.get("labelContent");
  6911. if (typeof content.nodeType === "undefined") {
  6912. this.labelDiv_.innerHTML = content;
  6913. this.eventDiv_.innerHTML = this.labelDiv_.innerHTML;
  6914. } else {
  6915. this.labelDiv_.innerHTML = ""; // Remove current content
  6916. this.labelDiv_.appendChild(content);
  6917. content = content.cloneNode(true);
  6918. this.eventDiv_.appendChild(content);
  6919. }
  6920. };
  6921. /**
  6922. * Sets the content of the tool tip for the label. It is
  6923. * always set to be the same as for the marker itself.
  6924. * @private
  6925. */
  6926. MarkerLabel_.prototype.setTitle = function () {
  6927. this.eventDiv_.title = this.marker_.getTitle() || "";
  6928. };
  6929. /**
  6930. * Sets the style of the label by setting the style sheet and applying
  6931. * other specific styles requested.
  6932. * @private
  6933. */
  6934. MarkerLabel_.prototype.setStyles = function () {
  6935. var i, labelStyle;
  6936. // Apply style values from the style sheet defined in the labelClass parameter:
  6937. this.labelDiv_.className = this.marker_.get("labelClass");
  6938. this.eventDiv_.className = this.labelDiv_.className;
  6939. // Clear existing inline style values:
  6940. this.labelDiv_.style.cssText = "";
  6941. this.eventDiv_.style.cssText = "";
  6942. // Apply style values defined in the labelStyle parameter:
  6943. labelStyle = this.marker_.get("labelStyle");
  6944. for (i in labelStyle) {
  6945. if (labelStyle.hasOwnProperty(i)) {
  6946. this.labelDiv_.style[i] = labelStyle[i];
  6947. this.eventDiv_.style[i] = labelStyle[i];
  6948. }
  6949. }
  6950. this.setMandatoryStyles();
  6951. };
  6952. /**
  6953. * Sets the mandatory styles to the DIV representing the label as well as to the
  6954. * associated event DIV. This includes setting the DIV position, z-index, and visibility.
  6955. * @private
  6956. */
  6957. MarkerLabel_.prototype.setMandatoryStyles = function () {
  6958. this.labelDiv_.style.position = "absolute";
  6959. this.labelDiv_.style.overflow = "hidden";
  6960. // Make sure the opacity setting causes the desired effect on MSIE:
  6961. if (typeof this.labelDiv_.style.opacity !== "undefined" && this.labelDiv_.style.opacity !== "") {
  6962. this.labelDiv_.style.MsFilter = "\"progid:DXImageTransform.Microsoft.Alpha(opacity=" + (this.labelDiv_.style.opacity * 100) + ")\"";
  6963. this.labelDiv_.style.filter = "alpha(opacity=" + (this.labelDiv_.style.opacity * 100) + ")";
  6964. }
  6965. this.eventDiv_.style.position = this.labelDiv_.style.position;
  6966. this.eventDiv_.style.overflow = this.labelDiv_.style.overflow;
  6967. this.eventDiv_.style.opacity = 0.01; // Don't use 0; DIV won't be clickable on MSIE
  6968. this.eventDiv_.style.MsFilter = "\"progid:DXImageTransform.Microsoft.Alpha(opacity=1)\"";
  6969. this.eventDiv_.style.filter = "alpha(opacity=1)"; // For MSIE
  6970. this.setAnchor();
  6971. this.setPosition(); // This also updates z-index, if necessary.
  6972. this.setVisible();
  6973. };
  6974. /**
  6975. * Sets the anchor point of the label.
  6976. * @private
  6977. */
  6978. MarkerLabel_.prototype.setAnchor = function () {
  6979. var anchor = this.marker_.get("labelAnchor");
  6980. this.labelDiv_.style.marginLeft = -anchor.x + "px";
  6981. this.labelDiv_.style.marginTop = -anchor.y + "px";
  6982. this.eventDiv_.style.marginLeft = -anchor.x + "px";
  6983. this.eventDiv_.style.marginTop = -anchor.y + "px";
  6984. };
  6985. /**
  6986. * Sets the position of the label. The z-index is also updated, if necessary.
  6987. * @private
  6988. */
  6989. MarkerLabel_.prototype.setPosition = function (yOffset) {
  6990. var position = this.getProjection().fromLatLngToDivPixel(this.marker_.getPosition());
  6991. if (typeof yOffset === "undefined") {
  6992. yOffset = 0;
  6993. }
  6994. this.labelDiv_.style.left = Math.round(position.x) + "px";
  6995. this.labelDiv_.style.top = Math.round(position.y - yOffset) + "px";
  6996. this.eventDiv_.style.left = this.labelDiv_.style.left;
  6997. this.eventDiv_.style.top = this.labelDiv_.style.top;
  6998. this.setZIndex();
  6999. };
  7000. /**
  7001. * Sets the z-index of the label. If the marker's z-index property has not been defined, the z-index
  7002. * of the label is set to the vertical coordinate of the label. This is in keeping with the default
  7003. * stacking order for Google Maps: markers to the south are in front of markers to the north.
  7004. * @private
  7005. */
  7006. MarkerLabel_.prototype.setZIndex = function () {
  7007. var zAdjust = (this.marker_.get("labelInBackground") ? -1 : +1);
  7008. if (typeof this.marker_.getZIndex() === "undefined") {
  7009. this.labelDiv_.style.zIndex = parseInt(this.labelDiv_.style.top, 10) + zAdjust;
  7010. this.eventDiv_.style.zIndex = this.labelDiv_.style.zIndex;
  7011. } else {
  7012. this.labelDiv_.style.zIndex = this.marker_.getZIndex() + zAdjust;
  7013. this.eventDiv_.style.zIndex = this.labelDiv_.style.zIndex;
  7014. }
  7015. };
  7016. /**
  7017. * Sets the visibility of the label. The label is visible only if the marker itself is
  7018. * visible (i.e., its visible property is true) and the labelVisible property is true.
  7019. * @private
  7020. */
  7021. MarkerLabel_.prototype.setVisible = function () {
  7022. if (this.marker_.get("labelVisible")) {
  7023. this.labelDiv_.style.display = this.marker_.getVisible() ? "block" : "none";
  7024. } else {
  7025. this.labelDiv_.style.display = "none";
  7026. }
  7027. this.eventDiv_.style.display = this.labelDiv_.style.display;
  7028. };
  7029. /**
  7030. * @name MarkerWithLabelOptions
  7031. * @class This class represents the optional parameter passed to the {@link MarkerWithLabel} constructor.
  7032. * The properties available are the same as for <code>google.maps.Marker</code> with the addition
  7033. * of the properties listed below. To change any of these additional properties after the labeled
  7034. * marker has been created, call <code>google.maps.Marker.set(propertyName, propertyValue)</code>.
  7035. * <p>
  7036. * When any of these properties changes, a property changed event is fired. The names of these
  7037. * events are derived from the name of the property and are of the form <code>propertyname_changed</code>.
  7038. * For example, if the content of the label changes, a <code>labelcontent_changed</code> event
  7039. * is fired.
  7040. * <p>
  7041. * @property {string|Node} [labelContent] The content of the label (plain text or an HTML DOM node).
  7042. * @property {Point} [labelAnchor] By default, a label is drawn with its anchor point at (0,0) so
  7043. * that its top left corner is positioned at the anchor point of the associated marker. Use this
  7044. * property to change the anchor point of the label. For example, to center a 50px-wide label
  7045. * beneath a marker, specify a <code>labelAnchor</code> of <code>google.maps.Point(25, 0)</code>.
  7046. * (Note: x-values increase to the right and y-values increase to the top.)
  7047. * @property {string} [labelClass] The name of the CSS class defining the styles for the label.
  7048. * Note that style values for <code>position</code>, <code>overflow</code>, <code>top</code>,
  7049. * <code>left</code>, <code>zIndex</code>, <code>display</code>, <code>marginLeft</code>, and
  7050. * <code>marginTop</code> are ignored; these styles are for internal use only.
  7051. * @property {Object} [labelStyle] An object literal whose properties define specific CSS
  7052. * style values to be applied to the label. Style values defined here override those that may
  7053. * be defined in the <code>labelClass</code> style sheet. If this property is changed after the
  7054. * label has been created, all previously set styles (except those defined in the style sheet)
  7055. * are removed from the label before the new style values are applied.
  7056. * Note that style values for <code>position</code>, <code>overflow</code>, <code>top</code>,
  7057. * <code>left</code>, <code>zIndex</code>, <code>display</code>, <code>marginLeft</code>, and
  7058. * <code>marginTop</code> are ignored; these styles are for internal use only.
  7059. * @property {boolean} [labelInBackground] A flag indicating whether a label that overlaps its
  7060. * associated marker should appear in the background (i.e., in a plane below the marker).
  7061. * The default is <code>false</code>, which causes the label to appear in the foreground.
  7062. * @property {boolean} [labelVisible] A flag indicating whether the label is to be visible.
  7063. * The default is <code>true</code>. Note that even if <code>labelVisible</code> is
  7064. * <code>true</code>, the label will <i>not</i> be visible unless the associated marker is also
  7065. * visible (i.e., unless the marker's <code>visible</code> property is <code>true</code>).
  7066. * @property {boolean} [raiseOnDrag] A flag indicating whether the label and marker are to be
  7067. * raised when the marker is dragged. The default is <code>true</code>. If a draggable marker is
  7068. * being created and a version of Google Maps API earlier than V3.3 is being used, this property
  7069. * must be set to <code>false</code>.
  7070. * @property {boolean} [optimized] A flag indicating whether rendering is to be optimized for the
  7071. * marker. <b>Important: The optimized rendering technique is not supported by MarkerWithLabel,
  7072. * so the value of this parameter is always forced to <code>false</code>.
  7073. * @property {string} [crossImage="http://maps.gstatic.com/intl/en_us/mapfiles/drag_cross_67_16.png"]
  7074. * The URL of the cross image to be displayed while dragging a marker.
  7075. * @property {string} [handCursor="http://maps.gstatic.com/intl/en_us/mapfiles/closedhand_8_8.cur"]
  7076. * The URL of the cursor to be displayed while dragging a marker.
  7077. */
  7078. /**
  7079. * Creates a MarkerWithLabel with the options specified in {@link MarkerWithLabelOptions}.
  7080. * @constructor
  7081. * @param {MarkerWithLabelOptions} [opt_options] The optional parameters.
  7082. */
  7083. function MarkerWithLabel(opt_options) {
  7084. opt_options = opt_options || {};
  7085. opt_options.labelContent = opt_options.labelContent || "";
  7086. opt_options.labelAnchor = opt_options.labelAnchor || new google.maps.Point(0, 0);
  7087. opt_options.labelClass = opt_options.labelClass || "markerLabels";
  7088. opt_options.labelStyle = opt_options.labelStyle || {};
  7089. opt_options.labelInBackground = opt_options.labelInBackground || false;
  7090. if (typeof opt_options.labelVisible === "undefined") {
  7091. opt_options.labelVisible = true;
  7092. }
  7093. if (typeof opt_options.raiseOnDrag === "undefined") {
  7094. opt_options.raiseOnDrag = true;
  7095. }
  7096. if (typeof opt_options.clickable === "undefined") {
  7097. opt_options.clickable = true;
  7098. }
  7099. if (typeof opt_options.draggable === "undefined") {
  7100. opt_options.draggable = false;
  7101. }
  7102. if (typeof opt_options.optimized === "undefined") {
  7103. opt_options.optimized = false;
  7104. }
  7105. opt_options.crossImage = opt_options.crossImage || "http" + (document.location.protocol === "https:" ? "s" : "") + "://maps.gstatic.com/intl/en_us/mapfiles/drag_cross_67_16.png";
  7106. opt_options.handCursor = opt_options.handCursor || "http" + (document.location.protocol === "https:" ? "s" : "") + "://maps.gstatic.com/intl/en_us/mapfiles/closedhand_8_8.cur";
  7107. opt_options.optimized = false; // Optimized rendering is not supported
  7108. this.label = new MarkerLabel_(this, opt_options.crossImage, opt_options.handCursor); // Bind the label to the marker
  7109. // Call the parent constructor. It calls Marker.setValues to initialize, so all
  7110. // the new parameters are conveniently saved and can be accessed with get/set.
  7111. // Marker.set triggers a property changed event (called "propertyname_changed")
  7112. // that the marker label listens for in order to react to state changes.
  7113. google.maps.Marker.apply(this, arguments);
  7114. }
  7115. inherits(MarkerWithLabel, google.maps.Marker);
  7116. /**
  7117. * Overrides the standard Marker setMap function.
  7118. * @param {Map} theMap The map to which the marker is to be added.
  7119. * @private
  7120. */
  7121. MarkerWithLabel.prototype.setMap = function (theMap) {
  7122. // Call the inherited function...
  7123. google.maps.Marker.prototype.setMap.apply(this, arguments);
  7124. // ... then deal with the label:
  7125. this.label.setMap(theMap);
  7126. };