@@ -56,7 +56,6 @@ $.fn.storeLocator = function(options) {
5656 'jsonpCallback' : null ,
5757 //Language options
5858 'geocodeErrorAlert' : 'Geocode was not successful for the following reason: ' ,
59- 'blankInputAlert' : 'The input box was blank.' ,
6059 'addressErrorAlert' : 'Unable to find address' ,
6160 'autoGeocodeErrorAlert' : 'Automatic location detection failed. Please fill in your address or zip code.' ,
6261 'distanceErrorAlert' : 'Unfortunately, our closest location is more than ' ,
@@ -157,6 +156,39 @@ $.fn.storeLocator = function(options) {
157156 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 ) ) ) ) ) ;
158157 } ;
159158
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+
160192 //Geocode function for the origin location
161193 function GoogleGeocode ( ) {
162194 geocoder = new google . maps . Geocoder ( ) ;
@@ -199,35 +231,6 @@ $.fn.storeLocator = function(options) {
199231 return Math . round ( num * Math . pow ( 10 , dec ) ) / Math . pow ( 10 , dec ) ;
200232 }
201233
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-
231234 //If location is detected automatically
232235 function autoGeocode_query ( position ) {
233236 //The address needs to be determined for the directions link
@@ -255,41 +258,40 @@ $.fn.storeLocator = function(options) {
255258 var userinput = $ ( '#' + settings . inputID ) . val ( ) ;
256259
257260 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+ }
275277 }
276278
277279 //Process form input
278280 $ ( function ( ) {
279281 //Handle form submission
280282 function get_form_values ( e ) {
281283 //Stop the form submission
282- e . preventDefault ( ) ;
284+ e . preventDefault ( ) ;
283285
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+ }
293295 }
294296
295297 //ASP.net or regular submission?
@@ -377,28 +379,28 @@ $.fn.storeLocator = function(options) {
377379 if ( settings . dataType === 'json' || settings . dataType === 'jsonp' ) {
378380 //Process JSON
379381 $ . each ( data , function ( ) {
380- var key , value , locationData = { } ;
382+ var key , value , locationData = { } ;
381383
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 ] ;
385387
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+ }
392394
393- locationData [ key ] = value ;
394- }
395+ locationData [ key ] = value ;
396+ }
395397
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+ }
399401
400402 //Create the array
401- if ( settings . maxDistance === true && firstRun !== true ) {
403+ if ( settings . maxDistance === true && firstRun !== true && maxDistance ) {
402404 if ( locationData [ 'distance' ] < maxDistance ) {
403405 locationset [ i ] = locationData ;
404406 }
@@ -416,26 +418,17 @@ $.fn.storeLocator = function(options) {
416418 else if ( settings . dataType === 'kml' ) {
417419 //Process KML
418420 $ ( 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 ) ;
436429
437430 //Create the array
438- if ( settings . maxDistance === true && firstRun !== true ) {
431+ if ( settings . maxDistance === true && firstRun !== true && maxDistance ) {
439432 if ( locationData [ 'distance' ] < maxDistance ) {
440433 locationset [ i ] = locationData ;
441434 }
@@ -453,32 +446,32 @@ $.fn.storeLocator = function(options) {
453446 else {
454447 //Process XML
455448 $ ( 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)
477470
478471 locationData [ 'distance' ] = GeoCodeCalc . CalcDistance ( orig_lat , orig_lng , locationData [ 'lat' ] , locationData [ 'lng' ] , GeoCodeCalc . EarthRadius ) ;
479472
480473 //Create the array
481- if ( settings . maxDistance === true && firstRun !== true ) {
474+ if ( settings . maxDistance === true && firstRun !== true && maxDistance ) {
482475 if ( locationData [ 'distance' ] < maxDistance ) {
483476 locationset [ i ] = locationData ;
484477 }
@@ -525,7 +518,7 @@ $.fn.storeLocator = function(options) {
525518 var distUnit = ( settings . lengthUnit === "km" ) ? settings . kilometersLang : settings . milesLang ;
526519
527520 //Check the closest marker
528- if ( settings . maxDistance === true && firstRun !== true ) {
521+ if ( settings . maxDistance === true && firstRun !== true && maxDistance ) {
529522 if ( locationset [ 0 ] === undefined || locationset [ 0 ] [ 'distance' ] > maxDistance ) {
530523 alert ( settings . distanceErrorAlert + maxDistance + " " + distUnit ) ;
531524 return ;
@@ -540,19 +533,19 @@ $.fn.storeLocator = function(options) {
540533 //Create the map with jQuery
541534 $ ( function ( ) {
542535
543- var key , value , locationData = { } ;
536+ var key , value , locationData = { } ;
544537
545538 //Instead of repeating the same thing twice below
546539 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 ] ;
549542
550- if ( key === 'distance' ) {
551- value = roundNumber ( value , 2 ) ;
552- }
543+ if ( key === 'distance' ) {
544+ value = roundNumber ( value , 2 ) ;
545+ }
553546
554- locationData [ key ] = value ;
555- }
547+ locationData [ key ] = value ;
548+ }
556549 }
557550
558551 //Define the location data for the templates
@@ -589,13 +582,13 @@ $.fn.storeLocator = function(options) {
589582
590583 //Define location data
591584 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+ } ;
599592
600593 return locations ;
601594 }
@@ -668,7 +661,7 @@ $.fn.storeLocator = function(options) {
668661 }
669662
670663 //Add origin marker if the setting is set
671- if ( firstRun !== true && settings . originMarker === true ) {
664+ if ( settings . originMarker === true && settings . fullMapStart === false ) {
672665 var originPinShadow = new google . maps . MarkerImage ( "http://chart.apis.google.com/chart?chst=d_map_pin_shadow" ,
673666 new google . maps . Size ( 40 , 37 ) ,
674667 new google . maps . Point ( 0 , 0 ) ,
@@ -681,9 +674,6 @@ $.fn.storeLocator = function(options) {
681674 shadow : originPinShadow ,
682675 draggable : false
683676 } ) ;
684- if ( settings . zoomLevel === 0 ) {
685- bounds . extend ( originPoint ) ;
686- }
687677 }
688678
689679 //Add markers and infowindows loop
0 commit comments