Advertisement
zigojacko

googlemaps-store-locator

Jul 17th, 2013
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 33.99 KB | None | 0 0
  1. <div class="topclass">
  2.  
  3. <?php
  4.  
  5. $apikey_source = '';
  6. $distancecounter = 2;
  7. if(Mage::helper('gmapstrlocator')->getGMapAPIKey() != ''):
  8.  
  9. $apikey_source = 'http://maps.google.com/maps/api/js?key='.Mage::helper('gmapstrlocator')->getGMapAPIKey().'&sensor=false';
  10.  
  11. else :
  12.  
  13. $apikey_source = 'http://maps.google.com/maps/api/js?sensor=false';
  14.  
  15. endif;
  16.  
  17. ?>
  18.  
  19. <script type="text/javascript" src="<?php echo $apikey_source; ?>"></script>
  20. <script type="text/javascript" src="<?php echo $this->getJsUrl('gmapstrlocator/googlemarkerInfobox.js'); ?>"></script>
  21.  
  22.  
  23.  
  24.  
  25. <?php
  26.  
  27.    $Stores = $this->getAllStores();
  28.     if($Stores){
  29.     foreach($Stores as $key => $value){
  30.         $Stores[$key]['store_description'] = Mage::helper('gmapstrlocator')->getWysiwygFilter($Stores[$key]['store_description']);
  31.     }
  32.     }
  33.    
  34.     //Config values
  35.     $standard_lat = Mage::helper('gmapstrlocator')->getGMapStandardLatitude();
  36.     $standard_long = Mage::helper('gmapstrlocator')->getGMapStandardLongitude();
  37.    
  38.     //direction button text
  39.     $direction_button_text = Mage::helper('gmapstrlocator')->getDirectionButtonText();
  40.     if($direction_button_text == ''): $direction_button_text = 'Get Direction'; endif;
  41.    
  42.     //GMap Marker Image
  43.     $gmap_marker_image = Mage::helper('gmapstrlocator')->getGMapMarkerSrc();
  44.     if(!Mage::helper('gmapstrlocator')->getGMapMarkerExist()): $gmap_marker_image = $this->getSkinUrl('images/gmapstrlocator/ib_icon.png'); endif;
  45.    
  46.     //Popup Primary BG Image
  47.     $popup_primary_image = Mage::helper('gmapstrlocator')->getGMapPopupBgprimarySrc();
  48.     if(Mage::helper('gmapstrlocator')->getGMapPopupBgprimaryExist()):
  49. ?>
  50.  
  51.     <style title="text/css"> .izi_map .popup .inner .map_popup_top1, .map_popup_top1 { background: url("<?php echo $popup_primary_image; ?>") !important; </style>
  52.  
  53. <?php
  54.  
  55.    endif;
  56.    
  57.    if(Mage::helper('gmapstrlocator')->getGMapPopupBgsecondaryExist()):
  58.     $popup_secondary_image = Mage::helper('gmapstrlocator')->getGMapPopupBgsecondarySrc();
  59.     else:
  60.     $popup_secondary_image =  $this->getSkinUrl('images/gmapstrlocator/map_popup_bottom.png');
  61.     endif;
  62. ?>
  63.        
  64.     <script src="<?php echo $this->getJsUrl('gmapstrlocator/jquery.tinyscrollbar.min.js'); ?>" type="text/javascript"></script>
  65.     <script type="text/javascript">
  66.     jQuery(document).ready(function(){
  67.                 jQuery('#scrollbar1').tinyscrollbar();
  68.                
  69.                
  70.             });
  71.    
  72.    
  73.    
  74.     </script>
  75.    
  76.    
  77.    
  78.        
  79.         <div class="top_title">
  80.                 <h1><?php echo Mage::helper('gmapstrlocator')->getGMapPageHeading(); ?></h1>
  81.                 <p class="head-content"><?php echo Mage::helper('gmapstrlocator')->getGMapPageSubheading(); ?></p>
  82.         </div>
  83.         <div id="main">
  84.            
  85.             <div class="form">
  86.                
  87.                 <?php if(Mage::helper('gmapstrlocator')->isSearchByProductEnable()): ?>
  88.                 <div class="field1">
  89.                     <p><?php echo Mage::helper('gmapstrlocator')->__('Search for Products'); ?></p>
  90.                     <input type="text" class="input" name="prod_search" id="prod_search">
  91.                     <input type="button" class="button" value="<?php echo Mage::helper('gmapstrlocator')->__('Search'); ?>" name="" onclick="searchByProducts(this.value)">
  92.                 </div>
  93.                 <?php endif; ?>
  94.                
  95.                 <?php if(Mage::helper('gmapstrlocator')->isSearchByZipcodeEnable()): ?>
  96.                 <div class="field2">
  97.                     <p><?php echo Mage::helper('gmapstrlocator')->__('Search By Zip Code'); ?></p>
  98.                     <input type="text" class="input" id="zipcode_address" name="zipcode_address"  >
  99.                     <input id="search_by_zipcode_address_btn" type="button" class="button" value="<?php echo Mage::helper('gmapstrlocator')->__('Search'); ?>" name="" onclick="searchbyzipcode(this.value);">    
  100.                 </div>
  101.                 <?php endif; ?>
  102.                
  103.                 <?php if(Mage::helper('gmapstrlocator')->isSearchByAddressEnable()): ?>
  104.                 <div class="field2">
  105.                     <p><?php echo Mage::helper('gmapstrlocator')->__('Search By Address, State'); ?></p>
  106.                     <input type="text" class="input" name="" onkeypress="return MalikScript(event)" id="s_address" name="s_address"  >
  107.                     <input id="search_by_address_btn" type="button" class="button" value="<?php echo Mage::helper('gmapstrlocator')->__('Search'); ?>" name="" onclick="validatepost(this.value);">    
  108.                 </div>
  109.                 <?php endif; ?>
  110.                
  111.                 <?php if(Mage::helper('gmapstrlocator')->isSearchStoreSelectEnable()): ?>
  112.                 <div class="jump_menu1">
  113.                     <p><?php echo Mage::helper('gmapstrlocator')->__('Store(s)'); ?></p>
  114.                     <select class="jump_menu" id="store" onchange="updatemap('store')">
  115.                     <option value=""><?php echo $this->__('CHOOSE A STORE'); ?></option>
  116.                      <?php $Storelatlong = array();$newStorelatlong = array();
  117.                             $i=0;$j=-1;
  118.                             foreach($Stores as $Store):
  119.                             $Storelatlong[]='('.$Store['latitude'].','.$Store['longitude'].')';
  120.                             if($i++%25 == 0){
  121.                                 $j++;
  122.                             }
  123.                             $newStorelatlong[$j][]='('.$Store['latitude'].','.$Store['longitude'].')';
  124.                             ?>
  125.                        
  126.                         <option value="<?php echo $Store['store_name'] ;?>"><?php echo $Store['store_name']; ?></option>
  127.                    
  128.                     <?php endforeach;  ?>
  129.                     </select>                  
  130.                 </div>
  131.                 <?php endif; ?>
  132.                
  133.                 <div onclick="updatemap('all')" class="total_maps" id="total_maps">
  134.                        <?php echo __('STORES'); ?>
  135.                 </div>
  136.                
  137.                 <div class="clear"></div>
  138.             </div>    
  139.            
  140.            
  141.             <!------------------------------>          
  142.                 <div class="filter-select" style="display:none;">                  
  143.                     <div class="">
  144.                     <dl id="narrow-by-list">
  145.                         <dd class="odd" style="display: none;">
  146.                         <select id="region" class="selectBox" onchange="updatemap('region')">
  147.                             <option value=""><?php echo $this->__('SELECT A DISTRICT'); ?></option>
  148.                          
  149.                            
  150.                        
  151.                         </select>
  152.                         </dd>
  153.                         <dd class="odd" style="display: none;">
  154.                         <select id="store" class="selectBox" onchange="updatemap('store')">
  155.                             <option value=""><?php echo $this->__('CHOOSE A STORE'); ?></option>
  156.                             <?php $Storelatlong = array();$newStorelatlong = array();
  157.                             $i=0;$j=-1;
  158.                             foreach($Stores as $Store):
  159.                             $Storelatlong[]='('.$Store['latitude'].','.$Store['longitude'].')';
  160.                             if($i++%25 == 0){
  161.                                 $j++;
  162.                             }
  163.                             $newStorelatlong[$j][]='('.$Store['latitude'].','.$Store['longitude'].')';
  164.                             ?>
  165.                             <option value="<?php echo $Store['store_name'] ;?>"><?php echo $Store['store_name']; ?></option>
  166.                             <?php endforeach;?>
  167.                         </select>
  168.                         </dd>
  169.                         <dd class="odd" style="display: none;">
  170.                             <input  type="text" class="input-text" onkeypress="return MalikScript(event)" id="postcode" name="postcode" style="width:170px; float:left; padding-left:10px;" value="Enter the Postal Code" onfocus="if (this.value == 'Enter the Postal Code') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Enter the Postal Code';}"  title="Enter the Postal Code"/>
  171.                             <img id="flag_image" src="<?php echo $this->getSkinUrl('images/gmapstrlocator/mapserchbutton.png')?>" onmouseover="this.src='<?php echo $this->getSkinUrl('images/gmapstrlocator/mapserchbutton_over.png')?>'" onmouseout="this.src='<?php echo $this->getSkinUrl('images/gmapstrlocator/mapserchbutton.png')?>'"  style="margin-left: -1px; cursor:pointer;" onclick="validatepost(this.value);"/>
  172.                         </dd>
  173.                         <dd class="odd" >
  174.                             <input  type="text" class="input-text" onkeypress="return MalikScript(event)" id="s_address" name="s_address" style="width:170px; float:left; padding-left:10px;" value="Enter Address" onfocus="if (this.value == 'Enter Address') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Enter Address';}"  title="Enter Address"/>
  175.                             <img id="flag_image" src="<?php echo $this->getSkinUrl('images/gmapstrlocator/mapserchbutton.png')?>" onmouseover="this.src='<?php echo $this->getSkinUrl('images/gmapstrlocator/mapserchbutton_over.png')?>'" onmouseout="this.src='<?php echo $this->getSkinUrl('images/gmapstrlocator/mapserchbutton.png')?>'"  style="margin-left: -1px; cursor:pointer;" onclick="validatepost(this.value);"/>
  176.                         </dd>
  177.                        
  178.                        
  179.                        
  180.                     </dl>
  181.                     </div>
  182.                     <div onclick="updatemap('all')" class="total_maps" id="total_maps">
  183.                         STORES
  184.                     </div>
  185.                 </div>
  186.                 <div class="resultado" id="result_map" style="display:none;">
  187.                     <h1><?php echo $this->__('Result:');?></h1>   <?php echo $this->__(' We found,');?> <span id='results_tal'><?php echo $this->__('25 Stores');?> </span><div id="result_over" style="float:right;display:none">&nbsp;<?php echo $this->__('near its');?> <span id='result_loc'><?php echo $this->__(' Location');?></span></div>
  188.                 </div>
  189.             <!------------------------------>
  190.            
  191.             <div class="store-container">
  192.                 <div class="modal-container">
  193.                     <div class="stores" >          
  194.                         <div id="scrollbar1">
  195.                             <div class="scrollbar">
  196.                               <div class="track">
  197.                             <div class="thumb">
  198.                               <div class="end"></div>
  199.                             </div>
  200.                               </div>
  201.                             </div>
  202.                        
  203.                             <div class="viewport">
  204.                             <div class="overview">
  205.                                 <div class="content" id="gmap-store-list">
  206.                                
  207.                                 <div class="store" id="gmap-notfound" style="display:none; border-bottom:none;"><p><?php echo __('Sorry Nothing found'); ?></p></div>
  208.                                
  209.                                 <?php $i=0; foreach($Stores as $s_value): ?>
  210.                                
  211.                                     <div class="store" id="<?php echo 'gmap-store-'.$s_value['gmapstrlocator_id'] ?>">
  212.                                    
  213.                                     <a href="javascript: " onclick="showFromList('<?php echo $s_value['gmapstrlocator_id'] ?>');" ><?php echo $s_value['store_name']; ?></a>
  214.                                     <p><?php echo $s_value['address']; ?><?php echo __(', '.$s_value['postal_code']); ?>, <?php echo $s_value['district']; ?><?php if($s_value['state']){ echo $this->__(', '.$s_value['state']); }  ?><?php echo ', '.$s_value['country']; ?> </p>
  215.                                     <p><?php if($s_value['store_phone'] != '') { echo __('Phone: '); echo $s_value['store_phone']; }?><?php if($s_value['store_fax'] != ''){ echo __(', Fax: '); echo $s_value['store_fax']; } ?> </p>
  216.                                     <p id="<?php echo 'store_list_distance_'.$i; ?>">&nbsp;</p>
  217.                                     </div>
  218.                                
  219.                                 <?php  $i++; endforeach; ?>
  220.                            
  221.                                 </div>
  222.                             </div>
  223.                             </div>
  224.                        
  225.                        
  226.                         </div>
  227.                     </div>
  228.                    
  229.                     <div class="map">              
  230.                             <div id="map_canvas" style="height:550px;" ></div>
  231.                     </div>
  232.                 </div>
  233.             </div> 
  234.            
  235.            
  236.         </div>
  237.            
  238.         <div id="control"></div>
  239.        
  240.        
  241.        
  242.        
  243.     <script type="text/javascript">
  244.     var clientlat= '';
  245.     var clientlon='';
  246.     var marker, i;var map;
  247.     var locations = <?php echo json_encode($Stores); ?>;
  248.    
  249.     var Storelatlong =  <?php echo json_encode($Storelatlong); ?>;
  250.     var destinationIcon = '<?php echo $gmap_marker_image; ?>';
  251.     var geocoder;
  252.     var client_current_latlang='';
  253.     var stores_from_distances = [];
  254.     var search_markerArray = [];
  255.     <?php //if(count($newStorelatlong)>1): ?>
  256.     var totalStoreslatlong = <?php echo count($newStorelatlong); ?>;
  257.     var Storeslatlongarray = new Array();
  258.     <?php $i=0; foreach($newStorelatlong as $latlong): ?>
  259.      Storeslatlongarray[<?php echo $i; ?>] = <?php echo json_encode($latlong); ?>;
  260.     <?php $i++; endforeach; ?>
  261.     <?php  //endif; ?>
  262.     geocoder = new google.maps.Geocoder();
  263.    
  264.    
  265.    
  266.     var naddress;
  267.     var loc='';
  268.     var result_to = 0;
  269.     var shortest = new Array();
  270.     var distancecounter =1;
  271.         $('total_maps').update(locations.length + ' STORES');
  272.         if($('total_maps_top')) $('total_maps_top').update(locations.length);
  273.         updatemap('client');
  274.    
  275.        
  276.          
  277.     function calculateRoute(index) {
  278.         var stop = locations[index]['latitude'] + ',' + locations[index]['longitude'];
  279.         var start = clientlat + ',' + clientlon;
  280.        
  281.         if(!clientlat){
  282.             updatemap('all');
  283.             return;    
  284.         }
  285.         var map;
  286.         var directionsDisplay;
  287.         var directionsService;
  288.         var stepDisplay;
  289.         var markerArray = [];
  290.        
  291.         directionsService = new google.maps.DirectionsService();
  292.        
  293.        
  294.         /******  Standard Latitude and Longitude from Config  ********/
  295.        
  296.        
  297.           // Create a map and center it on Manhattan.
  298.           var portugal = new google.maps.LatLng(<?php echo $standard_lat; ?>,<?php echo $standard_long; ?>);
  299.           var myOptions = {
  300.             zoom: <?php echo Mage::helper('gmapstrlocator')->getGMapZoom(); ?>,
  301.             mapTypeId: google.maps.MapTypeId.ROADMAP,
  302.             center: portugal
  303.           }
  304.          
  305.          
  306.          
  307.           map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  308.        
  309.           // Create a renderer for directions and bind it to the map.
  310.           var rendererOptions = {
  311.             map: map
  312.           }
  313.           directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions)
  314.        
  315.           // Instantiate an info window to hold step text.
  316.           stepDisplay = new google.maps.InfoWindow();
  317.        
  318.                  // First, clear out any existing markerArray
  319.           // from previous calculations.
  320.           for (i = 0; i < markerArray.length; i++) {
  321.             markerArray[i].setMap(null);
  322.           }
  323.        
  324.         var request = {
  325.             origin:start,
  326.             destination:stop,
  327.             travelMode: google.maps.DirectionsTravelMode.DRIVING
  328.         };
  329.           // Route the directions and pass the response to a
  330.           // function to create markers for each step.
  331.           directionsService.route(request, function(response, status) {
  332.             if (status == google.maps.DirectionsStatus.OK) {
  333.               updateMessage(1 , locations[index]['district']);
  334.               directionsDisplay.setDirections(response);
  335.            
  336.             var route = response.routes[0];
  337.            
  338.             var     href = 'saddr=';
  339.                 href +=route.legs[0].start_address;
  340.                 href +='&daddr=';
  341.                 href +=locations[index]['postal_code'] + ' ' +locations[index]['district'] + ',' + locations[index]['country'];
  342.                 href +='&pw=2';
  343.             var nhref ='http://maps.google.com/maps?'+href;
  344.             var MainDiv = document.createElement('div');
  345.             var directinControl = new DirectionControl(MainDiv, map , nhref);
  346.              
  347.             MainDiv.index = 1;
  348.             map.controls[google.maps.ControlPosition.TOP_RIGHT].push(MainDiv);
  349.             }else{
  350.             updatemap('all');
  351.             return;
  352.           }
  353.           });
  354.        
  355.     }
  356.     function DirectionControl(maincontrolDiv, map , href) {
  357.  
  358.         maincontrolDiv.style.padding = '5px';
  359.          
  360.         var directioncontrolUI = document.createElement('div');
  361.         directioncontrolUI.style.backgroundColor = 'white';
  362.         directioncontrolUI.style.borderStyle = 'solid';
  363.         directioncontrolUI.style.borderWidth = '1px';
  364.         directioncontrolUI.style.cursor = 'pointer';
  365.         directioncontrolUI.style.textAlign = 'center';
  366.         directioncontrolUI.title = 'Click here to print directions';
  367.         maincontrolDiv.appendChild(directioncontrolUI);
  368.          
  369.         var controlText = document.createElement('div');
  370.         controlText.style.fontFamily = 'Arial,sans-serif';
  371.         controlText.style.fontSize = '12px';
  372.         controlText.style.padding = '2px 4px';
  373.         controlText.innerHTML = '<strong>Print directions<strong>';
  374.         directioncontrolUI.appendChild(controlText);
  375.          
  376.         google.maps.event.addDomListener(directioncontrolUI, 'click', function() {
  377.           window.open(href);
  378.         });
  379.     }
  380.    
  381.     function MalikScript(e) {
  382.         if (e.keyCode == 13) {
  383.           validatepost();
  384.             return false;
  385.         }
  386.     }
  387.    
  388.     //search by address, state, city, country
  389.     function validatepost() {
  390.         $('control').hide();
  391.        
  392.             var postcode =  document.getElementById('s_address').value;
  393.             if(postcode == ''){
  394.                 alert('Address Required');
  395.                 return false;
  396.             }
  397.            
  398.             //alert(postcode);
  399.             //concate country there
  400.             var paddress = postcode;  
  401.             var locate;
  402.             var result_to=0;
  403.             var  pgeocoder = new google.maps.Geocoder();
  404.             $('result_over').hide();
  405.             initialize();
  406.             var loc='';
  407.             var j;
  408.             var isexact=false;
  409.             jQuery('#gmap-store-list div').each(function(){
  410.                         this.hide();                       
  411.             });
  412.             for (j = 0; j < locations.length; j++) {
  413.                 var latlng = new google.maps.LatLng(locations[j]['latitude'], locations[j]['longitude']);
  414.                
  415.                 var curr_state = locations[j]['state'];
  416.                 if(curr_state != null){
  417.                    
  418.                     if((locations[j]['address'].toLowerCase().search(paddress.toLowerCase()) >= 0) || (locations[j]['state'].toLowerCase().search(paddress.toLowerCase()) >= 0))
  419.                     {
  420.                        
  421.                         isexact=true;
  422.                         loc = locations[j]['district'];
  423.                         result_to++;
  424.                         creatmarkers(latlng , j, map , locations[j]);
  425.                         map.setCenter(latlng);
  426.                         map.setZoom(12); <?php //echo Mage::helper('gmapstrlocator')->getGMapZoom(); ?>
  427.                                                
  428.                        
  429.                         jQuery('#gmap-store-'+locations[j]['gmapstrlocator_id']).show();
  430.                     }
  431.                 }else{
  432.                    
  433.                     if((locations[j]['address'].toLowerCase().search(paddress.toLowerCase()) >= 0))
  434.                     {
  435.                        
  436.                         isexact=true;
  437.                         loc = locations[j]['district'];
  438.                         result_to++;
  439.                         creatmarkers(latlng , j, map , locations[j]);
  440.                         map.setCenter(latlng);
  441.                         map.setZoom(12); <?php //echo Mage::helper('gmapstrlocator')->getGMapZoom(); ?>
  442.                                                
  443.                        
  444.                         jQuery('#gmap-store-'+locations[j]['gmapstrlocator_id']).show();
  445.                     }
  446.                    
  447.                    
  448.                 }
  449.             }
  450.             if(!isexact){
  451.                
  452.                 isexact=false;
  453.                 //checkpost(paddress);
  454.                 <?php if(Mage::helper('gmapstrlocator')->getGMapNearestAddressEnabled()):?>
  455.                 checkpost(paddress);
  456.                 <?php else: ?>
  457.                 jQuery('#gmap-notfound').show();
  458.                 map.setCenter(new google.maps.LatLng(<?php echo $standard_lat; ?>,<?php echo $standard_long; ?>));
  459.                 map.setZoom(<?php echo Mage::helper('gmapstrlocator')->getGMapZoom(); ?>);
  460.                 <?php endif; ?>
  461.                
  462.             }
  463.             //updateMessage(result_to , loc);
  464.         //}
  465.        
  466.         jQuery('#scrollbar1').tinyscrollbar_update();
  467.     }
  468.    
  469.    
  470.     function searchbyzipcode() {
  471.        
  472.         $('control').hide();
  473.            
  474.            
  475.             //checkpost();
  476.             var postcode =  document.getElementById('zipcode_address').value;
  477.             if(postcode == ''){
  478.                 alert('Zip Code Required');
  479.                 return false;
  480.             }
  481.            
  482.             //alert(postcode);
  483.             //concate country there
  484.             var paddress = postcode;  
  485.             var locate;
  486.             var result_to=0;
  487.             var  pgeocoder = new google.maps.Geocoder();
  488.             $('result_over').hide();
  489.             initialize();
  490.             var loc='';
  491.             var j;
  492.             var isexact=false;
  493.             jQuery('#gmap-store-list div').each(function(){
  494.                         this.hide();                       
  495.             });
  496.             for (j = 0; j < locations.length; j++) {
  497.                 var latlng = new google.maps.LatLng(locations[j]['latitude'], locations[j]['longitude']);
  498.                
  499.                 //Client custom work
  500.                 //var current_store_dis = parseFloat(stores_from_distances[j].replace(/\,/g,''));
  501.                 //current_store_dis < 96.56
  502.                
  503.                 if(locations[j]['postal_code'].toLowerCase().search(paddress.toLowerCase()) >= 0){
  504.                    
  505.                    
  506.                     isexact=true;
  507.                     loc = locations[j]['district'];
  508.                     result_to++;
  509.                     creatmarkers(latlng , j, map , locations[j]);
  510.                     map.setCenter(latlng);
  511.                     map.setZoom(12); <?php //echo Mage::helper('gmapstrlocator')->getGMapZoom(); ?>
  512.                     jQuery('#gmap-notfound').hide();
  513.                     jQuery('#gmap-store-'+locations[j]['gmapstrlocator_id']).show();
  514.                    
  515.                    
  516.                 }
  517.             }
  518.             if(!isexact){
  519.                
  520.                 isexact=false;
  521.                 <?php if(Mage::helper('gmapstrlocator')->getGMapNearestZipEnabled()):?>
  522.                 checkpost(paddress);
  523.                 <?php else: ?>
  524.                 jQuery('#gmap-notfound').show();
  525.                 map.setCenter(new google.maps.LatLng(<?php echo $standard_lat; ?>,<?php echo $standard_long; ?>));
  526.                 map.setZoom(<?php echo Mage::helper('gmapstrlocator')->getGMapZoom(); ?>);
  527.                 <?php endif; ?>
  528.             }
  529.             //updateMessage(result_to , loc);
  530.         //}
  531.        
  532.         jQuery('#scrollbar1').tinyscrollbar_update();
  533.     }
  534.    
  535.    
  536.    
  537.    
  538.    
  539.     function initialize() {
  540.        
  541.         var opts = {
  542.             //zoom: 6,
  543.             //center: new google.maps.LatLng(40, -5),
  544.             mapTypeId: google.maps.MapTypeId.ROADMAP
  545.         };
  546.         map = new google.maps.Map(document.getElementById('map_canvas'), opts);
  547.                  
  548.     }
  549.    
  550.     function checkpost(paddress) {
  551.         shortest = new Array();
  552.         distancecounter =1;
  553.         var  pgeocoder = new google.maps.Geocoder();
  554.         pgeocoder.geocode( { 'address': paddress}, function(results, status) {
  555.                 if (status == google.maps.GeocoderStatus.OK) {
  556.                     locate = results[0].geometry.location;
  557.                     //alert(locate);
  558.                     checkdistance(locate, Storeslatlongarray[0]);
  559.                    
  560.                 }
  561.         });
  562.        
  563.     }
  564.     function checkdistance(start, stop){
  565.         var service = new google.maps.DistanceMatrixService();
  566.         service.getDistanceMatrix(
  567.           {
  568.             origins: [start],
  569.             destinations: stop,
  570.             travelMode: google.maps.TravelMode.DRIVING,
  571.             avoidHighways: false,
  572.             avoidTolls: false
  573.           }, getdistance);
  574.        
  575.          
  576.     }
  577.    
  578.     function getdistance(response, status) {
  579.         if (status != google.maps.DistanceMatrixStatus.OK) {
  580.             updatemap('all');
  581.             return false;
  582.         } else {
  583.             var origins = response.originAddresses;
  584.             var destinations = response.destinationAddresses;
  585.             var distances = [];
  586.             for (var i = 0; i < origins.length; i++) {
  587.                 var results = response.rows[i].elements;
  588.                 for (var j = 0; j < results.length; j++) {
  589.                     if(results[j].distance != undefined){
  590.                        
  591.                         distances[j]=parseFloat(results[j].distance.text.replace("km", "").replace(/\,/g,'')); //reg exp removes the thousand seperator
  592.                        
  593.                         //alert(distances[j]);
  594.                     }
  595.                 }
  596.             }
  597.            
  598.             var ni=distances.indexOf(distances.min());
  599.            
  600.            
  601.             if(locations[ni] != undefined){
  602.                 if(totalStoreslatlong == 1){
  603.                     jQuery('#gmap-store-list div').each(function(){
  604.                     this.hide();                       
  605.                     });                    
  606.                      
  607.                     jQuery('#gmap-store-'+locations[ni]['gmapstrlocator_id']).show();          
  608.                     var nlatlng =new google.maps.LatLng(locations[ni]['latitude'], locations[ni]['longitude']);                    
  609.                     addNewMark(nlatlng , ni);
  610.                 }else{
  611.                
  612.                 if(distancecounter < totalStoreslatlong){
  613.                     shortest[distancecounter - 1]=Storeslatlongarray[distancecounter - 1][ni];
  614.                     checkdistance(locate, Storeslatlongarray[distancecounter]);
  615.                     distancecounter = distancecounter + 1;
  616.                    
  617.                 }else{
  618.                     if(distancecounter == totalStoreslatlong){
  619.                     shortest[distancecounter-1]=Storeslatlongarray[distancecounter-1][ni];
  620.                     distancecounter = distancecounter + 1;
  621.                     checkdistance(locate, shortest);
  622.                     }else{
  623.                     var pointer='';
  624.                     for( var i = 0, len = locations.length; i < len; i++ ) {
  625.                         var nlatlng ="(" +locations[i]['latitude'] + "," + locations[i]['longitude'] + ")";
  626.                         if( nlatlng == shortest[ni] ) {
  627.                         pointer = i;
  628.                         break;
  629.                         }
  630.                     }
  631.                     jQuery('#gmap-store-list div').each(function(){
  632.                         this.hide();                       
  633.                     });                    
  634.                      
  635.                     jQuery('#gmap-store-'+locations[pointer]['gmapstrlocator_id']).show();         
  636.                     var nlatlng =new google.maps.LatLng(locations[pointer]['latitude'], locations[pointer]['longitude']);                      
  637.                     addNewMark(nlatlng , pointer);
  638.                     }
  639.                 }
  640.                 }
  641.             }
  642.             return false;
  643.         }
  644.     }
  645.  
  646.     function addNewMark(method , ni){
  647.         result_to = 0;
  648.         var opts = {
  649.               zoom: <?php echo Mage::helper('gmapstrlocator')->getGMapZoom(); ?>,
  650.               center: method,
  651.           mapTypeId: google.maps.MapTypeId.ROADMAP
  652.         };
  653.         map = new google.maps.Map(document.getElementById('map_canvas'), opts);
  654.         creatmarkers(method , ni, map , locations[ni]);
  655.         result_to++;
  656.         loc = locations[ni]['district'];
  657.         updateMessage(result_to , loc);
  658.     }
  659.    
  660.     function updateByAddress(){
  661.        
  662.        
  663.     }
  664.    
  665.    
  666.     function showFromList(store_id){
  667.        
  668.         initialize();
  669.        
  670.         for (i = 0; i < locations.length; i++) {
  671.            
  672.             if(store_id == locations[i]['gmapstrlocator_id']){
  673.             loc = locations[i]['district'];
  674.            
  675.             var latlng = new google.maps.LatLng(locations[i]['latitude'], locations[i]['longitude']);
  676.            
  677.                    
  678.             creatmarkers(latlng , i, map , locations[i]);
  679.             map.setCenter(new google.maps.LatLng(locations[i]['latitude'], locations[i]['longitude']));
  680.             map.setZoom(12); <?php //echo Mage::helper('gmapstrlocator')->getGMapZoom(); ?>
  681.             }
  682.            
  683.         }
  684.     }
  685.    
  686.    
  687.     function updatemap(method){
  688.         $('control').hide();
  689.         $('result_over').hide();
  690.         initialize();
  691.        
  692.         result_to=0;
  693.        
  694.         for (i = 0; i < locations.length; i++) {
  695.             var region = document.getElementById('region').value;
  696.             var store =  document.getElementById('store').value;
  697.             var postcode =  document.getElementById('postcode').value;
  698.             var latlng = new google.maps.LatLng(locations[i]['latitude'], locations[i]['longitude']);
  699.            
  700.            
  701.            
  702.             if(region !='' && method == 'region' || (region !='' && method == 'store' && store == '' )){
  703.                 if(region == locations[i]['district']){
  704.                     loc = region;
  705.                     result_to++;
  706.                     creatmarkers(latlng , i, map , locations[i]);
  707.                 }
  708.                 naddress = region + ',' + locations[i]['country'];
  709.                 geocoder.geocode( { 'address': naddress}, function(results, status) {
  710.                     if (status == google.maps.GeocoderStatus.OK) {
  711.                       map.setCenter(results['store_name'].geometry.location);
  712.                       map.setZoom(<?php echo Mage::helper('gmapstrlocator')->getGMapZoom(); ?>);
  713.                      
  714.                     }
  715.                 });
  716.             }else if((store !='' && method == 'store') || (store !='' && method == 'region' && region == '' )){
  717.                 if(store == locations[i]['store_name']){
  718.                     loc = locations[i]['district'];
  719.                     result_to++;
  720.                    
  721.                     jQuery('#gmap-store-list div').each(function(){
  722.                         this.hide();                       
  723.                     });
  724.                    
  725.                     jQuery('#gmap-store-'+locations[i]['gmapstrlocator_id']).show();                   
  726.                    
  727.                     creatmarkers(latlng , i, map , locations[i]);
  728.                     map.setCenter(new google.maps.LatLng(locations[i]['latitude'], locations[i]['longitude']));
  729.                     map.setZoom(<?php echo Mage::helper('gmapstrlocator')->getGMapZoom(); ?>);
  730.                 }
  731.            
  732.             }else if(method == 'by_name'){
  733.                
  734.                 if(store == locations[i]['store_name']){
  735.                     loc = locations[i]['district'];
  736.                     result_to++;
  737.                     creatmarkers(latlng , i, map , locations[i]);
  738.                     map.setCenter(new google.maps.LatLng(locations[i]['latitude'], locations[i]['longitude']));
  739.                     map.setZoom(12); <?php // echo Mage::helper('gmapstrlocator')->getGMapZoom(); ?>
  740.                    
  741.                 }
  742.                
  743.                
  744.             }else if(method == 'client'){
  745.                    
  746.                            
  747.                     jQuery('#map_canvas').gmap({ 'zoom':<?php echo Mage::helper('gmapstrlocator')->getGMapZoom(); ?>,'center':new google.maps.LatLng(<?php echo $standard_lat; ?>,<?php echo $standard_long; ?>), 'callback': function() {
  748.                     updatemap('all');
  749.                     var self = this;
  750.                     self.getCurrentPosition(function(position, status) {
  751.                         if ( status === 'OK' ) {
  752.                             clientlat = position.coords.latitude;
  753.                             clientlon = position.coords.longitude;
  754.                             var clientlatlng = new google.maps.LatLng(clientlat, clientlon);
  755.                            
  756.                             setCurrentPositionOfClient(clientlatlng);
  757.                             findDistanceFromClientToStores();
  758.                            
  759.                             geocoder.geocode({'latLng': clientlatlng}, function(results, status) {
  760.                              
  761.                               if (status == google.maps.GeocoderStatus.OK) {
  762.                                 if (results[1]) {
  763.                                
  764.                                   checkpost(results[1].formatted_address);
  765.                                 }
  766.                               }
  767.                             });
  768.                         }
  769.                     });
  770.                    
  771.                     }});
  772.                
  773.                
  774.                
  775.                 break;
  776.             }
  777.             else{
  778.                
  779.                 jQuery('#gmap-store-list div').each(function(){
  780.                         this.show();                           
  781.                 });
  782.                 jQuery('#gmap-notfound').hide();
  783.                 result_to++;
  784.                 map.setCenter(new google.maps.LatLng(<?php echo $standard_lat; ?>,<?php echo $standard_long; ?>));
  785.                 map.setZoom(<?php echo Mage::helper('gmapstrlocator')->getGMapZoom(); ?>);
  786.                 creatmarkers(latlng , i, map , locations[i]);
  787.             }
  788.            
  789.            
  790.         }
  791.        
  792.         jQuery('#scrollbar1').tinyscrollbar();
  793.         jQuery('#scrollbar1').tinyscrollbar_update();
  794.        
  795.         updateMessage(result_to , loc);
  796.        
  797.        
  798.     }
  799.    
  800.    
  801.     function updateMessage(result_to , loc) {
  802.         $('results_tal').update(result_to+' Store ');
  803.         if(loc !=''){
  804.             $('result_over').show();
  805.             $('result_loc').update('Location ('+loc+')');  
  806.         }else{
  807.             $('result_over').hide();
  808.         }
  809.         return;
  810.     }
  811.    
  812.     //--------------------------------------------------------
  813.     //Current position of client
  814.     function setCurrentPositionOfClient(client_latlang){
  815.            
  816.         client_current_latlang = client_latlang;
  817.        
  818.     }
  819.    
  820.     function getCurrentPositionOfClient(){
  821.        
  822.         return client_current_latlang;
  823.     }
  824.    
  825.     function findDistanceFromClientToStores(){
  826.        
  827.        
  828.         var service = new google.maps.DistanceMatrixService();
  829.         service.getDistanceMatrix(
  830.           {
  831.             origins: [client_current_latlang],
  832.             destinations: Storelatlong,
  833.             travelMode: google.maps.TravelMode.DRIVING,
  834.             avoidHighways: false,
  835.             avoidTolls: false
  836.           }, calculatedistance);
  837.        
  838.        
  839.        
  840.     }
  841.     function calculatedistance(response, status) {
  842.         if (status != google.maps.DistanceMatrixStatus.OK) {
  843.             return false;
  844.         } else {
  845.             var origins = response.originAddresses;
  846.             var destinations = response.destinationAddresses;
  847.            
  848.             var distances = [0];
  849.             for (var i = 0; i < origins.length; i++) {
  850.                 var results = response.rows[i].elements;
  851.                 for (var j = 0; j < results.length; j++) {
  852.                    
  853.                     if(results[j].distance != undefined){
  854.                        
  855.                         distances[j]=results[j].distance.text;
  856.                         stores_from_distances[j] = distances[j];
  857.                    
  858.                    
  859.                         //Update/add the distance to leftbar list of stores
  860.                         if($('store_list_distance_'+j))
  861.                         {$('store_list_distance_'+j).update('Distance : '+stores_from_distances[j]);}
  862.                         //alert(stores_from_distances[j]);
  863.                     }
  864.                 }
  865.             }
  866.            
  867.            
  868.            
  869.             return false;
  870.         }
  871.        
  872.     }
  873.    
  874.    
  875.    
  876.     //-----------------------------------------------------
  877.    
  878.    
  879.     function creatmarkers(latlng , i, map , description) {
  880.         marker = new google.maps.Marker({
  881.               position: latlng,
  882.               icon:destinationIcon,
  883.               map: map
  884.             });
  885.        
  886.         search_markerArray.push(marker);
  887.        
  888.         google.maps.event.addListener(marker, 'click', (function(marker, i) {
  889.             return function() {
  890.                 var boxText ="";
  891.                 var s_distance = "";
  892.                 var s_image = "";
  893.                 var s_phone = '';
  894.                 var s_fax = '';
  895.                 var s_state= ',';
  896.                
  897.                 if(stores_from_distances[i])
  898.                     s_distance = '<span><b>Distance : </b> '+stores_from_distances[i]+'</span>';
  899.                
  900.                 if(description['store_image']){
  901.                     s_image_path = "<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'gmapstrlocator/' ?>";
  902.                     s_image_path = s_image_path+description['gmapstrlocator_id']+'/thumb/'+description['store_image'];
  903.                     s_image = "<div class='store-thumb'><img src='"+s_image_path+"'></div>";
  904.                 }
  905.                 if(description['store_phone'] != ''){
  906.                     s_phone = '<span><b><?php echo __('Phone:  '); ?></b></span> '+ description['store_phone']+'<br />';
  907.                 }
  908.                 if(description['store_fax'] != ''){
  909.                     s_fax = '<span><b><?php echo __('Fax:  '); ?></b></span> '+ description['store_fax']+'<br />';
  910.                 }
  911.                 if(description['state'] == '' || description['state'] == null){
  912.                     s_state = ', ';
  913.                 }else{
  914.                     s_state = ', '+ description['state']+',';                  
  915.                 }
  916.                
  917.                
  918.                 boxText = document.createElement("div");
  919.                 boxText.innerHTML ='<div id="pop_div" class="map_popup_top1"><h1>'+description['store_name']+'</h1>'+ description['store_description'] + '<div class="store-more-info">'+s_phone+s_fax+'<span><b><?php echo __('Address:  '); ?></b></span> '+ description['address'] +', '+ description['postal_code']+', '+ description['district']+s_state+ description['country']+'<br />'+s_distance+'</div>'+s_image+'<div class="getting_directions"><div class="clear"></div><a onClick="calculateRoute('+ i +')" href="#"><?php echo $direction_button_text; ?></a></div></div>';
  920.                 var box = boxText.innerHTML + '<div class="map_popup_bottom"><img src="<?php echo $popup_secondary_image; ?>" alt="" width="290px;" /></div>';
  921.                
  922.                 var myOptions = {
  923.                     content: box
  924.                     ,disableAutoPan: false
  925.                     ,maxWidth: 0
  926.                     ,pixelOffset: new google.maps.Size(0, -290)
  927.                     ,zIndex: null
  928.                     ,boxStyle: {
  929.                         background: "url('<?php echo $this->getSkinUrl('images/gmapstrlocator/map_popup_top.png')?>') no-repeat"
  930.                         ,opacity: 1
  931.                         ,width: "295px"
  932.                         ,height:"170px"
  933.                     }
  934.                     ,closeBoxMargin: "-13px -5px 2px"
  935.                     ,closeBoxURL: "<?php echo $this->getSkinUrl('images/gmapstrlocator/close_black.png')?>"
  936.                     ,close_onmouseover :"<?php echo $this->getSkinUrl('images/gmapstrlocator/close_icon.png')?>"
  937.                     ,close_onmouseout :"<?php echo $this->getSkinUrl('images/gmapstrlocator/close_black.png')?>"
  938.                     ,infoBoxClearance: new google.maps.Size(1, 1)
  939.                     ,isHidden: false
  940.                     ,pane: "floatPane"
  941.                     ,enableEventPropagation: true
  942.                 };
  943.                 var ib = new InfoBox(myOptions);
  944.                 ib.open(map, marker);
  945.             }
  946.         })(marker, i));
  947.  
  948.     }
  949.    
  950.     //----Search Stores By Product -----------------------------------------------------
  951.    
  952.     function searchByProducts(){
  953.        
  954.         var search_text = jQuery('#prod_search').val();
  955.         if(search_text == '' || search_text == null){
  956.        
  957.         alert('Search Contents Required');
  958.         return false;      
  959.         }else{
  960.        
  961.         //send the ajax call to index controller
  962.        
  963.         jQuery.ajax({
  964.             type: "POST",
  965.             url: "<?php echo $this->getUrl('gmapstrlocator/index/searchprod'); ?>",
  966.             data: { query_string: search_text },
  967.             dataType: "json",
  968.             success: function(data) {
  969.                            
  970.                //alert(data);
  971.                showStoresByLatLang(data);
  972.               }
  973.               });
  974.        
  975.         }      
  976.        
  977.     }
  978.    
  979.    
  980.     function showStoresByLatLang(arr){
  981.        
  982.         var is_matched = false;
  983.        
  984.         //Remove all stores from list
  985.         jQuery('#gmap-store-list div').each(function(){
  986.        
  987.         this.hide();       
  988.        
  989.         });
  990.        
  991.        
  992.        //Remove existing markers
  993.        
  994.        for(var k=0; k<search_markerArray.length; k++){
  995.        
  996.         search_markerArray[k].setMap(null);
  997.        }
  998.        
  999.        
  1000.        
  1001.         for(var i=0; i<arr.length; i++){
  1002.        
  1003.        
  1004.         for (j = 0; j < locations.length; j++) {
  1005.                
  1006.                 var cur_latlang = arr[i]['latitude']+','+arr[i]['longitude'];
  1007.                 var s_latlang = locations[j]['latitude']+','+locations[j]['longitude'];
  1008.                
  1009.                
  1010.                 var latlng = new google.maps.LatLng(locations[j]['latitude'], locations[j]['longitude']);
  1011.                 if(cur_latlang == s_latlang){
  1012.                    
  1013.                     is_matched = true;
  1014.                     jQuery('#gmap-notfound').hide();
  1015.                     jQuery('#gmap-store-'+arr[i]['gmapstrlocator_id']).show();
  1016.                     loc = latlng;
  1017.                     result_to++;
  1018.                     creatmarkers(latlng , j, map , locations[j]);
  1019.                     map.setCenter(latlng);
  1020.                     map.setZoom(12); <?php //echo Mage::helper('gmapstrlocator')->getGMapZoom(); ?>
  1021.                    
  1022.                 }
  1023.         }
  1024.        
  1025.         }
  1026.        
  1027.         if(is_matched == false){
  1028.        
  1029.         jQuery('#gmap-notfound').show();
  1030.        
  1031.         }
  1032.        
  1033.        
  1034.         jQuery('#scrollbar1').tinyscrollbar_update();
  1035.     }
  1036.    
  1037.    
  1038.    
  1039.    
  1040.    
  1041.         </script>
  1042. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement