@@ -377,38 +377,37 @@ $.fn.storeLocator = function(options) {
377
377
if ( settings . dataType === 'json' || settings . dataType === 'jsonp' ) {
378
378
//Process JSON
379
379
$ . each ( data , function ( ) {
380
- var name = this . locname ;
381
- var lat = this . lat ;
382
- var lng = this . lng ;
383
- var address = this . address ;
384
- var address2 = this . address2 ;
385
- var city = this . city ;
386
- var state = this . state ;
387
- var postal = this . postal ;
388
- var country = this . country ;
389
- var phone = this . phone ;
390
- var email = this . email ;
391
- var web = this . web ;
392
- if ( web ) web = web . replace ( "http://" , "" ) ;
393
- var hours1 = this . hours1 ;
394
- var hours2 = this . hours2 ;
395
- var hours3 = this . hours3 ;
396
- var category = this . category ;
397
- var featured = this . featured ;
398
-
399
- var distance = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , lat , lng , GeoCodeCalc . EarthRadius ) ;
400
-
380
+ var key , value , locationData = { } ;
381
+
382
+ // Parse each data variables
383
+ for ( key in this ) {
384
+ value = this [ key ] ;
385
+
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
+ }
392
+
393
+ locationData [ key ] = value ;
394
+ }
395
+
396
+ if ( ! locationData [ 'distance' ] ) {
397
+ locationData [ 'distance' ] = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , locationData [ 'lat' ] , locationData [ 'lng' ] , GeoCodeCalc . EarthRadius ) ;
398
+ }
399
+
401
400
//Create the array
402
401
if ( settings . maxDistance === true && firstRun !== true ) {
403
- if ( distance < maxDistance ) {
404
- locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , country , phone , email , web , hours1 , hours2 , hours3 , category , featured ] ;
402
+ if ( locationData [ ' distance' ] < maxDistance ) {
403
+ locationset [ i ] = locationData ;
405
404
}
406
405
else {
407
406
return ;
408
407
}
409
408
}
410
409
else {
411
- locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , country , phone , email , web , hours1 , hours2 , hours3 , category , featured ] ;
410
+ locationset [ i ] = locationData ;
412
411
}
413
412
414
413
i ++ ;
@@ -417,24 +416,26 @@ $.fn.storeLocator = function(options) {
417
416
else if ( settings . dataType === 'kml' ) {
418
417
//Process KML
419
418
$ ( data ) . find ( 'Placemark' ) . each ( function ( ) {
420
- var name = $ ( this ) . find ( 'name' ) . text ( ) ;
421
- var lat = $ ( this ) . find ( 'coordinates' ) . text ( ) . split ( "," ) [ 1 ] ;
422
- var lng = $ ( this ) . find ( 'coordinates' ) . text ( ) . split ( "," ) [ 0 ] ;
423
- var description = $ ( this ) . find ( 'description' ) . text ( ) ;
419
+ var locationData = {
420
+ 'name' : $ ( this ) . find ( 'name' ) . text ( ) ,
421
+ 'lat' : $ ( this ) . find ( 'coordinates' ) . text ( ) . split ( "," ) [ 1 ] ,
422
+ 'lng' : $ ( this ) . find ( 'coordinates' ) . text ( ) . split ( "," ) [ 0 ] ,
423
+ 'description' : $ ( this ) . find ( 'description' ) . text ( )
424
+ } ;
424
425
425
- var distance = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , lat , lng , GeoCodeCalc . EarthRadius ) ;
426
+ locationData [ ' distance' ] = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , locationData [ ' lat' ] , locationData [ ' lng' ] , GeoCodeCalc . EarthRadius ) ;
426
427
427
428
//Create the array
428
429
if ( settings . maxDistance === true && firstRun !== true ) {
429
- if ( distance < maxDistance ) {
430
- locationset [ i ] = [ distance , name , lat , lng , description ] ;
430
+ if ( locationData [ ' distance' ] < maxDistance ) {
431
+ locationset [ i ] = locationData ;
431
432
}
432
433
else {
433
434
return ;
434
435
}
435
436
}
436
437
else {
437
- locationset [ i ] = [ distance , name , lat , lng , description ] ;
438
+ locationset [ i ] = locationData ;
438
439
}
439
440
440
441
i ++ ;
@@ -443,38 +444,41 @@ $.fn.storeLocator = function(options) {
443
444
else {
444
445
//Process XML
445
446
$ ( data ) . find ( 'marker' ) . each ( function ( ) {
446
- var name = $ ( this ) . attr ( 'name' ) ;
447
- var lat = $ ( this ) . attr ( 'lat' ) ;
448
- var lng = $ ( this ) . attr ( 'lng' ) ;
449
- var address = $ ( this ) . attr ( 'address' ) ;
450
- var address2 = $ ( this ) . attr ( 'address2' ) ;
451
- var city = $ ( this ) . attr ( 'city' ) ;
452
- var state = $ ( this ) . attr ( 'state' ) ;
453
- var postal = $ ( this ) . attr ( 'postal' ) ;
454
- var country = $ ( this ) . attr ( 'country' ) ;
455
- var phone = $ ( this ) . attr ( 'phone' ) ;
456
- var email = $ ( this ) . attr ( 'email' ) ;
457
- var web = $ ( this ) . attr ( 'web' ) ;
458
- if ( web ) web = web . replace ( "http://" , "" ) ;
459
- var hours1 = $ ( this ) . attr ( 'hours1' ) ;
460
- var hours2 = $ ( this ) . attr ( 'hours2' ) ;
461
- var hours3 = $ ( this ) . attr ( 'hours3' ) ;
462
- var category = $ ( this ) . attr ( 'category' ) ;
463
- var featured = $ ( this ) . attr ( 'featured' ) ;
464
-
465
- var distance = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , lat , lng , GeoCodeCalc . EarthRadius ) ;
447
+ var locationData = {
448
+ 'name' : $ ( this ) . attr ( 'name' ) ,
449
+ 'lat' : $ ( this ) . attr ( 'lat' ) ,
450
+ 'lng' : $ ( this ) . attr ( 'lng' ) ,
451
+ 'address' : $ ( this ) . attr ( 'address' ) ,
452
+ 'address2' : $ ( this ) . attr ( 'address2' ) ,
453
+ 'city' : $ ( this ) . attr ( 'city' ) ,
454
+ 'state' : $ ( this ) . attr ( 'state' ) ,
455
+ 'postal' : $ ( this ) . attr ( 'postal' ) ,
456
+ 'country' : $ ( this ) . attr ( 'country' ) ,
457
+ 'phone' : $ ( this ) . attr ( 'phone' ) ,
458
+ 'email' : $ ( this ) . attr ( 'email' ) ,
459
+ 'web' : $ ( this ) . attr ( 'web' ) ,
460
+ 'hours1' : $ ( this ) . attr ( 'hours1' ) ,
461
+ 'hours2' : $ ( this ) . attr ( 'hours2' ) ,
462
+ 'hours3' : $ ( this ) . attr ( 'hours3' ) ,
463
+ 'category' : $ ( this ) . attr ( 'category' ) ,
464
+ 'featured' : $ ( this ) . attr ( 'featured' )
465
+ } ;
466
+
467
+ if ( locationData [ 'web' ] ) locationData [ 'web' ] = locationData [ 'web' ] . replace ( "http://" , "" ) ; // Remove scheme (todo: should NOT be done)
468
+
469
+ locationData [ 'distance' ] = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , locationData [ 'lat' ] , locationData [ 'lng' ] , GeoCodeCalc . EarthRadius ) ;
466
470
467
471
//Create the array
468
472
if ( settings . maxDistance === true && firstRun !== true ) {
469
- if ( distance < maxDistance ) {
470
- locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , country , phone , email , web , hours1 , hours2 , hours3 , category , featured ] ;
473
+ if ( locationData [ ' distance' ] < maxDistance ) {
474
+ locationset [ i ] = locationData ;
471
475
}
472
476
else {
473
477
return ;
474
478
}
475
479
}
476
480
else {
477
- locationset [ i ] = [ distance , name , lat , lng , address , address2 , city , state , postal , country , phone , email , web , hours1 , hours2 , hours3 , category , featured ] ;
481
+ locationset [ i ] = locationData ;
478
482
}
479
483
480
484
i ++ ;
@@ -484,9 +488,7 @@ $.fn.storeLocator = function(options) {
484
488
//Distance sorting function
485
489
function sort_numerically ( locationsarray ) {
486
490
locationsarray . sort ( function ( a , b ) {
487
- var x = a [ 0 ] ;
488
- var y = b [ 0 ] ;
489
- return ( ( x < y ) ? - 1 : ( ( x > y ) ? 1 : 0 ) ) ;
491
+ return ( ( a [ 'distance' ] < b [ 'distance' ] ) ? - 1 : ( ( a [ 'distance' ] > b [ 'distance' ] ) ? 1 : 0 ) ) ;
490
492
} ) ;
491
493
}
492
494
@@ -497,12 +499,12 @@ $.fn.storeLocator = function(options) {
497
499
if ( settings . featuredLocations === true ) {
498
500
//Create array for featured locations
499
501
featuredset = $ . grep ( locationset , function ( val , i ) {
500
- return val [ 17 ] === "true" ;
502
+ return val [ 'featured' ] === "true" ;
501
503
} ) ;
502
504
503
505
//Create array for normal locations
504
506
normalset = $ . grep ( locationset , function ( val , i ) {
505
- return val [ 17 ] !== "true" ;
507
+ return val [ 'featured' ] !== "true" ;
506
508
} ) ;
507
509
508
510
//Combine the arrays
@@ -515,62 +517,41 @@ $.fn.storeLocator = function(options) {
515
517
516
518
//Check the closest marker
517
519
if ( settings . maxDistance === true && firstRun !== true ) {
518
- if ( locationset [ 0 ] === undefined || locationset [ 0 ] [ 0 ] > maxDistance ) {
520
+ if ( locationset [ 0 ] === undefined || locationset [ 0 ] [ 'distance' ] > maxDistance ) {
519
521
alert ( settings . distanceErrorAlert + maxDistance + " " + distUnit ) ;
520
522
return ;
521
523
}
522
524
}
523
525
else {
524
- if ( settings . distanceAlert != - 1 && locationset [ 0 ] [ 0 ] > settings . distanceAlert ) {
526
+ if ( settings . distanceAlert != - 1 && locationset [ 0 ] [ 'distance' ] > settings . distanceAlert ) {
525
527
alert ( settings . distanceErrorAlert + settings . distanceAlert + " " + distUnit ) ;
526
528
}
527
529
}
528
530
529
531
//Create the map with jQuery
530
532
$ ( function ( ) {
531
533
532
- var storeDistance , storeName , storeAddress1 , storeAddress2 , storeCity , storeState , storeCountry , storeZip , storePhone , storeEmail , storeWeb , storeHours1 , storeHours2 , storeHours3 , storeDescription , storeCat , storeFeatured ;
534
+ var key , value , locationData = { } ;
533
535
534
536
//Instead of repeating the same thing twice below
535
537
function create_location_variables ( loopcount ) {
536
- storeDistance = locationset [ loopcount ] [ 0 ] ;
537
- storeDistance = roundNumber ( storeDistance , 2 ) ;
538
- storeName = locationset [ loopcount ] [ 1 ] ;
539
- storeAddress1 = locationset [ loopcount ] [ 4 ] ;
540
- storeAddress2 = locationset [ loopcount ] [ 5 ] ;
541
- storeCity = locationset [ loopcount ] [ 6 ] ;
542
- storeState = locationset [ loopcount ] [ 7 ] ;
543
- storeZip = locationset [ loopcount ] [ 8 ] ;
544
- storeCountry = locationset [ loopcount ] [ 9 ] ;
545
- storePhone = locationset [ loopcount ] [ 10 ] ;
546
- storeEmail = locationset [ loopcount ] [ 11 ]
547
- storeWeb = locationset [ loopcount ] [ 12 ] ;
548
- storeHours1 = locationset [ loopcount ] [ 13 ] ;
549
- storeHours2 = locationset [ loopcount ] [ 14 ] ;
550
- storeHours3 = locationset [ loopcount ] [ 15 ] ;
551
- storeCat = locationset [ loopcount ] [ 16 ] ;
552
- storeFeatured = locationset [ loopcount ] [ 17 ] ;
553
- }
538
+ for ( key in locationset [ loopcount ] ) {
539
+ value = locationset [ loopcount ] [ key ] ;
554
540
555
- //There are less variables for KML files
556
- function create_kml_location_variables ( loopcount ) {
557
- storeDistance = locationset [ loopcount ] [ 0 ] ;
558
- storeDistance = roundNumber ( storeDistance , 2 ) ;
559
- storeName = locationset [ loopcount ] [ 1 ] ;
560
- storeDescription = locationset [ loopcount ] [ 4 ] ;
541
+ if ( key == 'distance' ) {
542
+ value = roundNumber ( value , 2 ) ;
543
+ }
544
+
545
+ locationData [ key ] = value ;
546
+ }
561
547
}
562
548
563
549
//Define the location data for the templates
564
550
function define_location_data ( currentMarker ) {
565
- if ( settings . dataType === 'kml' ) {
566
- create_kml_location_variables ( currentMarker . get ( "id" ) ) ;
567
- }
568
- else {
569
- create_location_variables ( currentMarker . get ( "id" ) ) ;
570
- }
551
+ create_location_variables ( currentMarker . get ( "id" ) ) ;
571
552
572
553
var distLength ;
573
- if ( storeDistance <= 1 ) {
554
+ if ( locationData [ 'distance' ] <= 1 ) {
574
555
if ( settings . lengthUnit === "km" ) {
575
556
distLength = settings . kilometerLang ;
576
557
}
@@ -598,49 +579,14 @@ $.fn.storeLocator = function(options) {
598
579
}
599
580
600
581
//Define location data
601
- if ( settings . dataType === 'kml' ) {
602
- var locations = {
603
- location : [
604
- {
605
- "distance" : storeDistance ,
606
- "markerid" : markerId ,
607
- "marker" : indicator ,
608
- "name" : storeName ,
609
- "description" : storeDescription ,
610
- "length" : distLength ,
611
- "origin" : origin
612
- }
613
- ]
614
- } ;
615
- }
616
- else {
617
- var locations = {
618
- location : [
619
- {
620
- "distance" : storeDistance ,
621
- "markerid" : markerId ,
622
- "marker" : indicator ,
623
- "name" : storeName ,
624
- "address" : storeAddress1 ,
625
- "address2" : storeAddress2 ,
626
- "city" : storeCity ,
627
- "state" : storeState ,
628
- "postal" : storeZip ,
629
- "country" : storeCountry ,
630
- "phone" : storePhone ,
631
- "email" : storeEmail ,
632
- "web" : storeWeb ,
633
- "hours1" : storeHours1 ,
634
- "hours2" : storeHours2 ,
635
- "hours3" : storeHours3 ,
636
- "length" : distLength ,
637
- "origin" : origin ,
638
- "category" : storeCat ,
639
- "featured" : storeFeatured
640
- }
641
- ]
642
- } ;
643
- }
582
+ var locations = {
583
+ location : [ $ . extend ( locationData , {
584
+ 'markerid' : markerId ,
585
+ 'marker' : indicator ,
586
+ 'length' : distLength ,
587
+ 'origin' : origin
588
+ } ) ]
589
+ } ;
644
590
645
591
return locations ;
646
592
}
@@ -729,8 +675,8 @@ $.fn.storeLocator = function(options) {
729
675
//Add markers and infowindows loop
730
676
for ( var y = 0 ; y <= storenum ; y ++ ) {
731
677
var letter = String . fromCharCode ( "A" . charCodeAt ( 0 ) + y ) ;
732
- var point = new google . maps . LatLng ( locationset [ y ] [ 2 ] , locationset [ y ] [ 3 ] ) ;
733
- marker = createMarker ( point , locationset [ y ] [ 1 ] , locationset [ y ] [ 4 ] , letter , locationset [ y ] [ 14 ] ) ;
678
+ var point = new google . maps . LatLng ( locationset [ y ] [ 'lat' ] , locationset [ y ] [ 'lng' ] ) ;
679
+ marker = createMarker ( point , locationset [ y ] [ 'name' ] , locationset [ y ] [ 'address' ] , letter ) ;
734
680
marker . set ( "id" , y ) ;
735
681
markers [ y ] = marker ;
736
682
if ( ( settings . fullMapStart === true && firstRun === true ) || settings . zoomLevel === 0 ) {
@@ -789,7 +735,7 @@ $.fn.storeLocator = function(options) {
789
735
$ ( "#" + settings . listDiv + " ul li:odd" ) . css ( 'background' , "#" + settings . listColor2 ) ;
790
736
791
737
//Custom marker function - alphabetical
792
- function createMarker ( point , name , address , letter , type ) {
738
+ function createMarker ( point , name , address , letter ) {
793
739
//Set up pin icon with the Google Charts API for all of our markers
794
740
var pinImage = new google . maps . MarkerImage ( "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=" + letter + "|" + settings . pinColor + "|" + settings . pinTextColor ,
795
741
new google . maps . Size ( 21 , 34 ) ,
0 commit comments