Skip to content

Commit 8d485a6

Browse files
committed
fix issue allenhwkim#879
1 parent 0ec6dca commit 8d485a6

File tree

8 files changed

+285
-220
lines changed

8 files changed

+285
-220
lines changed

build/docs/index.html

Lines changed: 24 additions & 24 deletions
Large diffs are not rendered by default.

build/docs/shape.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</span> </td> </tr><tr> <td class="name" nowrap="">&lt;MapEvent></td> <td class="type"><span class="param-type"> String </span></td> <td class="description last"> <span> <p><a href="https://developers.google.com/maps/documentation/javascript/reference">Any Shape events</a></p>
1919
</span> </td> </tr> </tbody> </table> </div> <div> <h4>Example</h4> <pre class="prettyprint"><code><span class="str">Usage:
2020
&lt;map MAP_ATTRIBUTES>
21-
&lt;shape name=SHAPE_NAME ANY_SHAPE_OPTIONS ANY_SHAPE_EVENTS">&lt;/MARKER>
21+
&lt;shape name="SHAPE_NAME ANY_SHAPE_OPTIONS ANY_SHAPE_EVENTS">&lt;/shape>
2222
&lt;/map>
2323
Example:
2424
&lt;map zoom="11" center="[40.74, -74.18]">

build/docs/source/directions.html

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
(function() {
3030
'use strict';
3131
var NgMap, $timeout, NavigatorGeolocation;
32+
var requestTimeout, routeRequest;
33+
// Delay for each route render to accumulate all requests into a single one
34+
// This is required for simultaneous origin\waypoints\destination change
35+
// 20ms should be enough to merge all request data
36+
var routeRenderDelay = 20;
3237
var getDirectionsRenderer = function(options, events) {
3338
if (options.panel) {
3439
options.panel = document.getElementById(options.panel) ||
@@ -50,25 +55,49 @@
5055
'durationInTraffic', 'waypoints', 'optimizeWaypoints',
5156
'provideRouteAlternatives', 'avoidHighways', 'avoidTolls', 'region'
5257
];
53-
for(var key in request){
54-
(validKeys.indexOf(key) === -1) && (delete request[key]);
58+
if (request) {
59+
for(var key in request) {
60+
if (request.hasOwnProperty(key)) {
61+
(validKeys.indexOf(key) === -1) && (delete request[key]);
62+
}
63+
}
5564
}
5665
if(request.waypoints) {
57-
// Check fo valid values
58-
if(request.waypoints == "[]" || request.waypoints === "") {
66+
// Check for acceptable values
67+
if(!Array.isArray(request.waypoints)) {
5968
delete request.waypoints;
6069
}
6170
}
6271
var showDirections = function(request) {
63-
directionsService.route(request, function(response, status) {
64-
if (status == google.maps.DirectionsStatus.OK) {
65-
$timeout(function() {
66-
renderer.setDirections(response);
67-
});
72+
if (requestTimeout && request) {
73+
if (!routeRequest) {
74+
routeRequest = request;
75+
} else {
76+
for (var attr in request) {
77+
if (request.hasOwnProperty(attr)) {
78+
routeRequest[attr] = request[attr];
79+
}
80+
}
6881
}
69-
});
82+
} else {
83+
requestTimeout = $timeout(function() {
84+
if (!routeRequest) {
85+
routeRequest = request;
86+
}
87+
directionsService.route(routeRequest, function(response, status) {
88+
if (status == google.maps.DirectionsStatus.OK) {
89+
renderer.setDirections(response);
90+
// Unset request for the next call
91+
routeRequest = undefined;
92+
}
93+
});
94+
$timeout.cancel(requestTimeout);
95+
// Unset expired timeout for the next call
96+
requestTimeout = undefined;
97+
}, routeRenderDelay);
98+
}
7099
};
71-
if (request.origin && request.destination) {
100+
if (request && request.origin && request.destination) {
72101
if (request.origin == 'current-location') {
73102
NavigatorGeolocation.getCurrentPosition().then(function(ll) {
74103
request.origin = new google.maps.LatLng(ll.coords.latitude, ll.coords.longitude);
@@ -97,6 +126,10 @@
97126
var options = parser.getOptions(filtered, {scope: scope});
98127
var events = parser.getEvents(scope, filtered);
99128
var attrsToObserve = parser.getAttrsToObserve(orgAttrs);
129+
var attrsToObserve = [];
130+
if (!filtered.noWatcher) {
131+
attrsToObserve = parser.getAttrsToObserve(orgAttrs);
132+
}
100133
var renderer = getDirectionsRenderer(options, events);
101134
mapController.addObject('directionsRenderers', renderer);
102135
attrsToObserve.forEach(function(attrName) {

build/docs/source/heatmap-layer.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* set options
2828
*/
2929
var options = parser.getOptions(filtered, {scope: scope});
30-
options.data = $window[attrs.data] || scope[attrs.data];
30+
options.data = $window[attrs.data] || parseScope(attrs.data, scope);
3131
if (options.data instanceof Array) {
3232
options.data = new google.maps.MVCArray(options.data);
3333
} else {
@@ -40,6 +40,12 @@
4040
var events = parser.getEvents(scope, filtered);
4141
console.log('heatmap-layer options', layer, 'events', events);
4242
mapController.addObject('heatmapLayers', layer);
43+
//helper get nexted path
44+
function parseScope( path, obj ) {
45+
return path.split('.').reduce( function( prev, curr ) {
46+
return prev[curr];
47+
}, obj || this );
48+
}
4349
}
4450
}; // return
4551
}]);

build/docs/source/ngmap.custom-marker.html

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,20 @@
2828
(function() {
2929
'use strict';
3030
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 &lt; prefixes.length; i++) {
35+
if(div && div.style[prefixes[i]] !== undefined) {
36+
return prefixes[i];
37+
}
38+
}
39+
return false;
40+
})();
3141
var CustomMarker = function(options) {
3242
options = options || {};
3343
this.el = document.createElement('div');
34-
this.el.style.display = 'inline-block';
44+
this.el.style.display = 'block';
3545
this.el.style.visibility = "hidden";
3646
this.visible = true;
3747
for (var key in options) { /* jshint ignore:line */
@@ -43,6 +53,8 @@
4353
CustomMarker.prototype.setContent = function(html, scope) {
4454
this.el.innerHTML = html;
4555
this.el.style.position = 'absolute';
56+
this.el.style.top = 0;
57+
this.el.style.left = 0;
4658
if (scope) {
4759
$compile(angular.element(this.el).contents())(scope);
4860
}
@@ -66,8 +78,12 @@
6678
var posPixel = _this.getProjection().fromLatLngToDivPixel(_this.position);
6779
var x = Math.round(posPixel.x - (_this.el.offsetWidth/2));
6880
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+
}
7187
_this.el.style.visibility = "visible";
7288
};
7389
if (_this.el.offsetWidth && _this.el.offsetHeight) {
@@ -79,14 +95,20 @@
7995
}
8096
};
8197
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);
84101
};
85102
CustomMarker.prototype.getVisible = function() {
86103
return this.visible;
87104
};
88105
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+
}
90112
this.visible = visible;
91113
};
92114
CustomMarker.prototype.addClass = function(className) {
@@ -127,24 +149,27 @@
127149
element[0].style.display = 'none';
128150
console.log("custom-marker options", options);
129151
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) {
132155
customMarker.setContent(orgHtml, scope);
133156
}, true);
134157
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);
136161
customMarker.addClass('custom-marker');
137-
customMarker.addClass(classNames);
162+
classNames && customMarker.addClass(classNames);
138163
console.log('customMarker', customMarker, 'classNames', classNames);
139164
if (!(options.position instanceof google.maps.LatLng)) {
140165
NgMap.getGeoLocation(options.position).then(
141-
function(latlng) {
142-
customMarker.setPosition(latlng);
143-
}
166+
function(latlng) {
167+
customMarker.setPosition(latlng);
168+
}
144169
);
145170
}
146171
});
147-
console.log("custom-marker events", "events");
172+
console.log("custom-marker events", events);
148173
for (var eventName in events) { /* jshint ignore:line */
149174
google.maps.event.addDomListener(
150175
customMarker.el, eventName, events[eventName]);
@@ -172,6 +197,7 @@
172197
restrict: 'E',
173198
require: ['?^map','?^ngMap'],
174199
compile: function(element) {
200+
console.log('el', element);
175201
setCustomMarker();
176202
element[0].style.display ='none';
177203
var orgHtml = element.html();

build/docs/source/shape.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* @example
3030
* Usage:
3131
* &lt;map MAP_ATTRIBUTES>
32-
* &lt;shape name=SHAPE_NAME ANY_SHAPE_OPTIONS ANY_SHAPE_EVENTS">&lt;/MARKER>
32+
* &lt;shape name="SHAPE_NAME ANY_SHAPE_OPTIONS ANY_SHAPE_EVENTS">&lt;/shape>
3333
* &lt;/map>
3434
*
3535
* Example:

build/scripts/ng-map.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)