|
51 | 51 | })();;(function() {
|
52 | 52 | this.ngGmapModule = function(names, fn) {
|
53 | 53 | var space, _name;
|
| 54 | + if (fn == null) { |
| 55 | + fn = function() {}; |
| 56 | + } |
54 | 57 | if (typeof names === 'string') {
|
55 | 58 | names = names.split('.');
|
56 | 59 | }
|
|
385 | 388 | return opts;
|
386 | 389 | },
|
387 | 390 | createWindowOptions: function(gMarker, scope, content, defaults) {
|
388 |
| - return angular.extend({}, defaults, { |
389 |
| - content: content, |
390 |
| - position: angular.isObject(gMarker) ? gMarker.getPosition() : new google.maps.LatLng(scope.coords.latitude, scope.coords.longitude) |
391 |
| - }); |
| 391 | + if ((content != null) && (defaults != null)) { |
| 392 | + return angular.extend({}, defaults, { |
| 393 | + content: content, |
| 394 | + position: angular.isObject(gMarker) ? gMarker.getPosition() : new google.maps.LatLng(scope.coords.latitude, scope.coords.longitude) |
| 395 | + }); |
| 396 | + } |
392 | 397 | },
|
393 | 398 | defaultDelay: 50
|
394 | 399 | };
|
|
420 | 425 |
|
421 | 426 | (function() {
|
422 | 427 | this.ngGmapModule("directives.api.utils", function() {
|
423 |
| - return this.Logger = { |
| 428 | + var logger; |
| 429 | + this.Logger = { |
424 | 430 | logger: void 0,
|
425 | 431 | doLog: false,
|
426 | 432 | info: function(msg) {
|
427 |
| - if (directives.api.utils.Logger.doLog) { |
428 |
| - if (directives.api.utils.Logger.logger != null) { |
429 |
| - return directives.api.utils.Logger.logger.info(msg); |
| 433 | + if (logger.doLog) { |
| 434 | + if (logger.logger != null) { |
| 435 | + return logger.logger.info(msg); |
430 | 436 | } else {
|
431 | 437 | return console.info(msg);
|
432 | 438 | }
|
433 | 439 | }
|
| 440 | + }, |
| 441 | + error: function(msg) { |
| 442 | + if (logger.doLog) { |
| 443 | + if (logger.logger != null) { |
| 444 | + return logger.logger.error(msg); |
| 445 | + } else { |
| 446 | + return console.error(msg); |
| 447 | + } |
| 448 | + } |
434 | 449 | }
|
435 | 450 | };
|
| 451 | + return logger = this.Logger; |
436 | 452 | });
|
437 | 453 |
|
438 | 454 | }).call(this);
|
|
771 | 787 | return this.WindowChildModel = (function(_super) {
|
772 | 788 | __extends(WindowChildModel, _super);
|
773 | 789 |
|
774 |
| - function WindowChildModel(scope, opts, isIconVisibleOnClick, mapCtrl, markerCtrl, $http, $templateCache, $compile, needToManualDestroy) { |
| 790 | + WindowChildModel.include(directives.api.utils.GmapUtil); |
| 791 | + |
| 792 | + function WindowChildModel(scope, opts, isIconVisibleOnClick, mapCtrl, markerCtrl, $http, $templateCache, $compile, element, needToManualDestroy) { |
| 793 | + this.element = element; |
775 | 794 | if (needToManualDestroy == null) {
|
776 | 795 | needToManualDestroy = false;
|
777 | 796 | }
|
|
781 | 800 | this.handleClick = __bind(this.handleClick, this);
|
782 | 801 | this.watchCoords = __bind(this.watchCoords, this);
|
783 | 802 | this.watchShow = __bind(this.watchShow, this);
|
| 803 | + this.createGWin = __bind(this.createGWin, this); |
784 | 804 | this.scope = scope;
|
785 | 805 | this.opts = opts;
|
786 | 806 | this.mapCtrl = mapCtrl;
|
|
791 | 811 | this.$http = $http;
|
792 | 812 | this.$templateCache = $templateCache;
|
793 | 813 | this.$compile = $compile;
|
794 |
| - this.gWin = new google.maps.InfoWindow(opts); |
| 814 | + this.createGWin(); |
795 | 815 | if (this.markerCtrl != null) {
|
796 | 816 | this.markerCtrl.setClickable(true);
|
797 | 817 | }
|
|
802 | 822 | this.$log.info(this);
|
803 | 823 | }
|
804 | 824 |
|
| 825 | + WindowChildModel.prototype.createGWin = function(createOpts) { |
| 826 | + var _this = this; |
| 827 | + if (createOpts == null) { |
| 828 | + createOpts = false; |
| 829 | + } |
| 830 | + if ((this.gWin == null) && createOpts) { |
| 831 | + this.opts = this.markerCtrl != null ? this.createWindowOptions(this.markerCtrl, this.scope, this.element.html(), {}) : {}; |
| 832 | + } |
| 833 | + if ((this.opts != null) && this.gWin === void 0) { |
| 834 | + this.gWin = new google.maps.InfoWindow(this.opts); |
| 835 | + return google.maps.event.addListener(this.gWin, 'closeclick', function() { |
| 836 | + if (_this.markerCtrl != null) { |
| 837 | + _this.markerCtrl.setVisible(_this.initialMarkerVisibility); |
| 838 | + } |
| 839 | + if (_this.scope.closeClick != null) { |
| 840 | + return _this.scope.closeClick(); |
| 841 | + } |
| 842 | + }); |
| 843 | + } |
| 844 | + }; |
| 845 | + |
805 | 846 | WindowChildModel.prototype.watchShow = function() {
|
806 | 847 | var _this = this;
|
807 | 848 | return this.scope.$watch('show', function(newValue, oldValue) {
|
|
812 | 853 | return _this.hideWindow();
|
813 | 854 | }
|
814 | 855 | } else {
|
815 |
| - if (newValue && !_this.gWin.getMap()) { |
816 |
| - return _this.showWindow(); |
| 856 | + if (_this.gWin != null) { |
| 857 | + if (newValue && !_this.gWin.getMap()) { |
| 858 | + return _this.showWindow(); |
| 859 | + } |
817 | 860 | }
|
818 | 861 | }
|
819 | 862 | }, true);
|
|
831 | 874 | WindowChildModel.prototype.handleClick = function() {
|
832 | 875 | var _this = this;
|
833 | 876 | if (this.markerCtrl != null) {
|
834 |
| - google.maps.event.addListener(this.markerCtrl, 'click', function() { |
835 |
| - _this.gWin.setPosition(_this.markerCtrl.getPosition()); |
836 |
| - _this.gWin.open(_this.mapCtrl); |
| 877 | + return google.maps.event.addListener(this.markerCtrl, 'click', function() { |
| 878 | + var pos; |
| 879 | + _this.createGWin(true); |
| 880 | + pos = _this.markerCtrl.getPosition(); |
| 881 | + if (_this.gWin != null) { |
| 882 | + _this.gWin.setPosition(pos); |
| 883 | + _this.gWin.open(_this.mapCtrl); |
| 884 | + } |
837 | 885 | return _this.markerCtrl.setVisible(_this.isIconVisibleOnClick);
|
838 | 886 | });
|
839 | 887 | }
|
840 |
| - return google.maps.event.addListener(this.gWin, 'closeclick', function() { |
841 |
| - if (_this.markerCtrl != null) { |
842 |
| - _this.markerCtrl.setVisible(_this.initialMarkerVisibility); |
843 |
| - } |
844 |
| - if (_this.scope.closeClick != null) { |
845 |
| - return _this.scope.closeClick(); |
846 |
| - } |
847 |
| - }); |
848 | 888 | };
|
849 | 889 |
|
850 | 890 | WindowChildModel.prototype.showWindow = function() {
|
851 | 891 | var _this = this;
|
852 | 892 | if (this.scope.templateUrl) {
|
853 |
| - return this.$http.get(this.scope.templateUrl, { |
854 |
| - cache: this.$templateCache |
855 |
| - }).then(function(content) { |
856 |
| - var compiled, templateScope; |
857 |
| - templateScope = _this.scope.$new(); |
858 |
| - if (angular.isDefined(_this.scope.templateParameter)) { |
859 |
| - templateScope.parameter = _this.scope.templateParameter; |
860 |
| - } |
861 |
| - compiled = _this.$compile(content.data)(templateScope); |
862 |
| - _this.gWin.setContent(compiled.get(0)); |
863 |
| - return _this.gWin.open(_this.mapCtrl); |
864 |
| - }); |
| 893 | + if (this.gWin) { |
| 894 | + return this.$http.get(this.scope.templateUrl, { |
| 895 | + cache: this.$templateCache |
| 896 | + }).then(function(content) { |
| 897 | + var compiled, templateScope; |
| 898 | + templateScope = _this.scope.$new(); |
| 899 | + if (angular.isDefined(_this.scope.templateParameter)) { |
| 900 | + templateScope.parameter = _this.scope.templateParameter; |
| 901 | + } |
| 902 | + compiled = _this.$compile(content.data)(templateScope); |
| 903 | + _this.gWin.setContent(compiled.get(0)); |
| 904 | + return _this.gWin.open(_this.mapCtrl); |
| 905 | + }); |
| 906 | + } |
865 | 907 | } else {
|
866 |
| - return this.gWin.open(this.mapCtrl); |
| 908 | + if (this.gWin != null) { |
| 909 | + return this.gWin.open(this.mapCtrl); |
| 910 | + } |
867 | 911 | }
|
868 | 912 | };
|
869 | 913 |
|
870 | 914 | WindowChildModel.prototype.hideWindow = function() {
|
871 |
| - return this.gWin.close(); |
| 915 | + if (this.gWin != null) { |
| 916 | + return this.gWin.close(); |
| 917 | + } |
872 | 918 | };
|
873 | 919 |
|
874 | 920 | WindowChildModel.prototype.destroy = function() {
|
|
914 | 960 | };
|
915 | 961 |
|
916 | 962 | function IMarkerParentModel(scope, element, attrs, mapCtrl, $timeout) {
|
| 963 | + var self, |
| 964 | + _this = this; |
| 965 | + this.scope = scope; |
| 966 | + this.element = element; |
| 967 | + this.attrs = attrs; |
| 968 | + this.mapCtrl = mapCtrl; |
| 969 | + this.$timeout = $timeout; |
917 | 970 | this.linkInit = __bind(this.linkInit, this);
|
918 | 971 | this.onDestroy = __bind(this.onDestroy, this);
|
919 | 972 | this.onWatch = __bind(this.onWatch, this);
|
920 | 973 | this.watch = __bind(this.watch, this);
|
921 | 974 | this.validateScope = __bind(this.validateScope, this);
|
922 | 975 | this.onTimeOut = __bind(this.onTimeOut, this);
|
923 |
| - var self, |
924 |
| - _this = this; |
925 | 976 | self = this;
|
926 |
| - this.scope = scope; |
927 |
| - this.element = element; |
928 |
| - this.attrs = attrs; |
929 |
| - if (this.validateScope(scope)) { |
| 977 | + this.$log = directives.api.utils.Logger; |
| 978 | + if (!this.validateScope(scope)) { |
930 | 979 | return;
|
931 | 980 | }
|
932 | 981 | this.doClick = angular.isDefined(attrs.click);
|
933 |
| - this.mapCtrl = mapCtrl; |
934 |
| - this.$log = directives.api.utils.Logger; |
935 |
| - this.$timeout = $timeout; |
936 | 982 | if (scope.options != null) {
|
937 | 983 | this.DEFAULTS = scope.options;
|
938 | 984 | }
|
|
951 | 997 |
|
952 | 998 | IMarkerParentModel.prototype.validateScope = function(scope) {
|
953 | 999 | var ret;
|
954 |
| - ret = angular.isUndefined(scope.coords) || scope.coords === void 0; |
955 |
| - if (ret) { |
| 1000 | + if (scope == null) { |
| 1001 | + return false; |
| 1002 | + } |
| 1003 | + ret = scope.coords != null; |
| 1004 | + if (!ret) { |
956 | 1005 | this.$log.error(this.constructor.name + ": no valid coords attribute found");
|
957 | 1006 | }
|
958 | 1007 | return ret;
|
|
1114 | 1163 | function MarkerParentModel(scope, element, attrs, mapCtrl, $timeout) {
|
1115 | 1164 | this.onDestroy = __bind(this.onDestroy, this);
|
1116 | 1165 | this.onWatch = __bind(this.onWatch, this);
|
1117 |
| - this.validateScope = __bind(this.validateScope, this); |
1118 |
| - var self, |
1119 |
| - _this = this; |
| 1166 | + this.onTimeOut = __bind(this.onTimeOut, this); |
| 1167 | + var self; |
1120 | 1168 | MarkerParentModel.__super__.constructor.call(this, scope, element, attrs, mapCtrl, $timeout);
|
1121 | 1169 | self = this;
|
1122 |
| - $timeout(function() { |
1123 |
| - var opts; |
1124 |
| - opts = _this.createMarkerOptions(_this.scope.coords, _this.scope.icon, _this.scope.options, _this.mapCtrl.getMap()); |
1125 |
| - _this.gMarker = new google.maps.Marker(opts); |
1126 |
| - _this.element.data('instance', _this.gMarker); |
1127 |
| - google.maps.event.addListener(_this.gMarker, 'click', function() { |
1128 |
| - if (_this.doClick && (scope.click != null)) { |
1129 |
| - return $timeout(function() { |
1130 |
| - return _this.scope.click(); |
1131 |
| - }); |
1132 |
| - } |
1133 |
| - }); |
1134 |
| - return _this.$log.info(_this); |
1135 |
| - }, directives.api.utils.GmapUtil.defaultDelay); |
1136 | 1170 | }
|
1137 | 1171 |
|
1138 |
| - MarkerParentModel.prototype.validateScope = function(scope) { |
1139 |
| - return MarkerParentModel.__super__.validateScope.call(this, scope) || angular.isUndefined(scope.coords.latitude) || angular.isUndefined(scope.coords.longitude); |
| 1172 | + MarkerParentModel.prototype.onTimeOut = function(scope) { |
| 1173 | + var opts, |
| 1174 | + _this = this; |
| 1175 | + opts = this.createMarkerOptions(scope.coords, scope.icon, scope.options, this.mapCtrl.getMap()); |
| 1176 | + this.gMarker = new google.maps.Marker(opts); |
| 1177 | + this.element.data('instance', this.gMarker); |
| 1178 | + google.maps.event.addListener(this.gMarker, 'click', function() { |
| 1179 | + if (_this.doClick && (scope.click != null)) { |
| 1180 | + return _this.$timeout(function() { |
| 1181 | + return _this.scope.click(); |
| 1182 | + }); |
| 1183 | + } |
| 1184 | + }); |
| 1185 | + return this.$log.info(this); |
1140 | 1186 | };
|
1141 | 1187 |
|
1142 | 1188 | MarkerParentModel.prototype.onWatch = function(propNameToWatch, scope) {
|
@@ -1950,17 +1996,18 @@ not 1:1 in this setting.
|
1950 | 1996 | Window.prototype.link = function(scope, element, attrs, ctrls) {
|
1951 | 1997 | var _this = this;
|
1952 | 1998 | return this.$timeout(function() {
|
1953 |
| - var defaults, isIconVisibleOnClick, mapCtrl, markerCtrl, opts, window; |
| 1999 | + var defaults, hasScopeCoords, isIconVisibleOnClick, mapCtrl, markerCtrl, opts, window; |
1954 | 2000 | isIconVisibleOnClick = true;
|
1955 | 2001 | if (angular.isDefined(attrs.isiconvisibleonclick)) {
|
1956 | 2002 | isIconVisibleOnClick = scope.isIconVisibleOnClick;
|
1957 | 2003 | }
|
1958 | 2004 | mapCtrl = ctrls[0].getMap();
|
1959 | 2005 | markerCtrl = ctrls.length > 1 && (ctrls[1] != null) ? ctrls[1].getMarker() : void 0;
|
1960 | 2006 | defaults = scope.options != null ? scope.options : {};
|
1961 |
| - opts = _this.createWindowOptions(markerCtrl, scope, element.html(), defaults); |
| 2007 | + hasScopeCoords = (scope != null) && (scope.coords != null) && (scope.coords.latitude != null) && (scope.coords.longitude != null); |
| 2008 | + opts = (markerCtrl != null) && hasScopeCoords ? _this.createWindowOptions(markerCtrl, scope, element.html(), defaults) : void 0; |
1962 | 2009 | if (mapCtrl != null) {
|
1963 |
| - window = new directives.api.models.child.WindowChildModel(scope, opts, isIconVisibleOnClick, mapCtrl, markerCtrl, _this.$http, _this.$templateCache, _this.$compile); |
| 2010 | + window = new directives.api.models.child.WindowChildModel(scope, opts, isIconVisibleOnClick, mapCtrl, markerCtrl, _this.$http, _this.$templateCache, _this.$compile, element); |
1964 | 2011 | }
|
1965 | 2012 | return scope.$on("$destroy", function() {
|
1966 | 2013 | return window.destroy();
|
|
0 commit comments