|
28 | 28 | (function() { |
29 | 29 | 'use strict'; |
30 | 30 | var parser, $timeout, $compile, NgMap; |
| 31 | + var supportedTransform = (function getSupportedTransform() { |
| 32 | + var prefixes = 'transform WebkitTransform MozTransform OTransform msTransform'.split(' '); |
| 33 | + var div = document.createElement('div'); |
| 34 | + for(var i = 0; i < prefixes.length; i++) { |
| 35 | + if(div && div.style[prefixes[i]] !== undefined) { |
| 36 | + return prefixes[i]; |
| 37 | + } |
| 38 | + } |
| 39 | + return false; |
| 40 | + })(); |
31 | 41 | var CustomMarker = function(options) { |
32 | 42 | options = options || {}; |
33 | 43 | this.el = document.createElement('div'); |
34 | | - this.el.style.display = 'inline-block'; |
| 44 | + this.el.style.display = 'block'; |
35 | 45 | this.el.style.visibility = "hidden"; |
36 | 46 | this.visible = true; |
37 | 47 | for (var key in options) { /* jshint ignore:line */ |
|
43 | 53 | CustomMarker.prototype.setContent = function(html, scope) { |
44 | 54 | this.el.innerHTML = html; |
45 | 55 | this.el.style.position = 'absolute'; |
| 56 | + this.el.style.top = 0; |
| 57 | + this.el.style.left = 0; |
46 | 58 | if (scope) { |
47 | 59 | $compile(angular.element(this.el).contents())(scope); |
48 | 60 | } |
|
66 | 78 | var posPixel = _this.getProjection().fromLatLngToDivPixel(_this.position); |
67 | 79 | var x = Math.round(posPixel.x - (_this.el.offsetWidth/2)); |
68 | 80 | var y = Math.round(posPixel.y - _this.el.offsetHeight - 10); // 10px for anchor |
69 | | - _this.el.style.left = x + "px"; |
70 | | - _this.el.style.top = y + "px"; |
| 81 | + if (supportedTransform) { |
| 82 | + _this.el.style[supportedTransform] = "translate(" + x + "px, " + y + "px)"; |
| 83 | + } else { |
| 84 | + _this.el.style.left = x + "px"; |
| 85 | + _this.el.style.top = y + "px"; |
| 86 | + } |
71 | 87 | _this.el.style.visibility = "visible"; |
72 | 88 | }; |
73 | 89 | if (_this.el.offsetWidth && _this.el.offsetHeight) { |
|
79 | 95 | } |
80 | 96 | }; |
81 | 97 | CustomMarker.prototype.setZIndex = function(zIndex) { |
82 | | - zIndex && (this.zIndex = zIndex); /* jshint ignore:line */ |
83 | | - this.el.style.zIndex = this.zIndex; |
| 98 | + if (zIndex === undefined) return; |
| 99 | + (this.zIndex !== zIndex) && (this.zIndex = zIndex); /* jshint ignore:line */ |
| 100 | + (this.el.style.zIndex !== this.zIndex) && (this.el.style.zIndex = this.zIndex); |
84 | 101 | }; |
85 | 102 | CustomMarker.prototype.getVisible = function() { |
86 | 103 | return this.visible; |
87 | 104 | }; |
88 | 105 | CustomMarker.prototype.setVisible = function(visible) { |
89 | | - this.el.style.display = visible ? 'inline-block' : 'none'; |
| 106 | + if (this.el.style.display === 'none' && visible) |
| 107 | + { |
| 108 | + this.el.style.display = 'block'; |
| 109 | + } else if (this.el.style.display !== 'none' && !visible) { |
| 110 | + this.el.style.display = 'none'; |
| 111 | + } |
90 | 112 | this.visible = visible; |
91 | 113 | }; |
92 | 114 | CustomMarker.prototype.addClass = function(className) { |
|
127 | 149 | element[0].style.display = 'none'; |
128 | 150 | console.log("custom-marker options", options); |
129 | 151 | var customMarker = new CustomMarker(options); |
130 | | - $timeout(function() { //apply contents, class, and location after it is compiled |
131 | | - scope.$watch('[' + varsToWatch.join(',') + ']', function() { |
| 152 | + // Do we really need a timeout with $scope.$apply() here? |
| 153 | + setTimeout(function() { //apply contents, class, and location after it is compiled |
| 154 | + scope.$watch('[' + varsToWatch.join(',') + ']', function(newVal, oldVal) { |
132 | 155 | customMarker.setContent(orgHtml, scope); |
133 | 156 | }, true); |
134 | 157 | customMarker.setContent(element[0].innerHTML, scope); |
135 | | - var classNames = element[0].firstElementChild.className; |
| 158 | + var classNames = |
| 159 | + (element[0].firstElementChild) && (element[0].firstElementChild.className || ''); |
| 160 | + customMarker.class && (classNames += " " + customMarker.class); |
136 | 161 | customMarker.addClass('custom-marker'); |
137 | | - customMarker.addClass(classNames); |
| 162 | + classNames && customMarker.addClass(classNames); |
138 | 163 | console.log('customMarker', customMarker, 'classNames', classNames); |
139 | 164 | if (!(options.position instanceof google.maps.LatLng)) { |
140 | 165 | NgMap.getGeoLocation(options.position).then( |
141 | | - function(latlng) { |
142 | | - customMarker.setPosition(latlng); |
143 | | - } |
| 166 | + function(latlng) { |
| 167 | + customMarker.setPosition(latlng); |
| 168 | + } |
144 | 169 | ); |
145 | 170 | } |
146 | 171 | }); |
147 | | - console.log("custom-marker events", "events"); |
| 172 | + console.log("custom-marker events", events); |
148 | 173 | for (var eventName in events) { /* jshint ignore:line */ |
149 | 174 | google.maps.event.addDomListener( |
150 | 175 | customMarker.el, eventName, events[eventName]); |
|
172 | 197 | restrict: 'E', |
173 | 198 | require: ['?^map','?^ngMap'], |
174 | 199 | compile: function(element) { |
| 200 | + console.log('el', element); |
175 | 201 | setCustomMarker(); |
176 | 202 | element[0].style.display ='none'; |
177 | 203 | var orgHtml = element.html(); |
|
0 commit comments