1- /*! jquery-locationpicker - v0.1.12 - 2015-01-05 */
1+ /*! jquery-locationpicker - v0.1.13 - 2016-03-11 */
22( function ( $ ) {
33 function GMapContext ( domElement , options ) {
44 var _map = new google . maps . Map ( domElement , options ) ;
55 var _marker = new google . maps . Marker ( {
66 position : new google . maps . LatLng ( 54.19335 , - 3.92695 ) ,
77 map : _map ,
88 title : "Drag Me" ,
9- draggable : options . draggable
9+ draggable : options . draggable ,
10+ icon : options . markerIcon !== undefined ? options . markerIcon : undefined
1011 } ) ;
1112 return {
1213 map : _map ,
143144 } ) ;
144145 }
145146 if ( inputBinding . locationNameInput && gmapContext . settings . enableAutocomplete ) {
147+ var blur = false ;
146148 gmapContext . autocomplete = new google . maps . places . Autocomplete ( inputBinding . locationNameInput . get ( 0 ) ) ;
147149 google . maps . event . addListener ( gmapContext . autocomplete , "place_changed" , function ( ) {
150+ blur = false ;
148151 var place = gmapContext . autocomplete . getPlace ( ) ;
149152 if ( ! place . geometry ) {
150153 gmapContext . settings . onlocationnotfound ( place . name ) ;
155158 context . settings . onchanged . apply ( gmapContext . domContainer , [ GmUtility . locationFromLatLng ( context . location ) , context . radius , false ] ) ;
156159 } ) ;
157160 } ) ;
161+ if ( gmapContext . settings . enableAutocompleteBlur ) {
162+ inputBinding . locationNameInput . on ( "change" , function ( e ) {
163+ if ( ! e . originalEvent ) {
164+ return ;
165+ }
166+ blur = true ;
167+ } ) ;
168+ inputBinding . locationNameInput . on ( "blur" , function ( e ) {
169+ if ( ! e . originalEvent ) {
170+ return ;
171+ }
172+ setTimeout ( function ( ) {
173+ var address = $ ( inputBinding . locationNameInput ) . val ( ) ;
174+ if ( address . length > 5 && blur ) {
175+ blur = false ;
176+ gmapContext . geodecoder . geocode ( {
177+ address : address
178+ } , function ( results , status ) {
179+ if ( status == google . maps . GeocoderStatus . OK && results && results . length ) {
180+ GmUtility . setPosition ( gmapContext , results [ 0 ] . geometry . location , function ( context ) {
181+ updateInputValues ( inputBinding , context ) ;
182+ context . settings . onchanged . apply ( gmapContext . domContainer , [ GmUtility . locationFromLatLng ( context . location ) , context . radius , false ] ) ;
183+ } ) ;
184+ }
185+ } ) ;
186+ }
187+ } , 1e3 ) ;
188+ } ) ;
189+ }
158190 }
159191 if ( inputBinding . latitudeInput ) {
160192 inputBinding . latitudeInput . on ( "change" , function ( e ) {
184216 gmapContext . map . setCenter ( gmapContext . marker . position ) ;
185217 } , 300 ) ;
186218 }
219+ function updateMap ( gmapContext , $target , options ) {
220+ var settings = $ . extend ( { } , $ . fn . locationpicker . defaults , options ) , latNew = settings . location . latitude , lngNew = settings . location . longitude , radiusNew = settings . radius , latOld = gmapContext . settings . location . latitude , lngOld = gmapContext . settings . location . longitude , radiusOld = gmapContext . settings . radius ;
221+ if ( latNew == latOld && lngNew == lngOld && radiusNew == radiusOld ) return ;
222+ gmapContext . settings . location . latitude = latNew ;
223+ gmapContext . settings . location . longitude = lngNew ;
224+ gmapContext . radius = radiusNew ;
225+ GmUtility . setPosition ( gmapContext , new google . maps . LatLng ( gmapContext . settings . location . latitude , gmapContext . settings . location . longitude ) , function ( context ) {
226+ setupInputListenersInput ( gmapContext . settings . inputBinding , gmapContext ) ;
227+ context . settings . oninitialized ( $target ) ;
228+ } ) ;
229+ }
187230 $ . fn . locationpicker = function ( options , params ) {
188231 if ( typeof options == "string" ) {
189232 var _targetDomElement = this . get ( 0 ) ;
242285 }
243286 return this . each ( function ( ) {
244287 var $target = $ ( this ) ;
245- if ( isPluginApplied ( this ) ) return ;
288+ if ( isPluginApplied ( this ) ) {
289+ updateMap ( getContextForElement ( this ) , $ ( this ) , options ) ;
290+ return ;
291+ }
246292 var settings = $ . extend ( { } , $ . fn . locationpicker . defaults , options ) ;
247293 var gmapContext = new GMapContext ( this , {
248294 zoom : settings . zoom ,
255301 radius : settings . radius ,
256302 locationName : settings . locationName ,
257303 settings : settings ,
258- draggable : settings . draggable
304+ draggable : settings . draggable ,
305+ markerIcon : settings . markerIcon
259306 } ) ;
260307 $target . data ( "locationpicker" , gmapContext ) ;
261308 google . maps . event . addListener ( gmapContext . marker , "dragend" , function ( event ) {
275322 $ . fn . locationpicker . defaults = {
276323 location : {
277324 latitude : 40.7324319 ,
278- longitude : - 73.82480799999996
325+ longitude : - 73.82480777777776
279326 } ,
280327 locationName : "" ,
281328 radius : 500 ,
288335 locationNameInput : null
289336 } ,
290337 enableAutocomplete : false ,
338+ enableAutocompleteBlur : false ,
291339 enableReverseGeocode : true ,
292340 draggable : true ,
293341 onchanged : function ( currentLocation , radius , isMarkerDropped ) { } ,
294342 onlocationnotfound : function ( locationName ) { } ,
295- oninitialized : function ( component ) { }
343+ oninitialized : function ( component ) { } ,
344+ markerIcon : undefined
296345 } ;
297346} ) ( jQuery ) ;
0 commit comments