SZGoogleModuleMaps

The SZ - Google SZGoogleModuleMaps class.

Defined (1)

The class is defined in the following location(s).

/classes/module/SZGoogleModuleMaps.php  
  1. class SZGoogleModuleMaps extends SZGoogleModule 
  2. private $setJavascriptMaps = false; 
  3. private $setJavascriptOptions = array(); 
  4.  
  5. /** 
  6. * Definition of the initial variable array which are 
  7. * used to identify the module and options related to it 
  8. */ 
  9.  
  10. function moduleAddSetup() 
  11. $this->moduleSetClassName(__CLASS__); 
  12. $this->moduleSetOptionSet('sz_google_options_maps'); 
  13.  
  14. // Definition shortcode connected to the module with an array where you 
  15. // have to specify the name activation option with the shortcode and function 
  16.  
  17. $this->moduleSetShortcodes(array( 
  18. 'maps_s_enable' => array('sz-maps', array(new SZGoogleActionMaps(), 'getShortcode')),  
  19. )); 
  20.  
  21. // Definition widgets connected to the module with an array where you 
  22. // have to specify the name option of activating and class to be loaded 
  23.  
  24. $this->moduleSetWidgets(array( 
  25. 'maps_w_enable' => 'SZGoogleWidgetMaps',  
  26. )); 
  27.  
  28. /** 
  29. * Add the Javascript code in the various components 
  30. * of google plus footer and if control was performed 
  31. */ 
  32.  
  33. function addCodeJavascriptFooter($options=array()) 
  34. if (is_array($options) and !empty($options)) { 
  35. $this->setJavascriptOptions[] = (object) $options; 
  36.  
  37. // If you've already entered the Javascript code in the footer section 
  38. // I leave the function otherwise set the variable and constant 
  39.  
  40. if ($this->setJavascriptMaps) return; 
  41. else $this->setJavascriptMaps = true; 
  42.  
  43. // Loading action in the footer of the plugin to load 
  44. // the javascript framework made available by google 
  45.  
  46. add_action('SZ_FOOT', array($this, 'setJavascriptMaps')); 
  47.  
  48. /** 
  49. * Function to add javascript code in the footer of wordpress 
  50. * with asynchronous loading method according to google 
  51. */ 
  52.  
  53. function setJavascriptMaps() 
  54. // If you've already entered the Javascript code in the footer section 
  55. // leave the partition function otherwise the variable and constant 
  56.  
  57. if (self::$JavascriptMaps) return; 
  58. else self::$JavascriptMaps = true; 
  59.  
  60. // Definition of parameters to be passed to  
  61. // the javascript framework of google maps 
  62.  
  63. $parameters = 'v3=&callback=szgooglemapsinit'; 
  64.  
  65. // Check if instance of google maps is active otherwise 
  66. // insert the code without customization parameters 
  67.  
  68. if ($object = self::getObject('SZGoogleModuleMaps'))  
  69. $options = (object) $object->getOptions(); 
  70.  
  71. if ($options->maps_key != '' ) $parameters .= '&key='.$options->maps_key; 
  72. if ($options->maps_signin == '1') $parameters .= '&signed_in=true'; 
  73. if ($options->maps_sensor == '1') $parameters .= '&sensor=true'; 
  74.  
  75. if ($options->maps_language == '99') $parameters .= '&language='.substr(get_bloginfo('language'), 0, 2); 
  76. else $parameters .= '&language='.$options->maps_language; 
  77.  
  78. // Correct image for google maps when img present in 
  79. // webiste and have a CSS width max-image=100% (hack) 
  80.  
  81. $javascript = '<style>'; 
  82. $javascript .= '.sz-google-maps img { max-width:none } '; 
  83. $javascript .= '.sz-google-maps label { width:auto; display:inline }'; 
  84. $javascript .= '</style>'."\n"; 
  85.  
  86. // Javascript code to render the component google 
  87. // this method is used for asynchronous loading 
  88.  
  89. $javascript .= '<script>'; 
  90. $javascript .= 'function szgooglemapsinit() {'; 
  91.  
  92. // Creating Javascript code dynamically based on the number of available maps 
  93. // For each map is created by a unique key identification to allow more maps 
  94.  
  95. if (isset($this->setJavascriptOptions) and is_array($this->setJavascriptOptions))  
  96. foreach ($this->setJavascriptOptions as $key => $value)  
  97. if (is_object($value) and isset($value->idHTML))  
  98. // Check field for options map and convert value 
  99. // for javascript syntax in options array  
  100.  
  101. if ($value->wheel == '1') $value->wheel = 'true'; 
  102. else $value->wheel = 'false'; 
  103.  
  104. // Javascript code to render the component google 
  105. // maps with multiple division maps in the page 
  106.  
  107. $javascript .= 'var map_opt_'.$value->unique.' = {'; 
  108. $javascript .= 'zoom:'.$value->zoom.', '; 
  109. $javascript .= 'scrollwheel:'.$value->wheel.', '; 
  110. $javascript .= 'panControl:true, '; 
  111. $javascript .= 'zoomControl:true, '; 
  112. $javascript .= 'mapTypeControl:true, '; 
  113. $javascript .= 'scaleControl:true, '; 
  114. $javascript .= 'streetViewControl:true, '; 
  115. $javascript .= 'overviewMapControl:true, '; 
  116. $javascript .= "center:new google.maps.LatLng('".$value->lat."', '".$value->lng."'), "; 
  117. $javascript .= 'mapTypeId:google.maps.MapTypeId.'.$value->view; 
  118. $javascript .= '};'; 
  119.  
  120. $javascript .= "if(document.getElementById('".$value->idHTML."') != null && document.getElementById('".$value->idHTML."') != undefined) {"; 
  121. $javascript .= "var map_key_".$value->unique." = "; 
  122. $javascript .= "new google.maps.Map(document.getElementById('".$value->idHTML."'), map_opt_".$value->unique.");"; 
  123. $javascript .= "}"; 
  124.  
  125. // Add the layer BICYCLE/TRAFFIC/TRANSIT to the map display 
  126. // Each map has a unique code that the layer must be associated 
  127.  
  128. if ($value->layer == 'BICYCLE') { 
  129. $javascript .= 'var layer_bicycle_'.$value->unique.' = new google.maps.BicyclingLayer();'; 
  130. $javascript .= 'layer_bicycle_'.$value->unique.'.setMap(map_key_'.$value->unique.');'; 
  131.  
  132. if ($value->layer == 'TRAFFIC') { 
  133. $javascript .= 'var layer_traffic_'.$value->unique.' = new google.maps.TrafficLayer();'; 
  134. $javascript .= 'layer_traffic_'.$value->unique.'.setMap(map_key_'.$value->unique.');'; 
  135.  
  136. if ($value->layer == 'TRANSIT') { 
  137. $javascript .= 'var layer_transit_'.$value->unique.' = new google.maps.TransitLayer();'; 
  138. $javascript .= 'layer_transit_'.$value->unique.'.setMap(map_key_'.$value->unique.');'; 
  139.  
  140. // Add marker to MAP if option is set = 1. Use same value for 
  141. // position in center map and option specified in LAT and LNG 
  142.  
  143. if ($value->marker == '1') { 
  144. $javascript .= 'var marker_'.$value->unique.' = new google.maps.Marker({'; 
  145. $javascript .= "position:new google.maps.LatLng('".$value->lat."', '".$value->lng."'), "; 
  146. $javascript .= 'map:map_key_'.$value->unique; 
  147. $javascript .= '});'; 
  148.  
  149. $javascript .= '}'; 
  150. $javascript .= '</script>'."\n"; 
  151.  
  152. // If exists JetPack and load google maps disable load 
  153. // the sz-google and add javascript for load my maps 
  154.  
  155. if (wp_script_is('google-maps', 'enqueued'))  
  156. wp_enqueue_script("sz-google-maps-js",  
  157. plugins_url('frontend/files/js/sz-google-maps.js', SZ_PLUGIN_GOOGLE_MAIN), array('google-maps')); 
  158.  
  159. } else { 
  160.  
  161. // Procedure Asynchronous loading of javascript code 
  162. // and the function is called for initial operations 
  163.  
  164. $javascript .= '<script>'; 
  165. $javascript .= 'function szgooglemapsload() {'; 
  166. $javascript .= "var script = document.createElement('script');"; 
  167. $javascript .= "script.type = 'text/javascript';"; 
  168. $javascript .= "script.src = 'https://maps.googleapis.com/maps/api/js?".$parameters."';"; 
  169. $javascript .= "document.body.appendChild(script);"; 
  170. $javascript .= '}'; 
  171. $javascript .= 'szgooglemapsload();'; 
  172. $javascript .= '</script>'."\n"; 
  173.  
  174. // Running echo on the footer of the javascript code generated 
  175. // This code is added to a single block together with other functions 
  176.  
  177. echo $javascript;