1- /*! angular-google-maps 1.1.0 2014-05-31
1+ /*! angular-google-maps 1.1.1 2014-06-11
22 * AngularJS directives for Google Maps
33 * git: https://github.com/nlaplante/angular-google-maps.git
44 */
@@ -438,10 +438,9 @@ Nicholas McCready - https://twitter.com/nmccready
438438 if ( coords . type === "Point" && _ . isArray ( coords . coordinates ) && coords . coordinates . length === 2 ) {
439439 return true ;
440440 }
441- } else {
442- if ( coords && angular . isDefined ( ( coords != null ? coords . latitude : void 0 ) && angular . isDefined ( coords != null ? coords . longitude : void 0 ) ) ) {
443- return true ;
444- }
441+ }
442+ if ( coords && angular . isDefined ( ( coords != null ? coords . latitude : void 0 ) && angular . isDefined ( coords != null ? coords . longitude : void 0 ) ) ) {
443+ return true ;
445444 }
446445 return false ;
447446 } ;
@@ -519,7 +518,7 @@ Nicholas McCready - https://twitter.com/nmccready
519518 getCoords : getCoords ,
520519 validateCoords : validateCoords ,
521520 validatePath : function ( path ) {
522- var array , i ;
521+ var array , i , polygon , trackMaxVertices ;
523522 i = 0 ;
524523 if ( angular . isUndefined ( path . type ) ) {
525524 if ( ! Array . isArray ( path ) || path . length < 2 ) {
@@ -541,6 +540,22 @@ Nicholas McCready - https://twitter.com/nmccready
541540 return false ;
542541 }
543542 array = path . coordinates [ 0 ] ;
543+ } else if ( path . type === "MultiPolygon" ) {
544+ trackMaxVertices = {
545+ max : 0 ,
546+ index : 0
547+ } ;
548+ _ . forEach ( path . coordinates , function ( polygon , index ) {
549+ if ( polygon [ 0 ] . length > this . max ) {
550+ this . max = polygon [ 0 ] . length ;
551+ return this . index = index ;
552+ }
553+ } , trackMaxVertices ) ;
554+ polygon = path . coordinates [ trackMaxVertices . index ] ;
555+ array = polygon [ 0 ] ;
556+ if ( array . length < 4 ) {
557+ return false ;
558+ }
544559 } else if ( path . type === "LineString" ) {
545560 if ( path . coordinates . length < 2 ) {
546561 return false ;
@@ -559,7 +574,7 @@ Nicholas McCready - https://twitter.com/nmccready
559574 }
560575 } ,
561576 convertPathPoints : function ( path ) {
562- var array , i , latlng , result ;
577+ var array , i , latlng , result , trackMaxVertices ;
563578 i = 0 ;
564579 result = new google . maps . MVCArray ( ) ;
565580 if ( angular . isUndefined ( path . type ) ) {
@@ -577,6 +592,18 @@ Nicholas McCready - https://twitter.com/nmccready
577592 array ;
578593 if ( path . type === "Polygon" ) {
579594 array = path . coordinates [ 0 ] ;
595+ } else if ( path . type === "MultiPolygon" ) {
596+ trackMaxVertices = {
597+ max : 0 ,
598+ index : 0
599+ } ;
600+ _ . forEach ( path . coordinates , function ( polygon , index ) {
601+ if ( polygon [ 0 ] . length > this . max ) {
602+ this . max = polygon [ 0 ] . length ;
603+ return this . index = index ;
604+ }
605+ } , trackMaxVertices ) ;
606+ array = path . coordinates [ trackMaxVertices . index ] [ 0 ] ;
580607 } else if ( path . type === "LineString" ) {
581608 array = path . coordinates ;
582609 }
@@ -1120,7 +1147,7 @@ Nicholas McCready - https://twitter.com/nmccready
11201147( function ( ) {
11211148 angular . module ( "google-maps" ) . factory ( "array-sync" , [
11221149 "add-events" , function ( mapEvents ) {
1123- return function ( mapArray , scope , pathEval ) {
1150+ return function ( mapArray , scope , pathEval , pathChangedFn ) {
11241151 var geojsonArray , geojsonHandlers , geojsonWatcher , isSetFromScope , legacyHandlers , legacyWatcher , mapArrayListener , scopePath , watchListener ;
11251152 isSetFromScope = false ;
11261153 scopePath = scope . $eval ( pathEval ) ;
@@ -1293,7 +1320,7 @@ Nicholas McCready - https://twitter.com/nmccready
12931320 if ( angular . isUndefined ( scopePath . type ) ) {
12941321 watchListener = scope . $watchCollection ( pathEval , legacyWatcher ) ;
12951322 } else {
1296- watchListener = scope . $watch ( pathEval , geojsonWatcher ) ;
1323+ watchListener = scope . $watch ( pathEval , geojsonWatcher , true ) ;
12971324 }
12981325 }
12991326 return function ( ) {
@@ -1710,15 +1737,14 @@ Nicholas McCready - https://twitter.com/nmccready
17101737 PolylineChildModel . include ( GmapUtil ) ;
17111738
17121739 function PolylineChildModel ( scope , attrs , map , defaults , model ) {
1713- var arraySyncer , pathPoints , self ,
1740+ var arraySyncer , pathPoints ,
17141741 _this = this ;
17151742 this . scope = scope ;
17161743 this . attrs = attrs ;
17171744 this . map = map ;
17181745 this . defaults = defaults ;
17191746 this . model = model ;
17201747 this . buildOpts = __bind ( this . buildOpts , this ) ;
1721- self = this ;
17221748 pathPoints = this . convertPathPoints ( this . scope . path ) ;
17231749 this . polyline = new google . maps . Polyline ( this . buildOpts ( pathPoints ) ) ;
17241750 if ( this . isTrue ( this . attrs . fit ) ) {
@@ -1727,49 +1753,56 @@ Nicholas McCready - https://twitter.com/nmccready
17271753 if ( ! scope [ "static" ] && angular . isDefined ( scope . editable ) ) {
17281754 scope . $watch ( "editable" , function ( newValue , oldValue ) {
17291755 if ( newValue !== oldValue ) {
1730- return this . polyline . setEditable ( newValue ) ;
1756+ return _this . polyline . setEditable ( newValue ) ;
17311757 }
17321758 } ) ;
17331759 }
17341760 if ( angular . isDefined ( scope . draggable ) ) {
17351761 scope . $watch ( "draggable" , function ( newValue , oldValue ) {
17361762 if ( newValue !== oldValue ) {
1737- return this . polyline . setDraggable ( newValue ) ;
1763+ return _this . polyline . setDraggable ( newValue ) ;
17381764 }
17391765 } ) ;
17401766 }
17411767 if ( angular . isDefined ( scope . visible ) ) {
17421768 scope . $watch ( "visible" , function ( newValue , oldValue ) {
17431769 if ( newValue !== oldValue ) {
1744- return this . polyline . setVisible ( newValue ) ;
1770+ return _this . polyline . setVisible ( newValue ) ;
17451771 }
17461772 } ) ;
17471773 }
17481774 if ( angular . isDefined ( scope . geodesic ) ) {
17491775 scope . $watch ( "geodesic" , function ( newValue , oldValue ) {
17501776 if ( newValue !== oldValue ) {
1751- return this . polyline . setOptions ( this . buildOpts ( this . polyline . getPath ( ) ) ) ;
1777+ return _this . polyline . setOptions ( _this . buildOpts ( _this . polyline . getPath ( ) ) ) ;
17521778 }
17531779 } ) ;
17541780 }
17551781 if ( angular . isDefined ( scope . stroke ) && angular . isDefined ( scope . stroke . weight ) ) {
17561782 scope . $watch ( "stroke.weight" , function ( newValue , oldValue ) {
17571783 if ( newValue !== oldValue ) {
1758- return this . polyline . setOptions ( this . buildOpts ( this . polyline . getPath ( ) ) ) ;
1784+ return _this . polyline . setOptions ( _this . buildOpts ( _this . polyline . getPath ( ) ) ) ;
17591785 }
17601786 } ) ;
17611787 }
17621788 if ( angular . isDefined ( scope . stroke ) && angular . isDefined ( scope . stroke . color ) ) {
17631789 scope . $watch ( "stroke.color" , function ( newValue , oldValue ) {
17641790 if ( newValue !== oldValue ) {
1765- return this . polyline . setOptions ( this . buildOpts ( this . polyline . getPath ( ) ) ) ;
1791+ return _this . polyline . setOptions ( _this . buildOpts ( _this . polyline . getPath ( ) ) ) ;
1792+ }
1793+ } ) ;
1794+ }
1795+ if ( angular . isDefined ( scope . stroke ) && angular . isDefined ( scope . stroke . opacity ) ) {
1796+ scope . $watch ( "stroke.opacity" , function ( newValue , oldValue ) {
1797+ if ( newValue !== oldValue ) {
1798+ return _this . polyline . setOptions ( _this . buildOpts ( _this . polyline . getPath ( ) ) ) ;
17661799 }
17671800 } ) ;
17681801 }
17691802 if ( angular . isDefined ( scope . icons ) ) {
17701803 scope . $watch ( "icons" , function ( newValue , oldValue ) {
17711804 if ( newValue !== oldValue ) {
1772- return this . polyline . setOptions ( this . buildOpts ( this . polyline . getPath ( ) ) ) ;
1805+ return _this . polyline . setOptions ( _this . buildOpts ( _this . polyline . getPath ( ) ) ) ;
17731806 }
17741807 } ) ;
17751808 }
@@ -3626,7 +3659,7 @@ Nicholas McCready - https://twitter.com/nmccready
36263659 scope . $watch ( "center" , ( function ( newValue , oldValue ) {
36273660 var coords ;
36283661 coords = _this . getCoords ( newValue ) ;
3629- if ( newValue === oldValue || ( coords . lat ( ) === _m . center . lat ( ) && coords . lng ( ) === _m . center . lng ( ) ) ) {
3662+ if ( coords . lat ( ) === _m . center . lat ( ) && coords . lng ( ) === _m . center . lng ( ) ) {
36303663 return ;
36313664 }
36323665 settingCenterFromScope = true ;
@@ -3643,7 +3676,7 @@ Nicholas McCready - https://twitter.com/nmccready
36433676 return settingCenterFromScope = false ;
36443677 } ) , true ) ;
36453678 scope . $watch ( "zoom" , function ( newValue , oldValue ) {
3646- if ( newValue === oldValue || newValue === _m . zoom ) {
3679+ if ( newValue === _m . zoom ) {
36473680 return ;
36483681 }
36493682 return _ . defer ( function ( ) {
@@ -4284,15 +4317,16 @@ Rick Huizinga - https://plus.google.com/+RickHuizinga
42844317 visible : "=" ,
42854318 "static" : "=" ,
42864319 events : "=" ,
4287- zIndex : "=zindex"
4320+ zIndex : "=zindex" ,
4321+ fit : "="
42884322 } ,
42894323 link : function ( scope , element , attrs , mapCtrl ) {
42904324 if ( angular . isUndefined ( scope . path ) || scope . path === null || ! GmapUtil . validatePath ( scope . path ) ) {
42914325 $log . error ( "polygon: no valid path attribute found" ) ;
42924326 return ;
42934327 }
42944328 return $timeout ( function ( ) {
4295- var arraySyncer , buildOpts , eventName , getEventHandler , map , polygon ;
4329+ var arraySyncer , buildOpts , eventName , getEventHandler , map , pathPoints , polygon ;
42964330 buildOpts = function ( pathPoints ) {
42974331 var opts ;
42984332 opts = angular . extend ( { } , DEFAULTS , {
@@ -4311,6 +4345,7 @@ Rick Huizinga - https://plus.google.com/+RickHuizinga
43114345 geodesic : false ,
43124346 visible : true ,
43134347 "static" : false ,
4348+ fit : false ,
43144349 zIndex : 0
43154350 } , function ( defaultValue , key ) {
43164351 if ( angular . isUndefined ( scope [ key ] ) || scope [ key ] === null ) {
@@ -4325,8 +4360,9 @@ Rick Huizinga - https://plus.google.com/+RickHuizinga
43254360 return opts ;
43264361 } ;
43274362 map = mapCtrl . getMap ( ) ;
4328- polygon = new google . maps . Polygon ( buildOpts ( GmapUtil . convertPathPoints ( scope . path ) ) ) ;
4329- if ( isTrue ( attrs . fit ) ) {
4363+ pathPoints = GmapUtil . convertPathPoints ( scope . path ) ;
4364+ polygon = new google . maps . Polygon ( buildOpts ( pathPoints ) ) ;
4365+ if ( scope . fit ) {
43304366 GmapUtil . extendMapBounds ( map , pathPoints ) ;
43314367 }
43324368 if ( ! scope [ "static" ] && angular . isDefined ( scope . editable ) ) {
@@ -4409,7 +4445,11 @@ Rick Huizinga - https://plus.google.com/+RickHuizinga
44094445 }
44104446 }
44114447 }
4412- arraySyncer = arraySync ( polygon . getPath ( ) , scope , "path" ) ;
4448+ arraySyncer = arraySync ( polygon . getPath ( ) , scope , "path" , function ( pathPoints ) {
4449+ if ( scope . fit ) {
4450+ return GmapUtil . extendMapBounds ( map , pathPoints ) ;
4451+ }
4452+ } ) ;
44134453 return scope . $on ( "$destroy" , function ( ) {
44144454 polygon . setMap ( null ) ;
44154455 if ( arraySyncer ) {
0 commit comments