1
- /*! jquery-locationpicker - v0.1.13 - 2016-03-11 */
1
+ /*! jquery-locationpicker - v0.1.14 - 2016-09-20 */
2
2
( function ( $ ) {
3
3
function GMapContext ( domElement , options ) {
4
4
var _map = new google . maps . Map ( domElement , options ) ;
5
5
var _marker = new google . maps . Marker ( {
6
6
position : new google . maps . LatLng ( 54.19335 , - 3.92695 ) ,
7
7
map : _map ,
8
8
title : "Drag Me" ,
9
- draggable : options . draggable ,
9
+ visible : options . markerVisible ,
10
+ draggable : options . markerDraggable ,
10
11
icon : options . markerIcon !== undefined ? options . markerIcon : undefined
11
12
} ) ;
12
13
return {
60
61
gMapContext . map . panTo ( location ) ;
61
62
this . drawCircle ( gMapContext , location , gMapContext . radius , { } ) ;
62
63
if ( gMapContext . settings . enableReverseGeocode ) {
63
- gMapContext . geodecoder . geocode ( {
64
- latLng : gMapContext . location
65
- } , function ( results , status ) {
66
- if ( status == google . maps . GeocoderStatus . OK && results . length > 0 ) {
67
- gMapContext . locationName = results [ 0 ] . formatted_address ;
68
- gMapContext . addressComponents = GmUtility . address_component_from_google_geocode ( results [ 0 ] . address_components ) ;
69
- }
70
- if ( callback ) {
71
- callback . call ( this , gMapContext ) ;
72
- }
73
- } ) ;
64
+ this . updateLocationName ( gMapContext , callback ) ;
74
65
} else {
75
66
if ( callback ) {
76
67
callback . call ( this , gMapContext ) ;
83
74
longitude : lnlg . lng ( )
84
75
} ;
85
76
} ,
77
+ addressByFormat : function ( addresses , format ) {
78
+ var result = null ;
79
+ for ( var i = addresses . length - 1 ; i >= 0 ; i -- ) {
80
+ if ( addresses [ i ] . types . indexOf ( format ) >= 0 ) {
81
+ result = addresses [ i ] ;
82
+ }
83
+ }
84
+ return result || addresses [ 0 ] ;
85
+ } ,
86
+ updateLocationName : function ( gmapContext , callback ) {
87
+ gmapContext . geodecoder . geocode ( {
88
+ latLng : gmapContext . marker . position
89
+ } , function ( results , status ) {
90
+ if ( status == google . maps . GeocoderStatus . OK && results . length > 0 ) {
91
+ var address = GmUtility . addressByFormat ( results , gmapContext . settings . addressFormat ) ;
92
+ gmapContext . locationName = address . formatted_address ;
93
+ gmapContext . addressComponents = GmUtility . address_component_from_google_geocode ( address . address_components ) ;
94
+ }
95
+ if ( callback ) {
96
+ callback . call ( this , gmapContext ) ;
97
+ }
98
+ } ) ;
99
+ } ,
86
100
address_component_from_google_geocode : function ( address_components ) {
87
101
var result = { } ;
88
102
for ( var i = address_components . length - 1 ; i >= 0 ; i -- ) {
116
130
}
117
131
function updateInputValues ( inputBinding , gmapContext ) {
118
132
if ( ! inputBinding ) return ;
119
- var currentLocation = GmUtility . locationFromLatLng ( gmapContext . location ) ;
133
+ var currentLocation = GmUtility . locationFromLatLng ( gmapContext . marker . position ) ;
120
134
if ( inputBinding . latitudeInput ) {
121
135
inputBinding . latitudeInput . val ( currentLocation . latitude ) . change ( ) ;
122
136
}
145
159
}
146
160
if ( inputBinding . locationNameInput && gmapContext . settings . enableAutocomplete ) {
147
161
var blur = false ;
148
- gmapContext . autocomplete = new google . maps . places . Autocomplete ( inputBinding . locationNameInput . get ( 0 ) ) ;
162
+ gmapContext . autocomplete = new google . maps . places . Autocomplete ( inputBinding . locationNameInput . get ( 0 ) , gmapContext . settings . autocompleteOptions ) ;
149
163
google . maps . event . addListener ( gmapContext . autocomplete , "place_changed" , function ( ) {
150
164
blur = false ;
151
165
var place = gmapContext . autocomplete . getPlace ( ) ;
195
209
}
196
210
GmUtility . setPosition ( gmapContext , new google . maps . LatLng ( $ ( this ) . val ( ) , gmapContext . location . lng ( ) ) , function ( context ) {
197
211
context . settings . onchanged . apply ( gmapContext . domContainer , [ GmUtility . locationFromLatLng ( context . location ) , context . radius , false ] ) ;
212
+ updateInputValues ( gmapContext . settings . inputBinding , gmapContext ) ;
198
213
} ) ;
199
214
} ) ;
200
215
}
205
220
}
206
221
GmUtility . setPosition ( gmapContext , new google . maps . LatLng ( gmapContext . location . lat ( ) , $ ( this ) . val ( ) ) , function ( context ) {
207
222
context . settings . onchanged . apply ( gmapContext . domContainer , [ GmUtility . locationFromLatLng ( context . location ) , context . radius , false ] ) ;
223
+ updateInputValues ( gmapContext . settings . inputBinding , gmapContext ) ;
208
224
} ) ;
209
225
} ) ;
210
226
}
293
309
var gmapContext = new GMapContext ( this , {
294
310
zoom : settings . zoom ,
295
311
center : new google . maps . LatLng ( settings . location . latitude , settings . location . longitude ) ,
296
- mapTypeId : google . maps . MapTypeId . ROADMAP ,
312
+ mapTypeId : settings . mapTypeId ,
297
313
mapTypeControl : false ,
314
+ styles : settings . styles ,
298
315
disableDoubleClickZoom : false ,
299
316
scrollwheel : settings . scrollwheel ,
300
317
streetViewControl : false ,
301
318
radius : settings . radius ,
302
319
locationName : settings . locationName ,
303
320
settings : settings ,
321
+ autocompleteOptions : settings . autocompleteOptions ,
322
+ addressFormat : settings . addressFormat ,
304
323
draggable : settings . draggable ,
305
- markerIcon : settings . markerIcon
324
+ markerIcon : settings . markerIcon ,
325
+ markerDraggable : settings . markerDraggable ,
326
+ markerVisible : settings . markerVisible
306
327
} ) ;
307
328
$target . data ( "locationpicker" , gmapContext ) ;
308
- google . maps . event . addListener ( gmapContext . marker , "dragend" , function ( event ) {
329
+ function displayMarkerWithSelectedArea ( ) {
309
330
GmUtility . setPosition ( gmapContext , gmapContext . marker . position , function ( context ) {
310
331
var currentLocation = GmUtility . locationFromLatLng ( gmapContext . location ) ;
311
- context . settings . onchanged . apply ( gmapContext . domContainer , [ currentLocation , context . radius , true ] ) ;
312
332
updateInputValues ( gmapContext . settings . inputBinding , gmapContext ) ;
333
+ context . settings . onchanged . apply ( gmapContext . domContainer , [ currentLocation , context . radius , true ] ) ;
334
+ } ) ;
335
+ }
336
+ if ( settings . markerInCenter ) {
337
+ gmapContext . map . addListener ( "bounds_changed" , function ( ) {
338
+ if ( ! gmapContext . marker . dragging ) {
339
+ gmapContext . marker . setPosition ( gmapContext . map . center ) ;
340
+ updateInputValues ( gmapContext . settings . inputBinding , gmapContext ) ;
341
+ }
342
+ } ) ;
343
+ gmapContext . map . addListener ( "idle" , function ( ) {
344
+ if ( ! gmapContext . marker . dragging ) {
345
+ displayMarkerWithSelectedArea ( ) ;
346
+ }
313
347
} ) ;
348
+ }
349
+ google . maps . event . addListener ( gmapContext . marker , "drag" , function ( event ) {
350
+ updateInputValues ( gmapContext . settings . inputBinding , gmapContext ) ;
351
+ } ) ;
352
+ google . maps . event . addListener ( gmapContext . marker , "dragend" , function ( event ) {
353
+ displayMarkerWithSelectedArea ( ) ;
314
354
} ) ;
315
355
GmUtility . setPosition ( gmapContext , new google . maps . LatLng ( settings . location . latitude , settings . location . longitude ) , function ( context ) {
316
356
updateInputValues ( settings . inputBinding , gmapContext ) ;
327
367
locationName : "" ,
328
368
radius : 500 ,
329
369
zoom : 15 ,
370
+ mapTypeId : google . maps . MapTypeId . ROADMAP ,
371
+ styles : [ ] ,
330
372
scrollwheel : true ,
331
373
inputBinding : {
332
374
latitudeInput : null ,
336
378
} ,
337
379
enableAutocomplete : false ,
338
380
enableAutocompleteBlur : false ,
381
+ autocompleteOptions : null ,
382
+ addressFormat : "postal_code" ,
339
383
enableReverseGeocode : true ,
340
384
draggable : true ,
341
385
onchanged : function ( currentLocation , radius , isMarkerDropped ) { } ,
342
386
onlocationnotfound : function ( locationName ) { } ,
343
387
oninitialized : function ( component ) { } ,
344
- markerIcon : undefined
388
+ markerIcon : undefined ,
389
+ markerDraggable : true ,
390
+ markerVisible : true
345
391
} ;
346
392
} ) ( jQuery ) ;
0 commit comments