|
29 | 29 | 'use strict'; |
30 | 30 | var parser, $timeout, $compile, NgMap; |
31 | 31 |
|
| 32 | + var supportedTransform = (function getSupportedTransform() { |
| 33 | + var prefixes = 'transform WebkitTransform MozTransform OTransform msTransform'.split(' '); |
| 34 | + var div = document.createElement('div'); |
| 35 | + for(var i = 0; i < prefixes.length; i++) { |
| 36 | + if(div && div.style[prefixes[i]] !== undefined) { |
| 37 | + return prefixes[i]; |
| 38 | + } |
| 39 | + } |
| 40 | + return false; |
| 41 | + })(); |
| 42 | + |
32 | 43 | var CustomMarker = function(options) { |
33 | 44 | options = options || {}; |
34 | 45 |
|
35 | 46 | this.el = document.createElement('div'); |
36 | | - this.el.style.display = 'inline-block'; |
| 47 | + this.el.style.display = 'block'; |
37 | 48 | this.el.style.visibility = "hidden"; |
38 | 49 | this.visible = true; |
39 | 50 | for (var key in options) { /* jshint ignore:line */ |
|
46 | 57 | CustomMarker.prototype = new google.maps.OverlayView(); |
47 | 58 |
|
48 | 59 | CustomMarker.prototype.setContent = function(html, scope) { |
| 60 | + console.log('input html', html); |
49 | 61 | this.el.innerHTML = html; |
50 | 62 | this.el.style.position = 'absolute'; |
| 63 | + this.el.style.top = 0; |
| 64 | + this.el.style.left = 0; |
51 | 65 | if (scope) { |
52 | 66 | $compile(angular.element(this.el).contents())(scope); |
53 | 67 | } |
|
75 | 89 | var posPixel = _this.getProjection().fromLatLngToDivPixel(_this.position); |
76 | 90 | var x = Math.round(posPixel.x - (_this.el.offsetWidth/2)); |
77 | 91 | var y = Math.round(posPixel.y - _this.el.offsetHeight - 10); // 10px for anchor |
78 | | - _this.el.style.left = x + "px"; |
79 | | - _this.el.style.top = y + "px"; |
| 92 | + if (supportedTransform) { |
| 93 | + _this.el.style[supportedTransform] = "translate(" + x + "px, " + y + "px)"; |
| 94 | + } else { |
| 95 | + _this.el.style.left = x + "px"; |
| 96 | + _this.el.style.top = y + "px"; |
| 97 | + } |
80 | 98 | _this.el.style.visibility = "visible"; |
81 | 99 | }; |
82 | 100 | if (_this.el.offsetWidth && _this.el.offsetHeight) { |
|
90 | 108 |
|
91 | 109 | CustomMarker.prototype.setZIndex = function(zIndex) { |
92 | 110 | zIndex && (this.zIndex = zIndex); /* jshint ignore:line */ |
93 | | - this.el.style.zIndex = this.zIndex; |
| 111 | + (this.el.style.zIndex !== this.zIndex) && (this.el.style.zIndex = this.zIndex); |
94 | 112 | }; |
95 | 113 |
|
96 | 114 | CustomMarker.prototype.getVisible = function() { |
97 | 115 | return this.visible; |
98 | 116 | }; |
99 | 117 |
|
100 | 118 | CustomMarker.prototype.setVisible = function(visible) { |
101 | | - this.el.style.display = visible ? 'inline-block' : 'none'; |
| 119 | + if (this.el.style.display === 'none' && visible) |
| 120 | + { |
| 121 | + this.el.style.display = 'block'; |
| 122 | + } else if (this.el.style.display !== 'none' && !visible) { |
| 123 | + this.el.style.display = 'none'; |
| 124 | + } |
102 | 125 | this.visible = visible; |
103 | 126 | }; |
104 | 127 |
|
|
149 | 172 | console.log("custom-marker options", options); |
150 | 173 | var customMarker = new CustomMarker(options); |
151 | 174 |
|
152 | | - $timeout(function() { //apply contents, class, and location after it is compiled |
| 175 | + // Do we really need a timeout with $scope.$apply() here? |
| 176 | + setTimeout(function() { //apply contents, class, and location after it is compiled |
153 | 177 |
|
154 | 178 | scope.$watch('[' + varsToWatch.join(',') + ']', function() { |
155 | 179 | customMarker.setContent(orgHtml, scope); |
156 | 180 | }, true); |
157 | 181 |
|
158 | 182 | customMarker.setContent(element[0].innerHTML, scope); |
159 | | - var classNames = element[0].firstElementChild.className; |
| 183 | + var classNames = |
| 184 | + (element[0].firstElementChild) && (element[0].firstElementChild.className || ''); |
| 185 | + customMarker.class && (classNames += " " + customMarker.class); |
160 | 186 | customMarker.addClass('custom-marker'); |
161 | | - customMarker.addClass(classNames); |
| 187 | + classNames && customMarker.addClass(classNames); |
162 | 188 | console.log('customMarker', customMarker, 'classNames', classNames); |
163 | 189 |
|
164 | 190 | if (!(options.position instanceof google.maps.LatLng)) { |
165 | 191 | NgMap.getGeoLocation(options.position).then( |
166 | | - function(latlng) { |
167 | | - customMarker.setPosition(latlng); |
168 | | - } |
| 192 | + function(latlng) { |
| 193 | + customMarker.setPosition(latlng); |
| 194 | + } |
169 | 195 | ); |
170 | 196 | } |
171 | 197 |
|
|
0 commit comments