1
- /*! jquery-locationpicker - v0.1.12 - 2015-01-05 */
1
+ /*! jquery-locationpicker - v0.1.13 - 2016-03-11 */
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
+ draggable : options . draggable ,
10
+ icon : options . markerIcon !== undefined ? options . markerIcon : undefined
10
11
} ) ;
11
12
return {
12
13
map : _map ,
143
144
} ) ;
144
145
}
145
146
if ( inputBinding . locationNameInput && gmapContext . settings . enableAutocomplete ) {
147
+ var blur = false ;
146
148
gmapContext . autocomplete = new google . maps . places . Autocomplete ( inputBinding . locationNameInput . get ( 0 ) ) ;
147
149
google . maps . event . addListener ( gmapContext . autocomplete , "place_changed" , function ( ) {
150
+ blur = false ;
148
151
var place = gmapContext . autocomplete . getPlace ( ) ;
149
152
if ( ! place . geometry ) {
150
153
gmapContext . settings . onlocationnotfound ( place . name ) ;
155
158
context . settings . onchanged . apply ( gmapContext . domContainer , [ GmUtility . locationFromLatLng ( context . location ) , context . radius , false ] ) ;
156
159
} ) ;
157
160
} ) ;
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
+ }
158
190
}
159
191
if ( inputBinding . latitudeInput ) {
160
192
inputBinding . latitudeInput . on ( "change" , function ( e ) {
184
216
gmapContext . map . setCenter ( gmapContext . marker . position ) ;
185
217
} , 300 ) ;
186
218
}
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
+ }
187
230
$ . fn . locationpicker = function ( options , params ) {
188
231
if ( typeof options == "string" ) {
189
232
var _targetDomElement = this . get ( 0 ) ;
242
285
}
243
286
return this . each ( function ( ) {
244
287
var $target = $ ( this ) ;
245
- if ( isPluginApplied ( this ) ) return ;
288
+ if ( isPluginApplied ( this ) ) {
289
+ updateMap ( getContextForElement ( this ) , $ ( this ) , options ) ;
290
+ return ;
291
+ }
246
292
var settings = $ . extend ( { } , $ . fn . locationpicker . defaults , options ) ;
247
293
var gmapContext = new GMapContext ( this , {
248
294
zoom : settings . zoom ,
255
301
radius : settings . radius ,
256
302
locationName : settings . locationName ,
257
303
settings : settings ,
258
- draggable : settings . draggable
304
+ draggable : settings . draggable ,
305
+ markerIcon : settings . markerIcon
259
306
} ) ;
260
307
$target . data ( "locationpicker" , gmapContext ) ;
261
308
google . maps . event . addListener ( gmapContext . marker , "dragend" , function ( event ) {
275
322
$ . fn . locationpicker . defaults = {
276
323
location : {
277
324
latitude : 40.7324319 ,
278
- longitude : - 73.82480799999996
325
+ longitude : - 73.82480777777776
279
326
} ,
280
327
locationName : "" ,
281
328
radius : 500 ,
288
335
locationNameInput : null
289
336
} ,
290
337
enableAutocomplete : false ,
338
+ enableAutocompleteBlur : false ,
291
339
enableReverseGeocode : true ,
292
340
draggable : true ,
293
341
onchanged : function ( currentLocation , radius , isMarkerDropped ) { } ,
294
342
onlocationnotfound : function ( locationName ) { } ,
295
- oninitialized : function ( component ) { }
343
+ oninitialized : function ( component ) { } ,
344
+ markerIcon : undefined
296
345
} ;
297
346
} ) ( jQuery ) ;
0 commit comments