Advertisement
Guest User

Untitled

a guest
Oct 14th, 2017
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 90.47 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. /**
  4. * CodeIgniter Google Maps API V3 Class
  5. *
  6. * Displays a Google Map
  7. *
  8. * @package CodeIgniter
  9. * @subpackage Libraries
  10. * @category Libraries
  11. * @author BIOSTALL (Steve Marks)
  12. * @link http://biostall.com/codeigniter-google-maps-v3-api-library
  13. * @docs http://biostall.com/wp-content/uploads/2010/07/Google_Maps_V3_API_Documentation.pdf
  14. */
  15.  
  16. class Googlemaps {
  17.  
  18. var $adsense = FALSE; // Whether Google Adsense For Content should be enabled
  19. var $adsenseChannelNumber = ''; // The Adsense channel number for tracking the performance of this AdUnit
  20. var $adsenseFormat = 'HALF_BANNER'; // The format of the AdUnit
  21. var $adsensePosition = 'TOP_CENTER'; // The position of the AdUnit
  22. var $adsensePublisherID = ''; // Your Google AdSense publisher ID
  23. var $apiKey = ''; // If you've got an API key you can use it by passing this parameter. Setup an API key here: https://code.google.com/apis/console
  24. var $backgroundColor = ''; // A hex color value shown as the map background when tiles have not yet loaded as the user pans
  25. var $bicyclingOverlay = FALSE; // If set to TRUE will overlay bicycling information (ie. bike paths and suggested routes) onto the map by default
  26. var $center = "37.4419, -122.1419"; // Sets the default center location (lat/long co-ordinate or address) of the map. If defaulting to the users location set to "auto"
  27. var $class = ''; // A class name if wishing to style the map further through CSS. Can also be useful if wanting it to be responsive etc.
  28. var $cluster = FALSE; // Whether to cluster markers
  29. var $clusterGridSize = 60; // The grid size of a cluster in pixels
  30. var $clusterMaxZoom = ''; // The maximum zoom level that a marker can be part of a cluster
  31. var $clusterZoomOnClick = TRUE; // Whether the default behaviour of clicking on a cluster is to zoom into it
  32. var $clusterAverageCenter = FALSE; // Whether the center of each cluster should be the average of all markers in the cluster
  33. var $clusterMinimumClusterSize = 2; // The minimum number of markers to be in a cluster before the markers are hidden and a count is shown
  34. var $disableDefaultUI = FALSE; // If set to TRUE will hide the default controls (ie. zoom, scale etc)
  35. var $disableDoubleClickZoom = FALSE; // If set to TRUE will disable zooming when a double click occurs
  36. var $disableMapTypeControl = FALSE; // If set to TRUE will hide the MapType control (ie. Map, Satellite, Hybrid, Terrain)
  37. var $disableNavigationControl = FALSE; // If set to TRUE will hide the Navigation control (ie. zoom in/out, pan)
  38. var $disableScaleControl = FALSE; // If set to TRUE will hide the Scale control
  39. var $disableStreetViewControl = FALSE; // If set to TRUE will hide the Street View control
  40. var $draggable = TRUE; // If set to FALSE will prevent the map from being dragged around
  41. var $draggableCursor = ''; // The name or url of the cursor to display on a draggable object
  42. var $draggingCursor = ''; // The name or url of the cursor to display when an object is being dragged
  43. var $geocodeCaching = FALSE; // If set to TRUE will cache any geocode requests made when an address is used instead of a lat/long. Requires DB table to be created (see documentation)
  44. var $https = FALSE; // If set to TRUE will load the Google Maps JavaScript API over HTTPS, allowing you to utilize the API within your HTTPS secure application
  45. var $navigationControlPosition = ''; // The position of the Navigation control, eg. 'BOTTOM_RIGHT'
  46. var $infowindowMaxWidth = 0; // The maximum width of the infowindow in pixels. Expecting an integer without units
  47. var $keyboardShortcuts = TRUE; // If set to FALSE will disable to map being controlled via the keyboard
  48. var $jsfile = ''; // Set this to the path of an external JS file if you wish the JavaScript to be placed in a file rather than output directly into the <head></head> section. The library will try to create the file if it does not exist already. Please ensure the destination file is writeable
  49. var $kmlLayerURL = ''; // A URL to publicly available KML or GeoRSS data for displaying geographic information. Multiple KML layers can be passed in by using an array of URL's. Note, if using multiple you'll probably have to set $kmlLayerPreserveViewport to true and manually set map center and zoom
  50. var $kmlLayerPreserveViewport = FALSE; // Specifies whether the map should be adjusted to the bounds of the KmlLayer's contents. By default the map is zoomed and positioned to show the entirety of the layer's contents
  51. var $language = ''; // The map will by default load in the language of the browser. This can be overriden however here. For a full list of codes see https://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1
  52. var $loadAsynchronously = FALSE; // Load the map and API asynchronously once the page has loaded
  53. var $map_div_id = "map_canvas"; // The ID of the <div></div> that is output which contains the map
  54. var $map_height = "900px"; // The height of the map container. Any units (ie 'px') can be used. If no units are provided 'px' will be presumed
  55. var $map_name = "map"; // The JS reference to the map. Currently not used but to be used in the future when multiple maps are supported
  56. var $map_type = "HYBRID"; // The default MapType. Values accepted are 'HYBRID', 'ROADMAP', 'SATELLITE' or 'TERRAIN'
  57. var $map_types_available = array(); // The other MapTypes available for selection on the map
  58. var $map_width = "100%"; // The width of the map container. Any units (ie 'px') can be used. If no units are provided 'px' will be presumed
  59. var $maps_loaded = 0; // Counter which keeps track of how many maps have been created to avoid standard functions being output twice
  60. var $mapTypeControlPosition = ''; // The position of the MapType control, eg. 'BOTTOM_RIGHT'
  61. var $mapTypeControlStyle = ''; // The style of the MapType control. blank, 'DROPDOWN_MENU' or 'HORIZONTAL_BAR' values accepted.
  62. var $minzoom = ''; // The minimum zoom level which will be displayed on the map
  63. var $maxzoom = ''; // The maximum zoom level which will be displayed on the map
  64. var $minifyJS = FALSE; // If TRUE will run the JavaScript through Jsmin.php (this file and PHP5+ required) to minify the code
  65. var $noClear = FALSE; // If TRUE do not clear the contents of the map div
  66. var $onboundschanged = ''; // The JavaScript action to perform when the viewport bounds have changed
  67. var $oncenterchanged = ''; // The JavaScript action to perform when themap center property changes
  68. var $onclick = ''; // The JavaScript action to perform when the map is clicked
  69. var $ondblclick = ''; // The JavaScript action to perform when the map is double-clicked
  70. var $ondrag = ''; // The JavaScript action to perform while the map is dragged
  71. var $ondragend = ''; // The JavaScript action to perform when the user stops dragging the map
  72. var $ondragstart = ''; // The JavaScript action to perform when the user starts dragging the map
  73. var $onidle = ''; // The JavaScript action to perform when the map becomes idle after panning or zooming
  74. var $onload = ''; // The JavaScript action to perform when the map first loads. This library hi-jacks the window.load event so add any bespoke code using this option
  75. var $onmousemove = ''; // The JavaScript action to perform when the user's mouse moves over the map container
  76. var $onmouseout = ''; // The JavaScript action to perform when the user's mouse exits the map container
  77. var $onmouseover = ''; // The JavaScript action to perform when the user's mouse enters the map container
  78. var $onresize = ''; // The JavaScript action to perform when the maps div changes size
  79. var $onrightclick = ''; // The JavaScript action to perform when the map is right-clicked
  80. var $ontilesloaded = ''; // The JavaScript action to perform when the visible tiles have finished loading
  81. var $onzoomchanged = ''; // The JavaScript action to perform when the maps zoom property changes
  82. var $panoramio = FALSE; // If TRUE will add photos from Panoramio as a layer to your maps as a series of large and small photo icons
  83. var $panoramioTag = ''; // Restrict the set of Panoramio photos shown to those matching a certain textual tag
  84. var $panoramioUser = ''; // Restrict the set of Panoramio photos shown to those matching a particular user
  85. var $region = ''; // Country code top-level domain (eg "uk") within which to search. Useful if supplying addresses rather than lat/longs
  86. var $scaleControlPosition = ''; // The position of the Scale control, eg. 'BOTTOM_RIGHT'
  87. var $scrollwheel = TRUE; // If set to FALSE will disable zooming by scrolling of the mouse wheel
  88. var $sensor = FALSE; // Set to TRUE if being used on a device that can detect a users location
  89. var $streetViewAddressControl = TRUE; // If set to FALSE will hide the Address control
  90. var $streetViewAddressPosition = ''; // The position of the Address control, eg. 'BOTTOM'
  91. var $streetViewControlPosition = ''; // The position of the Street View control when viewing normal aerial map, eg. 'BOTTOM_RIGHT'
  92. var $streetViewCloseButton = FALSE; // If set to TRUE will show the close button in the top right. The close button allows users to return to the aerial map
  93. var $streetViewLinksControl = TRUE; // If set to FALSE will hide the Links control
  94. var $streetViewPanControl = TRUE; // If set to FALSE will hide the Pan control
  95. var $streetViewPanPosition = ''; // The position of the Scale control, eg. 'TOP_RIGHT'
  96. var $streetViewPovHeading = 0; // The Street View camera heading in degrees relative to true north. True north is 0, east is 90, south is 180, west is 270
  97. var $streetViewPovPitch = 0; // The Street View camera pitch in degrees, relative to the street view vehicle. Directly upwards is 90, Directly downwards is -90.
  98. var $streetViewPovZoom = 0; // The Street View zoom level. Fully zoomed-out is level 0, zooming in increases the zoom level.
  99. var $streetViewZoomControl = TRUE; // If set to FALSE will hide the Zoom control
  100. var $streetViewZoomPosition = ''; // The position of the Scale control, eg. 'TOP_RIGHT'
  101. var $streetViewZoomStyle = ''; // The size of the Street View zoom control. blank, 'SMALL' or 'LARGE' values accepted.
  102. var $styles = array(); // An array of styles used to colour aspects of the map and turn points of interest on and off
  103. var $stylesAsMapTypes = false; // If applying styles, whether to apply them to the default map or add them as additional map types
  104. var $stylesAsMapTypesDefault = ''; // If $stylesAsMapTypes is true the default style. Should contain the 'Name' of the style
  105. var $tilt = 0; // The angle of tilt. Currently only supports the values 0 and 45 in SATELLITE and HYBRID map types and at certain zoom levels
  106. var $trafficOverlay = FALSE; // If set to TRUE will overlay traffic information onto the map by default
  107. var $version = "3"; // Version of the API being used. Not currently used in the library
  108. var $zoom = 19; // The default zoom level of the map. If set to "auto" will autozoom/center to fit in all visible markers. If "auto", also overrides the $center parameter
  109. var $zoomControlPosition = ''; // The position of the Zoom control, eg. 'BOTTOM_RIGHT'
  110. var $zoomControlStyle = ''; // The size of the zoom control. blank, 'SMALL' or 'LARGE' values accepted.
  111.  
  112. var $markers = array(); // An array used by the library to store the markers as they are produced
  113. var $markersInfo = array(); // An array containing marker information (id, latitude, longitude etc) for use elsewhere
  114. var $polylines = array(); // An array used by the library to store the polylines as they are produced
  115. var $polygons = array(); // An array used by the library to store the polygons as they are produced
  116. var $circles = array(); // An array used by the library to store the circles as they are produced
  117. var $rectangles = array(); // An array used by the library to store the rectangles as they are produced
  118. var $overlays = array(); // An array used by the library to store the overlays as they are produced
  119.  
  120. var $directions = FALSE; // Whether or not the map will be used to show directions
  121. var $directionsStart = ""; // The starting location (lat/long co-ordinate or address) of the directions. Set to 'auto' to default it to the users location
  122. var $directionsEnd = ""; // The destination point (lat/long co-ordinate or address) of the directions. Set to 'auto' to default it to the users location
  123. var $directionsDivID = ""; // An element's ID on the page where textual directions will be output to. Leave blank if not required
  124. var $directionsMode = "DRIVING"; // DRIVING, WALKING or BICYCLING (US Only) - The vehicle/mode of transport to show directions for
  125. var $directionsAvoidTolls = FALSE; // Whether or not directions should avoid tolls
  126. var $directionsAvoidHighways = FALSE; // Whether or not directions should avoid highways
  127. var $directionsDraggable = FALSE; // Whether or not directions on the map are draggable
  128. var $directionsChanged = ""; // JavaScript to perform when directions are dragged
  129. var $directionsUnits = ""; // 'metric' for kilometers and meters or 'imperial for miles and feet. Leave blank and it will default to the region or country of where directions are being obtained
  130. var $directionsWaypointArray = array(); // An array of waypoints. eg array("Boston, MA", "Times Square, NY");
  131. var $directionsWaypointsOptimize= FALSE; // Should the waypoints be optimised? If TRUE, waypoints will be re-ordered to provide the most efficient route.
  132.  
  133. var $drawing = FALSE; // Whether or not the drawing library tools will be loaded
  134. var $drawingControl = TRUE; // If set to FALSE will hide the Drawing Manager control
  135. var $drawingControlPosition = 'TOP_CENTER'; // The position of the Drawing Manager control, eg. 'TOP_RIGHT'
  136. var $drawingDefaultMode = 'marker'; // The default mode for the Drawing Manager. Accepted values are marker, polygon, polyline, rectangle, circle, or null. null means that the user can interact with the map as normal when the map loads, and clicks do not draw anything.
  137. var $drawingModes = array(); // An array of modes available for use. Accepted values are marker, polygon, polyline, rectangle, circle
  138. var $drawingOnComplete = array(); // An array of JS to execute when shapes are completed, one array element per shape. For example: array('circle'=>'JS here', 'polygon'=>'JS here');
  139. var $drawingOnEdit = array(); // An array of JS to execute when shapes are changed/resized, one array element per shape. For example: array('circle'=>'JS here', 'polygon'=>'JS here');
  140.  
  141. var $places = FALSE; // Whether or not the map will be used to show places
  142. var $placesLocation = ''; // A point (lat/long co-ordinate or address) on the map if the search for places is based around a central point
  143. var $placesRadius = 0; // The radius (in meters) if search is based around a central position
  144. var $placesLocationSW = ''; // If preferring to search within bounds the South-West position (latitude/longitude coordinate OR address)
  145. var $placesLocationNE = ''; // If preferring to search within bounds the North-East position (latitude/longitude coordinate OR address)
  146. var $placesTypes = array(); // The types of places to search for. For a list of supported types see http://code.google.com/apis/maps/documentation/places/supported_types.html
  147. var $placesName = ''; // A term to be matched against when searching for places to display on the map
  148. var $placesAutocompleteInputID = ''; // The ID attribute of the textfield that the autocomplete should effect
  149. var $placesAutocompleteTypes = array(); // The types of places for the autocomplete to return. Options can be seen here https://developers.google.com/maps/documentation/javascript/places#places_autocomplete but include 'establishment' to only return business results, '(cities)', or '(regions)'
  150. var $placesAutocompleteBoundSW = ''; // By specifying an area in which to search for Places, the results are biased towards, but not restricted to, Places contained within these bounds.
  151. var $placesAutocompleteBoundNE = ''; // Both South-West (lat/long co-ordinate or address) and North-East (lat/long co-ordinate or address) values are required if wishing to set bounds
  152. var $placesAutocompleteBoundsMap= FALSE; // An alternative to setting the SW and NE bounds is to use the bounds of the current viewport. If set to TRUE, the bounds will be set to the viewport of the visible map, even if dragged or zoomed
  153. var $placesAutocompleteOnChange = ''; // The JavaScript action to perform when a place is selected
  154.  
  155. function Googlemaps($config = array())
  156. {
  157. if (count($config) > 0)
  158. {
  159. $this->initialize($config);
  160. }
  161.  
  162. log_message('debug', "Google Maps Class Initialized");
  163. }
  164.  
  165. function initialize($config = array())
  166. {
  167. foreach ($config as $key => $val)
  168. {
  169. if (isset($this->$key))
  170. {
  171. $this->$key = $val;
  172. }
  173. }
  174.  
  175. if ($this->sensor) { $this->sensor = "true"; }else{ $this->sensor = "false"; }
  176.  
  177. }
  178.  
  179. function add_marker($params = array())
  180. {
  181.  
  182. $marker = array();
  183. $this->markersInfo['marker_'.count($this->markers)] = array();
  184.  
  185. $marker['position'] = ''; // The position (lat/long co-ordinate or address) at which the marker will appear
  186. $marker['infowindow_content'] = ''; // If not blank, creates an infowindow (aka bubble) with the content provided. Can be plain text or HTML
  187. $marker['id'] = ''; // The unique identifier of the marker suffix (ie. marker_yourID). If blank, this will default to marker_X where X is an incremental number
  188. $marker['clickable'] = TRUE; // Defines if the marker is clickable
  189. $marker['cursor'] = ''; // The name or url of the cursor to display on hover
  190. $marker['draggable'] = FALSE; // Defines if the marker is draggable
  191. $marker['flat'] = FALSE; // If set to TRUE will not display a shadow beneath the icon
  192. $marker['icon'] = ''; // The name or url of the icon to use for the marker
  193. $marker['icon_size'] = ''; // The display size of the sprite or image being used. When using sprites, you must specify the sprite size. Expecting two comma-separated values for width and height respectively (ie '20,30'). See https://developers.google.com/maps/documentation/javascript/3.exp/reference#Icon
  194. $marker['icon_scaledSize'] = ''; // The size of the entire image after scaling, if any. Use this property to stretch/shrink an image or a sprite. Expecting two comma-separated values for width and height respectively (ie '20,30')
  195. $marker['icon_origin'] = ''; // If using a sprite, the position of the image within the sprite. Expecting two comma-separated values for distance from the top and left respectively (ie '20,30')
  196. $marker['icon_anchor'] = ''; // The position at which to anchor an image in correspondance to the location of the marker on the map. By default, the anchor is located along the center point of the bottom of the image. Expecting two comma-separated values (ie '20,30'). Credit to https://github.com/colethorsen
  197. $marker['animation'] = ''; // blank, 'DROP' or 'BOUNCE'
  198. $marker['onclick'] = ''; // JavaScript performed when a marker is clicked
  199. $marker['ondblclick'] = ''; // JavaScript performed when a marker is double-clicked
  200. $marker['ondrag'] = ''; // JavaScript repeatedly performed while the marker is being dragged
  201. $marker['ondragstart'] = ''; // JavaScript performed when a marker is started to be dragged
  202. $marker['ondragend'] = ''; // JavaScript performed when a draggable marker is dropped
  203. $marker['onmousedown'] = ''; // JavaScript performed when a mousedown event occurs on a marker
  204. $marker['onmouseout'] = ''; // JavaScript performed when the mouse leaves the area of the marker icon
  205. $marker['onmouseover'] = ''; // JavaScript performed when the mouse enters the area of the marker icon
  206. $marker['onmouseup'] = ''; // JavaScript performed when a mouseup event occurs on a marker
  207. $marker['onpositionchanged'] = ''; // JavaScript performed when the markers position changes
  208. $marker['onrightclick'] = ''; // JavaScript performed when a right-click occurs on a marker
  209. $marker['raiseondrag'] = TRUE; // If FALSE, disables the raising and lowering of the icon when a marker is being dragged
  210. $marker['shadow'] = ''; // The name or url of the icon's shadow
  211. $marker['title'] = ''; // The tooltip text to show on hover
  212. $marker['visible'] = TRUE; // Defines if the marker is visible by default
  213. $marker['zIndex'] = ''; // The zIndex of the marker. If two markers overlap, the marker with the higher zIndex will appear on top
  214.  
  215. $marker_output = '';
  216.  
  217. foreach ($params as $key => $value) {
  218.  
  219. if (isset($marker[$key])) {
  220.  
  221. $marker[$key] = $value;
  222.  
  223. }
  224.  
  225. }
  226.  
  227. $marker_id = count($this->markers);
  228. if (trim($marker['id']) != "")
  229. {
  230. $marker_id = $marker['id'];
  231. }
  232.  
  233. if ($marker['position']!="") {
  234. if ($this->is_lat_long($marker['position'])) {
  235. $marker_output .= '
  236. var myLatlng = new google.maps.LatLng('.$marker['position'].');
  237. ';
  238. $explodePosition = explode(",", $marker['position']);
  239. $this->markersInfo['marker_'.$marker_id]['latitude'] = trim($explodePosition[0]);
  240. $this->markersInfo['marker_'.$marker_id]['longitude'] = trim($explodePosition[1]);
  241. }else{
  242. $lat_long = $this->get_lat_long_from_address($marker['position']);
  243. $marker_output .= '
  244. var myLatlng = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');';
  245. $this->markersInfo['marker_'.$marker_id]['latitude'] = $lat_long[0];
  246. $this->markersInfo['marker_'.$marker_id]['longitude'] = $lat_long[1];
  247. }
  248. }
  249.  
  250. if ($marker['icon']!="") {
  251. $marker_output .= '
  252. var marker_icon = {
  253. url: "'.$marker['icon'].'"';
  254. if ($marker['icon_size']!="") {
  255. $marker_output .= ',
  256. size: new google.maps.Size('.$marker['icon_size'].')';
  257. }
  258. if ($marker['icon_scaledSize']!="") {
  259. $marker_output .= ',
  260. scaledSize: new google.maps.Size('.$marker['icon_scaledSize'].')';
  261. }
  262. if ($marker['icon_origin']!="") {
  263. $marker_output .= ',
  264. origin: new google.maps.Point('.$marker['icon_origin'].')';
  265. }
  266. if ($marker['icon_anchor']!="") {
  267. $marker_output .= ',
  268. anchor: new google.maps.Point('.$marker['icon_anchor'].')';
  269. }
  270. $marker_output .= '};
  271. ';
  272. }
  273.  
  274. $marker_output .= '
  275. var markerOptions = {
  276. map: '.$this->map_name;
  277. if ($marker['position']!="") {
  278. $marker_output .= ',
  279. position: myLatlng';
  280. }
  281. if (!$marker['clickable']) {
  282. $marker_output .= ',
  283. clickable: false';
  284. }
  285. if ($marker['cursor']!="") {
  286. $marker_output .= ',
  287. cursor: "'.$marker['cursor'].'"';
  288. }
  289. if ($marker['draggable']) {
  290. $marker_output .= ',
  291. draggable: true';
  292. }
  293. if ($marker['flat']) {
  294. $marker_output .= ',
  295. flat: true';
  296. }
  297. if ($marker['icon']!="") {
  298. $marker_output .= ',
  299. icon: marker_icon';
  300. }
  301. if (!$marker['raiseondrag']) {
  302. $marker_output .= ',
  303. raiseOnDrag: false';
  304. }
  305. if ($marker['shadow']!="") {
  306. $marker_output .= ',
  307. shadow: "'.$marker['shadow'].'"';
  308. }
  309. if ($marker['title']!="") {
  310. $marker_output .= ',
  311. title: "'.$marker['title'].'"';
  312. $this->markersInfo['marker_'.$marker_id]['title'] = $marker['title'];
  313. }
  314. if (!$marker['visible']) {
  315. $marker_output .= ',
  316. visible: false';
  317. }
  318. if ($marker['zIndex']!="" && is_numeric($marker['zIndex'])) {
  319. $marker_output .= ',
  320. zIndex: '.$marker['zIndex'];
  321. }
  322. if ($marker['animation']!="" && (strtoupper($marker['animation'])=="DROP" || strtoupper($marker['animation']=="BOUNCE"))) {
  323. $marker_output .= ',
  324. animation: google.maps.Animation.'.strtoupper($marker['animation']);
  325. }
  326. $marker_output .= '
  327. };
  328. marker_'.$marker_id.' = createMarker_'.$this->map_name.'(markerOptions);
  329. ';
  330.  
  331. if ($marker['infowindow_content']!="") {
  332.  
  333. // Escape any quotes in the event that HTML is being added to the infowindow
  334. $marker['infowindow_content'] = str_replace('\"', '"', $marker['infowindow_content']);
  335. $marker['infowindow_content'] = str_replace('"', '\"', $marker['infowindow_content']);
  336.  
  337. $marker_output .= '
  338. marker_'.$marker_id.'.set("content", "'.strip_tags($marker['infowindow_content']).'");
  339.  
  340. google.maps.event.addListener(marker_'.$marker_id.', "click", function(event) {
  341. iw_'.$this->map_name.'.setContent(this.get("content"));
  342. iw_'.$this->map_name.'.open('.$this->map_name.', this);
  343. ';
  344. if ($marker['onclick']!="") { $marker_output .= $marker['onclick'].'
  345. '; }
  346. $marker_output .= '
  347. });
  348. ';
  349. }else{
  350. if ($marker['onclick']!="") {
  351. $marker_output .= '
  352. google.maps.event.addListener(marker_'.$marker_id.', "click", function(event) {
  353. '.$marker['onclick'].'
  354. });
  355. ';
  356. }
  357. }
  358.  
  359. if ($marker['ondblclick']!="") {
  360. $marker_output .= '
  361. google.maps.event.addListener(marker_'.$marker_id.', "dblclick", function(event) {
  362. '.$marker['ondblclick'].'
  363. });
  364. ';
  365. }
  366. if ($marker['onmousedown']!="") {
  367. $marker_output .= '
  368. google.maps.event.addListener(marker_'.$marker_id.', "mousedown", function(event) {
  369. '.$marker['onmousedown'].'
  370. });
  371. ';
  372. }
  373. if ($marker['onmouseout']!="") {
  374. $marker_output .= '
  375. google.maps.event.addListener(marker_'.$marker_id.', "mouseout", function(event) {
  376. '.$marker['onmouseout'].'
  377. });
  378. ';
  379. }
  380. if ($marker['onmouseover']!="") {
  381. $marker_output .= '
  382. google.maps.event.addListener(marker_'.$marker_id.', "mouseover", function(event) {
  383. '.$marker['onmouseover'].'
  384. });
  385. ';
  386. }
  387. if ($marker['onmouseup']!="") {
  388. $marker_output .= '
  389. google.maps.event.addListener(marker_'.$marker_id.', "mouseup", function(event) {
  390. '.$marker['onmouseup'].'
  391. });
  392. ';
  393. }
  394. if ($marker['onpositionchanged']!="") {
  395. $marker_output .= '
  396. google.maps.event.addListener(marker_'.$marker_id.', "position_changed", function(event) {
  397. '.$marker['onpositionchanged'].'
  398. });
  399. ';
  400. }
  401. if ($marker['onrightclick']!="") {
  402. $marker_output .= '
  403. google.maps.event.addListener(marker_'.$marker_id.', "rightclick", function(event) {
  404. '.$marker['onrightclick'].'
  405. });
  406. ';
  407. }
  408.  
  409. if ($marker['draggable']) {
  410. if ($marker['ondrag']!="") {
  411. $marker_output .= '
  412. google.maps.event.addListener(marker_'.$marker_id.', "drag", function(event) {
  413. '.$marker['ondrag'].'
  414. });
  415. ';
  416. }
  417. if ($marker['ondragend']!="") {
  418. $marker_output .= '
  419. google.maps.event.addListener(marker_'.$marker_id.', "dragend", function(event) {
  420. '.$marker['ondragend'].'
  421. });
  422. ';
  423. }
  424. if ($marker['ondragstart']!="") {
  425. $marker_output .= '
  426. google.maps.event.addListener(marker_'.$marker_id.', "dragstart", function(event) {
  427. '.$marker['ondragstart'].'
  428. });
  429. ';
  430. }
  431. }
  432.  
  433. array_push($this->markers, $marker_output);
  434.  
  435. }
  436.  
  437. function add_polyline($params = array())
  438. {
  439.  
  440. $polyline = array();
  441.  
  442. $polyline['points'] = array(); // An array of latitude/longitude coordinates OR addresses, or a mixture of both. If an address is supplied the Google geocoding service will be used to return a lat/long.
  443. $polyline['clickable'] = TRUE; // Defines if the polyline is clickable
  444. $polyline['strokeColor'] = '#FF0000'; // The hex value of the polylines color
  445. $polyline['strokeOpacity'] = '1.0'; // The opacity of the polyline. 0 to 1.0
  446. $polyline['strokeWeight'] = '2'; // The thickness of the polyline
  447. $polyline['onclick'] = ''; // JavaScript performed when a polyline is clicked
  448. $polyline['ondblclick'] = ''; // JavaScript performed when a polyline is double-clicked
  449. $polyline['onmousedown'] = ''; // JavaScript performed when a mousedown event occurs on a polyline
  450. $polyline['onmousemove'] = ''; // JavaScript performed when the mouse moves in the area of the polyline
  451. $polyline['onmouseout'] = ''; // JavaScript performed when the mouse leaves the area of the polyline
  452. $polyline['onmouseover'] = ''; // JavaScript performed when the mouse enters the area of the polyline
  453. $polyline['onmouseup'] = ''; // JavaScript performed when a mouseup event occurs on a polyline
  454. $polyline['onrightclick'] = ''; // JavaScript performed when a right-click occurs on a polyline
  455. $polyline['zIndex'] = ''; // The zIndex of the polyline. If two polylines overlap, the polyline with the higher zIndex will appear on top
  456.  
  457. $polyline_output = '';
  458.  
  459. foreach ($params as $key => $value) {
  460.  
  461. if (isset($polyline[$key])) {
  462.  
  463. $polyline[$key] = $value;
  464.  
  465. }
  466.  
  467. }
  468.  
  469. if (count($polyline['points'])) {
  470.  
  471. $polyline_output .= '
  472. var polyline_plan_'.count($this->polylines).' = [';
  473. $i=0;
  474. $lat_long_output = '';
  475. foreach ($polyline['points'] as $point) {
  476. if ($i>0) { $polyline_output .= ','; }
  477. $lat_long_to_push = '';
  478. if ($this->is_lat_long($point)) {
  479. $lat_long_to_push = $point;
  480. $polyline_output .= '
  481. new google.maps.LatLng('.$point.')
  482. ';
  483. }else{
  484. $lat_long = $this->get_lat_long_from_address($point);
  485. $polyline_output .= '
  486. new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
  487. $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
  488. }
  489. $lat_long_output .= '
  490. lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
  491. ';
  492. $i++;
  493. }
  494. $polyline_output .= '];';
  495.  
  496. $polyline_output .= $lat_long_output;
  497.  
  498. $polyline_output .= '
  499. var polyline_'.count($this->polylines).' = new google.maps.Polyline({
  500. path: polyline_plan_'.count($this->polylines).',
  501. strokeColor: "'.$polyline['strokeColor'].'",
  502. strokeOpacity: '.$polyline['strokeOpacity'].',
  503. strokeWeight: '.$polyline['strokeWeight'];
  504. if (!$polyline['clickable']) {
  505. $polyline_output .= ',
  506. clickable: false';
  507. }
  508. if ($polyline['zIndex']!="" && is_numeric($polyline['zIndex'])) {
  509. $polyline_output .= ',
  510. zIndex: '.$polyline['zIndex'];
  511. }
  512. $polyline_output .= '
  513. });
  514.  
  515. polyline_'.count($this->polylines).'.setMap('.$this->map_name.');
  516.  
  517. ';
  518.  
  519. if ($polyline['onclick']!="") {
  520. $polyline_output .= '
  521. google.maps.event.addListener(polyline_'.count($this->polylines).', "click", function() {
  522. '.$polyline['onclick'].'
  523. });
  524. ';
  525. }
  526. if ($polyline['ondblclick']!="") {
  527. $polyline_output .= '
  528. google.maps.event.addListener(polyline_'.count($this->polylines).', "dblclick", function() {
  529. '.$polyline['ondblclick'].'
  530. });
  531. ';
  532. }
  533. if ($polyline['onmousedown']!="") {
  534. $polyline_output .= '
  535. google.maps.event.addListener(polyline_'.count($this->polylines).', "mousedown", function() {
  536. '.$polyline['onmousedown'].'
  537. });
  538. ';
  539. }
  540. if ($polyline['onmousemove']!="") {
  541. $polyline_output .= '
  542. google.maps.event.addListener(polyline_'.count($this->polylines).', "mousemove", function() {
  543. '.$polyline['onmousemove'].'
  544. });
  545. ';
  546. }
  547. if ($polyline['onmouseout']!="") {
  548. $polyline_output .= '
  549. google.maps.event.addListener(polyline_'.count($this->polylines).', "mouseout", function() {
  550. '.$polyline['onmouseout'].'
  551. });
  552. ';
  553. }
  554. if ($polyline['onmouseover']!="") {
  555. $polyline_output .= '
  556. google.maps.event.addListener(polyline_'.count($this->polylines).', "mouseover", function() {
  557. '.$polyline['onmouseover'].'
  558. });
  559. ';
  560. }
  561. if ($polyline['onmouseup']!="") {
  562. $polyline_output .= '
  563. google.maps.event.addListener(polyline_'.count($this->polylines).', "mouseup", function() {
  564. '.$polyline['onmouseup'].'
  565. });
  566. ';
  567. }
  568. if ($polyline['onrightclick']!="") {
  569. $polyline_output .= '
  570. google.maps.event.addListener(polyline_'.count($this->polylines).', "rightclick", function() {
  571. '.$polyline['onrightclick'].'
  572. });
  573. ';
  574. }
  575.  
  576. array_push($this->polylines, $polyline_output);
  577.  
  578. }
  579.  
  580. }
  581.  
  582. function add_polygon($params = array())
  583. {
  584.  
  585. $polygon = array();
  586.  
  587. $polygon['points'] = array(); // The positions (latitude/longitude coordinates OR addresses) at which the polygon points will appear. NOTE: The first and last elements of the array must be the same
  588. $polygon['clickable'] = TRUE; // Defines if the polygon is clickable
  589. $polygon['strokeColor'] = '#FF0000'; // The hex value of the polygons border color
  590. $polygon['strokeOpacity'] = '0.8'; // The opacity of the polygon border. 0 to 1.0
  591. $polygon['strokeWeight'] = '2'; // The thickness of the polygon border
  592. $polygon['fillColor'] = '#FF0000'; // The hex value of the polygons fill color
  593. $polygon['fillOpacity'] = '0.3'; // The opacity of the polygons fill
  594. $polygon['onclick'] = ''; // JavaScript performed when a polygon is clicked
  595. $polygon['ondblclick'] = ''; // JavaScript performed when a polygon is double-clicked
  596. $polygon['onmousedown'] = ''; // JavaScript performed when a mousedown event occurs on a polygon
  597. $polygon['onmousemove'] = ''; // JavaScript performed when the mouse moves in the area of the polygon
  598. $polygon['onmouseout'] = ''; // JavaScript performed when the mouse leaves the area of the polygon
  599. $polygon['onmouseover'] = ''; // JavaScript performed when the mouse enters the area of the polygon
  600. $polygon['onmouseup'] = ''; // JavaScript performed when a mouseup event occurs on a polygon
  601. $polygon['onrightclick'] = ''; // JavaScript performed when a right-click occurs on a polygon
  602. $polygon['zIndex'] = ''; // The zIndex of the polygon. If two polygons overlap, the polygon with the higher zIndex will appear on top
  603.  
  604. $polygon_output = '';
  605.  
  606. foreach ($params as $key => $value) {
  607.  
  608. if (isset($polygon[$key])) {
  609.  
  610. $polygon[$key] = $value;
  611.  
  612. }
  613.  
  614. }
  615.  
  616. if (count($polygon['points'])) {
  617.  
  618. $polygon_output .= '
  619. var polygon_plan_'.count($this->polygons).' = [';
  620. $i=0;
  621. $lat_long_output = '';
  622. foreach ($polygon['points'] as $point) {
  623. if ($i>0) { $polygon_output .= ','; }
  624. $lat_long_to_push = '';
  625. if ($this->is_lat_long($point)) {
  626. $lat_long_to_push = $point;
  627. $polygon_output .= '
  628. new google.maps.LatLng('.$point.')
  629. ';
  630. }else{
  631. $lat_long = $this->get_lat_long_from_address($point);
  632. $polygon_output .= '
  633. new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
  634. $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
  635. }
  636. $lat_long_output .= '
  637. lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
  638. ';
  639. $i++;
  640. }
  641. $polygon_output .= '];';
  642.  
  643. $polygon_output .= $lat_long_output;
  644.  
  645. }
  646.  
  647. $polygon_output .= '
  648. var polygon_'.count($this->polygons).' = new google.maps.Polygon({
  649. ';
  650. if (count($polygon['points'])) {
  651. $polygon_output .= 'path: polygon_plan_'.count($this->polygons).',
  652. ';
  653. }
  654. $polygon_output .= '
  655. strokeColor: "'.$polygon['strokeColor'].'",
  656. strokeOpacity: '.$polygon['strokeOpacity'].',
  657. strokeWeight: '.$polygon['strokeWeight'].',
  658. fillColor: "'.$polygon['fillColor'].'",
  659. fillOpacity: '.$polygon['fillOpacity'];
  660. if (!$polygon['clickable']) {
  661. $polygon_output .= ',
  662. clickable: false';
  663. }
  664. if ($polygon['zIndex']!="" && is_numeric($polygon['zIndex'])) {
  665. $polygon_output .= ',
  666. zIndex: '.$polygon['zIndex'];
  667. }
  668. $polygon_output .= '
  669. });
  670.  
  671. polygon_'.count($this->polygons).'.setMap('.$this->map_name.');
  672.  
  673. ';
  674.  
  675. if ($polygon['onclick']!="") {
  676. $polygon_output .= '
  677. google.maps.event.addListener(polygon_'.count($this->polygons).', "click", function() {
  678. '.$polygon['onclick'].'
  679. });
  680. ';
  681. }
  682. if ($polygon['ondblclick']!="") {
  683. $polygon_output .= '
  684. google.maps.event.addListener(polygon_'.count($this->polygons).', "dblclick", function() {
  685. '.$polygon['ondblclick'].'
  686. });
  687. ';
  688. }
  689. if ($polygon['onmousedown']!="") {
  690. $polygon_output .= '
  691. google.maps.event.addListener(polygon_'.count($this->polygons).', "mousedown", function() {
  692. '.$polygon['onmousedown'].'
  693. });
  694. ';
  695. }
  696. if ($polygon['onmousemove']!="") {
  697. $polygon_output .= '
  698. google.maps.event.addListener(polygon_'.count($this->polygons).', "mousemove", function() {
  699. '.$polygon['onmousemove'].'
  700. });
  701. ';
  702. }
  703. if ($polygon['onmouseout']!="") {
  704. $polygon_output .= '
  705. google.maps.event.addListener(polygon_'.count($this->polygons).', "mouseout", function() {
  706. '.$polygon['onmouseout'].'
  707. });
  708. ';
  709. }
  710. if ($polygon['onmouseover']!="") {
  711. $polygon_output .= '
  712. google.maps.event.addListener(polygon_'.count($this->polygons).', "mouseover", function() {
  713. '.$polygon['onmouseover'].'
  714. });
  715. ';
  716. }
  717. if ($polygon['onmouseup']!="") {
  718. $polygon_output .= '
  719. google.maps.event.addListener(polygon_'.count($this->polygons).', "mouseup", function() {
  720. '.$polygon['onmouseup'].'
  721. });
  722. ';
  723. }
  724. if ($polygon['onrightclick']!="") {
  725. $polygon_output .= '
  726. google.maps.event.addListener(polygon_'.count($this->polygons).', "rightclick", function() {
  727. '.$polygon['onrightclick'].'
  728. });
  729. ';
  730. }
  731.  
  732. array_push($this->polygons, $polygon_output);
  733.  
  734. }
  735.  
  736. function add_circle($params = array())
  737. {
  738.  
  739. $circle = array();
  740.  
  741. $circle['center'] = ''; // The center position (latitude/longitude coordinate OR addresse) at which the circle will appear
  742. $circle['clickable'] = TRUE; // Defines if the circle is clickable
  743. $circle['radius'] = 0; // The circle radius (in metres)
  744. $circle['strokeColor'] = '0.8'; // The hex value of the circles border color
  745. $circle['strokeOpacity'] = '0.8'; // The opacity of the circle border
  746. $circle['strokeWeight'] = '2'; // The thickness of the circle border
  747. $circle['fillColor'] = '#FF0000'; // The hex value of the circles fill color
  748. $circle['fillOpacity'] = '0.3'; // The opacity of the circles fill
  749. $circle['onclick'] = ''; // JavaScript performed when a circle is clicked
  750. $circle['ondblclick'] = ''; // JavaScript performed when a circle is double-clicked
  751. $circle['onmousedown'] = ''; // JavaScript performed when a mousedown event occurs on a circle
  752. $circle['onmousemove'] = ''; // JavaScript performed when the mouse moves in the area of the circle
  753. $circle['onmouseout'] = ''; // JavaScript performed when the mouse leaves the area of the circle
  754. $circle['onmouseover'] = ''; // JavaScript performed when the mouse enters the area of the circle
  755. $circle['onmouseup'] = ''; // JavaScript performed when a mouseup event occurs on a circle
  756. $circle['onrightclick'] = ''; // JavaScript performed when a right-click occurs on a circle
  757. $circle['zIndex'] = ''; // The zIndex of the circle. If two circles overlap, the circle with the higher zIndex will appear on top
  758.  
  759. $circle_output = '';
  760.  
  761. foreach ($params as $key => $value) {
  762.  
  763. if (isset($circle[$key])) {
  764.  
  765. $circle[$key] = $value;
  766.  
  767. }
  768.  
  769. }
  770.  
  771. if ($circle['radius']>0 && $circle['center']!="") {
  772.  
  773. $lat_long_to_push = '';
  774. if ($this->is_lat_long($circle['center'])) {
  775. $lat_long_to_push = $circle['center'];
  776. $circle_output = '
  777. var circleCenter = new google.maps.LatLng('.$circle['center'].')
  778. ';
  779. }else{
  780. $lat_long = $this->get_lat_long_from_address($circle['center']);
  781. $circle_output = '
  782. var circleCenter = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
  783. $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
  784. }
  785. $circle_output .= '
  786. lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
  787. ';
  788.  
  789. $circle_output .= '
  790. var circleOptions = {
  791. strokeColor: "'.$circle['strokeColor'].'",
  792. strokeOpacity: '.$circle['strokeOpacity'].',
  793. strokeWeight: '.$circle['strokeWeight'].',
  794. fillColor: "'.$circle['fillColor'].'",
  795. fillOpacity: '.$circle['fillOpacity'].',
  796. map: '.$this->map_name.',
  797. center: circleCenter,
  798. radius: '.$circle['radius'];
  799. if (!$circle['clickable']) {
  800. $circle_output .= ',
  801. clickable: false';
  802. }
  803. if ($circle['zIndex']!="" && is_numeric($circle['zIndex'])) {
  804. $circle_output .= ',
  805. zIndex: '.$circle['zIndex'];
  806. }
  807. $circle_output .= '
  808. };
  809. var circle_'.count($this->circles).' = new google.maps.Circle(circleOptions);
  810. ';
  811.  
  812. if ($circle['onclick']!="") {
  813. $circle_output .= '
  814. google.maps.event.addListener(circle_'.count($this->circles).', "click", function() {
  815. '.$circle['onclick'].'
  816. });
  817. ';
  818. }
  819. if ($circle['ondblclick']!="") {
  820. $circle_output .= '
  821. google.maps.event.addListener(circle_'.count($this->circles).', "dblclick", function() {
  822. '.$circle['ondblclick'].'
  823. });
  824. ';
  825. }
  826. if ($circle['onmousedown']!="") {
  827. $circle_output .= '
  828. google.maps.event.addListener(circle_'.count($this->circles).', "mousedown", function() {
  829. '.$circle['onmousedown'].'
  830. });
  831. ';
  832. }
  833. if ($circle['onmousemove']!="") {
  834. $circle_output .= '
  835. google.maps.event.addListener(circle_'.count($this->circles).', "mousemove", function() {
  836. '.$circle['onmousemove'].'
  837. });
  838. ';
  839. }
  840. if ($circle['onmouseout']!="") {
  841. $circle_output .= '
  842. google.maps.event.addListener(circle_'.count($this->circles).', "mouseout", function() {
  843. '.$circle['onmouseout'].'
  844. });
  845. ';
  846. }
  847. if ($circle['onmouseover']!="") {
  848. $circle_output .= '
  849. google.maps.event.addListener(circle_'.count($this->circles).', "mouseover", function() {
  850. '.$circle['onmouseover'].'
  851. });
  852. ';
  853. }
  854. if ($circle['onmouseup']!="") {
  855. $circle_output .= '
  856. google.maps.event.addListener(circle_'.count($this->circles).', "mouseup", function() {
  857. '.$circle['onmouseup'].'
  858. });
  859. ';
  860. }
  861. if ($circle['onrightclick']!="") {
  862. $circle_output .= '
  863. google.maps.event.addListener(circle_'.count($this->circles).', "rightclick", function() {
  864. '.$circle['onrightclick'].'
  865. });
  866. ';
  867. }
  868.  
  869. array_push($this->circles, $circle_output);
  870.  
  871. }
  872.  
  873. }
  874.  
  875. function add_rectangle($params = array())
  876. {
  877.  
  878. $rectangle = array();
  879.  
  880. $rectangle['positionSW'] = ''; // The South-West position (latitude/longitude coordinate OR address) at which the rectangle will appear
  881. $rectangle['positionNE'] = ''; // The North-East position(latitude/longitude coordinate OR address) at which the rectangle will appear
  882. $rectangle['clickable'] = TRUE; // Defines if the rectangle is clickable
  883. $rectangle['strokeColor'] = '0.8'; // The hex value of the rectangles border color
  884. $rectangle['strokeOpacity'] = '0.8'; // The opacity of the rectangle border
  885. $rectangle['strokeWeight'] = '2'; // The thickness of the rectangle border
  886. $rectangle['fillColor'] = '#FF0000'; // The hex value of the rectangles fill color
  887. $rectangle['fillOpacity'] = '0.3'; // The opacity of the rectangles fill
  888. $rectangle['onclick'] = ''; // JavaScript performed when a rectangle is clicked
  889. $rectangle['ondblclick'] = ''; // JavaScript performed when a rectangle is double-clicked
  890. $rectangle['onmousedown'] = ''; // JavaScript performed when a mousedown event occurs on a rectangle
  891. $rectangle['onmousemove'] = ''; // JavaScript performed when the mouse moves in the area of the rectangle
  892. $rectangle['onmouseout'] = ''; // JavaScript performed when the mouse leaves the area of the rectangle
  893. $rectangle['onmouseover'] = ''; // JavaScript performed when the mouse enters the area of the rectangle
  894. $rectangle['onmouseup'] = ''; // JavaScript performed when a mouseup event occurs on a rectangle
  895. $rectangle['onrightclick'] = ''; // JavaScript performed when a right-click occurs on a rectangle
  896. $rectangle['zIndex'] = ''; // The zIndex of the rectangle. If two rectangles overlap, the rectangle with the higher zIndex will appear on top
  897.  
  898. $rectangle_output = '';
  899.  
  900. foreach ($params as $key => $value) {
  901.  
  902. if (isset($rectangle[$key])) {
  903.  
  904. $rectangle[$key] = $value;
  905.  
  906. }
  907.  
  908. }
  909.  
  910. if ($rectangle['positionSW']!="" && $rectangle['positionNE']!="") {
  911.  
  912. $lat_long_to_push = '';
  913. if ($this->is_lat_long($rectangle['positionSW'])) {
  914. $lat_long_to_push = $rectangle['positionSW'];
  915. $rectangle_output .= '
  916. var positionSW = new google.maps.LatLng('.$rectangle['positionSW'].')
  917. ';
  918. }else{
  919. $lat_long = $this->get_lat_long_from_address($rectangle['positionSW']);
  920. $rectangle_output .= '
  921. var positionSW = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
  922. $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
  923. }
  924. $rectangle_output .= '
  925. lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
  926. ';
  927.  
  928. $lat_long_to_push = '';
  929. if ($this->is_lat_long($rectangle['positionNE'])) {
  930. $lat_long_to_push = $rectangle['positionNE'];
  931. $rectangle_output .= '
  932. var positionNE = new google.maps.LatLng('.$rectangle['positionNE'].')
  933. ';
  934. }else{
  935. $lat_long = $this->get_lat_long_from_address($rectangle['positionNE']);
  936. $rectangle_output .= '
  937. var positionNE = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
  938. $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
  939. }
  940. $rectangle_output .= '
  941. lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
  942. ';
  943.  
  944. $rectangle_output .= '
  945. var rectangleOptions = {
  946. strokeColor: "'.$rectangle['strokeColor'].'",
  947. strokeOpacity: '.$rectangle['strokeOpacity'].',
  948. strokeWeight: '.$rectangle['strokeWeight'].',
  949. fillColor: "'.$rectangle['fillColor'].'",
  950. fillOpacity: '.$rectangle['fillOpacity'].',
  951. map: '.$this->map_name.',
  952. bounds: new google.maps.LatLngBounds(positionSW, positionNE)';
  953. if (!$rectangle['clickable']) {
  954. $rectangle_output .= ',
  955. clickable: false';
  956. }
  957. if ($rectangle['zIndex']!="" && is_numeric($rectangle['zIndex'])) {
  958. $rectangle_output .= ',
  959. zIndex: '.$rectangle['zIndex'];
  960. }
  961. $rectangle_output .= '
  962. };';
  963.  
  964. $rectangle_output .= '
  965. var rectangle_'.count($this->rectangles).' = new google.maps.Rectangle(rectangleOptions);
  966. ';
  967.  
  968. if ($rectangle['onclick']!="") {
  969. $rectangle_output .= '
  970. google.maps.event.addListener(rectangle_'.count($this->rectangles).', "click", function() {
  971. '.$rectangle['onclick'].'
  972. });
  973. ';
  974. }
  975. if ($rectangle['ondblclick']!="") {
  976. $rectangle_output .= '
  977. google.maps.event.addListener(rectangle_'.count($this->rectangles).', "dblclick", function() {
  978. '.$rectangle['ondblclick'].'
  979. });
  980. ';
  981. }
  982. if ($rectangle['onmousedown']!="") {
  983. $rectangle_output .= '
  984. google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mousedown", function() {
  985. '.$rectangle['onmousedown'].'
  986. });
  987. ';
  988. }
  989. if ($rectangle['onmousemove']!="") {
  990. $rectangle_output .= '
  991. google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mousemove", function() {
  992. '.$rectangle['onmousemove'].'
  993. });
  994. ';
  995. }
  996. if ($rectangle['onmouseout']!="") {
  997. $rectangle_output .= '
  998. google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mouseout", function() {
  999. '.$rectangle['onmouseout'].'
  1000. });
  1001. ';
  1002. }
  1003. if ($rectangle['onmouseover']!="") {
  1004. $rectangle_output .= '
  1005. google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mouseover", function() {
  1006. '.$rectangle['onmouseover'].'
  1007. });
  1008. ';
  1009. }
  1010. if ($rectangle['onmouseup']!="") {
  1011. $rectangle_output .= '
  1012. google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mouseup", function() {
  1013. '.$rectangle['onmouseup'].'
  1014. });
  1015. ';
  1016. }
  1017. if ($rectangle['onrightclick']!="") {
  1018. $rectangle_output .= '
  1019. google.maps.event.addListener(rectangle_'.count($this->rectangles).', "rightclick", function() {
  1020. '.$rectangle['onrightclick'].'
  1021. });
  1022. ';
  1023. }
  1024.  
  1025. array_push($this->rectangles, $rectangle_output);
  1026.  
  1027. }
  1028.  
  1029. }
  1030.  
  1031. function add_ground_overlay($params = array())
  1032. {
  1033.  
  1034. $overlay = array();
  1035.  
  1036. $overlay['image'] = ''; // JavaScript performed when a ground overlay is clicked
  1037. $overlay['positionSW'] = ''; // The South-West position (latitude/longitude coordinate OR addresse) at which the ground overlay will appear
  1038. $overlay['positionNE'] = ''; // The North-East position (latitude/longitude coordinate OR addresse) at which the ground overlay will appear
  1039. $overlay['clickable'] = TRUE; // Defines if the ground overlay is clickable
  1040. $overlay['onclick'] = ''; // JavaScript performed when a ground overlay is clicked
  1041.  
  1042. $overlay_output = '';
  1043.  
  1044. foreach ($params as $key => $value) {
  1045.  
  1046. if (isset($overlay[$key])) {
  1047.  
  1048. $overlay[$key] = $value;
  1049.  
  1050. }
  1051.  
  1052. }
  1053.  
  1054. if ($overlay['image']!="" && $overlay['positionSW']!="" && $overlay['positionNE']!="") {
  1055.  
  1056. $lat_long_to_push = '';
  1057. if ($this->is_lat_long($overlay['positionSW'])) {
  1058. $lat_long_to_push = $overlay['positionSW'];
  1059. $overlay_output .= '
  1060. var positionSW = new google.maps.LatLng('.$overlay['positionSW'].')
  1061. ';
  1062. }else{
  1063. $lat_long = $this->get_lat_long_from_address($overlay['positionSW']);
  1064. $overlay_output .= '
  1065. var positionSW = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
  1066. $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
  1067. }
  1068. $overlay_output .= '
  1069. lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
  1070. ';
  1071.  
  1072. $lat_long_to_push = '';
  1073. if ($this->is_lat_long($overlay['positionNE'])) {
  1074. $lat_long_to_push = $overlay['positionNE'];
  1075. $overlay_output .= '
  1076. var positionNE = new google.maps.LatLng('.$overlay['positionNE'].')
  1077. ';
  1078. }else{
  1079. $lat_long = $this->get_lat_long_from_address($overlay['positionNE']);
  1080. $overlay_output .= '
  1081. var positionNE = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
  1082. $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
  1083. }
  1084. $overlay_output .= '
  1085. lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
  1086. ';
  1087.  
  1088. $overlay_output .= '
  1089. var overlay_'.count($this->overlays).' = new google.maps.GroundOverlay("'.$overlay['image'].'", new google.maps.LatLngBounds(positionSW, positionNE), { map: '.$this->map_name;
  1090. if (!$overlay['clickable']) { $overlay_output .= ', clickable: false'; }
  1091. $overlay_output .= '});
  1092. ';
  1093.  
  1094. if ($overlay['onclick']!="") {
  1095. $overlay_output .= '
  1096. google.maps.event.addListener(overlay_'.count($this->overlays).', "click", function() {
  1097. '.$overlay['onclick'].'
  1098. });
  1099. ';
  1100. }
  1101.  
  1102. array_push($this->overlays, $overlay_output);
  1103.  
  1104. }
  1105.  
  1106. }
  1107.  
  1108. function create_map()
  1109. {
  1110. $this->output_js = '';
  1111. $this->output_js_contents = '';
  1112. $this->output_html = '';
  1113.  
  1114. if ($this->maps_loaded == 0)
  1115. {
  1116. if ($this->apiKey!="")
  1117. {
  1118. if ($this->https) { $apiLocation = 'https'; }else{ $apiLocation = 'http'; }
  1119. $apiLocation .= '://maps.googleapis.com/maps/api/js?key='.$this->apiKey.'&';
  1120. }
  1121. else
  1122. {
  1123. if ($this->https) { $apiLocation = 'https://maps-api-ssl'; }else{ $apiLocation = 'http://maps'; }
  1124. $apiLocation .= '.google.com/maps/api/js?';
  1125. }
  1126. $apiLocation .= 'sensor='.$this->sensor;
  1127. if ($this->region!="" && strlen($this->region)==2) { $apiLocation .= '&region='.strtoupper($this->region); }
  1128. if ($this->language!="") { $apiLocation .= '&language='.$this->language; }
  1129. $libraries = array();
  1130. if ($this->adsense!="") { array_push($libraries, 'adsense'); }
  1131. if ($this->places!="") { array_push($libraries, 'places'); }
  1132. if ($this->panoramio) { array_push($libraries, 'panoramio'); }
  1133. if ($this->drawing) { array_push($libraries, 'drawing'); }
  1134. if (count($libraries)) { $apiLocation .= '&libraries='.implode(",", $libraries); }
  1135.  
  1136. if (!$this->loadAsynchronously)
  1137. {
  1138. $this->output_js .= '
  1139. <script type="text/javascript" src="'.$apiLocation.'"></script>';
  1140. }
  1141.  
  1142. if ($this->cluster) { $this->output_js .= '
  1143. <script type="text/javascript" src="' . ( ($this->https) ? 'https' : 'http' ) . '://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer_compiled.js"></script>
  1144. '; }
  1145. }
  1146. if ($this->jsfile=="") {
  1147. $this->output_js .= '
  1148. <script type="text/javascript">
  1149. //<![CDATA[
  1150. ';
  1151. }
  1152.  
  1153. $this->output_js_contents .= '
  1154. var '.$this->map_name.'; // Global declaration of the map
  1155. var lat_longs_'.$this->map_name.' = new Array();
  1156. var markers_'.$this->map_name.' = new Array();
  1157. var iw_'.$this->map_name.';
  1158. ';
  1159. if ($this->cluster) {
  1160. $this->output_js_contents .= 'var markerCluster;
  1161. ';
  1162. }
  1163. if ($this->directions) {
  1164. $rendererOptions = '';
  1165. if ($this->directionsDraggable) {
  1166. $this->output_js_contents .= '
  1167. var rendererOptions = { draggable: true };
  1168. ';
  1169. $rendererOptions = 'rendererOptions';
  1170. }
  1171. $this->output_js_contents .= 'var directionsDisplay = new google.maps.DirectionsRenderer('.$rendererOptions.');
  1172. var directionsService = new google.maps.DirectionsService();
  1173. ';
  1174. }
  1175. if ($this->places) {
  1176. $this->output_js_contents .= 'var placesService;
  1177. ';
  1178. if ($this->placesAutocompleteInputID != "")
  1179. {
  1180. $this->output_js_contents .= 'var placesAutocomplete;
  1181. ';
  1182. }
  1183. }
  1184. if ($this->adsense) {
  1185. $this->output_js_contents .= 'var adUnit;
  1186. ';
  1187. }
  1188. if ($this->drawing) {
  1189. $this->output_js_contents .= 'var drawingManager;
  1190. ';
  1191. }
  1192.  
  1193. $this->output_js_contents .= '
  1194. iw_'.$this->map_name.' = new google.maps.InfoWindow(';
  1195. if ($this->infowindowMaxWidth != 0)
  1196. {
  1197. $this->output_js_contents .= '{
  1198. maxWidth: '.$this->infowindowMaxWidth.'
  1199. }';
  1200. }
  1201. $this->output_js_contents .= ');
  1202.  
  1203. ';
  1204.  
  1205. $this->output_js_contents .= 'function initialize_'.$this->map_name.'() {
  1206.  
  1207. ';
  1208.  
  1209. $styleOutput = '';
  1210. if (count($this->styles)) {
  1211. $styles = 0;
  1212. foreach ($this->styles as $style) {
  1213. $this->output_js_contents .= 'var styles_'.$styles.' = '.json_encode($style['definition']).';
  1214. ';
  1215.  
  1216. if ($this->stylesAsMapTypes) {
  1217. $this->output_js_contents .= 'var styles_'.$styles.' = new google.maps.StyledMapType(styles_'.$styles.', {name:"'.$style['name'].'"});
  1218. ';
  1219. }else{
  1220. $styleOutput .= $this->map_name.'.setOptions({styles: styles_'.$styles.'});
  1221. ';
  1222. break;
  1223. }
  1224.  
  1225. ++$styles;
  1226. }
  1227. }
  1228.  
  1229. if ($this->center!="auto") {
  1230. if ($this->is_lat_long($this->center)) { // if centering the map on a lat/long
  1231. $this->output_js_contents .= 'var myLatlng = new google.maps.LatLng('.$this->center.');';
  1232. }else{ // if centering the map on an address
  1233. $lat_long = $this->get_lat_long_from_address($this->center);
  1234. $this->output_js_contents .= 'var myLatlng = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');';
  1235. }
  1236. }
  1237.  
  1238. $this->output_js_contents .= '
  1239. var myOptions = {
  1240. ';
  1241. if ($this->zoom=="auto") { $this->output_js_contents .= 'zoom: 13,'; }else{ $this->output_js_contents .= 'zoom: '.$this->zoom.','; }
  1242. if ($this->center!="auto") { $this->output_js_contents .= '
  1243. center: myLatlng,'; }
  1244. if (strtolower($this->map_type)=="street") { $map_type = "ROADMAP"; }else{ $map_type = $this->map_type; }
  1245. $this->output_js_contents .= '
  1246. mapTypeId: google.maps.MapTypeId.'.$map_type;
  1247. if ($this->backgroundColor) {
  1248. $this->output_js_contents .= ',
  1249. backgroundColor: \''.$this->backgroundColor.'\'';
  1250. }
  1251. if ($this->disableDefaultUI) {
  1252. $this->output_js_contents .= ',
  1253. disableDefaultUI: true';
  1254. }
  1255. if ($this->disableMapTypeControl) {
  1256. $this->output_js_contents .= ',
  1257. mapTypeControl: false';
  1258. }
  1259. if ($this->disableNavigationControl) {
  1260. $this->output_js_contents .= ',
  1261. navigationControl: false';
  1262. }
  1263. if ($this->disableScaleControl) {
  1264. $this->output_js_contents .= ',
  1265. scaleControl: false';
  1266. }
  1267. if ($this->disableStreetViewControl) {
  1268. $this->output_js_contents .= ',
  1269. streetViewControl: false';
  1270. }
  1271. if ($this->disableDoubleClickZoom) {
  1272. $this->output_js_contents .= ',
  1273. disableDoubleClickZoom: true';
  1274. }
  1275. if (!$this->draggable) {
  1276. $this->output_js_contents .= ',
  1277. draggable: false';
  1278. }
  1279. if ($this->draggableCursor!="") {
  1280. $this->output_js_contents .= ',
  1281. draggableCursor: "'.$this->draggableCursor.'"';
  1282. }
  1283. if ($this->draggingCursor!="") {
  1284. $this->output_js_contents .= ',
  1285. draggingCursor: "'.$this->draggingCursor.'"';
  1286. }
  1287. if (!$this->keyboardShortcuts) {
  1288. $this->output_js_contents .= ',
  1289. keyboardShortcuts: false';
  1290. }
  1291. $mapTypeControlOptions = array();
  1292. $map_types = array();
  1293. if ($this->mapTypeControlPosition!="") {
  1294. array_push($mapTypeControlOptions, 'position: google.maps.ControlPosition.'.strtoupper($this->mapTypeControlPosition));
  1295. }
  1296. if ($this->mapTypeControlStyle!="" && (strtoupper($this->mapTypeControlStyle)=="DROPDOWN_MENU" || strtoupper($this->mapTypeControlStyle)=="HORIZONTAL_BAR")) {
  1297. array_push($mapTypeControlOptions, 'style: google.maps.MapTypeControlStyle.'.strtoupper($this->mapTypeControlStyle));
  1298. }
  1299. if (count($this->map_types_available)) {
  1300. foreach ($this->map_types_available as $map_type) { array_push($map_types, 'google.maps.MapTypeId.'.strtoupper($map_type)); }
  1301. }
  1302. if (count($this->styles) && $this->stylesAsMapTypes) {
  1303. $styles = 0;
  1304. foreach ($this->styles as $style) {
  1305. array_push($map_types, '"style'.$styles.'"');
  1306. $styleOutput .= '
  1307. '.$this->map_name.'.mapTypes.set("style'.$styles.'", styles_'.$styles.');
  1308. ';
  1309. if ($this->stylesAsMapTypesDefault==$style['name']) {
  1310. $styleOutput .= '
  1311. '.$this->map_name.'.setMapTypeId("style'.$styles.'");
  1312. ';
  1313. }
  1314. $styles++;
  1315. }
  1316. }
  1317. if (count($map_types)) {
  1318. array_push($mapTypeControlOptions, 'mapTypeIds: ['.implode(", ", $map_types).']');
  1319. }
  1320. if (count($mapTypeControlOptions)) {
  1321. $this->output_js_contents .= ',
  1322. mapTypeControlOptions: {'.implode(",", $mapTypeControlOptions).'}';
  1323. }
  1324. if ($this->minzoom!="") {
  1325. $this->output_js_contents .= ',
  1326. minZoom: '.$this->minzoom;
  1327. }
  1328. if ($this->maxzoom!="") {
  1329. $this->output_js_contents .= ',
  1330. maxZoom: '.$this->maxzoom;
  1331. }
  1332. if ($this->noClear) {
  1333. $this->output_js_contents .= ',
  1334. noClear: true';
  1335. }
  1336. if ($this->navigationControlPosition!="") {
  1337. $this->output_js_contents .= ',
  1338. navigationControlOptions: {position: google.maps.ControlPosition.'.strtoupper($this->navigationControlPosition).'}';
  1339. }
  1340. if ($this->scaleControlPosition!="") {
  1341. $this->output_js_contents .= ',
  1342. scaleControl: true,
  1343. scaleControlOptions: {position: google.maps.ControlPosition.'.strtoupper($this->scaleControlPosition).'}';
  1344. }
  1345. if (!$this->scrollwheel) {
  1346. $this->output_js_contents .= ',
  1347. scrollwheel: false';
  1348. }
  1349. if ($this->streetViewControlPosition!="") {
  1350. $this->output_js_contents .= ',
  1351. streetViewControlOptions: {position: google.maps.ControlPosition.'.strtoupper($this->streetViewControlPosition).'}';
  1352. }
  1353. if ($this->tilt==45) {
  1354. $this->output_js_contents .= ',
  1355. tilt: '.$this->tilt;
  1356. }
  1357. $zoomControlOptions = array();
  1358. if ($this->zoomControlPosition!="") { array_push($zoomControlOptions, 'position: google.maps.ControlPosition.'.strtoupper($this->zoomControlPosition)); }
  1359. if ($this->zoomControlStyle!="" && (strtoupper($this->zoomControlStyle)=="SMALL" || strtoupper($this->zoomControlStyle)=="LARGE")) { array_push($zoomControlOptions, 'style: google.maps.ZoomControlStyle.'.strtoupper($this->zoomControlStyle)); }
  1360. if (count($zoomControlOptions)) {
  1361. $this->output_js_contents .= ',
  1362. zoomControlOptions: {'.implode(",", $zoomControlOptions).'}';
  1363. }
  1364. $this->output_js_contents .= '}
  1365. '.$this->map_name.' = new google.maps.Map(document.getElementById("'.$this->map_div_id.'"), myOptions);
  1366. ';
  1367.  
  1368. if ($styleOutput!="") {
  1369. $this->output_js_contents .= $styleOutput.'
  1370. ';
  1371. }
  1372.  
  1373. if ($this->trafficOverlay) {
  1374. $this->output_js_contents .= 'var trafficLayer = new google.maps.TrafficLayer();
  1375. trafficLayer.setMap('.$this->map_name.');
  1376. ';
  1377. }
  1378. if ($this->bicyclingOverlay) {
  1379. $this->output_js_contents .= 'var bikeLayer = new google.maps.BicyclingLayer();
  1380. bikeLayer.setMap('.$this->map_name.');
  1381. ';
  1382. }
  1383.  
  1384. if ((is_array($this->kmlLayerURL) && count($this->kmlLayerURL)) || (!is_array($this->kmlLayerURL) && $this->kmlLayerURL != ""))
  1385. {
  1386. if (!is_array($this->kmlLayerURL))
  1387. {
  1388. // Need to convert single KML layer to array
  1389. $this->kmlLayerURL = array($this->kmlLayerURL);
  1390. }
  1391. if (count($this->kmlLayerURL))
  1392. {
  1393. $i = 0;
  1394. foreach ($this->kmlLayerURL as $kmlLayerURL)
  1395. {
  1396. $this->output_js_contents .= '
  1397. var kmlLayerOptions = {
  1398. map: '.$this->map_name;
  1399. if ($this->kmlLayerPreserveViewport) {
  1400. $this->output_js_contents .= ',
  1401. preserveViewport: true';
  1402. }
  1403. $this->output_js_contents .= '
  1404. }
  1405. var kmlLayer_'.$i.' = new google.maps.KmlLayer("'.$kmlLayerURL.'", kmlLayerOptions);
  1406. ';
  1407. ++$i;
  1408. }
  1409. }
  1410. }
  1411.  
  1412. if ($this->panoramio) {
  1413. $this->output_js_contents .= 'var panoramioLayer = new google.maps.panoramio.PanoramioLayer();
  1414. ';
  1415. if ($this->panoramioTag!="") { $this->output_js_contents .= 'panoramioLayer.setTag("'.$this->panoramioTag.'");
  1416. '; }
  1417. if ($this->panoramioUser!="") { $this->output_js_contents .= 'panoramioLayer.setUserId("'.$this->panoramioUser.'");
  1418. '; }
  1419. $this->output_js_contents .= '
  1420. panoramioLayer.setMap('.$this->map_name.');
  1421. ';
  1422. }
  1423.  
  1424. if (strtolower($this->map_type)=="street") { // if defaulting the map to Street View
  1425. $this->output_js_contents .= '
  1426. var streetViewOptions = {
  1427. position: myLatlng';
  1428. if (!$this->streetViewAddressControl) {
  1429. $this->output_js_contents .= ',
  1430. addressControl: false';
  1431. }
  1432. if ($this->streetViewAddressPosition!="") {
  1433. $this->output_js_contents .= ',
  1434. addressControlOptions: { position: google.maps.ControlPosition.'.$this->streetViewAddressPosition.' }';
  1435. }
  1436. if ($this->streetViewCloseButton) {
  1437. $this->output_js_contents .= ',
  1438. enableCloseButton: true';
  1439. }
  1440. if (!$this->streetViewLinksControl) {
  1441. $this->output_js_contents .= ',
  1442. linksControl: false';
  1443. }
  1444. if (!$this->streetViewPanControl) {
  1445. $this->output_js_contents .= ',
  1446. panControl: false';
  1447. }
  1448. if ($this->streetViewPanPosition!="") {
  1449. $this->output_js_contents .= ',
  1450. panControlOptions: { position: google.maps.ControlPosition.'.$this->streetViewPanPosition.' }';
  1451. }
  1452. if ($this->streetViewPovHeading!=0 || $this->streetViewPovPitch!=0 || $this->streetViewPovZoom!=0) {
  1453. $this->output_js_contents .= ',
  1454. pov: {
  1455. heading: '.$this->streetViewPovHeading.',
  1456. pitch: '.$this->streetViewPovPitch.',
  1457. zoom: '.$this->streetViewPovZoom.'
  1458. }';
  1459. }
  1460. if (!$this->streetViewZoomControl) {
  1461. $this->output_js_contents .= ',
  1462. zoomControl: false';
  1463. }
  1464. if ($this->streetViewZoomPosition!="" || $this->streetViewZoomStyle!="") {
  1465. $this->output_js_contents .= ',
  1466. zoomControlOptions: {';
  1467. if ($this->streetViewZoomPosition!="") {
  1468. $this->output_js_contents .= '
  1469. position: google.maps.ControlPosition.'.$this->streetViewZoomPosition.',';
  1470. }
  1471. if ($this->streetViewZoomStyle!="") {
  1472. $this->output_js_contents .= '
  1473. style: google.maps.ZoomControlStyle.'.$this->streetViewZoomStyle.',';
  1474. }
  1475. $this->output_js_contents = trim($this->output_js_contents, ",");
  1476. $this->output_js_contents .= '}';
  1477. }
  1478. $this->output_js_contents .= '
  1479. };
  1480. var streetView = new google.maps.StreetViewPanorama(document.getElementById("'.$this->map_div_id.'"), streetViewOptions);
  1481. streetView.setVisible(true);
  1482. ';
  1483. }
  1484.  
  1485. if ($this->center=="auto") { // if wanting to center on the users location
  1486. $this->output_js_contents .= '
  1487. // Try W3C Geolocation (Preferred)
  1488. if(navigator.geolocation) {
  1489. navigator.geolocation.getCurrentPosition(function(position) {
  1490. '.$this->map_name.'.setCenter(new google.maps.LatLng(position.coords.latitude,position.coords.longitude));
  1491. }, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); });
  1492. // Browser doesn\'t support Geolocation
  1493. }else{
  1494. alert(\'Your browser does not support geolocation.\');
  1495. }
  1496. ';
  1497. }
  1498.  
  1499. if ($this->directions) {
  1500. $this->output_js_contents .= 'directionsDisplay.setMap('.$this->map_name.');
  1501. ';
  1502. if ($this->directionsDivID!="") {
  1503. $this->output_js_contents .= 'directionsDisplay.setPanel(document.getElementById("'.$this->directionsDivID.'"));
  1504. ';
  1505. }
  1506. if ($this->directionsDraggable && $this->directionsChanged!="") {
  1507. $this->output_js_contents .= 'google.maps.event.addListener(directionsDisplay, "directions_changed", function() {
  1508. '.$this->directionsChanged.'
  1509. });
  1510. ';
  1511. }
  1512. }
  1513.  
  1514. if ($this->drawing) {
  1515.  
  1516. if ($this->drawingControlPosition=='') { $this->drawingControlPosition = 'TOP_CENTER'; }
  1517.  
  1518. $this->output_js_contents .= 'drawingManager = new google.maps.drawing.DrawingManager({
  1519. drawingMode: google.maps.drawing.OverlayType.'.strtoupper($this->drawingDefaultMode).',
  1520. drawingControl: '.(!$this->drawingControl ? 'false' : 'true').',
  1521. drawingControlOptions: {
  1522. position: google.maps.ControlPosition.'.strtoupper($this->drawingControlPosition);
  1523. $shapeOptions = '';
  1524. if (count($this->drawingModes)) {
  1525. $this->output_js_contents .= ',
  1526. drawingModes: [';
  1527. $i=0;
  1528. foreach ($this->drawingModes as $drawingMode) {
  1529. if ($i>0) { $this->output_js_contents .= ','; }
  1530. $this->output_js_contents .= 'google.maps.drawing.OverlayType.'.strtoupper($drawingMode);
  1531. if (strtoupper($drawingMode)!="MARKER") {
  1532. $shapeOptions .= ',
  1533. '.strtolower($drawingMode).'Options: {
  1534. editable: true
  1535. }';
  1536. }
  1537. $i++;
  1538. }
  1539. $this->output_js_contents .= ']';
  1540. }
  1541. $this->output_js_contents .= '
  1542. }'.$shapeOptions.'
  1543. });
  1544. drawingManager.setMap('.$this->map_name.');
  1545. ';
  1546.  
  1547. $this->output_js_contents .= '
  1548. google.maps.event.addListener(drawingManager, "overlaycomplete", function(event) {
  1549. var newShape = event.overlay;
  1550. newShape.type = event.type;
  1551. ';
  1552. if (count($this->drawingOnComplete)) {
  1553. foreach ($this->drawingOnComplete as $shape=>$js) {
  1554. $this->output_js_contents .= 'if (event.type==google.maps.drawing.OverlayType.'.strtoupper($shape).') {
  1555. '.$js.'
  1556. }
  1557. ';
  1558. }
  1559. }
  1560.  
  1561. if (count($this->drawingOnEdit)) {
  1562.  
  1563. if (isset($this->drawingOnEdit['polygon'])) {
  1564. $this->output_js_contents .= '
  1565. if (newShape.type==google.maps.drawing.OverlayType.POLYGON) {
  1566. var newShapePaths = newShape.getPaths();
  1567. for (var i=0; i<newShapePaths.length; i++) {
  1568. google.maps.event.addListener(newShapePaths.getAt(i), "set_at", function(event) {
  1569. '.$this->drawingOnEdit['polygon'].'
  1570. });
  1571. google.maps.event.addListener(newShapePaths.getAt(i), "insert_at", function(event) {
  1572. '.$this->drawingOnEdit['polygon'].'
  1573. });
  1574. google.maps.event.addListener(newShapePaths.getAt(i), "remove_at", function(event) {
  1575. '.$this->drawingOnEdit['polygon'].'
  1576. });
  1577. }
  1578. }';
  1579. }
  1580. if (isset($this->drawingOnEdit['polyline'])) {
  1581. $this->output_js_contents .= '
  1582. if (newShape.type==google.maps.drawing.OverlayType.POLYLINE) {
  1583. var newShapePaths = newShape.getPaths();
  1584. for (var i=0; i<newShapePaths.length; i++) {
  1585. google.maps.event.addListener(newShapePaths.getAt(i), "set_at", function(event) {
  1586. '.$this->drawingOnEdit['polyline'].'
  1587. });
  1588. google.maps.event.addListener(newShapePaths.getAt(i), "insert_at", function(event) {
  1589. '.$this->drawingOnEdit['polyline'].'
  1590. });
  1591. google.maps.event.addListener(newShapePaths.getAt(i), "remove_at", function(event) {
  1592. '.$this->drawingOnEdit['polyline'].'
  1593. });
  1594. }
  1595. }';
  1596. }
  1597. if (isset($this->drawingOnEdit['rectangle'])) {
  1598. $this->output_js_contents .= '
  1599. if (newShape.type==google.maps.drawing.OverlayType.RECTANGLE) {
  1600. google.maps.event.addListener(newShape, "bounds_changed", function(event) {
  1601. '.$this->drawingOnEdit['rectangle'].'
  1602. });
  1603. }';
  1604. }
  1605. if (isset($this->drawingOnEdit['circle'])) {
  1606. $this->output_js_contents .= '
  1607. if (newShape.type==google.maps.drawing.OverlayType.CIRCLE) {
  1608. google.maps.event.addListener(newShape, "radius_changed", function(event) {
  1609. '.$this->drawingOnEdit['circle'].'
  1610. });
  1611. google.maps.event.addListener(newShape, "center_changed", function(event) {
  1612. '.$this->drawingOnEdit['circle'].'
  1613. });
  1614. }';
  1615. }
  1616. }
  1617.  
  1618. $this->output_js_contents .= '
  1619. });';
  1620.  
  1621. }
  1622.  
  1623. if ($this->places) {
  1624.  
  1625. $placesLocationSet = false;
  1626.  
  1627. if ($this->placesLocationSW!="" && $this->placesLocationNE!="") { // if search based on bounds
  1628.  
  1629. $placesLocationSet = true;
  1630.  
  1631. if ($this->is_lat_long($this->placesLocationSW)) {
  1632. $this->output_js_contents .= 'var placesLocationSW = new google.maps.LatLng('.$this->placesLocationSW.');
  1633. ';
  1634. }else{ // if centering the map on an address
  1635. $lat_long = $this->get_lat_long_from_address($this->placesLocationSW);
  1636. $this->output_js_contents .= 'var placesLocationSW = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');
  1637. ';
  1638. }
  1639.  
  1640. if ($this->is_lat_long($this->placesLocationNE)) {
  1641. $this->output_js_contents .= 'var placesLocationNE = new google.maps.LatLng('.$this->placesLocationNE.');
  1642. ';
  1643. }else{ // if centering the map on an address
  1644. $lat_long = $this->get_lat_long_from_address($this->placesLocationNE);
  1645. $this->output_js_contents .= 'var placesLocationNE = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');
  1646. ';
  1647. }
  1648.  
  1649. }
  1650.  
  1651. if (($placesLocationSet || $this->placesLocation!="") || count($this->placesTypes) || $this->placesName!="")
  1652. {
  1653. $this->output_js_contents .= 'var placesRequest = {
  1654. ';
  1655. if ($placesLocationSet) {
  1656. $this->output_js_contents .= 'bounds: new google.maps.LatLngBounds(placesLocationSW, placesLocationNE)
  1657. ';
  1658. }else{
  1659. if ($this->placesLocation!="") { // if search based on a center point
  1660. if ($this->is_lat_long($this->placesLocation)) { // if centering the map on a lat/long
  1661. $this->output_js_contents .= 'location: new google.maps.LatLng('.$this->placesLocation.')
  1662. ';
  1663. }else{ // if centering the map on an address
  1664. $lat_long = $this->get_lat_long_from_address($this->placesLocation);
  1665. $this->output_js_contents .= 'location: new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')
  1666. ';
  1667. }
  1668. $this->output_js_contents .= ',radius: '.$this->placesRadius.'
  1669. ';
  1670. }
  1671. }
  1672.  
  1673. if (count($this->placesTypes)) {
  1674. $this->output_js_contents .= ',types: [\''.implode("','", $this->placesTypes).'\']
  1675. ';
  1676. }
  1677. if ($this->placesName!="") {
  1678. $this->output_js_contents .= ',name : \''.$this->placesName.'\'
  1679. ';
  1680. }
  1681. $this->output_js_contents .= '};
  1682.  
  1683. placesService = new google.maps.places.PlacesService('.$this->map_name.');
  1684. placesService.search(placesRequest, placesCallback);
  1685. ';
  1686. }
  1687.  
  1688. if ($this->placesAutocompleteInputID != "")
  1689. {
  1690. $this->output_js_contents .= 'var autocompleteOptions = {
  1691. ';
  1692. $autocompleteOptions = '';
  1693. if ($this->placesAutocompleteBoundSW != "" && $this->placesAutocompleteBoundNE != "")
  1694. {
  1695. if ($this->is_lat_long($this->placesAutocompleteBoundSW)) {
  1696. $autocompleteOptionsSW = 'new google.maps.LatLng('.$this->placesAutocompleteBoundSW.')
  1697. ';
  1698. }else{ // if centering the map on an address
  1699. $lat_long = $this->get_lat_long_from_address($this->placesAutocompleteBoundSW);
  1700. $autocompleteOptionsSW = 'new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')
  1701. ';
  1702. }
  1703.  
  1704. if ($this->is_lat_long($this->placesAutocompleteBoundNE)) {
  1705. $autocompleteOptionsNE = 'new google.maps.LatLng('.$this->placesAutocompleteBoundNE.')
  1706. ';
  1707. }else{ // if centering the map on an address
  1708. $lat_long = $this->get_lat_long_from_address($this->placesAutocompleteBoundNE);
  1709. $autocompleteOptionsNE = 'new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')
  1710. ';
  1711. }
  1712. $autocompleteOptions .= 'bounds: new google.maps.LatLngBounds('.$autocompleteOptionsSW.', '.$autocompleteOptionsNE.')';
  1713. }
  1714. if (count($this->placesAutocompleteTypes))
  1715. {
  1716. if ($autocompleteOptions != "")
  1717. {
  1718. $autocompleteOptions .= ',
  1719. ';
  1720. }
  1721. $autocompleteOptions .= 'types: [\''.implode("','", $this->placesAutocompleteTypes).'\']';
  1722. }
  1723. $this->output_js_contents .= $autocompleteOptions;
  1724. $this->output_js_contents .= '}';
  1725.  
  1726. $this->output_js_contents .= '
  1727. var autocompleteInput = document.getElementById(\''.$this->placesAutocompleteInputID.'\');
  1728.  
  1729. placesAutocomplete = new google.maps.places.Autocomplete(autocompleteInput, autocompleteOptions);
  1730. ';
  1731.  
  1732. if ($this->placesAutocompleteBoundsMap)
  1733. {
  1734. $this->output_js_contents .= 'placesAutocomplete.bindTo(\'bounds\', map);
  1735. ';
  1736. }
  1737.  
  1738. if ($this->placesAutocompleteOnChange != "")
  1739. {
  1740. $this->output_js_contents .= 'google.maps.event.addListener(placesAutocomplete, \'place_changed\', function() {
  1741. '.$this->placesAutocompleteOnChange.'
  1742. });
  1743. ';
  1744. }
  1745. }
  1746.  
  1747. }
  1748.  
  1749. if ($this->onboundschanged!="") {
  1750. $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "bounds_changed", function(event) {
  1751. '.$this->onboundschanged.'
  1752. });
  1753. ';
  1754. }
  1755. if ($this->oncenterchanged!="") {
  1756. $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "center_changed", function(event) {
  1757. '.$this->oncenterchanged.'
  1758. });
  1759. ';
  1760. }
  1761. if ($this->onclick!="") {
  1762. $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "click", function(event) {
  1763. '.$this->onclick.'
  1764. });
  1765. ';
  1766. }
  1767. if ($this->ondblclick!="") {
  1768. $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "dblclick", function(event) {
  1769. '.$this->ondblclick.'
  1770. });
  1771. ';
  1772. }
  1773. if ($this->ondrag!="") {
  1774. $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "drag", function(event) {
  1775. '.$this->ondrag.'
  1776. });
  1777. ';
  1778. }
  1779. if ($this->ondragend!="") {
  1780. $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "dragend", function(event) {
  1781. '.$this->ondragend.'
  1782. });
  1783. ';
  1784. }
  1785. if ($this->ondragstart!="") {
  1786. $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "dragstart", function(event) {
  1787. '.$this->ondragstart.'
  1788. });
  1789. ';
  1790. }
  1791. if ($this->onidle!="") {
  1792. $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "idle", function(event) {
  1793. '.$this->onidle.'
  1794. });
  1795. ';
  1796. }
  1797. if ($this->onmousemove!="") {
  1798. $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "mousemove", function(event) {
  1799. '.$this->onmousemove.'
  1800. });
  1801. ';
  1802. }
  1803. if ($this->onmouseout!="") {
  1804. $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "mouseout", function(event) {
  1805. '.$this->onmouseout.'
  1806. });
  1807. ';
  1808. }
  1809. if ($this->onmouseover!="") {
  1810. $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "mouseover", function(event) {
  1811. '.$this->onmouseover.'
  1812. });
  1813. ';
  1814. }
  1815. if ($this->onresize!="") {
  1816. $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "resize", function(event) {
  1817. '.$this->onresize.'
  1818. });
  1819. ';
  1820. }
  1821. if ($this->onrightclick!="") {
  1822. $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "rightclick", function(event) {
  1823. '.$this->onrightclick.'
  1824. });
  1825. ';
  1826. }
  1827. if ($this->ontilesloaded!="") {
  1828. $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "tilesloaded", function(event) {
  1829. '.$this->ontilesloaded.'
  1830. });
  1831. ';
  1832. }
  1833. if ($this->onzoomchanged!="") {
  1834. $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "zoom_changed", function(event) {
  1835. '.$this->onzoomchanged.'
  1836. });
  1837. ';
  1838. }
  1839.  
  1840. // add markers
  1841. if (count($this->markers)) {
  1842. foreach ($this->markers as $marker) {
  1843. $this->output_js_contents .= $marker;
  1844. }
  1845. }
  1846. //
  1847.  
  1848. if ($this->cluster) {
  1849. $this->output_js_contents .= '
  1850. var clusterOptions = {
  1851. gridSize: '.$this->clusterGridSize;
  1852. if ($this->clusterMaxZoom!="") { $this->output_js_contents .= ',
  1853. maxZoom: '.$this->clusterMaxZoom; }
  1854. if (!$this->clusterZoomOnClick) { $this->output_js_contents .= ',
  1855. zoomOnClick: false'; }
  1856. if ($this->clusterAverageCenter) { $this->output_js_contents .= ',
  1857. averageCenter: true'; }
  1858. $this->output_js_contents .= ',
  1859. minimumClusterSize: '.$this->clusterMinimumClusterSize.'
  1860. };
  1861. markerCluster = new MarkerClusterer('.$this->map_name.', markers_'.$this->map_name.', clusterOptions);
  1862. ';
  1863. }
  1864.  
  1865. // add polylines
  1866. if (count($this->polylines)) {
  1867. foreach ($this->polylines as $polyline) {
  1868. $this->output_js_contents .= $polyline;
  1869. }
  1870. }
  1871. //
  1872.  
  1873. // add polygons
  1874. if (count($this->polygons)) {
  1875. foreach ($this->polygons as $polygon) {
  1876. $this->output_js_contents .= $polygon;
  1877. }
  1878. }
  1879. //
  1880.  
  1881. // add circles
  1882. if (count($this->circles)) {
  1883. foreach ($this->circles as $circle) {
  1884. $this->output_js_contents .= $circle;
  1885. }
  1886. }
  1887. //
  1888.  
  1889. // add rectangles
  1890. if (count($this->rectangles)) {
  1891. foreach ($this->rectangles as $rectangle) {
  1892. $this->output_js_contents .= $rectangle;
  1893. }
  1894. }
  1895. //
  1896.  
  1897. // add ground overlays
  1898. if (count($this->overlays)) {
  1899. foreach ($this->overlays as $overlay) {
  1900. $this->output_js_contents .= $overlay;
  1901. }
  1902. }
  1903. //
  1904.  
  1905. if ($this->zoom=="auto") {
  1906.  
  1907. $this->output_js_contents .= '
  1908. fitMapToBounds_'.$this->map_name.'();
  1909. ';
  1910.  
  1911. }
  1912.  
  1913. if ($this->adsense) {
  1914. $this->output_js_contents .= '
  1915. var adUnitDiv = document.createElement("div");
  1916.  
  1917. // Note: replace the publisher ID noted here with your own
  1918. // publisher ID.
  1919. var adUnitOptions = {
  1920. format: google.maps.adsense.AdFormat.'.$this->adsenseFormat.',
  1921. position: google.maps.ControlPosition.'.$this->adsensePosition.',
  1922. publisherId: "'.$this->adsensePublisherID.'",
  1923. ';
  1924. if ($this->adsenseChannelNumber!="") { $this->output_js_contents .= 'channelNumber: "'.$this->adsenseChannelNumber.'",
  1925. '; }
  1926. $this->output_js_contents .= 'map: '.$this->map_name.',
  1927. visible: true
  1928. };
  1929. adUnit = new google.maps.adsense.AdUnit(adUnitDiv, adUnitOptions);
  1930. ';
  1931. }
  1932.  
  1933. if ($this->directions && $this->directionsStart!="" && $this->directionsEnd!="") {
  1934. if ($this->directionsStart=="auto" && $this->directionsEnd=="auto") {
  1935. // Both start and finish are at the users current location
  1936. $this->output_js_contents .= '
  1937. // Try W3C Geolocation (Preferred)
  1938. if(navigator.geolocation) {
  1939. navigator.geolocation.getCurrentPosition(function(position) {
  1940. start = position.coords.latitude+","+position.coords.longitude;
  1941. calcRoute(start, start);
  1942. }, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); });
  1943. // Browser doesn\'t support Geolocation
  1944. }else{
  1945. alert(\'Your browser does not support geolocation.\');
  1946. }
  1947. ';
  1948. }else if ($this->directionsStart=="auto") {
  1949. // The start point should be at the users current location
  1950. $this->output_js_contents .= '
  1951. // Try W3C Geolocation (Preferred)
  1952. if(navigator.geolocation) {
  1953. navigator.geolocation.getCurrentPosition(function(position) {
  1954. start = position.coords.latitude+","+position.coords.longitude;
  1955. calcRoute(start, \''.$this->directionsEnd.'\');
  1956. }, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); });
  1957. // Browser doesn\'t support Geolocation
  1958. }else{
  1959. alert(\'Your browser does not support geolocation.\');
  1960. }
  1961. ';
  1962. }else if ($this->directionsEnd=="auto") {
  1963. // The end point should be at the users current location
  1964. $this->output_js_contents .= '
  1965. // Try W3C Geolocation (Preferred)
  1966. if(navigator.geolocation) {
  1967. navigator.geolocation.getCurrentPosition(function(position) {
  1968. end = position.coords.latitude+","+position.coords.longitude;
  1969. calcRoute(\''.$this->directionsStart.'\', end);
  1970. }, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); });
  1971. // Browser doesn\'t support Geolocation
  1972. }else{
  1973. alert(\'Your browser does not support geolocation.\');
  1974. }
  1975. ';
  1976. }else{
  1977. // The start and end point are at pre-defined locations
  1978. $this->output_js_contents .= '
  1979. calcRoute(\''.$this->directionsStart.'\', \''.$this->directionsEnd.'\');
  1980. ';
  1981. }
  1982. }
  1983.  
  1984. if ($this->onload!="") {
  1985. $this->output_js_contents .= '
  1986. '.$this->onload;
  1987. }
  1988.  
  1989. $this->output_js_contents .= '
  1990.  
  1991. }
  1992.  
  1993. ';
  1994.  
  1995. // add markers
  1996. $this->output_js_contents .= '
  1997. function createMarker_'.$this->map_name.'(markerOptions) {
  1998. var marker = new google.maps.Marker(markerOptions);
  1999. markers_'.$this->map_name.'.push(marker);
  2000. lat_longs_'.$this->map_name.'.push(marker.getPosition());
  2001. return marker;
  2002. }
  2003. ';
  2004. //
  2005.  
  2006. if ($this->directions) {
  2007.  
  2008. $this->output_js_contents .= 'function calcRoute(start, end) {
  2009.  
  2010. var request = {
  2011. origin:start,
  2012. destination:end,
  2013. travelMode: google.maps.TravelMode.'.$this->directionsMode.'
  2014. ';
  2015.  
  2016. if (count($this->directionsWaypointArray)) {
  2017.  
  2018. $directionsWaypointStr = '';
  2019. foreach ($this->directionsWaypointArray as $waypoint) {
  2020. if ($directionsWaypointStr != '') { $directionsWaypointStr .= ','; }
  2021. $directionsWaypointStr .= '{ location: "' . $waypoint . '", stopover: true}';
  2022. }
  2023. $this->output_js_contents .= ', waypoints: [' . $directionsWaypointStr . ']';
  2024.  
  2025. if ($this->directionsWaypointsOptimize)
  2026. {
  2027. $this->output_js_contents .= ', optimizeWaypoints: true'
  2028. ;
  2029. }
  2030. }
  2031. if ($this->region!="" && strlen($this->region)==2) {
  2032. $this->output_js_contents .= ',region: '.strtoupper($this->region).'
  2033. ';
  2034. }
  2035. if (trim($this->directionsUnits)!="" && (strtolower(trim($this->directionsUnits)) == "metric" || strtolower(trim($this->directionsUnits)) == "imperial")) {
  2036. $this->output_js_contents .= ',unitSystem: google.maps.UnitSystem.'.strtoupper(trim($this->directionsUnits)).'
  2037. ';
  2038. }
  2039. if ($this->directionsAvoidTolls) {
  2040. $this->output_js_contents .= ',avoidTolls: true
  2041. ';
  2042. }
  2043. if ($this->directionsAvoidHighways) {
  2044. $this->output_js_contents .= ',avoidHighways: true
  2045. ';
  2046. }
  2047.  
  2048. $this->output_js_contents .= '
  2049. };
  2050. directionsService.route(request, function(response, status) {
  2051. if (status == google.maps.DirectionsStatus.OK) {
  2052. directionsDisplay.setDirections(response);
  2053. }else{
  2054. switch (status) {
  2055. case "NOT_FOUND": { alert("Either the start location or destination were not recognised"); break }
  2056. case "ZERO_RESULTS": { alert("No route could be found between the start location and destination"); break }
  2057. case "MAX_WAYPOINTS_EXCEEDED": { alert("Maximum waypoints exceeded. Maximum of 8 allowed"); break }
  2058. case "INVALID_REQUEST": { alert("Invalid request made for obtaining directions"); break }
  2059. case "OVER_QUERY_LIMIT": { alert("This webpage has sent too many requests recently. Please try again later"); break }
  2060. case "REQUEST_DENIED": { alert("This webpage is not allowed to request directions"); break }
  2061. case "UNKNOWN_ERROR": { alert("Unknown error with the server. Please try again later"); break }
  2062. }
  2063. }
  2064. });
  2065. }
  2066. ';
  2067.  
  2068. }
  2069.  
  2070. if ($this->places) {
  2071. $this->output_js_contents .= 'function placesCallback(results, status) {
  2072. if (status == google.maps.places.PlacesServiceStatus.OK) {
  2073. for (var i = 0; i < results.length; i++) {
  2074.  
  2075. var place = results[i];
  2076.  
  2077. var placeLoc = place.geometry.location;
  2078. var placePosition = new google.maps.LatLng(placeLoc.lat(), placeLoc.lng());
  2079. var markerOptions = {
  2080. map: '.$this->map_name.',
  2081. position: placePosition
  2082. };
  2083. var marker = createMarker_'.$this->map_name.'(markerOptions);
  2084. marker.set("content", place.name);
  2085. google.maps.event.addListener(marker, "click", function() {
  2086. iw_'.$this->map_name.'.setContent(this.get("content"));
  2087. iw_'.$this->map_name.'.open('.$this->map_name.', this);
  2088. });
  2089.  
  2090. lat_longs_'.$this->map_name.'.push(placePosition);
  2091.  
  2092. }
  2093. ';
  2094. if ($this->zoom=="auto") { $this->output_js_contents .= 'fitMapToBounds_'.$this->map_name.'();'; }
  2095. $this->output_js_contents .= '
  2096. }
  2097. }
  2098. ';
  2099. }
  2100.  
  2101. if ($this->zoom=="auto") {
  2102. $this->output_js_contents .= '
  2103. function fitMapToBounds_'.$this->map_name.'() {
  2104. var bounds = new google.maps.LatLngBounds();
  2105. if (lat_longs_'.$this->map_name.'.length>0) {
  2106. for (var i=0; i<lat_longs_'.$this->map_name.'.length; i++) {
  2107. bounds.extend(lat_longs_'.$this->map_name.'[i]);
  2108. }
  2109. '.$this->map_name.'.fitBounds(bounds);
  2110. }
  2111. }
  2112. ';
  2113. }
  2114.  
  2115. if ($this->loadAsynchronously) {
  2116. $this->output_js_contents .= '
  2117. function loadScript_'.$this->map_name.'() {
  2118. var script = document.createElement("script");
  2119. script.type = "text/javascript";
  2120. script.src = "'.$apiLocation.'&callback=initialize_'.$this->map_name.'";
  2121. document.body.appendChild(script);
  2122. }
  2123. window.onload = loadScript_'.$this->map_name.';
  2124. ';
  2125. }else{
  2126. $this->output_js_contents .= '
  2127. google.maps.event.addDomListener(window, "load", initialize_'.$this->map_name.');
  2128. ';
  2129. }
  2130.  
  2131. // Minify the Javascript if the $minifyJS config value is true. Requires Jsmin.php and PHP 5+
  2132. if ($this->minifyJS) {
  2133. $CI =& get_instance();
  2134. $CI->load->library('jsmin');
  2135. $this->output_js_contents = $CI->jsmin->min($this->output_js_contents);
  2136. }
  2137.  
  2138. if ($this->jsfile=="") {
  2139. $this->output_js .= $this->output_js_contents;
  2140. }else{ // if needs writing to external js file
  2141. if (!$handle = fopen($this->jsfile, "w")) {
  2142. $this->output_js .= $this->output_js_contents;
  2143. }else{
  2144. if (!fwrite($handle, $this->output_js_contents)) {
  2145. $this->output_js .= $this->output_js_contents;
  2146. }else{
  2147. $this->output_js .= '
  2148. <script src="'.$this->jsfile.'" type="text/javascript"></script>';
  2149. }
  2150. }
  2151. }
  2152.  
  2153. if ($this->jsfile=="") {
  2154. $this->output_js .= '
  2155. //]]>
  2156. </script>';
  2157. }
  2158.  
  2159. // set height and width
  2160. if (is_numeric($this->map_width)) { // if no width type set
  2161. $this->map_width = $this->map_width.'px';
  2162. }
  2163. if (is_numeric($this->map_height)) { // if no height type set
  2164. $this->map_height = $this->map_height.'px';
  2165. }
  2166. //
  2167.  
  2168. $this->output_html .= '<div id="'.$this->map_div_id.'" style="width:'.$this->map_width.'; height:'.$this->map_height.';"'.(($this->class != "") ? ' class="'.$this->class.'"' : '').'></div>';
  2169.  
  2170. ++$this->maps_loaded;
  2171.  
  2172. return array('js'=>$this->output_js, 'html'=>$this->output_html, 'markers'=>$this->markersInfo);
  2173.  
  2174. }
  2175.  
  2176. function is_lat_long($input)
  2177. {
  2178.  
  2179. $input = str_replace(", ", ",", trim($input));
  2180. $input = explode(",", $input);
  2181. if (count($input)==2) {
  2182.  
  2183. if (is_numeric($input[0]) && is_numeric($input[1])) { // is a lat long
  2184. return true;
  2185. }else{ // not a lat long - incorrect values
  2186. return false;
  2187. }
  2188.  
  2189. }else{ // not a lat long - too many parts
  2190. return false;
  2191. }
  2192.  
  2193. }
  2194.  
  2195. function get_lat_long_from_address($address, $attempts = 0)
  2196. {
  2197.  
  2198. $lat = 0;
  2199. $lng = 0;
  2200.  
  2201. $error = '';
  2202.  
  2203. if ($this->geocodeCaching) { // if caching of geocode requests is activated
  2204.  
  2205. $CI =& get_instance();
  2206. $CI->load->database();
  2207. $CI->db->select("latitude,longitude");
  2208. $CI->db->from("geocoding");
  2209. $CI->db->where("address", trim(strtolower($address)));
  2210. $query = $CI->db->get();
  2211.  
  2212. if ($query->num_rows()>0) {
  2213. $row = $query->row();
  2214. return array($row->latitude, $row->longitude);
  2215. }
  2216.  
  2217. }
  2218.  
  2219. if ($this->https) { $data_location = 'https://'; }else{ $data_location = 'http://'; }
  2220. $data_location .= "maps.google.com/maps/api/geocode/json?address=".urlencode(utf8_encode($address))."&sensor=".$this->sensor;
  2221. if ($this->region!="" && strlen($this->region)==2) { $data_location .= "&region=".$this->region; }
  2222. $data = file_get_contents($data_location);
  2223.  
  2224. $data = json_decode($data);
  2225.  
  2226. if ($data->status=="OK")
  2227. {
  2228. $lat = $data->results[0]->geometry->location->lat;
  2229. $lng = $data->results[0]->geometry->location->lng;
  2230.  
  2231. if ($this->geocodeCaching) { // if we to need to cache this result
  2232. if ($address != "" && $lat != 0 && $lng != 0)
  2233. {
  2234. $data = array(
  2235. "address"=>trim(strtolower($address)),
  2236. "latitude"=>$lat,
  2237. "longitude"=>$lng
  2238. );
  2239. $CI->db->insert("geocoding", $data);
  2240. }
  2241. }
  2242. }
  2243. else
  2244. {
  2245. if ($data->status == "OVER_QUERY_LIMIT")
  2246. {
  2247. $error = $data->status;
  2248. if ($attempts < 2)
  2249. {
  2250. sleep(1);
  2251. ++$attempts;
  2252. list($lat, $lng, $error) = $this->get_lat_long_from_address($address, $attempts);
  2253. }
  2254. }
  2255. }
  2256.  
  2257. return array($lat, $lng, $error);
  2258.  
  2259. }
  2260.  
  2261. }
  2262.  
  2263. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement