@@ -56,7 +56,6 @@ $.fn.storeLocator = function(options) {
56
56
'jsonpCallback' : null ,
57
57
//Language options
58
58
'geocodeErrorAlert' : 'Geocode was not successful for the following reason: ' ,
59
- 'blankInputAlert' : 'The input box was blank.' ,
60
59
'addressErrorAlert' : 'Unable to find address' ,
61
60
'autoGeocodeErrorAlert' : 'Automatic location detection failed. Please fill in your address or zip code.' ,
62
61
'distanceErrorAlert' : 'Unfortunately, our closest location is more than ' ,
@@ -157,6 +156,39 @@ $.fn.storeLocator = function(options) {
157
156
return radius * 2 * Math . asin ( Math . min ( 1 , Math . sqrt ( ( Math . pow ( Math . sin ( ( GeoCodeCalc . DiffRadian ( lat1 , lat2 ) ) / 2.0 ) , 2.0 ) + Math . cos ( GeoCodeCalc . ToRadian ( lat1 ) ) * Math . cos ( GeoCodeCalc . ToRadian ( lat2 ) ) * Math . pow ( Math . sin ( ( GeoCodeCalc . DiffRadian ( lng1 , lng2 ) ) / 2.0 ) , 2.0 ) ) ) ) ) ;
158
157
} ;
159
158
159
+ start ( ) ;
160
+
161
+ function start ( ) {
162
+ //If a default location is set
163
+ if ( settings . defaultLoc === true ) {
164
+ //The address needs to be determined for the directions link
165
+ var r = new ReverseGoogleGeocode ( ) ;
166
+ var latlng = new google . maps . LatLng ( settings . defaultLat , settings . defaultLng ) ;
167
+ r . geocode ( latlng , function ( data ) {
168
+ if ( data !== null ) {
169
+ var originAddress = data . address ;
170
+ mapping ( settings . defaultLat , settings . defaultLng , originAddress ) ;
171
+ } else {
172
+ //Unable to geocode
173
+ alert ( settings . addressErrorAlert ) ;
174
+ }
175
+ } ) ;
176
+ }
177
+
178
+ //If show full map option is true
179
+ if ( settings . fullMapStart === true ) {
180
+ //Just do the mapping without an origin
181
+ mapping ( ) ;
182
+ }
183
+
184
+ //HTML5 geolocation API option
185
+ if ( settings . autoGeocode === true ) {
186
+ if ( navigator . geolocation ) {
187
+ navigator . geolocation . getCurrentPosition ( autoGeocode_query , autoGeocode_error ) ;
188
+ }
189
+ }
190
+ }
191
+
160
192
//Geocode function for the origin location
161
193
function GoogleGeocode ( ) {
162
194
geocoder = new google . maps . Geocoder ( ) ;
@@ -199,35 +231,6 @@ $.fn.storeLocator = function(options) {
199
231
return Math . round ( num * Math . pow ( 10 , dec ) ) / Math . pow ( 10 , dec ) ;
200
232
}
201
233
202
- //If a default location is set
203
- if ( settings . defaultLoc === true ) {
204
- //The address needs to be determined for the directions link
205
- var r = new ReverseGoogleGeocode ( ) ;
206
- var latlng = new google . maps . LatLng ( settings . defaultLat , settings . defaultLng ) ;
207
- r . geocode ( latlng , function ( data ) {
208
- if ( data !== null ) {
209
- var originAddress = data . address ;
210
- mapping ( settings . defaultLat , settings . defaultLng , originAddress ) ;
211
- } else {
212
- //Unable to geocode
213
- alert ( settings . addressErrorAlert ) ;
214
- }
215
- } ) ;
216
- }
217
-
218
- //If show full map option is true
219
- if ( settings . fullMapStart === true ) {
220
- //Just do the mapping without an origin
221
- mapping ( ) ;
222
- }
223
-
224
- //HTML5 geolocation API option
225
- if ( settings . autoGeocode === true ) {
226
- if ( navigator . geolocation ) {
227
- navigator . geolocation . getCurrentPosition ( autoGeocode_query , autoGeocode_error ) ;
228
- }
229
- }
230
-
231
234
//If location is detected automatically
232
235
function autoGeocode_query ( position ) {
233
236
//The address needs to be determined for the directions link
@@ -255,41 +258,40 @@ $.fn.storeLocator = function(options) {
255
258
var userinput = $ ( '#' + settings . inputID ) . val ( ) ;
256
259
257
260
if ( userinput === "" ) {
258
- //Show alert and stop processing
259
- alert ( settings . blankInputAlert ) ;
260
- }
261
- else {
262
- var g = new GoogleGeocode ( ) ;
263
- var address = userinput ;
264
- g . geocode ( address , function ( data ) {
265
- if ( data !== null ) {
266
- olat = data . latitude ;
267
- olng = data . longitude ;
268
- mapping ( olat , olng , userinput , distance ) ;
269
- } else {
270
- //Unable to geocode
271
- alert ( settings . addressErrorAlert ) ;
272
- }
273
- } ) ;
274
- }
261
+ start ( ) ;
262
+ }
263
+ else {
264
+ var g = new GoogleGeocode ( ) ;
265
+ var address = userinput ;
266
+ g . geocode ( address , function ( data ) {
267
+ if ( data !== null ) {
268
+ olat = data . latitude ;
269
+ olng = data . longitude ;
270
+ mapping ( olat , olng , userinput , distance ) ;
271
+ } else {
272
+ //Unable to geocode
273
+ alert ( settings . addressErrorAlert ) ;
274
+ }
275
+ } ) ;
276
+ }
275
277
}
276
278
277
279
//Process form input
278
280
$ ( function ( ) {
279
281
//Handle form submission
280
282
function get_form_values ( e ) {
281
283
//Stop the form submission
282
- e . preventDefault ( ) ;
284
+ e . preventDefault ( ) ;
283
285
284
- if ( settings . maxDistance === true ) {
285
- var maxDistance = $ ( '#' + settings . maxDistanceID ) . val ( ) ;
286
- //Start the mapping
287
- begin_mapping ( maxDistance ) ;
288
- }
289
- else {
290
- //Start the mapping
291
- begin_mapping ( ) ;
292
- }
286
+ if ( settings . maxDistance === true ) {
287
+ var maxDistance = $ ( '#' + settings . maxDistanceID ) . val ( ) ;
288
+ //Start the mapping
289
+ begin_mapping ( maxDistance ) ;
290
+ }
291
+ else {
292
+ //Start the mapping
293
+ begin_mapping ( ) ;
294
+ }
293
295
}
294
296
295
297
//ASP.net or regular submission?
@@ -377,28 +379,28 @@ $.fn.storeLocator = function(options) {
377
379
if ( settings . dataType === 'json' || settings . dataType === 'jsonp' ) {
378
380
//Process JSON
379
381
$ . each ( data , function ( ) {
380
- var key , value , locationData = { } ;
382
+ var key , value , locationData = { } ;
381
383
382
- // Parse each data variables
383
- for ( key in this ) {
384
- value = this [ key ] ;
384
+ // Parse each data variables
385
+ for ( key in this ) {
386
+ value = this [ key ] ;
385
387
386
- if ( key === 'locname' ) {
387
- key = 'name' ; // Translate locname to name (todo: should NOT be done)
388
- }
389
- else if ( key === 'web' ) {
390
- if ( value ) value = value . replace ( "http://" , "" ) ; // Remove scheme (todo: should NOT be done)
391
- }
388
+ if ( key === 'locname' ) {
389
+ key = 'name' ; // Translate locname to name (todo: should NOT be done)
390
+ }
391
+ else if ( key === 'web' ) {
392
+ if ( value ) value = value . replace ( "http://" , "" ) ; // Remove scheme (todo: should NOT be done)
393
+ }
392
394
393
- locationData [ key ] = value ;
394
- }
395
+ locationData [ key ] = value ;
396
+ }
395
397
396
- if ( ! locationData [ 'distance' ] ) {
397
- locationData [ 'distance' ] = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , locationData [ 'lat' ] , locationData [ 'lng' ] , GeoCodeCalc . EarthRadius ) ;
398
- }
398
+ if ( ! locationData [ 'distance' ] ) {
399
+ locationData [ 'distance' ] = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , locationData [ 'lat' ] , locationData [ 'lng' ] , GeoCodeCalc . EarthRadius ) ;
400
+ }
399
401
400
402
//Create the array
401
- if ( settings . maxDistance === true && firstRun !== true ) {
403
+ if ( settings . maxDistance === true && firstRun !== true && maxDistance ) {
402
404
if ( locationData [ 'distance' ] < maxDistance ) {
403
405
locationset [ i ] = locationData ;
404
406
}
@@ -416,26 +418,17 @@ $.fn.storeLocator = function(options) {
416
418
else if ( settings . dataType === 'kml' ) {
417
419
//Process KML
418
420
$ ( data ) . find ( 'Placemark' ) . each ( function ( ) {
419
- var $placemark = $ ( this ) , locationData = {
420
- 'name' : $placemark . find ( 'name' ) . text ( ) ,
421
- 'lat' : $placemark . find ( 'coordinates' ) . text ( ) . split ( "," ) [ 1 ] ,
422
- 'lng' : $placemark . find ( 'coordinates' ) . text ( ) . split ( "," ) [ 0 ] ,
423
- // Promote setting a locdescription key for a singular description to use in templates instead, as some KML generators (like Google Maps Engine) populates the generic description including all key: values set.
424
- 'description' : $placemark . find ( 'description' ) . text ( )
425
- } ;
426
-
427
- $placemark . find ( 'displayName' ) . each ( function ( ) {
428
- var thisDataKey = $ ( this ) . text ( ) ,
429
- thisDataVal = $ ( this ) . next ( ) . text ( ) ;
430
- locationData [ thisDataKey ] = thisDataVal ;
431
- } ) ;
432
-
433
- if ( locationData [ 'web' ] ) locationData [ 'web' ] = locationData [ 'web' ] . replace ( "http://" , "" ) ; // Remove scheme (todo: should NOT be done)
434
-
435
- locationData [ 'distance' ] = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , locationData [ 'lat' ] , locationData [ 'lng' ] , GeoCodeCalc . EarthRadius ) ;
421
+ var locationData = {
422
+ 'name' : $ ( this ) . find ( 'name' ) . text ( ) ,
423
+ 'lat' : $ ( this ) . find ( 'coordinates' ) . text ( ) . split ( "," ) [ 1 ] ,
424
+ 'lng' : $ ( this ) . find ( 'coordinates' ) . text ( ) . split ( "," ) [ 0 ] ,
425
+ 'description' : $ ( this ) . find ( 'description' ) . text ( )
426
+ } ;
427
+
428
+ locationData [ 'distance' ] = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , locationData [ 'lat' ] , locationData [ 'lng' ] , GeoCodeCalc . EarthRadius ) ;
436
429
437
430
//Create the array
438
- if ( settings . maxDistance === true && firstRun !== true ) {
431
+ if ( settings . maxDistance === true && firstRun !== true && maxDistance ) {
439
432
if ( locationData [ 'distance' ] < maxDistance ) {
440
433
locationset [ i ] = locationData ;
441
434
}
@@ -453,32 +446,32 @@ $.fn.storeLocator = function(options) {
453
446
else {
454
447
//Process XML
455
448
$ ( data ) . find ( 'marker' ) . each ( function ( ) {
456
- var locationData = {
457
- 'name' : $ ( this ) . attr ( 'name' ) ,
458
- 'lat' : $ ( this ) . attr ( 'lat' ) ,
459
- 'lng' : $ ( this ) . attr ( 'lng' ) ,
460
- 'address' : $ ( this ) . attr ( 'address' ) ,
461
- 'address2' : $ ( this ) . attr ( 'address2' ) ,
462
- 'city' : $ ( this ) . attr ( 'city' ) ,
463
- 'state' : $ ( this ) . attr ( 'state' ) ,
464
- 'postal' : $ ( this ) . attr ( 'postal' ) ,
465
- 'country' : $ ( this ) . attr ( 'country' ) ,
466
- 'phone' : $ ( this ) . attr ( 'phone' ) ,
467
- 'email' : $ ( this ) . attr ( 'email' ) ,
468
- 'web' : $ ( this ) . attr ( 'web' ) ,
469
- 'hours1' : $ ( this ) . attr ( 'hours1' ) ,
470
- 'hours2' : $ ( this ) . attr ( 'hours2' ) ,
471
- 'hours3' : $ ( this ) . attr ( 'hours3' ) ,
472
- 'category' : $ ( this ) . attr ( 'category' ) ,
473
- 'featured' : $ ( this ) . attr ( 'featured' )
474
- } ;
475
-
476
- if ( locationData [ 'web' ] ) locationData [ 'web' ] = locationData [ 'web' ] . replace ( "http://" , "" ) ; // Remove scheme (todo: should NOT be done)
449
+ var locationData = {
450
+ 'name' : $ ( this ) . attr ( 'name' ) ,
451
+ 'lat' : $ ( this ) . attr ( 'lat' ) ,
452
+ 'lng' : $ ( this ) . attr ( 'lng' ) ,
453
+ 'address' : $ ( this ) . attr ( 'address' ) ,
454
+ 'address2' : $ ( this ) . attr ( 'address2' ) ,
455
+ 'city' : $ ( this ) . attr ( 'city' ) ,
456
+ 'state' : $ ( this ) . attr ( 'state' ) ,
457
+ 'postal' : $ ( this ) . attr ( 'postal' ) ,
458
+ 'country' : $ ( this ) . attr ( 'country' ) ,
459
+ 'phone' : $ ( this ) . attr ( 'phone' ) ,
460
+ 'email' : $ ( this ) . attr ( 'email' ) ,
461
+ 'web' : $ ( this ) . attr ( 'web' ) ,
462
+ 'hours1' : $ ( this ) . attr ( 'hours1' ) ,
463
+ 'hours2' : $ ( this ) . attr ( 'hours2' ) ,
464
+ 'hours3' : $ ( this ) . attr ( 'hours3' ) ,
465
+ 'category' : $ ( this ) . attr ( 'category' ) ,
466
+ 'featured' : $ ( this ) . attr ( 'featured' )
467
+ } ;
468
+
469
+ if ( locationData [ 'web' ] ) locationData [ 'web' ] = locationData [ 'web' ] . replace ( "http://" , "" ) ; // Remove scheme (todo: should NOT be done)
477
470
478
471
locationData [ 'distance' ] = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , locationData [ 'lat' ] , locationData [ 'lng' ] , GeoCodeCalc . EarthRadius ) ;
479
472
480
473
//Create the array
481
- if ( settings . maxDistance === true && firstRun !== true ) {
474
+ if ( settings . maxDistance === true && firstRun !== true && maxDistance ) {
482
475
if ( locationData [ 'distance' ] < maxDistance ) {
483
476
locationset [ i ] = locationData ;
484
477
}
@@ -525,7 +518,7 @@ $.fn.storeLocator = function(options) {
525
518
var distUnit = ( settings . lengthUnit === "km" ) ? settings . kilometersLang : settings . milesLang ;
526
519
527
520
//Check the closest marker
528
- if ( settings . maxDistance === true && firstRun !== true ) {
521
+ if ( settings . maxDistance === true && firstRun !== true && maxDistance ) {
529
522
if ( locationset [ 0 ] === undefined || locationset [ 0 ] [ 'distance' ] > maxDistance ) {
530
523
alert ( settings . distanceErrorAlert + maxDistance + " " + distUnit ) ;
531
524
return ;
@@ -540,19 +533,19 @@ $.fn.storeLocator = function(options) {
540
533
//Create the map with jQuery
541
534
$ ( function ( ) {
542
535
543
- var key , value , locationData = { } ;
536
+ var key , value , locationData = { } ;
544
537
545
538
//Instead of repeating the same thing twice below
546
539
function create_location_variables ( loopcount ) {
547
- for ( key in locationset [ loopcount ] ) {
548
- value = locationset [ loopcount ] [ key ] ;
540
+ for ( key in locationset [ loopcount ] ) {
541
+ value = locationset [ loopcount ] [ key ] ;
549
542
550
- if ( key === 'distance' ) {
551
- value = roundNumber ( value , 2 ) ;
552
- }
543
+ if ( key === 'distance' ) {
544
+ value = roundNumber ( value , 2 ) ;
545
+ }
553
546
554
- locationData [ key ] = value ;
555
- }
547
+ locationData [ key ] = value ;
548
+ }
556
549
}
557
550
558
551
//Define the location data for the templates
@@ -589,13 +582,13 @@ $.fn.storeLocator = function(options) {
589
582
590
583
//Define location data
591
584
var locations = {
592
- location : [ $ . extend ( locationData , {
593
- 'markerid' : markerId ,
594
- 'marker' : indicator ,
595
- 'length' : distLength ,
596
- 'origin' : origin
597
- } ) ]
598
- } ;
585
+ location : [ $ . extend ( locationData , {
586
+ 'markerid' : markerId ,
587
+ 'marker' : indicator ,
588
+ 'length' : distLength ,
589
+ 'origin' : origin
590
+ } ) ]
591
+ } ;
599
592
600
593
return locations ;
601
594
}
@@ -668,7 +661,7 @@ $.fn.storeLocator = function(options) {
668
661
}
669
662
670
663
//Add origin marker if the setting is set
671
- if ( firstRun !== true && settings . originMarker === true ) {
664
+ if ( settings . originMarker === true && settings . fullMapStart === false ) {
672
665
var originPinShadow = new google . maps . MarkerImage ( "http://chart.apis.google.com/chart?chst=d_map_pin_shadow" ,
673
666
new google . maps . Size ( 40 , 37 ) ,
674
667
new google . maps . Point ( 0 , 0 ) ,
@@ -681,9 +674,6 @@ $.fn.storeLocator = function(options) {
681
674
shadow : originPinShadow ,
682
675
draggable : false
683
676
} ) ;
684
- if ( settings . zoomLevel === 0 ) {
685
- bounds . extend ( originPoint ) ;
686
- }
687
677
}
688
678
689
679
//Add markers and infowindows loop
0 commit comments