@@ -196,7 +196,7 @@ angular.module('ngMap', []);
196
196
}
197
197
198
198
// set options
199
- mapOptions . zoom = mapOptions . zoom || 15 ;
199
+ mapOptions . zoom = ( mapOptions . zoom && ! isNaN ( mapOptions . zoom ) ) ? + mapOptions . zoom : 15 ;
200
200
var center = mapOptions . center ;
201
201
var exprRegExp = new RegExp ( escapeRegExp ( exprStartSymbol ) + '.*' + escapeRegExp ( exprEndSymbol ) ) ;
202
202
@@ -411,13 +411,20 @@ angular.module('ngMap', []);
411
411
var filtered = parser . filter ( attrs ) ;
412
412
var options = parser . getOptions ( filtered , { scope : scope } ) ;
413
413
var events = parser . getEvents ( scope , filtered ) ;
414
+ var innerScope = scope . $new ( ) ;
414
415
415
416
/**
416
417
* build a custom control element
417
418
*/
418
419
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
+
421
428
422
429
/**
423
430
* set events
@@ -715,12 +722,6 @@ angular.module('ngMap', []);
715
722
'use strict' ;
716
723
var NgMap , $timeout , NavigatorGeolocation ;
717
724
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
-
724
725
var getDirectionsRenderer = function ( options , events ) {
725
726
if ( options . panel ) {
726
727
options . panel = document . getElementById ( options . panel ) ||
@@ -756,37 +757,13 @@ angular.module('ngMap', []);
756
757
}
757
758
758
759
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 ( ) {
786
763
renderer . setDirections ( response ) ;
787
- }
788
- } ) ;
789
- }
764
+ } ) ;
765
+ }
766
+ } ) ;
790
767
} ;
791
768
792
769
if ( request . origin && request . destination ) {
@@ -1909,6 +1886,7 @@ angular.module('ngMap', []);
1909
1886
* Example:
1910
1887
* <script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
1911
1888
* <input places-auto-complete types="['geocode']" on-place-changed="myCallback(place)" component-restrictions="{country:'au'}"/>
1889
+ *
1912
1890
*/
1913
1891
/* global google */
1914
1892
( function ( ) {
@@ -1925,6 +1903,7 @@ angular.module('ngMap', []);
1925
1903
var options = parser . getOptions ( filtered , { scope : scope } ) ;
1926
1904
var events = parser . getEvents ( scope , filtered ) ;
1927
1905
var autocomplete = new google . maps . places . Autocomplete ( element [ 0 ] , options ) ;
1906
+ autocomplete . setOptions ( { strictBounds : options . strictBounds === true } ) ;
1928
1907
for ( var eventName in events ) {
1929
1908
google . maps . event . addListener ( autocomplete , eventName , events [ eventName ] ) ;
1930
1909
}
@@ -1937,20 +1916,37 @@ angular.module('ngMap', []);
1937
1916
google . maps . event . addListener ( autocomplete , 'place_changed' , updateModel ) ;
1938
1917
element [ 0 ] . addEventListener ( 'change' , updateModel ) ;
1939
1918
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
+
1940
1936
attrs . $observe ( 'types' , function ( val ) {
1941
1937
if ( val ) {
1942
1938
var optionValue = parser . toOptionValue ( val , { key : 'types' } ) ;
1943
1939
autocomplete . setTypes ( optionValue ) ;
1944
1940
}
1945
1941
} ) ;
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
+ } ) ;
1952
1948
} ;
1953
-
1949
+
1954
1950
return {
1955
1951
restrict : 'A' ,
1956
1952
require : '?ngModel' ,
0 commit comments