Skip to content

Commit aef5b59

Browse files
committed
Revert "Fix directions re-render issue"
This reverts commit 3019aee.
1 parent 3019aee commit aef5b59

File tree

5 files changed

+139
-176
lines changed

5 files changed

+139
-176
lines changed

build/scripts/ng-map.debug.js

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ angular.module('ngMap', []);
196196
}
197197

198198
// set options
199-
mapOptions.zoom = mapOptions.zoom || 15;
199+
mapOptions.zoom = (mapOptions.zoom && !isNaN(mapOptions.zoom)) ? +mapOptions.zoom : 15;
200200
var center = mapOptions.center;
201201
var exprRegExp = new RegExp(escapeRegExp(exprStartSymbol) + '.*' + escapeRegExp(exprEndSymbol));
202202

@@ -411,13 +411,20 @@ angular.module('ngMap', []);
411411
var filtered = parser.filter(attrs);
412412
var options = parser.getOptions(filtered, {scope: scope});
413413
var events = parser.getEvents(scope, filtered);
414+
var innerScope = scope.$new();
414415

415416
/**
416417
* build a custom control element
417418
*/
418419
var customControlEl = element[0].parentElement.removeChild(element[0]);
419-
var content = $transclude();
420-
angular.element(customControlEl).append(content);
420+
var content = $transclude( innerScope, function( clone ) {
421+
element.empty();
422+
element.append( clone );
423+
element.on( '$destroy', function() {
424+
innerScope.$destroy();
425+
});
426+
});
427+
421428

422429
/**
423430
* set events
@@ -715,12 +722,6 @@ angular.module('ngMap', []);
715722
'use strict';
716723
var NgMap, $timeout, NavigatorGeolocation;
717724

718-
var requestTimeout, routeRequest;
719-
// Delay for each route render to accumulate all requests into a single one
720-
// This is required for simultaneous origin\waypoints\destination change
721-
// 20ms should be enough to merge all request data
722-
var routeRenderDelay = 20;
723-
724725
var getDirectionsRenderer = function(options, events) {
725726
if (options.panel) {
726727
options.panel = document.getElementById(options.panel) ||
@@ -756,37 +757,13 @@ angular.module('ngMap', []);
756757
}
757758

758759
var showDirections = function(request) {
759-
if (requestTimeout) {
760-
for (var attr in request)
761-
{
762-
if (request.hasOwnProperty(attr))
763-
{
764-
routeRequest[attr] = request[attr];
765-
}
766-
}
767-
}
768-
else
769-
{
770-
requestTimeout = $timeout(function()
771-
{
772-
if (!routeRequest)
773-
{
774-
routeRequest = request;
775-
}
776-
requestRoute(routeRequest);
777-
requestTimeout = undefined;
778-
}, routeRenderDelay);
779-
}
780-
781-
function requestRoute(routeRequest)
782-
{
783-
directionsService.route(routeRequest, function(response, status) {
784-
console.log('route response', response, status);
785-
if (status == google.maps.DirectionsStatus.OK) {
760+
directionsService.route(request, function(response, status) {
761+
if (status == google.maps.DirectionsStatus.OK) {
762+
$timeout(function() {
786763
renderer.setDirections(response);
787-
}
788-
});
789-
}
764+
});
765+
}
766+
});
790767
};
791768

792769
if (request.origin && request.destination) {
@@ -1909,6 +1886,7 @@ angular.module('ngMap', []);
19091886
* Example:
19101887
* <script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
19111888
* <input places-auto-complete types="['geocode']" on-place-changed="myCallback(place)" component-restrictions="{country:'au'}"/>
1889+
*
19121890
*/
19131891
/* global google */
19141892
(function() {
@@ -1925,6 +1903,7 @@ angular.module('ngMap', []);
19251903
var options = parser.getOptions(filtered, {scope: scope});
19261904
var events = parser.getEvents(scope, filtered);
19271905
var autocomplete = new google.maps.places.Autocomplete(element[0], options);
1906+
autocomplete.setOptions({strictBounds: options.strictBounds === true});
19281907
for (var eventName in events) {
19291908
google.maps.event.addListener(autocomplete, eventName, events[eventName]);
19301909
}
@@ -1937,20 +1916,37 @@ angular.module('ngMap', []);
19371916
google.maps.event.addListener(autocomplete, 'place_changed', updateModel);
19381917
element[0].addEventListener('change', updateModel);
19391918

1919+
attrs.$observe('rectBounds', function(val) {
1920+
if (val) {
1921+
var bounds = parser.toOptionValue(val, {key: 'rectBounds'});
1922+
autocomplete.setBounds(new google.maps.LatLngBounds(
1923+
new google.maps.LatLng(bounds.south_west.lat, bounds.south_west.lng),
1924+
new google.maps.LatLng(bounds.north_east.lat, bounds.north_east.lng)));
1925+
}
1926+
});
1927+
1928+
attrs.$observe('circleBounds', function(val) {
1929+
if (val) {
1930+
var bounds = parser.toOptionValue(val, {key: 'circleBounds'});
1931+
var circle = new google.maps.Circle(bounds);
1932+
autocomplete.setBounds(circle.getBounds());
1933+
}
1934+
});
1935+
19401936
attrs.$observe('types', function(val) {
19411937
if (val) {
19421938
var optionValue = parser.toOptionValue(val, {key: 'types'});
19431939
autocomplete.setTypes(optionValue);
19441940
}
19451941
});
1946-
1947-
attrs.$observe('componentRestrictions', function (val) {
1948-
if (val) {
1949-
autocomplete.setComponentRestrictions(scope.$eval(val));
1950-
}
1951-
});
1942+
1943+
attrs.$observe('componentRestrictions', function (val) {
1944+
if (val) {
1945+
autocomplete.setComponentRestrictions(scope.$eval(val));
1946+
}
1947+
});
19521948
};
1953-
1949+
19541950
return {
19551951
restrict: 'A',
19561952
require: '?ngModel',

build/scripts/ng-map.js

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ angular.module('ngMap', []);
205205
}
206206

207207
// set options
208-
mapOptions.zoom = mapOptions.zoom || 15;
208+
mapOptions.zoom = (mapOptions.zoom && !isNaN(mapOptions.zoom)) ? +mapOptions.zoom : 15;
209209
var center = mapOptions.center;
210210
var exprRegExp = new RegExp(escapeRegExp(exprStartSymbol) + '.*' + escapeRegExp(exprEndSymbol));
211211

@@ -420,13 +420,20 @@ angular.module('ngMap', []);
420420
var filtered = parser.filter(attrs);
421421
var options = parser.getOptions(filtered, {scope: scope});
422422
var events = parser.getEvents(scope, filtered);
423+
var innerScope = scope.$new();
423424

424425
/**
425426
* build a custom control element
426427
*/
427428
var customControlEl = element[0].parentElement.removeChild(element[0]);
428-
var content = $transclude();
429-
angular.element(customControlEl).append(content);
429+
var content = $transclude( innerScope, function( clone ) {
430+
element.empty();
431+
element.append( clone );
432+
element.on( '$destroy', function() {
433+
innerScope.$destroy();
434+
});
435+
});
436+
430437

431438
/**
432439
* set events
@@ -724,12 +731,6 @@ angular.module('ngMap', []);
724731
'use strict';
725732
var NgMap, $timeout, NavigatorGeolocation;
726733

727-
var requestTimeout, routeRequest;
728-
// Delay for each route render to accumulate all requests into a single one
729-
// This is required for simultaneous origin\waypoints\destination change
730-
// 20ms should be enough to merge all request data
731-
var routeRenderDelay = 20;
732-
733734
var getDirectionsRenderer = function(options, events) {
734735
if (options.panel) {
735736
options.panel = document.getElementById(options.panel) ||
@@ -765,37 +766,13 @@ angular.module('ngMap', []);
765766
}
766767

767768
var showDirections = function(request) {
768-
if (requestTimeout) {
769-
for (var attr in request)
770-
{
771-
if (request.hasOwnProperty(attr))
772-
{
773-
routeRequest[attr] = request[attr];
774-
}
775-
}
776-
}
777-
else
778-
{
779-
requestTimeout = $timeout(function()
780-
{
781-
if (!routeRequest)
782-
{
783-
routeRequest = request;
784-
}
785-
requestRoute(routeRequest);
786-
requestTimeout = undefined;
787-
}, routeRenderDelay);
788-
}
789-
790-
function requestRoute(routeRequest)
791-
{
792-
directionsService.route(routeRequest, function(response, status) {
793-
void 0;
794-
if (status == google.maps.DirectionsStatus.OK) {
769+
directionsService.route(request, function(response, status) {
770+
if (status == google.maps.DirectionsStatus.OK) {
771+
$timeout(function() {
795772
renderer.setDirections(response);
796-
}
797-
});
798-
}
773+
});
774+
}
775+
});
799776
};
800777

801778
if (request.origin && request.destination) {
@@ -1917,6 +1894,7 @@ angular.module('ngMap', []);
19171894
* Example:
19181895
* <script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
19191896
* <input places-auto-complete types="['geocode']" on-place-changed="myCallback(place)" component-restrictions="{country:'au'}"/>
1897+
*
19201898
*/
19211899
/* global google */
19221900
(function() {
@@ -1933,6 +1911,7 @@ angular.module('ngMap', []);
19331911
var options = parser.getOptions(filtered, {scope: scope});
19341912
var events = parser.getEvents(scope, filtered);
19351913
var autocomplete = new google.maps.places.Autocomplete(element[0], options);
1914+
autocomplete.setOptions({strictBounds: options.strictBounds === true});
19361915
for (var eventName in events) {
19371916
google.maps.event.addListener(autocomplete, eventName, events[eventName]);
19381917
}
@@ -1945,20 +1924,37 @@ angular.module('ngMap', []);
19451924
google.maps.event.addListener(autocomplete, 'place_changed', updateModel);
19461925
element[0].addEventListener('change', updateModel);
19471926

1927+
attrs.$observe('rectBounds', function(val) {
1928+
if (val) {
1929+
var bounds = parser.toOptionValue(val, {key: 'rectBounds'});
1930+
autocomplete.setBounds(new google.maps.LatLngBounds(
1931+
new google.maps.LatLng(bounds.south_west.lat, bounds.south_west.lng),
1932+
new google.maps.LatLng(bounds.north_east.lat, bounds.north_east.lng)));
1933+
}
1934+
});
1935+
1936+
attrs.$observe('circleBounds', function(val) {
1937+
if (val) {
1938+
var bounds = parser.toOptionValue(val, {key: 'circleBounds'});
1939+
var circle = new google.maps.Circle(bounds);
1940+
autocomplete.setBounds(circle.getBounds());
1941+
}
1942+
});
1943+
19481944
attrs.$observe('types', function(val) {
19491945
if (val) {
19501946
var optionValue = parser.toOptionValue(val, {key: 'types'});
19511947
autocomplete.setTypes(optionValue);
19521948
}
19531949
});
1954-
1955-
attrs.$observe('componentRestrictions', function (val) {
1956-
if (val) {
1957-
autocomplete.setComponentRestrictions(scope.$eval(val));
1958-
}
1959-
});
1950+
1951+
attrs.$observe('componentRestrictions', function (val) {
1952+
if (val) {
1953+
autocomplete.setComponentRestrictions(scope.$eval(val));
1954+
}
1955+
});
19601956
};
1961-
1957+
19621958
return {
19631959
restrict: 'A',
19641960
require: '?ngModel',

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)