Map::create_map()   F
last analyzed

Complexity

Conditions 212

Size

Total Lines 1120
Code Lines 547

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
eloc 547
c 6
b 0
f 0
dl 0
loc 1120
rs 3.3333
cc 212
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php namespace GeneaLabs\LaravelMaps;
2
3
class Map
4
{
5
6
    protected $output_js;
7
    protected $output_js_contents;
8
    protected $output_html;
9
10
    public $adsense = false;                    // Whether Google Adsense For Content should be enabled
11
    public $adsenseChannelNumber = '';                        // The Adsense channel number for tracking the performance of this AdUnit
12
    public $adsenseFormat = 'HALF_BANNER';            // The format of the AdUnit
13
    public $adsensePosition = 'TOP_CENTER';                // The position of the AdUnit
14
    public $adsensePublisherID = '';                        // Your Google AdSense publisher ID
15
    public $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
16
    public $backgroundColor = '';                        // A hex color value shown as the map background when tiles have not yet loaded as the user pans
17
    public $bicyclingOverlay = false;                    // If set to TRUE will overlay bicycling information (ie. bike paths and suggested routes) onto the map by default
18
    public $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"
19
20
    public $class = '';                        // A class name if wishing to style the map further through CSS. Can also be useful if wanting it to be responsive etc.
21
    public $cluster = false;                    // Whether to cluster markers
22
    public $clusterGridSize = 60;                        // The grid size of a cluster in pixels
23
    public $clusterMaxZoom = '';                        // The maximum zoom level that a marker can be part of a cluster
24
    public $clusterZoomOnClick = true;                        // Whether the default behaviour of clicking on a cluster is to zoom into it
25
    public $clusterAverageCenter = false;                    // Whether the center of each cluster should be the average of all markers in the cluster
26
    public $clusterMinimumClusterSize = 2;                        // The minimum number of markers to be in a cluster before the markers are hidden and a count is shown
27
    public $clusterStyles = []; 				// (object) An array that has style properties: *  'url': (string) The image url. *  'height': (number) The image height. *  'width': (number) The image width. *  'anchor': (Array) The anchor position of the label text. *  'textColor': (string) The text color. *  'textSize': (number) The text size. *  'backgroundPosition': (string) The position of the backgound x, y.
28
    public $disableDefaultUI = false;                    // If set to TRUE will hide the default controls (ie. zoom, scale etc)
29
    public $disableClickableIcons = false;
30
    public $disableDoubleClickZoom = false;                    // If set to TRUE will disable zooming when a double click occurs
31
    public $disableMapTypeControl = false;                    // If set to TRUE will hide the MapType control (ie. Map, Satellite, Hybrid, Terrain)
32
    public $disableNavigationControl = false;                    // If set to TRUE will hide the Navigation control (ie. zoom in/out, pan)
33
    public $disableScaleControl = false;                    // If set to TRUE will hide the Scale control
34
    public $disableStreetViewControl = false;                    // If set to TRUE will hide the Street View control
35
    public $draggable = true;                        // If set to FALSE will prevent the map from being dragged around
36
    public $draggableCursor = '';                        // The name or url of the cursor to display on a draggable object
37
    public $draggingCursor = '';                        // The name or url of the cursor to display when an object is being dragged
38
    public $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)
39
    public $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
40
    public $navigationControlPosition = '';                        // The position of the Navigation control, eg. 'BOTTOM_RIGHT'
41
    public $infowindowMaxWidth = 0;                        // The maximum width of the infowindow in pixels. Expecting an integer without units
42
    public $infoAutoPan = false;                        //Disable auto-pan on open. By default, the info window will pan the map so that it is fully visible when it opens.
43
    public $keyboardShortcuts = true;                        // If set to FALSE will disable to map being controlled via the keyboard
44
    public $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
45
    public $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
46
    public $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
47
    public $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
48
    public $loadAsynchronously = false;                    // Load the map and API asynchronously once the page has loaded
49
    public $map_div_id = "map_canvas";                // The ID of the <div></div> that is output which contains the map
50
    public $map_height = "450px";                    // The height of the map container. Any units (ie 'px') can be used. If no units are provided 'px' will be presumed
51
    public $map_name = "map";                    // The JS reference to the map. Currently not used but to be used in the future when multiple maps are supported
52
    public $map_type = "ROADMAP";                // The default MapType. Values accepted are 'HYBRID', 'ROADMAP', 'SATELLITE' or 'TERRAIN'
53
    public $map_types_available = array();                    // The other MapTypes available for selection on the map
54
    public $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
55
    public $maps_loaded = 0;                        // Counter which keeps track of how many maps have been created to avoid standard functions being output twice
56
    public $mapTypeControlPosition = '';                        // The position of the MapType control, eg. 'BOTTOM_RIGHT'
57
    public $mapTypeControlStyle = '';                        // The style of the MapType control. blank, 'DROPDOWN_MENU' or 'HORIZONTAL_BAR' values accepted.
58
    public $minzoom = '';                        // The minimum zoom level which will be displayed on the map
59
    public $maxzoom = '';                        // The maximum zoom level which will be displayed on the map
60
    public $minifyJS = false;                    // If TRUE will run the JavaScript through Jsmin.php (this file and PHP5+ required) to minify the code
61
    public $noClear = false;                    // If TRUE do not clear the contents of the map div
62
    public $onboundschanged = '';                        // The JavaScript action to perform when the viewport bounds have changed
63
    public $oncenterchanged = '';                        // The JavaScript action to perform when themap center property changes
64
    public $onclick = '';                        // The JavaScript action to perform when the map is clicked
65
    public $ondblclick = '';                        // The JavaScript action to perform when the map is double-clicked
66
    public $ondrag = '';                        // The JavaScript action to perform while the map is dragged
67
    public $ondragend = '';                        // The JavaScript action to perform when the user stops dragging the map
68
    public $ondragstart = '';                        // The JavaScript action to perform when the user starts dragging the map
69
    public $onidle = '';                        // The JavaScript action to perform when the map becomes idle after panning or zooming
70
    public $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
71
    public $onmousemove = '';                        // The JavaScript action to perform when the user's mouse moves over the map container
72
    public $onmouseout = '';                        // The JavaScript action to perform when the user's mouse exits the map container
73
    public $onmouseover = '';                        // The JavaScript action to perform when the user's mouse enters the map container
74
    public $onresize = '';                        // The JavaScript action to perform when the maps div changes size
75
    public $onrightclick = '';                        // The JavaScript action to perform when the map is right-clicked
76
    public $ontilesloaded = '';                        // The JavaScript action to perform when the visible tiles have finished loading
77
    public $onzoomchanged = '';                        // The JavaScript action to perform when the maps zoom property changes
78
    public $panoramio = false;                    // If TRUE will add photos from Panoramio as a layer to your maps as a series of large and small photo icons
79
    public $panoramioTag = '';                        // Restrict the set of Panoramio photos shown to those matching a certain textual tag
80
    public $panoramioUser = '';                        // Restrict the set of Panoramio photos shown to those matching a particular user
81
    public $region = '';                        // Country code top-level domain (eg "uk") within which to search. Useful if supplying addresses rather than lat/longs
82
    public $scaleControlPosition = '';                        // The position of the Scale control, eg. 'BOTTOM_RIGHT'
83
    public $scrollwheel = true;                        // If set to FALSE will disable zooming by scrolling of the mouse wheel
84
    public $streetViewAddressControl = true;                        // If set to FALSE will hide the Address control
85
    public $streetViewAddressPosition = '';                        // The position of the Address control, eg. 'BOTTOM'
86
    public $streetViewControlPosition = '';                        // The position of the Street View control when viewing normal aerial map, eg. 'BOTTOM_RIGHT'
87
    public $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
88
    public $streetViewLinksControl = true;                        // If set to FALSE will hide the Links control
89
    public $streetViewPanControl = true;                        // If set to FALSE will hide the Pan control
90
    public $streetViewPanPosition = '';                        // The position of the Scale control, eg. 'TOP_RIGHT'
91
    public $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
92
    public $streetViewPovPitch = 0;                        // The Street View camera pitch in degrees, relative to the street view vehicle. Directly upwards is 90, Directly downwards is -90.
93
    public $streetViewPovZoom = 0;                        // The Street View zoom level. Fully zoomed-out is level 0, zooming in increases the zoom level.
94
    public $streetViewZoomControl = true;                        // If set to FALSE will hide the Zoom control
95
    public $streetViewZoomPosition = '';                        // The position of the Scale control, eg. 'TOP_RIGHT'
96
    public $streetViewZoomStyle = '';                        // The size of the Street View zoom control. blank, 'SMALL' or 'LARGE' values accepted.
97
    public $styles = array();                    // An array of styles used to colour aspects of the map and turn points of interest on and off
98
    public $stylesAsMapTypes = false;                    // If applying styles, whether to apply them to the default map or add them as additional map types
99
    public $stylesAsMapTypesDefault = '';                        // If $stylesAsMapTypes is true the default style. Should contain the 'Name' of the style
100
    public $tiledOverlayLayers = [];
101
    public $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
102
    public $trafficOverlay = false;                    // If set to TRUE will overlay traffic information onto the map by default
103
    public $version = "3";                        // Version of the API being used. Not currently used in the library
104
    public $zoom = 13;                        // 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
105
    public $zoomControlPosition = '';                        // The position of the Zoom control, eg. 'BOTTOM_RIGHT'
106
    public $zoomControlStyle = '';                        // The size of the zoom control. blank, 'SMALL' or 'LARGE' values accepted.
107
108
    public $markers = array();                    // An array used by the library to store the markers as they are produced
109
    public $markersInfo = array();                    // An array containing marker information (id, latitude, longitude etc) for use elsewhere
110
    public $polylines = array();                    // An array used by the library to store the polylines as they are produced
111
    public $polygons = array();                    // An array used by the library to store the polygons as they are produced
112
    public $circles = array();                    // An array used by the library to store the circles as they are produced
113
    public $rectangles = array();                    // An array used by the library to store the rectangles as they are produced
114
    public $overlays = array();                    // An array used by the library to store the overlays as they are produced
115
116
    public $directions = false;                    // Whether or not the map will be used to show directions
117
    public $directionsStart = "";                        // The starting location (lat/long co-ordinate or address) of the directions. Set to 'auto' to default it to the users location
118
    public $directionsEnd = "";                        // The destination point (lat/long co-ordinate or address) of the directions. Set to 'auto' to default it to the users location
119
    public $directionsDivID = "";                        // An element's ID on the page where textual directions will be output to. Leave blank if not required
120
    public $directionsMode = "DRIVING";                // DRIVING, WALKING or BICYCLING (US Only) - The vehicle/mode of transport to show directions for
121
    public $directionsAvoidTolls = false;                    // Whether or not directions should avoid tolls
122
    public $directionsAvoidHighways = false;                    // Whether or not directions should avoid highways
123
    public $directionsDraggable = false;                    // Whether or not directions on the map are draggable
124
    public $directionsChanged = "";                        // JavaScript to perform when directions are dragged
125
    public $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
126
    public $directionsWaypointArray = array();                    // An array of waypoints. eg array("Boston, MA", "Times Square, NY");
127
    public $directionsWaypointsOptimize = false;                    // Should the waypoints be optimised? If TRUE, waypoints will be re-ordered to provide the most efficient route.
128
129
    public $drawing = false;                    // Whether or not the drawing library tools will be loaded
130
    public $drawingControl = true;                        // If set to FALSE will hide the Drawing Manager control
131
    public $drawingControlPosition = 'TOP_CENTER';                // The position of the Drawing Manager control, eg. 'TOP_RIGHT'
132
    public $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.
133
    public $drawingModes = array();                    // An array of modes available for use. Accepted values are marker, polygon, polyline, rectangle, circle
134
    public $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');
135
    public $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');
136
137
    public $places = false;                    // Whether or not the map will be used to show places
138
    public $placesLocation = '';                        // A point (lat/long co-ordinate or address) on the map if the search for places is based around a central point
139
    public $placesRadius = 0;                        // The radius (in meters) if search is based around a central position
140
    public $placesLocationSW = '';                        // If preferring to search within bounds the South-West position (latitude/longitude coordinate OR address)
141
    public $placesLocationNE = '';                        // If preferring to search within bounds the North-East position (latitude/longitude coordinate OR address)
142
    public $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
143
    public $placesName = '';                        // A term to be matched against when searching for places to display on the map
144
    public $placesAutocompleteInputID = '';                        // The ID attribute of the textfield that the autocomplete should effect
145
    public $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)'
146
    public $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.
147
    public $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
148
    public $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
149
    public $placesAutocompleteOnChange = '';                        // The JavaScript action to perform when a place is selected
150
    public $gestureHandling = 'auto';                                // Controls the panning and scrolling behavior of a map when viewed on a mobile device. greedy(allways moves on touch), cooperative(1 finger scroll 2 finger move), none(not pannable or pinchable), auto
151
152
153
    public function __construct($config = array())
154
    {
155
        if (count($config) > 0) {
156
            $this->initialize($config);
157
        }
158
159
        #Log::info('debug', "Google Maps Class Initialized");
160
    }
161
162
    public function create($center)
163
    {
164
        $gmapsConfig = [];
165
        $gmapsConfig['center'] = $center->latitude . ', ' . $center->longitude;
166
        $gmapsConfig['onboundschanged'] = "if ((typeof centreGot === 'undefined') || !centreGot) {
167
            var mapCentre = map.getCenter();
168
            marker_0.setOptions({
169
                position: new google.maps.LatLng(mapCentre.lat(), mapCentre.lng())
170
            });
171
        }
172
        centreGot = true;";
173
        $this->initialize($gmapsConfig);
174
        $gmapsMarker = [];
175
        $gmapsMarker['position'] = $center->latitude . ', ' . $center->longitude;
176
        $gmapsMarker['animation'] = 'DROP';
177
        $gmapsMarker['highlightBackgroundColor'] = 'ff0000';
178
        $this->add_marker($gmapsMarker);
179
180
        return $this->create_map();
181
    }
182
183
    public function initialize($config = array())
184
    {
185
        foreach ($config as $key => $val) {
186
            if (isset($this->$key)) {
187
                $this->$key = $val;
188
            }
189
        }
190
    }
191
192
    public function addOverlayLayer(
193
        string $tileOverlayFolderUrl,
194
        float $latTopLeft,
195
        float $longTopLeft,
196
        float $latBottomRight,
197
        float $longBottomRight
198
    ) {
199
        if (! $tileOverlayFolderUrl) {
200
            return;
201
        }
202
203
        $index = count($this->tiledOverlayLayers);
204
205
        $this->tiledOverlayLayers[] = "var maptiler_{$index} = new google.maps.ImageMapType({
206
            getTileUrl: function(coord, zoom) {
207
                var mapBounds = new google.maps.LatLngBounds(
208
                    new google.maps.LatLng({$latTopLeft}, {$longTopLeft}),
209
                    new google.maps.LatLng({$latBottomRight}, {$longBottomRight}));
210
                var mapMinZoom = 9;
211
                var mapMaxZoom = 14;
212
                var proj = map.getProjection();
213
                var z2 = Math.pow(2, zoom);
214
                var tileXSize = 256 / z2;
215
                var tileYSize = 256 / z2;
216
                var tileBounds = new google.maps.LatLngBounds(
217
                    proj.fromPointToLatLng(new google.maps.Point(coord.x * tileXSize, (coord.y + 1) * tileYSize)),
218
                    proj.fromPointToLatLng(new google.maps.Point((coord.x + 1) * tileXSize, coord.y * tileYSize))
219
                );
220
                var y = coord.y;
221
                var x = coord.x >= 0
222
                    ? coord.x
223
                    : z2 + coord.x;
224
225
                if (mapBounds.intersects(tileBounds)) {
226
                    return \"{$tileOverlayFolderUrl}/\" + zoom + \"/\" + x + \"/\" + y + \".png\";
227
                } else {
228
                    return \"https://www.maptiler.com/img/none.png\";
229
                }
230
            },
231
            tileSize: new google.maps.Size(256, 256),
232
            isPng: true,
233
            opacity: 1.0
234
        });";
235
236
        return;
237
    }
238
239
    public function add_marker($params = array())
240
    {
241
        $marker = array();
242
        $this->markersInfo['marker_'.count($this->markers)] = array();
243
244
        $marker['position'] = '';                                // The position (lat/long co-ordinate or address) at which the marker will appear
245
        $marker['infowindow_content'] = '';                        // If not blank, creates an infowindow (aka bubble) with the content provided. Can be plain text or HTML
246
        $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
247
        $marker['clickable'] = true;                            // Defines if the marker is clickable
248
        $marker['cursor'] = '';                                    // The name or url of the cursor to display on hover
249
        $marker['draggable'] = false;                            // Defines if the marker is draggable
250
        $marker['flat'] = false;                                // If set to TRUE will not display a shadow beneath the icon
251
        $marker['icon'] = '';                                    // The name or url of the icon to use for the marker
252
        $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
253
        $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')
254
        $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')
255
        $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
256
        $marker['animation'] = '';                                // blank, 'DROP' or 'BOUNCE'
257
        $marker['onclick'] = '';                                // JavaScript performed when a marker is clicked
258
        $marker['ondblclick'] = '';                                // JavaScript performed when a marker is double-clicked
259
        $marker['ondrag'] = '';                                    // JavaScript repeatedly performed while the marker is being dragged
260
        $marker['ondragstart'] = '';                            // JavaScript performed when a marker is started to be dragged
261
        $marker['ondragend'] = '';                                // JavaScript performed when a draggable marker is dropped
262
        $marker['onmousedown'] = '';                            // JavaScript performed when a mousedown event occurs on a marker
263
        $marker['onmouseout'] = '';                                // JavaScript performed when the mouse leaves the area of the marker icon
264
        $marker['onmouseover'] = '';                            // JavaScript performed when the mouse enters the area of the marker icon
265
        $marker['onmouseup'] = '';                                // JavaScript performed when a mouseup event occurs on a marker
266
        $marker['onpositionchanged'] = '';                        // JavaScript performed when the markers position changes
267
        $marker['onrightclick'] = '';                            // JavaScript performed when a right-click occurs on a marker
268
        $marker['raiseondrag'] = true;                            // If FALSE, disables the raising and lowering of the icon when a marker is being dragged
269
        $marker['shadow'] = '';                                    // The name or url of the icon's shadow
270
        $marker['title'] = '';                                    // The tooltip text to show on hover
271
        $marker['visible'] = true;                                // Defines if the marker is visible by default
272
        $marker['zIndex'] = '';                                    // The zIndex of the marker. If two markers overlap, the marker with the higher zIndex will appear on top
273
        $marker['label'] = '';                                    // The label of the marker.
274
        $marker['label_color'] = '';                              // The color of the label text. Default color is black.
275
        $marker['label_fontSize'] = '';                           // The font family of the label text (equivalent to the CSS font-family property).
276
        $marker['label_fontFamily'] = '';                         // The font size of the label text (equivalent to the CSS font-size property). Default size is 14px.
277
        $marker['label_fontWeight'] = '';                         // The font weight of the label text (equivalent to the CSS font-weight property).
278
279
        $marker_output = '';
280
281
        foreach ($params as $key => $value) {
282
            if (isset($marker[$key])) {
283
                $marker[$key] = $value;
284
            }
285
        }
286
287
        $marker_id = count($this->markers);
288
        if (trim($marker['id']) != "") {
289
            $marker_id = $marker['id'];
290
        }
291
292
        if ($marker['position'] != "") {
293
            if ($this->is_lat_long($marker['position'])) {
294
                $marker_output .= '
295
			var myLatlng = new google.maps.LatLng('.$marker['position'].');
296
			';
297
                $explodePosition = explode(",", $marker['position']);
298
                $this->markersInfo['marker_'.$marker_id]['latitude'] = trim($explodePosition[0]);
299
                $this->markersInfo['marker_'.$marker_id]['longitude'] = trim($explodePosition[1]);
300
            } else {
301
                $lat_long = $this->get_lat_long_from_address($marker['position']);
302
                $marker_output .= '
303
			var myLatlng = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');';
304
                $this->markersInfo['marker_'.$marker_id]['latitude'] = $lat_long[0];
305
                $this->markersInfo['marker_'.$marker_id]['longitude'] = $lat_long[1];
306
            }
307
        }
308
309
        if ($marker['icon'] != "") {
310
            $marker_output .= '
311
				var marker_icon = {
312
					url: "'.$marker['icon'].'"';
313
            if ($marker['icon_size'] != "") {
314
                $marker_output .= ',
315
					size: new google.maps.Size('.$marker['icon_size'].')';
316
            }
317
            if ($marker['icon_scaledSize'] != "") {
318
                $marker_output .= ',
319
					scaledSize: new google.maps.Size('.$marker['icon_scaledSize'].')';
320
            }
321
            if ($marker['icon_origin'] != "") {
322
                $marker_output .= ',
323
					origin: new google.maps.Point('.$marker['icon_origin'].')';
324
            }
325
            if ($marker['icon_anchor'] != "") {
326
                $marker_output .= ',
327
					anchor: new google.maps.Point('.$marker['icon_anchor'].')';
328
            }
329
            $marker_output .= '};
330
			';
331
        }
332
333
        $marker_output .= '
334
			var markerOptions = {
335
				map: '.$this->map_name;
336
        if ($marker['position'] != "") {
337
            $marker_output .= ',
338
				position: myLatlng';
339
        }
340
        if (!$marker['clickable']) {
341
            $marker_output .= ',
342
				clickable: false';
343
        }
344
        if ($marker['cursor'] != "") {
345
            $marker_output .= ',
346
				cursor: "'.$marker['cursor'].'"';
347
        }
348
        if ($marker['draggable']) {
349
            $marker_output .= ',
350
				draggable: true';
351
        }
352
        if ($marker['flat']) {
353
            $marker_output .= ',
354
				flat: true';
355
        }
356
        if ($marker['icon'] != "") {
357
            $marker_output .= ',
358
				icon: marker_icon';
359
        }
360
        if (!$marker['raiseondrag']) {
361
            $marker_output .= ',
362
				raiseOnDrag: false';
363
        }
364
        if ($marker['shadow'] != "") {
365
            $marker_output .= ',
366
				shadow: "'.$marker['shadow'].'"';
367
        }
368
        if ($marker['title'] != "") {
369
            $marker_output .= ',
370
				title: "'.$marker['title'].'"';
371
            $this->markersInfo['marker_'.$marker_id]['title'] = $marker['title'];
372
        }
373
        if (!$marker['visible']) {
374
            $marker_output .= ',
375
				visible: false';
376
        }
377
        if ($marker['zIndex'] != "" && is_numeric($marker['zIndex'])) {
378
            $marker_output .= ',
379
				zIndex: '.$marker['zIndex'];
380
        }
381
        if ($marker['animation'] != "" && (strtoupper($marker['animation']) == "DROP" || strtoupper($marker['animation'] == "BOUNCE"))) {
382
            $marker_output .= ',
383
				animation:  google.maps.Animation.'.strtoupper($marker['animation']);
384
        }
385
        if ($marker['label'] != "") {
386
            $marker_output .= ',
387
            label: {
388
                text: "'.$marker['label'].'",
389
                color: "'.$marker['label_color'].'",
390
                fontSize: "'.$marker['label_fontSize'].'",
391
                fontFamily: "'.$marker['label_fontFamily'].'",
392
                fontWeight: "'.$marker['label_fontWeight'].'"
393
            }';
394
        }
395
396
397
398
        $marker_output .= '
399
			};
400
			marker_'.$marker_id.' = createMarker_'.$this->map_name.'(markerOptions);
401
			';
402
403
        if ($marker['infowindow_content'] != "") {
404
405
            // Escape any quotes in the event that HTML is being added to the infowindow
406
            $marker['infowindow_content'] = str_replace('\"', '"', $marker['infowindow_content']);
407
            $marker['infowindow_content'] = str_replace('"', '\"', $marker['infowindow_content']);
408
409
            $marker_output .= '
410
			marker_'.$marker_id.'.set("content", "'.$marker['infowindow_content'].'");
411
412
			google.maps.event.addListener(marker_'.$marker_id.', "click", function(event) {
413
				iw_'.$this->map_name.'.setContent(this.get("content"));
414
				iw_'.$this->map_name.'.open('.$this->map_name.', this);
415
			';
416
            if ($marker['onclick'] != "") {
417
                $marker_output .= $marker['onclick'].'
418
			';
419
            }
420
            $marker_output .= '
421
			});
422
			';
423
        } else {
424
            if ($marker['onclick'] != "") {
425
                $marker_output .= '
426
				google.maps.event.addListener(marker_'.$marker_id.', "click", function(event) {
427
					'.$marker['onclick'].'
428
				});
429
				';
430
            }
431
        }
432
433
        if ($marker['ondblclick'] != "") {
434
            $marker_output .= '
435
			google.maps.event.addListener(marker_'.$marker_id.', "dblclick", function(event) {
436
				'.$marker['ondblclick'].'
437
			});
438
			';
439
        }
440
        if ($marker['onmousedown'] != "") {
441
            $marker_output .= '
442
			google.maps.event.addListener(marker_'.$marker_id.', "mousedown", function(event) {
443
				'.$marker['onmousedown'].'
444
			});
445
			';
446
        }
447
        if ($marker['onmouseout'] != "") {
448
            $marker_output .= '
449
			google.maps.event.addListener(marker_'.$marker_id.', "mouseout", function(event) {
450
				'.$marker['onmouseout'].'
451
			});
452
			';
453
        }
454
        if ($marker['onmouseover'] != "") {
455
            $marker_output .= '
456
			google.maps.event.addListener(marker_'.$marker_id.', "mouseover", function(event) {
457
				'.$marker['onmouseover'].'
458
			});
459
			';
460
        }
461
        if ($marker['onmouseup'] != "") {
462
            $marker_output .= '
463
			google.maps.event.addListener(marker_'.$marker_id.', "mouseup", function(event) {
464
				'.$marker['onmouseup'].'
465
			});
466
			';
467
        }
468
        if ($marker['onpositionchanged'] != "") {
469
            $marker_output .= '
470
			google.maps.event.addListener(marker_'.$marker_id.', "position_changed", function(event) {
471
				'.$marker['onpositionchanged'].'
472
			});
473
			';
474
        }
475
        if ($marker['onrightclick'] != "") {
476
            $marker_output .= '
477
			google.maps.event.addListener(marker_'.$marker_id.', "rightclick", function(event) {
478
				'.$marker['onrightclick'].'
479
			});
480
			';
481
        }
482
483
        if ($marker['draggable']) {
484
            if ($marker['ondrag'] != "") {
485
                $marker_output .= '
486
				google.maps.event.addListener(marker_'.$marker_id.', "drag", function(event) {
487
					'.$marker['ondrag'].'
488
				});
489
				';
490
            }
491
            if ($marker['ondragend'] != "") {
492
                $marker_output .= '
493
				google.maps.event.addListener(marker_'.$marker_id.', "dragend", function(event) {
494
					'.$marker['ondragend'].'
495
				});
496
				';
497
            }
498
            if ($marker['ondragstart'] != "") {
499
                $marker_output .= '
500
				google.maps.event.addListener(marker_'.$marker_id.', "dragstart", function(event) {
501
					'.$marker['ondragstart'].'
502
				});
503
				';
504
            }
505
        }
506
507
        array_push($this->markers, $marker_output);
508
    }
509
510
    public function add_polyline($params = array())
511
    {
512
        $polyline = array();
513
514
        $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.
515
        $polyline['clickable'] = true;                            // Defines if the polyline is clickable
516
        $polyline['strokeColor'] = '#FF0000';                    // The hex value of the polylines color
517
        $polyline['strokeOpacity'] = '1.0';                        // The opacity of the polyline. 0 to 1.0
518
        $polyline['strokeWeight'] = '2';                        // The thickness of the polyline
519
        $polyline['onclick'] = '';                                // JavaScript performed when a polyline is clicked
520
        $polyline['ondblclick'] = '';                            // JavaScript performed when a polyline is double-clicked
521
        $polyline['onmousedown'] = '';                            // JavaScript performed when a mousedown event occurs on a polyline
522
        $polyline['onmousemove'] = '';                            // JavaScript performed when the mouse moves in the area of the polyline
523
        $polyline['onmouseout'] = '';                            // JavaScript performed when the mouse leaves the area of the polyline
524
        $polyline['onmouseover'] = '';                            // JavaScript performed when the mouse enters the area of the polyline
525
        $polyline['onmouseup'] = '';                            // JavaScript performed when a mouseup event occurs on a polyline
526
        $polyline['onrightclick'] = '';                            // JavaScript performed when a right-click occurs on a polyline
527
        $polyline['zIndex'] = '';                                // The zIndex of the polyline. If two polylines overlap, the polyline with the higher zIndex will appear on top
528
529
        $polyline_output = '';
530
531
        foreach ($params as $key => $value) {
532
            if (isset($polyline[$key])) {
533
                $polyline[$key] = $value;
534
            }
535
        }
536
537
        if (count($polyline['points'])) {
538
            $polyline_output .= '
539
				var polyline_plan_'.count($this->polylines).' = [';
540
            $i = 0;
541
            $lat_long_output = '';
542
            foreach ($polyline['points'] as $point) {
543
                if ($i > 0) {
544
                    $polyline_output .= ',';
545
                }
546
                $lat_long_to_push = '';
547
                if ($this->is_lat_long($point)) {
548
                    $lat_long_to_push = $point;
549
                    $polyline_output .= '
550
					new google.maps.LatLng('.$point.')
551
					';
552
                } else {
553
                    $lat_long = $this->get_lat_long_from_address($point);
554
                    $polyline_output .= '
555
					new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
556
                    $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
557
                }
558
                $lat_long_output .= '
559
					lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
560
				';
561
                $i++;
562
            }
563
            $polyline_output .= '];';
564
565
            $polyline_output .= $lat_long_output;
566
567
            $polyline_output .= '
568
				var polyline_'.count($this->polylines).' = new google.maps.Polyline({
569
    				path: polyline_plan_'.count($this->polylines).',
570
    				strokeColor: "'.$polyline['strokeColor'].'",
571
    				strokeOpacity: '.$polyline['strokeOpacity'].',
572
    				strokeWeight: '.$polyline['strokeWeight'];
573
            if (!$polyline['clickable']) {
574
                $polyline_output .= ',
575
					clickable: false';
576
            }
577
            if ($polyline['zIndex'] != "" && is_numeric($polyline['zIndex'])) {
578
                $polyline_output .= ',
579
					zIndex: '.$polyline['zIndex'];
580
            }
581
            $polyline_output .= '
582
				});
583
584
				polyline_'.count($this->polylines).'.setMap('.$this->map_name.');
585
586
			';
587
588
            if ($polyline['onclick'] != "") {
589
                $polyline_output .= '
590
				google.maps.event.addListener(polyline_'.count($this->polylines).', "click", function() {
591
					'.$polyline['onclick'].'
592
				});
593
				';
594
            }
595
            if ($polyline['ondblclick'] != "") {
596
                $polyline_output .= '
597
				google.maps.event.addListener(polyline_'.count($this->polylines).', "dblclick", function() {
598
					'.$polyline['ondblclick'].'
599
				});
600
				';
601
            }
602
            if ($polyline['onmousedown'] != "") {
603
                $polyline_output .= '
604
				google.maps.event.addListener(polyline_'.count($this->polylines).', "mousedown", function() {
605
					'.$polyline['onmousedown'].'
606
				});
607
				';
608
            }
609
            if ($polyline['onmousemove'] != "") {
610
                $polyline_output .= '
611
				google.maps.event.addListener(polyline_'.count($this->polylines).', "mousemove", function() {
612
					'.$polyline['onmousemove'].'
613
				});
614
				';
615
            }
616
            if ($polyline['onmouseout'] != "") {
617
                $polyline_output .= '
618
				google.maps.event.addListener(polyline_'.count($this->polylines).', "mouseout", function() {
619
					'.$polyline['onmouseout'].'
620
				});
621
				';
622
            }
623
            if ($polyline['onmouseover'] != "") {
624
                $polyline_output .= '
625
				google.maps.event.addListener(polyline_'.count($this->polylines).', "mouseover", function() {
626
					'.$polyline['onmouseover'].'
627
				});
628
				';
629
            }
630
            if ($polyline['onmouseup'] != "") {
631
                $polyline_output .= '
632
				google.maps.event.addListener(polyline_'.count($this->polylines).', "mouseup", function() {
633
					'.$polyline['onmouseup'].'
634
				});
635
				';
636
            }
637
            if ($polyline['onrightclick'] != "") {
638
                $polyline_output .= '
639
				google.maps.event.addListener(polyline_'.count($this->polylines).', "rightclick", function() {
640
					'.$polyline['onrightclick'].'
641
				});
642
				';
643
            }
644
645
            array_push($this->polylines, $polyline_output);
646
        }
647
    }
648
649
    public function add_polygon($params = array())
650
    {
651
        $polygon = array();
652
653
        $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
654
        $polygon['clickable'] = true;                            // Defines if the polygon is clickable
655
        $polygon['strokeColor'] = '#FF0000';                    // The hex value of the polygons border color
656
        $polygon['strokeOpacity'] = '0.8';                        // The opacity of the polygon border. 0 to 1.0
657
        $polygon['strokeWeight'] = '2';                            // The thickness of the polygon border
658
        $polygon['fillColor'] = '#FF0000';                        // The hex value of the polygons fill color
659
        $polygon['fillOpacity'] = '0.3';                        // The opacity of the polygons fill
660
        $polygon['onclick'] = '';                                // JavaScript performed when a polygon is clicked
661
        $polygon['ondblclick'] = '';                            // JavaScript performed when a polygon is double-clicked
662
        $polygon['onmousedown'] = '';                            // JavaScript performed when a mousedown event occurs on a polygon
663
        $polygon['onmousemove'] = '';                            // JavaScript performed when the mouse moves in the area of the polygon
664
        $polygon['onmouseout'] = '';                            // JavaScript performed when the mouse leaves the area of the polygon
665
        $polygon['onmouseover'] = '';                            // JavaScript performed when the mouse enters the area of the polygon
666
        $polygon['onmouseup'] = '';                                // JavaScript performed when a mouseup event occurs on a polygon
667
        $polygon['onrightclick'] = '';                            // JavaScript performed when a right-click occurs on a polygon
668
        $polygon['zIndex'] = '';                                // The zIndex of the polygon. If two polygons overlap, the polygon with the higher zIndex will appear on top
669
670
        $polygon_output = '';
671
672
        foreach ($params as $key => $value) {
673
            if (isset($polygon[$key])) {
674
                $polygon[$key] = $value;
675
            }
676
        }
677
678
        if (count($polygon['points'])) {
679
            $polygon_output .= '
680
				var polygon_plan_'.count($this->polygons).' = [';
681
            $i = 0;
682
            $lat_long_output = '';
683
            foreach ($polygon['points'] as $point) {
684
                if ($i > 0) {
685
                    $polygon_output .= ',';
686
                }
687
                $lat_long_to_push = '';
688
                if ($this->is_lat_long($point)) {
689
                    $lat_long_to_push = $point;
690
                    $polygon_output .= '
691
					new google.maps.LatLng('.$point.')
692
					';
693
                } else {
694
                    $lat_long = $this->get_lat_long_from_address($point);
695
                    $polygon_output .= '
696
					new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
697
                    $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
698
                }
699
                $lat_long_output .= '
700
					lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
701
				';
702
                $i++;
703
            }
704
            $polygon_output .= '];';
705
706
            $polygon_output .= $lat_long_output;
707
        }
708
709
        $polygon_output .= '
710
			var polygon_'.count($this->polygons).' = new google.maps.Polygon({
711
    			';
712
        if (count($polygon['points'])) {
713
            $polygon_output .= 'path: polygon_plan_'.count($this->polygons).',
714
					';
715
        }
716
        $polygon_output .= '
717
    			strokeColor: "'.$polygon['strokeColor'].'",
718
    			strokeOpacity: '.$polygon['strokeOpacity'].',
719
    			strokeWeight: '.$polygon['strokeWeight'].',
720
				fillColor: "'.$polygon['fillColor'].'",
721
				fillOpacity: '.$polygon['fillOpacity'];
722
        if (!$polygon['clickable']) {
723
            $polygon_output .= ',
724
				clickable: false';
725
        }
726
        if ($polygon['zIndex'] != "" && is_numeric($polygon['zIndex'])) {
727
            $polygon_output .= ',
728
				zIndex: '.$polygon['zIndex'];
729
        }
730
        $polygon_output .= '
731
			});
732
733
			polygon_'.count($this->polygons).'.setMap('.$this->map_name.');
734
735
		';
736
737
        if ($polygon['onclick'] != "") {
738
            $polygon_output .= '
739
			google.maps.event.addListener(polygon_'.count($this->polygons).', "click", function() {
740
				'.$polygon['onclick'].'
741
			});
742
			';
743
        }
744
        if ($polygon['ondblclick'] != "") {
745
            $polygon_output .= '
746
			google.maps.event.addListener(polygon_'.count($this->polygons).', "dblclick", function() {
747
				'.$polygon['ondblclick'].'
748
			});
749
			';
750
        }
751
        if ($polygon['onmousedown'] != "") {
752
            $polygon_output .= '
753
			google.maps.event.addListener(polygon_'.count($this->polygons).', "mousedown", function() {
754
				'.$polygon['onmousedown'].'
755
			});
756
			';
757
        }
758
        if ($polygon['onmousemove'] != "") {
759
            $polygon_output .= '
760
			google.maps.event.addListener(polygon_'.count($this->polygons).', "mousemove", function() {
761
				'.$polygon['onmousemove'].'
762
			});
763
			';
764
        }
765
        if ($polygon['onmouseout'] != "") {
766
            $polygon_output .= '
767
			google.maps.event.addListener(polygon_'.count($this->polygons).', "mouseout", function() {
768
				'.$polygon['onmouseout'].'
769
			});
770
			';
771
        }
772
        if ($polygon['onmouseover'] != "") {
773
            $polygon_output .= '
774
			google.maps.event.addListener(polygon_'.count($this->polygons).', "mouseover", function() {
775
				'.$polygon['onmouseover'].'
776
			});
777
			';
778
        }
779
        if ($polygon['onmouseup'] != "") {
780
            $polygon_output .= '
781
			google.maps.event.addListener(polygon_'.count($this->polygons).', "mouseup", function() {
782
				'.$polygon['onmouseup'].'
783
			});
784
			';
785
        }
786
        if ($polygon['onrightclick'] != "") {
787
            $polygon_output .= '
788
			google.maps.event.addListener(polygon_'.count($this->polygons).', "rightclick", function() {
789
				'.$polygon['onrightclick'].'
790
			});
791
			';
792
        }
793
794
        array_push($this->polygons, $polygon_output);
795
    }
796
797
    public function add_circle($params = array())
798
    {
799
        $circle = array();
800
801
        $circle['center'] = '';                                    // The center position (latitude/longitude coordinate OR addresse) at which the circle will appear
802
        $circle['clickable'] = true;                            // Defines if the circle is clickable
803
        $circle['radius'] = 0;                                    // The circle radius (in metres)
804
        $circle['strokeColor'] = '0.8';                            // The hex value of the circles border color
805
        $circle['strokeOpacity'] = '0.8';                        // The opacity of the circle border
806
        $circle['strokeWeight'] = '2';                            // The thickness of the circle border
807
        $circle['fillColor'] = '#FF0000';                        // The hex value of the circles fill color
808
        $circle['fillOpacity'] = '0.3';                            // The opacity of the circles fill
809
        $circle['onclick'] = '';                                // JavaScript performed when a circle is clicked
810
        $circle['ondblclick'] = '';                                // JavaScript performed when a circle is double-clicked
811
        $circle['onmousedown'] = '';                            // JavaScript performed when a mousedown event occurs on a circle
812
        $circle['onmousemove'] = '';                            // JavaScript performed when the mouse moves in the area of the circle
813
        $circle['onmouseout'] = '';                                // JavaScript performed when the mouse leaves the area of the circle
814
        $circle['onmouseover'] = '';                            // JavaScript performed when the mouse enters the area of the circle
815
        $circle['onmouseup'] = '';                                // JavaScript performed when a mouseup event occurs on a circle
816
        $circle['onrightclick'] = '';                            // JavaScript performed when a right-click occurs on a circle
817
        $circle['zIndex'] = '';                                    // The zIndex of the circle. If two circles overlap, the circle with the higher zIndex will appear on top
818
819
        $circle_output = '';
820
821
        foreach ($params as $key => $value) {
822
            if (isset($circle[$key])) {
823
                $circle[$key] = $value;
824
            }
825
        }
826
827
        if ($circle['radius'] > 0 && $circle['center'] != "") {
828
            $lat_long_to_push = '';
829
            if ($this->is_lat_long($circle['center'])) {
830
                $lat_long_to_push = $circle['center'];
831
                $circle_output = '
832
				var circleCenter = new google.maps.LatLng('.$circle['center'].')
833
				';
834
            } else {
835
                $lat_long = $this->get_lat_long_from_address($circle['center']);
836
                $circle_output = '
837
				var circleCenter = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
838
                $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
839
            }
840
            $circle_output .= '
841
				lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
842
			';
843
844
            $circle_output .= '
845
				var circleOptions = {
846
					strokeColor: "'.$circle['strokeColor'].'",
847
					strokeOpacity: '.$circle['strokeOpacity'].',
848
					strokeWeight: '.$circle['strokeWeight'].',
849
					fillColor: "'.$circle['fillColor'].'",
850
					fillOpacity: '.$circle['fillOpacity'].',
851
					map: '.$this->map_name.',
852
					center: circleCenter,
853
					radius: '.$circle['radius'];
854
            if (!$circle['clickable']) {
855
                $circle_output .= ',
856
					clickable: false';
857
            }
858
            if ($circle['zIndex'] != "" && is_numeric($circle['zIndex'])) {
859
                $circle_output .= ',
860
					zIndex: '.$circle['zIndex'];
861
            }
862
            $circle_output .= '
863
				};
864
				var circle_'.count($this->circles).' = new google.maps.Circle(circleOptions);
865
			';
866
867
            if ($circle['onclick'] != "") {
868
                $circle_output .= '
869
				google.maps.event.addListener(circle_'.count($this->circles).', "click", function() {
870
					'.$circle['onclick'].'
871
				});
872
				';
873
            }
874
            if ($circle['ondblclick'] != "") {
875
                $circle_output .= '
876
				google.maps.event.addListener(circle_'.count($this->circles).', "dblclick", function() {
877
					'.$circle['ondblclick'].'
878
				});
879
				';
880
            }
881
            if ($circle['onmousedown'] != "") {
882
                $circle_output .= '
883
				google.maps.event.addListener(circle_'.count($this->circles).', "mousedown", function() {
884
					'.$circle['onmousedown'].'
885
				});
886
				';
887
            }
888
            if ($circle['onmousemove'] != "") {
889
                $circle_output .= '
890
				google.maps.event.addListener(circle_'.count($this->circles).', "mousemove", function() {
891
					'.$circle['onmousemove'].'
892
				});
893
				';
894
            }
895
            if ($circle['onmouseout'] != "") {
896
                $circle_output .= '
897
				google.maps.event.addListener(circle_'.count($this->circles).', "mouseout", function() {
898
					'.$circle['onmouseout'].'
899
				});
900
				';
901
            }
902
            if ($circle['onmouseover'] != "") {
903
                $circle_output .= '
904
				google.maps.event.addListener(circle_'.count($this->circles).', "mouseover", function() {
905
					'.$circle['onmouseover'].'
906
				});
907
				';
908
            }
909
            if ($circle['onmouseup'] != "") {
910
                $circle_output .= '
911
				google.maps.event.addListener(circle_'.count($this->circles).', "mouseup", function() {
912
					'.$circle['onmouseup'].'
913
				});
914
				';
915
            }
916
            if ($circle['onrightclick'] != "") {
917
                $circle_output .= '
918
				google.maps.event.addListener(circle_'.count($this->circles).', "rightclick", function() {
919
					'.$circle['onrightclick'].'
920
				});
921
				';
922
            }
923
924
            array_push($this->circles, $circle_output);
925
        }
926
    }
927
928
    public function add_rectangle($params = array())
929
    {
930
        $rectangle = array();
931
932
        $rectangle['positionSW'] = '';                            // The South-West position (latitude/longitude coordinate OR address) at which the rectangle will appear
933
        $rectangle['positionNE'] = '';                            // The North-East position(latitude/longitude coordinate OR address) at which the rectangle will appear
934
        $rectangle['clickable'] = true;                            // Defines if the rectangle is clickable
935
        $rectangle['strokeColor'] = '0.8';                        // The hex value of the rectangles border color
936
        $rectangle['strokeOpacity'] = '0.8';                    // The opacity of the rectangle border
937
        $rectangle['strokeWeight'] = '2';                        // The thickness of the rectangle border
938
        $rectangle['fillColor'] = '#FF0000';                    // The hex value of the rectangles fill color
939
        $rectangle['fillOpacity'] = '0.3';                        // The opacity of the rectangles fill
940
        $rectangle['onclick'] = '';                                // JavaScript performed when a rectangle is clicked
941
        $rectangle['ondblclick'] = '';                            // JavaScript performed when a rectangle is double-clicked
942
        $rectangle['onmousedown'] = '';                            // JavaScript performed when a mousedown event occurs on a rectangle
943
        $rectangle['onmousemove'] = '';                            // JavaScript performed when the mouse moves in the area of the rectangle
944
        $rectangle['onmouseout'] = '';                            // JavaScript performed when the mouse leaves the area of the rectangle
945
        $rectangle['onmouseover'] = '';                            // JavaScript performed when the mouse enters the area of the rectangle
946
        $rectangle['onmouseup'] = '';                            // JavaScript performed when a mouseup event occurs on a rectangle
947
        $rectangle['onrightclick'] = '';                        // JavaScript performed when a right-click occurs on a rectangle
948
        $rectangle['zIndex'] = '';                                // The zIndex of the rectangle. If two rectangles overlap, the rectangle with the higher zIndex will appear on top
949
950
        $rectangle_output = '';
951
952
        foreach ($params as $key => $value) {
953
            if (isset($rectangle[$key])) {
954
                $rectangle[$key] = $value;
955
            }
956
        }
957
958
        if ($rectangle['positionSW'] != "" && $rectangle['positionNE'] != "") {
959
            $lat_long_to_push = '';
960
            if ($this->is_lat_long($rectangle['positionSW'])) {
961
                $lat_long_to_push = $rectangle['positionSW'];
962
                $rectangle_output .= '
963
				var positionSW = new google.maps.LatLng('.$rectangle['positionSW'].')
964
				';
965
            } else {
966
                $lat_long = $this->get_lat_long_from_address($rectangle['positionSW']);
967
                $rectangle_output .= '
968
				var positionSW = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
969
                $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
970
            }
971
            $rectangle_output .= '
972
				lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
973
			';
974
975
            $lat_long_to_push = '';
976
            if ($this->is_lat_long($rectangle['positionNE'])) {
977
                $lat_long_to_push = $rectangle['positionNE'];
978
                $rectangle_output .= '
979
				var positionNE = new google.maps.LatLng('.$rectangle['positionNE'].')
980
				';
981
            } else {
982
                $lat_long = $this->get_lat_long_from_address($rectangle['positionNE']);
983
                $rectangle_output .= '
984
				var positionNE = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
985
                $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
986
            }
987
            $rectangle_output .= '
988
				lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
989
			';
990
991
            $rectangle_output .= '
992
				var rectangleOptions = {
993
					strokeColor: "'.$rectangle['strokeColor'].'",
994
					strokeOpacity: '.$rectangle['strokeOpacity'].',
995
					strokeWeight: '.$rectangle['strokeWeight'].',
996
					fillColor: "'.$rectangle['fillColor'].'",
997
					fillOpacity: '.$rectangle['fillOpacity'].',
998
					map: '.$this->map_name.',
999
					bounds: new google.maps.LatLngBounds(positionSW, positionNE)';
1000
            if (!$rectangle['clickable']) {
1001
                $rectangle_output .= ',
1002
					clickable: false';
1003
            }
1004
            if ($rectangle['zIndex'] != "" && is_numeric($rectangle['zIndex'])) {
1005
                $rectangle_output .= ',
1006
					zIndex: '.$rectangle['zIndex'];
1007
            }
1008
            $rectangle_output .= '
1009
				};';
1010
1011
            $rectangle_output .= '
1012
				var rectangle_'.count($this->rectangles).' = new google.maps.Rectangle(rectangleOptions);
1013
			';
1014
1015
            if ($rectangle['onclick'] != "") {
1016
                $rectangle_output .= '
1017
				google.maps.event.addListener(rectangle_'.count($this->rectangles).', "click", function() {
1018
					'.$rectangle['onclick'].'
1019
				});
1020
				';
1021
            }
1022
            if ($rectangle['ondblclick'] != "") {
1023
                $rectangle_output .= '
1024
				google.maps.event.addListener(rectangle_'.count($this->rectangles).', "dblclick", function() {
1025
					'.$rectangle['ondblclick'].'
1026
				});
1027
				';
1028
            }
1029
            if ($rectangle['onmousedown'] != "") {
1030
                $rectangle_output .= '
1031
				google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mousedown", function() {
1032
					'.$rectangle['onmousedown'].'
1033
				});
1034
				';
1035
            }
1036
            if ($rectangle['onmousemove'] != "") {
1037
                $rectangle_output .= '
1038
				google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mousemove", function() {
1039
					'.$rectangle['onmousemove'].'
1040
				});
1041
				';
1042
            }
1043
            if ($rectangle['onmouseout'] != "") {
1044
                $rectangle_output .= '
1045
				google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mouseout", function() {
1046
					'.$rectangle['onmouseout'].'
1047
				});
1048
				';
1049
            }
1050
            if ($rectangle['onmouseover'] != "") {
1051
                $rectangle_output .= '
1052
				google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mouseover", function() {
1053
					'.$rectangle['onmouseover'].'
1054
				});
1055
				';
1056
            }
1057
            if ($rectangle['onmouseup'] != "") {
1058
                $rectangle_output .= '
1059
				google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mouseup", function() {
1060
					'.$rectangle['onmouseup'].'
1061
				});
1062
				';
1063
            }
1064
            if ($rectangle['onrightclick'] != "") {
1065
                $rectangle_output .= '
1066
				google.maps.event.addListener(rectangle_'.count($this->rectangles).', "rightclick", function() {
1067
					'.$rectangle['onrightclick'].'
1068
				});
1069
				';
1070
            }
1071
1072
            array_push($this->rectangles, $rectangle_output);
1073
        }
1074
    }
1075
1076
    public function add_ground_overlay($params = array())
1077
    {
1078
        $overlay = array();
1079
1080
        $overlay['image'] = '';                                    // JavaScript performed when a ground overlay is clicked
1081
        $overlay['positionSW'] = '';                            // The South-West position (latitude/longitude coordinate OR addresse) at which the ground overlay will appear
1082
        $overlay['positionNE'] = '';                            // The North-East position (latitude/longitude coordinate OR addresse) at which the ground overlay will appear
1083
        $overlay['clickable'] = true;                            // Defines if the ground overlay is clickable
1084
        $overlay['onclick'] = '';                                // JavaScript performed when a ground overlay is clicked
1085
1086
        $overlay_output = '';
1087
1088
        foreach ($params as $key => $value) {
1089
            if (isset($overlay[$key])) {
1090
                $overlay[$key] = $value;
1091
            }
1092
        }
1093
1094
        if ($overlay['image'] != "" && $overlay['positionSW'] != "" && $overlay['positionNE'] != "") {
1095
            $lat_long_to_push = '';
1096
            if ($this->is_lat_long($overlay['positionSW'])) {
1097
                $lat_long_to_push = $overlay['positionSW'];
1098
                $overlay_output .= '
1099
				var positionSW = new google.maps.LatLng('.$overlay['positionSW'].')
1100
				';
1101
            } else {
1102
                $lat_long = $this->get_lat_long_from_address($overlay['positionSW']);
1103
                $overlay_output .= '
1104
				var positionSW = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
1105
                $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
1106
            }
1107
            $overlay_output .= '
1108
				lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
1109
			';
1110
1111
            $lat_long_to_push = '';
1112
            if ($this->is_lat_long($overlay['positionNE'])) {
1113
                $lat_long_to_push = $overlay['positionNE'];
1114
                $overlay_output .= '
1115
				var positionNE = new google.maps.LatLng('.$overlay['positionNE'].')
1116
				';
1117
            } else {
1118
                $lat_long = $this->get_lat_long_from_address($overlay['positionNE']);
1119
                $overlay_output .= '
1120
				var positionNE = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
1121
                $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
1122
            }
1123
            $overlay_output .= '
1124
				lat_longs_'.$this->map_name.'.push(new google.maps.LatLng('.$lat_long_to_push.'));
1125
			';
1126
1127
            $overlay_output .= '
1128
				var overlay_'.count($this->overlays).' = new google.maps.GroundOverlay("'.$overlay['image'].'", new google.maps.LatLngBounds(positionSW, positionNE), { map: '.$this->map_name;
1129
            if (!$overlay['clickable']) {
1130
                $overlay_output .= ', clickable: false';
1131
            }
1132
            $overlay_output .= '});
1133
			';
1134
1135
            if ($overlay['onclick'] != "") {
1136
                $overlay_output .= '
1137
				google.maps.event.addListener(overlay_'.count($this->overlays).', "click", function() {
1138
					'.$overlay['onclick'].'
1139
				});
1140
				';
1141
            }
1142
1143
            array_push($this->overlays, $overlay_output);
1144
        }
1145
    }
1146
1147
    public function create_map()
1148
    {
1149
        $this->output_js = '';
1150
        $this->output_js_contents = '';
1151
        $this->output_html = "";
1152
1153
        if ($this->maps_loaded == 0) {
1154
            if ($this->apiKey != "") {
1155
                $apiLocation = 'https://maps.googleapis.com/maps/api/js?v=3&key='.$this->apiKey.'&';
1156
            } else {
1157
                $apiLocation = 'https://maps.google.com/maps/api/js?v=3&';
1158
            }
1159
            if ($this->region != "" && strlen($this->region) == 2) {
1160
                $apiLocation .= '&region='.strtoupper($this->region);
1161
            }
1162
            if ($this->language != "") {
1163
                $apiLocation .= '&language='.$this->language;
1164
            }
1165
            $libraries = array();
1166
            if ($this->adsense != "") {
1167
                array_push($libraries, 'adsense');
1168
            }
1169
            if ($this->places != "") {
1170
                array_push($libraries, 'places');
1171
            }
1172
            if ($this->panoramio) {
1173
                array_push($libraries, 'panoramio');
1174
            }
1175
            if ($this->drawing) {
1176
                array_push($libraries, 'drawing');
1177
            }
1178
            if (count($libraries)) {
1179
                $apiLocation .= '&libraries='.implode(",", $libraries);
1180
            }
1181
1182
            if (!$this->loadAsynchronously) {
1183
                $this->output_js .= '
1184
				<script type="text/javascript" src="'.$apiLocation.'"></script>';
1185
            }
1186
1187
            if ($this->cluster) {
1188
                $this->output_js .= '
1189
1190
			<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/js-marker-clusterer/1.0.0/markerclusterer_compiled.js"></script >
1191
					';
1192
            }
1193
        }
1194
        if ($this->jsfile == "") {
1195
            $this->output_js .= '
1196
			<script type="text/javascript">
1197
			//<![CDATA[
1198
			';
1199
        }
1200
1201
        $this->output_js_contents .= '
1202
			var '.$this->map_name.'; // Global declaration of the map
1203
			var lat_longs_'.$this->map_name.' = new Array();
1204
			var markers_'.$this->map_name.' = new Array();
1205
            var iw_'.$this->map_name.';
1206
			';
1207
        if ($this->cluster) {
1208
            $this->output_js_contents .= 'var markerCluster;
1209
			';
1210
        }
1211
        if ($this->directions) {
1212
            $rendererOptions = '';
1213
            if ($this->directionsDraggable) {
1214
                $this->output_js_contents .= '
1215
			var rendererOptions = { draggable: true };
1216
			';
1217
                $rendererOptions = 'rendererOptions';
1218
            }
1219
            $this->output_js_contents .= 'var directionsDisplay = new google.maps.DirectionsRenderer('.$rendererOptions.');
1220
			var directionsService = new google.maps.DirectionsService();
1221
			';
1222
        }
1223
        if ($this->places) {
1224
            $this->output_js_contents .= 'var placesService;
1225
			';
1226
            if ($this->placesAutocompleteInputID != "") {
1227
                $this->output_js_contents .= 'var placesAutocomplete;
1228
			';
1229
            }
1230
        }
1231
        if ($this->adsense) {
1232
            $this->output_js_contents .= 'var adUnit;
1233
			';
1234
        }
1235
        if ($this->drawing) {
1236
            $this->output_js_contents .= 'var drawingManager;
1237
			';
1238
        }
1239
1240
        $this->output_js_contents .= '
1241
            iw_'.$this->map_name.' = new google.maps.InfoWindow({';
1242
        if ($this->infowindowMaxWidth != 0) {
1243
            $this->output_js_contents .= 'maxWidth: '.$this->infowindowMaxWidth.',';
1244
        }
1245
        if ($this->infoAutoPan != false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
1246
            $this->output_js_contents .= 'disableAutoPan: '.$this->infoAutoPan.',';
0 ignored issues
show
Bug introduced by
Are you sure $this->infoAutoPan of type true can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1246
            $this->output_js_contents .= 'disableAutoPan: './** @scrutinizer ignore-type */ $this->infoAutoPan.',';
Loading history...
1247
        }
1248
        $this->output_js_contents .= '});
1249
1250
                 ';
1251
1252
        $this->output_js_contents .= 'function initialize_'.$this->map_name.'() {
1253
1254
				';
1255
1256
        $styleOutput = '';
1257
        if (count($this->styles)) {
1258
            $styles = 0;
1259
            foreach ($this->styles as $style) {
1260
                $this->output_js_contents .= 'var styles_'.$styles.' = '.json_encode($style['definition']).';
1261
				';
1262
1263
                if ($this->stylesAsMapTypes) {
1264
                    $this->output_js_contents .= 'var styles_'.$styles.' = new google.maps.StyledMapType(styles_'.$styles.', {name:"'.$style['name'].'"});
1265
				';
1266
                } else {
1267
                    $styleOutput .= $this->map_name.'.setOptions({styles: styles_'.$styles.'});
1268
				';
1269
                    break;
1270
                }
1271
1272
                ++$styles;
1273
            }
1274
        }
1275
1276
        if ($this->center != "auto") {
1277
            if ($this->is_lat_long($this->center)) { // if centering the map on a lat/long
1278
                $this->output_js_contents .= 'var myLatlng = new google.maps.LatLng('.$this->center.');';
1279
            } else {  // if centering the map on an address
1280
                $lat_long = $this->get_lat_long_from_address($this->center);
1281
                $this->output_js_contents .= 'var myLatlng = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');';
1282
            }
1283
        }
1284
1285
        $this->output_js_contents .= '
1286
				var myOptions = {
1287
			  		';
1288
        if ($this->zoom == "auto") {
1289
            $this->output_js_contents .= 'zoom: 13,';
1290
        } else {
1291
            $this->output_js_contents .= 'zoom: '.$this->zoom.',';
1292
        }
1293
        if ($this->center != "auto") {
1294
            $this->output_js_contents .= '
1295
					center: myLatlng,';
1296
        }
1297
        if($this->gestureHandling != 'auto'){
1298
            $this->output_js_contents .= '
1299
                    gestureHandling: \''.$this->gestureHandling .'\',';
1300
        }
1301
        if (strtolower($this->map_type) == "street") {
1302
            $map_type = "ROADMAP";
1303
        } else {
1304
            $map_type = $this->map_type;
1305
        }
1306
        $this->output_js_contents .= '
1307
			  		mapTypeId: google.maps.MapTypeId.'.$map_type;
1308
        if ($this->backgroundColor) {
1309
            $this->output_js_contents .= ',
1310
					backgroundColor: \''.$this->backgroundColor.'\'';
1311
        }
1312
        if ($this->disableClickableIcons) {
1313
            $this->output_js_contents .= ',
1314
					clickableIcons: false';
1315
        }
1316
        if ($this->disableDefaultUI) {
1317
            $this->output_js_contents .= ',
1318
					disableDefaultUI: true';
1319
        }
1320
        if ($this->disableMapTypeControl) {
1321
            $this->output_js_contents .= ',
1322
					mapTypeControl: false';
1323
        }
1324
        if ($this->disableNavigationControl) {
1325
            $this->output_js_contents .= ',
1326
					navigationControl: false';
1327
        }
1328
        if ($this->disableScaleControl) {
1329
            $this->output_js_contents .= ',
1330
					scaleControl: false';
1331
        }
1332
        if ($this->disableStreetViewControl) {
1333
            $this->output_js_contents .= ',
1334
					streetViewControl: false';
1335
        }
1336
        if ($this->disableDoubleClickZoom) {
1337
            $this->output_js_contents .= ',
1338
					disableDoubleClickZoom: true';
1339
        }
1340
        if (!$this->draggable) {
1341
            $this->output_js_contents .= ',
1342
					draggable: false';
1343
        }
1344
        if ($this->draggableCursor != "") {
1345
            $this->output_js_contents .= ',
1346
					draggableCursor: "'.$this->draggableCursor.'"';
1347
        }
1348
        if ($this->draggingCursor != "") {
1349
            $this->output_js_contents .= ',
1350
					draggingCursor: "'.$this->draggingCursor.'"';
1351
        }
1352
        if (!$this->keyboardShortcuts) {
1353
            $this->output_js_contents .= ',
1354
					keyboardShortcuts: false';
1355
        }
1356
        $mapTypeControlOptions = array();
1357
        $map_types = array();
1358
        if ($this->mapTypeControlPosition != "") {
1359
            array_push($mapTypeControlOptions, 'position: google.maps.ControlPosition.'.strtoupper($this->mapTypeControlPosition));
1360
        }
1361
        if ($this->mapTypeControlStyle != "" && (strtoupper($this->mapTypeControlStyle) == "DROPDOWN_MENU" || strtoupper($this->mapTypeControlStyle) == "HORIZONTAL_BAR")) {
1362
            array_push($mapTypeControlOptions, 'style: google.maps.MapTypeControlStyle.'.strtoupper($this->mapTypeControlStyle));
1363
        }
1364
        if (count($this->map_types_available)) {
1365
            foreach ($this->map_types_available as $map_type) {
1366
                array_push($map_types, 'google.maps.MapTypeId.'.strtoupper($map_type));
1367
            }
1368
        }
1369
        if (count($this->styles) && $this->stylesAsMapTypes) {
1370
            $styles = 0;
1371
            foreach ($this->styles as $style) {
1372
                array_push($map_types, '"style'.$styles.'"');
1373
                $styleOutput .= '
1374
					  '.$this->map_name.'.mapTypes.set("style'.$styles.'", styles_'.$styles.');
1375
				';
1376
                if ($this->stylesAsMapTypesDefault == $style['name']) {
1377
                    $styleOutput .= '
1378
					  '.$this->map_name.'.setMapTypeId("style'.$styles.'");
1379
				';
1380
                }
1381
                $styles++;
1382
            }
1383
        }
1384
        if (count($map_types)) {
1385
            array_push($mapTypeControlOptions, 'mapTypeIds: ['.implode(", ", $map_types).']');
1386
        }
1387
        if (count($mapTypeControlOptions)) {
1388
            $this->output_js_contents .= ',
1389
					mapTypeControlOptions: {'.implode(",", $mapTypeControlOptions).'}';
1390
        }
1391
        if ($this->minzoom != "") {
1392
            $this->output_js_contents .= ',
1393
					minZoom: '.$this->minzoom;
1394
        }
1395
        if ($this->maxzoom != "") {
1396
            $this->output_js_contents .= ',
1397
					maxZoom: '.$this->maxzoom;
1398
        }
1399
        if ($this->noClear) {
1400
            $this->output_js_contents .= ',
1401
					noClear: true';
1402
        }
1403
        if ($this->navigationControlPosition != "") {
1404
            $this->output_js_contents .= ',
1405
					navigationControlOptions: {position: google.maps.ControlPosition.'.strtoupper($this->navigationControlPosition).'}';
1406
        }
1407
        if ($this->scaleControlPosition != "") {
1408
            $this->output_js_contents .= ',
1409
			         scaleControl: true,
1410
					scaleControlOptions: {position: google.maps.ControlPosition.'.strtoupper($this->scaleControlPosition).'}';
1411
        }
1412
        if (!$this->scrollwheel) {
1413
            $this->output_js_contents .= ',
1414
					scrollwheel: false';
1415
        }
1416
        if ($this->streetViewControlPosition != "") {
1417
            $this->output_js_contents .= ',
1418
					streetViewControlOptions: {position: google.maps.ControlPosition.'.strtoupper($this->streetViewControlPosition).'}';
1419
        }
1420
        if ($this->tilt == 45) {
1421
            $this->output_js_contents .= ',
1422
					tilt: '.$this->tilt;
1423
        }
1424
        $zoomControlOptions = array();
1425
        if ($this->zoomControlPosition != "") {
1426
            array_push($zoomControlOptions, 'position: google.maps.ControlPosition.'.strtoupper($this->zoomControlPosition));
1427
        }
1428
        if ($this->zoomControlStyle != "" && (strtoupper($this->zoomControlStyle) == "SMALL" || strtoupper($this->zoomControlStyle) == "LARGE")) {
1429
            array_push($zoomControlOptions, 'style: google.maps.ZoomControlStyle.'.strtoupper($this->zoomControlStyle));
1430
        }
1431
        if (count($zoomControlOptions)) {
1432
            $this->output_js_contents .= ',
1433
					zoomControlOptions: {'.implode(",", $zoomControlOptions).'}';
1434
        }
1435
1436
1437
        $this->output_js_contents .= '};';
1438
        $this->output_js_contents .= $this->map_name .' = new google.maps.Map(document.getElementById("'.$this->map_div_id.'"), myOptions);';
1439
1440
        if (count($this->tiledOverlayLayers)) {
1441
            foreach ($this->tiledOverlayLayers as $index => $javascript) {
1442
                $this->output_js_contents .= "{$this->map_name}.overlayMapTypes.insertAt({$index}, maptiler_{$index});";
1443
            }
1444
        }
1445
1446
1447
        if ($styleOutput != "") {
1448
            $this->output_js_contents .= $styleOutput.'
1449
				';
1450
        }
1451
1452
        if ($this->trafficOverlay) {
1453
            $this->output_js_contents .= 'var trafficLayer = new google.maps.TrafficLayer();
1454
				trafficLayer.setMap('.$this->map_name.');
1455
				';
1456
        }
1457
        if ($this->bicyclingOverlay) {
1458
            $this->output_js_contents .= 'var bikeLayer = new google.maps.BicyclingLayer();
1459
				bikeLayer.setMap('.$this->map_name.');
1460
				';
1461
        }
1462
1463
        if ((is_array($this->kmlLayerURL) && count($this->kmlLayerURL)) || (!is_array($this->kmlLayerURL) && $this->kmlLayerURL != "")) {
0 ignored issues
show
introduced by
The condition is_array($this->kmlLayerURL) is always false.
Loading history...
1464
            if (!is_array($this->kmlLayerURL)) {
1465
                // Need to convert single KML layer to array
1466
                $this->kmlLayerURL = array($this->kmlLayerURL);
1467
            }
1468
            if (count($this->kmlLayerURL)) {
1469
                $i = 0;
1470
                foreach ($this->kmlLayerURL as $kmlLayerURL) {
1471
                    $this->output_js_contents .= '
1472
						var kmlLayerOptions = {
1473
							map: '.$this->map_name;
1474
                    if ($this->kmlLayerPreserveViewport) {
1475
                        $this->output_js_contents .= ',
1476
							preserveViewport: true';
1477
                    }
1478
                    $this->output_js_contents .= '
1479
						}
1480
						var kmlLayer_'.$i.' = new google.maps.KmlLayer("'.$kmlLayerURL.'", kmlLayerOptions);
1481
						';
1482
                    ++$i;
1483
                }
1484
            }
1485
        }
1486
1487
        if ($this->panoramio) {
1488
            $this->output_js_contents .= 'var panoramioLayer = new google.maps.panoramio.PanoramioLayer();
1489
				';
1490
            if ($this->panoramioTag != "") {
1491
                $this->output_js_contents .= 'panoramioLayer.setTag("'.$this->panoramioTag.'");
1492
				';
1493
            }
1494
            if ($this->panoramioUser != "") {
1495
                $this->output_js_contents .= 'panoramioLayer.setUserId("'.$this->panoramioUser.'");
1496
				';
1497
            }
1498
            $this->output_js_contents .= '
1499
				panoramioLayer.setMap('.$this->map_name.');
1500
				';
1501
        }
1502
1503
        if (strtolower($this->map_type) == "street") { // if defaulting the map to Street View
1504
            $this->output_js_contents .= '
1505
			  	var streetViewOptions = {
1506
			    	position: myLatlng';
1507
            if (!$this->streetViewAddressControl) {
1508
                $this->output_js_contents .= ',
1509
					addressControl: false';
1510
            }
1511
            if ($this->streetViewAddressPosition != "") {
1512
                $this->output_js_contents .= ',
1513
					addressControlOptions: { position: google.maps.ControlPosition.'.$this->streetViewAddressPosition.' }';
1514
            }
1515
            if ($this->streetViewCloseButton) {
1516
                $this->output_js_contents .= ',
1517
					enableCloseButton: true';
1518
            }
1519
            if (!$this->streetViewLinksControl) {
1520
                $this->output_js_contents .= ',
1521
					linksControl: false';
1522
            }
1523
            if (!$this->streetViewPanControl) {
1524
                $this->output_js_contents .= ',
1525
					panControl: false';
1526
            }
1527
            if ($this->streetViewPanPosition != "") {
1528
                $this->output_js_contents .= ',
1529
					panControlOptions: { position: google.maps.ControlPosition.'.$this->streetViewPanPosition.' }';
1530
            }
1531
            if ($this->streetViewPovHeading != 0 || $this->streetViewPovPitch != 0 || $this->streetViewPovZoom != 0) {
1532
                $this->output_js_contents .= ',
1533
					pov: {
1534
						heading: '.$this->streetViewPovHeading.',
1535
						pitch: '.$this->streetViewPovPitch.',
1536
						zoom: '.$this->streetViewPovZoom.'
1537
					}';
1538
            }
1539
            if (!$this->streetViewZoomControl) {
1540
                $this->output_js_contents .= ',
1541
					zoomControl: false';
1542
            }
1543
            if ($this->streetViewZoomPosition != "" || $this->streetViewZoomStyle != "") {
1544
                $this->output_js_contents .= ',
1545
					zoomControlOptions: {';
1546
                if ($this->streetViewZoomPosition != "") {
1547
                    $this->output_js_contents .= '
1548
						position: google.maps.ControlPosition.'.$this->streetViewZoomPosition.',';
1549
                }
1550
                if ($this->streetViewZoomStyle != "") {
1551
                    $this->output_js_contents .= '
1552
						style: google.maps.ZoomControlStyle.'.$this->streetViewZoomStyle.',';
1553
                }
1554
                $this->output_js_contents = trim($this->output_js_contents, ",");
1555
                $this->output_js_contents .= '}';
1556
            }
1557
            $this->output_js_contents .= '
1558
				};
1559
				var streetView = new google.maps.StreetViewPanorama(document.getElementById("'.$this->map_div_id.'"), streetViewOptions);
1560
				streetView.setVisible(true);
1561
	      		';
1562
        }
1563
1564
        if ($this->center == "auto") { // if wanting to center on the users location
1565
            $this->output_js_contents .= '
1566
				// Try W3C Geolocation (Preferred)
1567
				if(navigator.geolocation) {
1568
					navigator.geolocation.getCurrentPosition(function(position) {
1569
						'.$this->map_name.'.setCenter(new google.maps.LatLng(position.coords.latitude,position.coords.longitude));
1570
					}, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); });
1571
				// Browser doesn\'t support Geolocation
1572
				}else{
1573
					alert(\'Your browser does not support geolocation.\');
1574
				}
1575
			';
1576
        }
1577
1578
        if ($this->directions) {
1579
            $this->output_js_contents .= 'directionsDisplay.setMap('.$this->map_name.');
1580
			';
1581
            if ($this->directionsDivID != "") {
1582
                $this->output_js_contents .= 'directionsDisplay.setPanel(document.getElementById("'.$this->directionsDivID.'"));
1583
			';
1584
            }
1585
            if ($this->directionsDraggable && $this->directionsChanged != "") {
1586
                $this->output_js_contents .= 'google.maps.event.addListener(directionsDisplay, "directions_changed", function() {
1587
					'.$this->directionsChanged.'
1588
				});
1589
			';
1590
            }
1591
        }
1592
1593
        if ($this->drawing) {
1594
            if ($this->drawingControlPosition == '') {
1595
                $this->drawingControlPosition = 'TOP_CENTER';
1596
            }
1597
1598
            $this->output_js_contents .= 'drawingManager = new google.maps.drawing.DrawingManager({
1599
				drawingMode: google.maps.drawing.OverlayType.'.strtoupper($this->drawingDefaultMode).',
1600
  				drawingControl: '.(!$this->drawingControl ? 'false' : 'true').',
1601
  				drawingControlOptions: {
1602
  					position: google.maps.ControlPosition.'.strtoupper($this->drawingControlPosition);
1603
            $shapeOptions = '';
1604
            if (count($this->drawingModes)) {
1605
                $this->output_js_contents .= ',
1606
					drawingModes: [';
1607
                $i = 0;
1608
                foreach ($this->drawingModes as $drawingMode) {
1609
                    if ($i > 0) {
1610
                        $this->output_js_contents .= ',';
1611
                    }
1612
                    $this->output_js_contents .= 'google.maps.drawing.OverlayType.'.strtoupper($drawingMode);
1613
                    if (strtoupper($drawingMode) != "MARKER") {
1614
                        $shapeOptions .= ',
1615
						'.strtolower($drawingMode).'Options: {
1616
							editable: true
1617
						}';
1618
                    }
1619
                    $i++;
1620
                }
1621
                $this->output_js_contents .= ']';
1622
            }
1623
            $this->output_js_contents .= '
1624
				}'.$shapeOptions.'
1625
			});
1626
			drawingManager.setMap('.$this->map_name.');
1627
			';
1628
1629
            $this->output_js_contents .= '
1630
			google.maps.event.addListener(drawingManager, "overlaycomplete", function(event) {
1631
				var newShape = event.overlay;
1632
				newShape.type = event.type;
1633
				';
1634
            if (count($this->drawingOnComplete)) {
1635
                foreach ($this->drawingOnComplete as $shape => $js) {
1636
                    $this->output_js_contents .= 'if (event.type==google.maps.drawing.OverlayType.'.strtoupper($shape).') {
1637
						'.$js.'
1638
					}
1639
					';
1640
                }
1641
            }
1642
1643
            if (count($this->drawingOnEdit)) {
1644
                if (isset($this->drawingOnEdit['polygon'])) {
1645
                    $this->output_js_contents .= '
1646
				if (newShape.type==google.maps.drawing.OverlayType.POLYGON) {
1647
					var newShapePaths = newShape.getPaths();
1648
					for (var i=0; i<newShapePaths.length; i++) {
1649
						google.maps.event.addListener(newShapePaths.getAt(i), "set_at", function(event) {
1650
							'.$this->drawingOnEdit['polygon'].'
1651
						});
1652
						google.maps.event.addListener(newShapePaths.getAt(i), "insert_at", function(event) {
1653
							'.$this->drawingOnEdit['polygon'].'
1654
						});
1655
						google.maps.event.addListener(newShapePaths.getAt(i), "remove_at", function(event) {
1656
							'.$this->drawingOnEdit['polygon'].'
1657
						});
1658
					}
1659
				}';
1660
                }
1661
                if (isset($this->drawingOnEdit['polyline'])) {
1662
                    $this->output_js_contents .= '
1663
				if (newShape.type==google.maps.drawing.OverlayType.POLYLINE) {
1664
					var newShapePaths = newShape.getPaths();
1665
					for (var i=0; i<newShapePaths.length; i++) {
1666
						google.maps.event.addListener(newShapePaths.getAt(i), "set_at", function(event) {
1667
							'.$this->drawingOnEdit['polyline'].'
1668
						});
1669
						google.maps.event.addListener(newShapePaths.getAt(i), "insert_at", function(event) {
1670
							'.$this->drawingOnEdit['polyline'].'
1671
						});
1672
						google.maps.event.addListener(newShapePaths.getAt(i), "remove_at", function(event) {
1673
							'.$this->drawingOnEdit['polyline'].'
1674
						});
1675
					}
1676
				}';
1677
                }
1678
                if (isset($this->drawingOnEdit['rectangle'])) {
1679
                    $this->output_js_contents .= '
1680
				if (newShape.type==google.maps.drawing.OverlayType.RECTANGLE) {
1681
					google.maps.event.addListener(newShape, "bounds_changed", function(event) {
1682
						'.$this->drawingOnEdit['rectangle'].'
1683
					});
1684
				}';
1685
                }
1686
                if (isset($this->drawingOnEdit['circle'])) {
1687
                    $this->output_js_contents .= '
1688
				if (newShape.type==google.maps.drawing.OverlayType.CIRCLE) {
1689
					google.maps.event.addListener(newShape, "radius_changed", function(event) {
1690
						'.$this->drawingOnEdit['circle'].'
1691
					});
1692
					google.maps.event.addListener(newShape, "center_changed", function(event) {
1693
						'.$this->drawingOnEdit['circle'].'
1694
					});
1695
				}';
1696
                }
1697
            }
1698
1699
            $this->output_js_contents .= '
1700
			});';
1701
        }
1702
1703
        if ($this->places) {
1704
            $placesLocationSet = false;
1705
1706
            if ($this->placesLocationSW != "" && $this->placesLocationNE != "") { // if search based on bounds
1707
1708
                $placesLocationSet = true;
1709
1710
                if ($this->is_lat_long($this->placesLocationSW)) {
1711
                    $this->output_js_contents .= 'var placesLocationSW = new google.maps.LatLng('.$this->placesLocationSW.');
1712
			';
1713
                } else {  // if centering the map on an address
1714
                    $lat_long = $this->get_lat_long_from_address($this->placesLocationSW);
1715
                    $this->output_js_contents .= 'var placesLocationSW = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');
1716
			';
1717
                }
1718
1719
                if ($this->is_lat_long($this->placesLocationNE)) {
1720
                    $this->output_js_contents .= 'var placesLocationNE = new google.maps.LatLng('.$this->placesLocationNE.');
1721
			';
1722
                } else {  // if centering the map on an address
1723
                    $lat_long = $this->get_lat_long_from_address($this->placesLocationNE);
1724
                    $this->output_js_contents .= 'var placesLocationNE = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');
1725
			';
1726
                }
1727
            }
1728
1729
            if (($placesLocationSet || $this->placesLocation != "") || count($this->placesTypes) || $this->placesName != "") {
1730
                $this->output_js_contents .= 'var placesRequest = {
1731
					';
1732
                if ($placesLocationSet) {
1733
                    $this->output_js_contents .= 'bounds: new google.maps.LatLngBounds(placesLocationSW, placesLocationNE)
1734
						';
1735
                } else {
1736
                    if ($this->placesLocation != "") { // if search based on a center point
1737
                        if ($this->is_lat_long($this->placesLocation)) { // if centering the map on a lat/long
1738
                            $this->output_js_contents .= 'location: new google.maps.LatLng('.$this->placesLocation.')
1739
						';
1740
                        } else {  // if centering the map on an address
1741
                            $lat_long = $this->get_lat_long_from_address($this->placesLocation);
1742
                            $this->output_js_contents .= 'location: new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')
1743
						';
1744
                        }
1745
                        $this->output_js_contents .= ',radius: '.$this->placesRadius.'
1746
						';
1747
                    }
1748
                }
1749
1750
                if (count($this->placesTypes)) {
1751
                    $this->output_js_contents .= ',types: [\''.implode("','", $this->placesTypes).'\']
1752
						';
1753
                }
1754
                if ($this->placesName != "") {
1755
                    $this->output_js_contents .= ',name : \''.$this->placesName.'\'
1756
						';
1757
                }
1758
                $this->output_js_contents .= '};
1759
1760
				placesService = new google.maps.places.PlacesService('.$this->map_name.');
1761
				placesService.search(placesRequest, placesCallback);
1762
				';
1763
            }
1764
1765
            if ($this->placesAutocompleteInputID != "") {
1766
                $this->output_js_contents .= 'var autocompleteOptions = {
1767
					';
1768
                $autocompleteOptions = '';
1769
                if ($this->placesAutocompleteBoundSW != "" && $this->placesAutocompleteBoundNE != "") {
1770
                    if ($this->is_lat_long($this->placesAutocompleteBoundSW)) {
1771
                        $autocompleteOptionsSW = 'new google.maps.LatLng('.$this->placesAutocompleteBoundSW.')
1772
					';
1773
                    } else {  // if centering the map on an address
1774
                        $lat_long = $this->get_lat_long_from_address($this->placesAutocompleteBoundSW);
1775
                        $autocompleteOptionsSW = 'new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')
1776
					';
1777
                    }
1778
1779
                    if ($this->is_lat_long($this->placesAutocompleteBoundNE)) {
1780
                        $autocompleteOptionsNE = 'new google.maps.LatLng('.$this->placesAutocompleteBoundNE.')
1781
					';
1782
                    } else {  // if centering the map on an address
1783
                        $lat_long = $this->get_lat_long_from_address($this->placesAutocompleteBoundNE);
1784
                        $autocompleteOptionsNE = 'new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')
1785
					';
1786
                    }
1787
                    $autocompleteOptions .= 'bounds: new google.maps.LatLngBounds('.$autocompleteOptionsSW.', '.$autocompleteOptionsNE.')';
1788
                }
1789
                if (count($this->placesAutocompleteTypes)) {
1790
                    if ($autocompleteOptions != "") {
1791
                        $autocompleteOptions .= ',
1792
						 ';
1793
                    }
1794
                    $autocompleteOptions .= 'types: [\''.implode("','", $this->placesAutocompleteTypes).'\']';
1795
                }
1796
                $this->output_js_contents .= $autocompleteOptions;
1797
                $this->output_js_contents .= '}';
1798
1799
                $this->output_js_contents .= '
1800
				var autocompleteInput = document.getElementById(\''.$this->placesAutocompleteInputID.'\');
1801
1802
				placesAutocomplete = new google.maps.places.Autocomplete(autocompleteInput, autocompleteOptions);
1803
				';
1804
1805
                if ($this->placesAutocompleteBoundsMap) {
1806
                    $this->output_js_contents .= 'placesAutocomplete.bindTo(\'bounds\', map);
1807
					';
1808
                }
1809
1810
                if ($this->placesAutocompleteOnChange != "") {
1811
                    $this->output_js_contents .= 'google.maps.event.addListener(placesAutocomplete, \'place_changed\', function() {
1812
						'.$this->placesAutocompleteOnChange.'
1813
					});
1814
					';
1815
                }
1816
            }
1817
        }
1818
1819
        if ($this->onboundschanged != "") {
1820
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "bounds_changed", function(event) {
1821
    			'.$this->onboundschanged.'
1822
  			});
1823
			';
1824
        }
1825
        if ($this->oncenterchanged != "") {
1826
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "center_changed", function(event) {
1827
    			'.$this->oncenterchanged.'
1828
  			});
1829
			';
1830
        }
1831
        if ($this->onclick != "") {
1832
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "click", function(event) {
1833
    			'.$this->onclick.'
1834
  			});
1835
			';
1836
        }
1837
        if ($this->ondblclick != "") {
1838
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "dblclick", function(event) {
1839
    			'.$this->ondblclick.'
1840
  			});
1841
			';
1842
        }
1843
        if ($this->ondrag != "") {
1844
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "drag", function(event) {
1845
    			'.$this->ondrag.'
1846
  			});
1847
			';
1848
        }
1849
        if ($this->ondragend != "") {
1850
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "dragend", function(event) {
1851
    			'.$this->ondragend.'
1852
  			});
1853
			';
1854
        }
1855
        if ($this->ondragstart != "") {
1856
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "dragstart", function(event) {
1857
    			'.$this->ondragstart.'
1858
  			});
1859
			';
1860
        }
1861
        if ($this->onidle != "") {
1862
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "idle", function(event) {
1863
    			'.$this->onidle.'
1864
  			});
1865
			';
1866
        }
1867
        if ($this->onmousemove != "") {
1868
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "mousemove", function(event) {
1869
    			'.$this->onmousemove.'
1870
  			});
1871
			';
1872
        }
1873
        if ($this->onmouseout != "") {
1874
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "mouseout", function(event) {
1875
    			'.$this->onmouseout.'
1876
  			});
1877
			';
1878
        }
1879
        if ($this->onmouseover != "") {
1880
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "mouseover", function(event) {
1881
    			'.$this->onmouseover.'
1882
  			});
1883
			';
1884
        }
1885
        if ($this->onresize != "") {
1886
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "resize", function(event) {
1887
    			'.$this->onresize.'
1888
  			});
1889
			';
1890
        }
1891
        if ($this->onrightclick != "") {
1892
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "rightclick", function(event) {
1893
    			'.$this->onrightclick.'
1894
  			});
1895
			';
1896
        }
1897
        if ($this->ontilesloaded != "") {
1898
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "tilesloaded", function(event) {
1899
    			'.$this->ontilesloaded.'
1900
  			});
1901
			';
1902
        }
1903
        if ($this->onzoomchanged != "") {
1904
            $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "zoom_changed", function(event) {
1905
    			'.$this->onzoomchanged.'
1906
  			});
1907
			';
1908
        }
1909
1910
        // add markers
1911
        if (count($this->markers)) {
1912
            foreach ($this->markers as $marker) {
1913
                $this->output_js_contents .= $marker;
1914
            }
1915
        }
1916
        //
1917
1918
        if ($this->cluster) {
1919
            $this->output_js_contents .= '
1920
			var clusterOptions = {
1921
				gridSize: '.$this->clusterGridSize;
1922
            if ($this->clusterMaxZoom != "") {
1923
                $this->output_js_contents .= ',
1924
				maxZoom: '.$this->clusterMaxZoom;
1925
            }
1926
            if (!$this->clusterZoomOnClick) {
1927
                $this->output_js_contents .= ',
1928
				zoomOnClick: false';
1929
            }
1930
            if ($this->clusterAverageCenter) {
1931
                $this->output_js_contents .= ',
1932
				averageCenter: true';
1933
            }
1934
            if (count($this->clusterStyles) > 0) {
1935
1936
                $this->output_js_contents .= ',
1937
				styles: [ ';
1938
                $styleOutput = [];
1939
                foreach($this->clusterStyles as $clusterStyle){
1940
                    $attributes =[];
1941
                    foreach($clusterStyle as $key => $style){
1942
                        $attributes[] = $key.':"'.$style.'"';
1943
                    }
1944
                    $styleOutput[] = '{'.implode(',',$attributes).'}';
1945
                }
1946
                $this->output_js_contents .= implode(',',$styleOutput);
1947
                $this->output_js_contents .= ']';
1948
            }
1949
1950
            $this->output_js_contents .= ',
1951
				minimumClusterSize: '.$this->clusterMinimumClusterSize.'
1952
			};
1953
			markerCluster = new MarkerClusterer('.$this->map_name.', markers_'.$this->map_name.', clusterOptions);
1954
			';
1955
        }
1956
1957
        // add polylines
1958
        if (count($this->polylines)) {
1959
            foreach ($this->polylines as $polyline) {
1960
                $this->output_js_contents .= $polyline;
1961
            }
1962
        }
1963
        //
1964
1965
        // add polygons
1966
        if (count($this->polygons)) {
1967
            foreach ($this->polygons as $polygon) {
1968
                $this->output_js_contents .= $polygon;
1969
            }
1970
        }
1971
        //
1972
1973
        // add circles
1974
        if (count($this->circles)) {
1975
            foreach ($this->circles as $circle) {
1976
                $this->output_js_contents .= $circle;
1977
            }
1978
        }
1979
        //
1980
1981
        // add rectangles
1982
        if (count($this->rectangles)) {
1983
            foreach ($this->rectangles as $rectangle) {
1984
                $this->output_js_contents .= $rectangle;
1985
            }
1986
        }
1987
        //
1988
1989
        // add ground overlays
1990
        if (count($this->overlays)) {
1991
            foreach ($this->overlays as $overlay) {
1992
                $this->output_js_contents .= $overlay;
1993
            }
1994
        }
1995
        //
1996
1997
        if ($this->zoom == "auto") {
1998
            $this->output_js_contents .= '
1999
			fitMapToBounds_'.$this->map_name.'();
2000
			';
2001
        }
2002
2003
        if ($this->adsense) {
2004
            $this->output_js_contents .= '
2005
			var adUnitDiv = document.createElement("div");
2006
2007
		    // Note: replace the publisher ID noted here with your own
2008
		    // publisher ID.
2009
		    var adUnitOptions = {
2010
		    	format: google.maps.adsense.AdFormat.'.$this->adsenseFormat.',
2011
		    	position: google.maps.ControlPosition.'.$this->adsensePosition.',
2012
		    	publisherId: "'.$this->adsensePublisherID.'",
2013
		    	';
2014
            if ($this->adsenseChannelNumber != "") {
2015
                $this->output_js_contents .= 'channelNumber: "'.$this->adsenseChannelNumber.'",
2016
		    	';
2017
            }
2018
            $this->output_js_contents .= 'map: '.$this->map_name.',
2019
		    	visible: true
2020
		    };
2021
		    adUnit = new google.maps.adsense.AdUnit(adUnitDiv, adUnitOptions);
2022
		    ';
2023
        }
2024
2025
        if ($this->directions && $this->directionsStart != "" && $this->directionsEnd != "") {
2026
            if ($this->directionsStart == "auto" && $this->directionsEnd == "auto") {
2027
                // Both start and finish are at the users current location
2028
                $this->output_js_contents .= '
2029
				// Try W3C Geolocation (Preferred)
2030
				if(navigator.geolocation) {
2031
					navigator.geolocation.getCurrentPosition(function(position) {
2032
						start = position.coords.latitude+","+position.coords.longitude;
2033
						calcRoute(start, start);
2034
					}, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); });
2035
				// Browser doesn\'t support Geolocation
2036
				}else{
2037
					alert(\'Your browser does not support geolocation.\');
2038
				}
2039
				';
2040
            } elseif ($this->directionsStart == "auto") {
2041
                // The start point should be at the users current location
2042
                $this->output_js_contents .= '
2043
				// Try W3C Geolocation (Preferred)
2044
				if(navigator.geolocation) {
2045
					navigator.geolocation.getCurrentPosition(function(position) {
2046
						start = position.coords.latitude+","+position.coords.longitude;
2047
						calcRoute(start, \''.$this->directionsEnd.'\');
2048
					}, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); });
2049
				// Browser doesn\'t support Geolocation
2050
				}else{
2051
					alert(\'Your browser does not support geolocation.\');
2052
				}
2053
				';
2054
            } elseif ($this->directionsEnd == "auto") {
2055
                // The end point should be at the users current location
2056
                $this->output_js_contents .= '
2057
				// Try W3C Geolocation (Preferred)
2058
				if(navigator.geolocation) {
2059
					navigator.geolocation.getCurrentPosition(function(position) {
2060
						end = position.coords.latitude+","+position.coords.longitude;
2061
						calcRoute(\''.$this->directionsStart.'\', end);
2062
					}, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); });
2063
				// Browser doesn\'t support Geolocation
2064
				}else{
2065
					alert(\'Your browser does not support geolocation.\');
2066
				}
2067
				';
2068
            } else {
2069
                // The start and end point are at pre-defined locations
2070
                $this->output_js_contents .= '
2071
				calcRoute(\''.$this->directionsStart.'\', \''.$this->directionsEnd.'\');
2072
				';
2073
            }
2074
        }
2075
2076
        if ($this->onload != "") {
2077
            $this->output_js_contents .= '
2078
				'.$this->onload;
2079
        }
2080
2081
        $this->output_js_contents .= '
2082
2083
			}
2084
2085
		';
2086
2087
        // add markers
2088
        $this->output_js_contents .= '
2089
		function createMarker_'.$this->map_name.'(markerOptions) {
2090
			var marker = new google.maps.Marker(markerOptions);
2091
			markers_'.$this->map_name.'.push(marker);
2092
			lat_longs_'.$this->map_name.'.push(marker.getPosition());
2093
			return marker;
2094
		}
2095
		';
2096
        //
2097
2098
        if ($this->directions) {
2099
            $this->output_js_contents .= 'function calcRoute(start, end) {
2100
2101
			var request = {
2102
			    	origin:start,
2103
			    	destination:end,
2104
			    	travelMode: google.maps.TravelMode.'.$this->directionsMode.'
2105
			    	';
2106
2107
            if (count($this->directionsWaypointArray)) {
2108
                $directionsWaypointStr = '';
2109
                foreach ($this->directionsWaypointArray as $waypoint) {
2110
                    if ($directionsWaypointStr != '') {
2111
                        $directionsWaypointStr .= ',';
2112
                    }
2113
                    $directionsWaypointStr .= '{ location: "'.$waypoint.'", stopover: true}';
2114
                }
2115
                $this->output_js_contents .= ', waypoints: ['.$directionsWaypointStr.']';
2116
2117
                if ($this->directionsWaypointsOptimize) {
2118
                    $this->output_js_contents .= ', optimizeWaypoints: true';
2119
                }
2120
            }
2121
            if ($this->region != "" && strlen($this->region) == 2) {
2122
                $this->output_js_contents .= ',region: '.strtoupper($this->region).'
2123
					';
2124
            }
2125
            if (trim($this->directionsUnits) != "" && (strtolower(trim($this->directionsUnits)) == "metric" || strtolower(trim($this->directionsUnits)) == "imperial")) {
2126
                $this->output_js_contents .= ',unitSystem: google.maps.UnitSystem.'.strtoupper(trim($this->directionsUnits)).'
2127
					';
2128
            }
2129
            if ($this->directionsAvoidTolls) {
2130
                $this->output_js_contents .= ',avoidTolls: true
2131
					';
2132
            }
2133
            if ($this->directionsAvoidHighways) {
2134
                $this->output_js_contents .= ',avoidHighways: true
2135
					';
2136
            }
2137
2138
            $this->output_js_contents .= '
2139
			};
2140
			  	directionsService.route(request, function(response, status) {
2141
			    	if (status == google.maps.DirectionsStatus.OK) {
2142
			      		directionsDisplay.setDirections(response);
2143
			    	}else{
2144
			    		switch (status) {
2145
			    			case "NOT_FOUND": { alert("Either the start location or destination were not recognised"); break }
2146
			    			case "ZERO_RESULTS": { alert("No route could be found between the start location and destination"); break }
2147
			    			case "MAX_WAYPOINTS_EXCEEDED": { alert("Maximum waypoints exceeded. Maximum of 8 allowed"); break }
2148
			    			case "INVALID_REQUEST": { alert("Invalid request made for obtaining directions"); break }
2149
			    			case "OVER_QUERY_LIMIT": { alert("This webpage has sent too many requests recently. Please try again later"); break }
2150
			    			case "REQUEST_DENIED": { alert("This webpage is not allowed to request directions"); break }
2151
			    			case "UNKNOWN_ERROR": { alert("Unknown error with the server. Please try again later"); break }
2152
			    		}
2153
			    	}
2154
			  	});
2155
			}
2156
			';
2157
        }
2158
2159
        if ($this->places) {
2160
            $this->output_js_contents .= 'function placesCallback(results, status) {
2161
				if (status == google.maps.places.PlacesServiceStatus.OK) {
2162
					for (var i = 0; i < results.length; i++) {
2163
2164
						var place = results[i];
2165
2166
						var placeLoc = place.geometry.location;
2167
						var placePosition = new google.maps.LatLng(placeLoc.lat(), placeLoc.lng());
2168
						var markerOptions = {
2169
				 			map: '.$this->map_name.',
2170
				        	position: placePosition
2171
				      	};
2172
				      	var marker = createMarker_'.$this->map_name.'(markerOptions);
2173
				      	marker.set("content", place.name);
2174
				      	google.maps.event.addListener(marker, "click", function() {
2175
				        	iw_'.$this->map_name.'.setContent(this.get("content"));
2176
				        	iw_'.$this->map_name.'.open('.$this->map_name.', this);
2177
				      	});
2178
2179
				      	lat_longs_'.$this->map_name.'.push(placePosition);
2180
2181
					}
2182
					';
2183
            if ($this->zoom == "auto") {
2184
                $this->output_js_contents .= 'fitMapToBounds_'.$this->map_name.'();';
2185
            }
2186
            $this->output_js_contents .= '
2187
				}
2188
			}
2189
			';
2190
        }
2191
2192
        if ($this->zoom == "auto") {
2193
            $this->output_js_contents .= '
2194
			function fitMapToBounds_'.$this->map_name.'() {
2195
				var bounds = new google.maps.LatLngBounds();
2196
				if (lat_longs_'.$this->map_name.'.length>0) {
2197
					for (var i=0; i<lat_longs_'.$this->map_name.'.length; i++) {
2198
						bounds.extend(lat_longs_'.$this->map_name.'[i]);
2199
					}
2200
					'.$this->map_name.'.fitBounds(bounds);
2201
				}
2202
			}
2203
			';
2204
        }
2205
2206
        if ($this->loadAsynchronously) {
2207
            $this->output_js_contents .= '
2208
			function loadScript_'.$this->map_name.'() {
2209
				var script = document.createElement("script");
2210
  				script.type = "text/javascript";
2211
  				script.src = "'.$apiLocation.'&callback=initialize_'.$this->map_name.'";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $apiLocation does not seem to be defined for all execution paths leading up to this point.
Loading history...
2212
  				document.body.appendChild(script);
2213
			}
2214
			window.onload = loadScript_'.$this->map_name.';
2215
			';
2216
        } else {
2217
            foreach ($this->tiledOverlayLayers as $index => $javascript) {
2218
                $this->output_js_contents .= $this->tiledOverlayLayers[$index];
2219
            }
2220
2221
            $this->output_js_contents .= '
2222
			google.maps.event.addDomListener(window, "load", initialize_'.$this->map_name.');
2223
			';
2224
        }
2225
2226
        // Minify the Javascript if the $minifyJS config value is true. Requires Jsmin.php and PHP 5+
2227
        if ($this->minifyJS) {
2228
            $CI = \App::make('jsmin');
2229
            $this->output_js_contents = $CI->jsmin->min($this->output_js_contents);
2230
        }
2231
2232
        if ($this->jsfile == "") {
2233
            $this->output_js .= $this->output_js_contents;
2234
        } else { // if needs writing to external js file
2235
            if (!$handle = fopen($this->jsfile, "w")) {
2236
                $this->output_js .= $this->output_js_contents;
2237
            } else {
2238
                if (!fwrite($handle, $this->output_js_contents)) {
2239
                    $this->output_js .= $this->output_js_contents;
2240
                } else {
2241
                    $this->output_js .= '
2242
					<script src="'.$this->jsfile.'" type="text/javascript"></script>';
2243
                }
2244
            }
2245
        }
2246
2247
        if ($this->jsfile == "") {
2248
            $this->output_js .= '
2249
			//]]>
2250
			</script>';
2251
        }
2252
2253
        // set height and width
2254
        if (is_numeric($this->map_width)) { // if no width type set
2255
            $this->map_width = $this->map_width.'px';
2256
        }
2257
        if (is_numeric($this->map_height)) { // if no height type set
2258
            $this->map_height = $this->map_height.'px';
2259
        }
2260
        //
2261
2262
        $this->output_html .= '<div id="'.$this->map_div_id.'" style="width:'.$this->map_width.'; height:'.$this->map_height.';"'.(($this->class != "") ? ' class="'.$this->class.'"' : '').'></div>';
2263
2264
        ++$this->maps_loaded;
2265
2266
        return array('js' => $this->output_js, 'html' => $this->output_html, 'markers' => $this->markersInfo);
2267
    }
2268
2269
    public function is_lat_long($input)
2270
    {
2271
        $input = str_replace(", ", ",", trim($input));
2272
        $input = explode(",", $input);
2273
        if (count($input) == 2) {
2274
            if (is_numeric($input[0]) && is_numeric($input[1])) { // is a lat long
2275
                return true;
2276
            } else { // not a lat long - incorrect values
2277
                return false;
2278
            }
2279
        } else { // not a lat long - too many parts
2280
            return false;
2281
        }
2282
    }
2283
2284
    public function get_lat_long_from_address($address, $attempts = 0)
2285
    {
2286
        $lat = 0;
2287
        $lng = 0;
2288
2289
        $error = '';
2290
2291
        if ($this->geocodeCaching) { // if caching of geocode requests is activated
2292
2293
            $CI = & get_instance();
0 ignored issues
show
Bug introduced by
The function get_instance was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2293
            $CI = & /** @scrutinizer ignore-call */ get_instance();
Loading history...
2294
            $CI->load->database();
2295
            $CI->db->select("latitude,longitude");
2296
            $CI->db->from("geocoding");
2297
            $CI->db->where("address", trim(strtolower($address)));
2298
            $query = $CI->db->get();
2299
2300
            if ($query->num_rows() > 0) {
2301
                $row = $query->row();
2302
2303
                return array($row->latitude, $row->longitude);
2304
            }
2305
        }
2306
	//utf8_encode($address) will return only english adress mean it's take only english address.
2307
    	// Remove utf8_encode from urlencode then it'll support all languages(eg. en, ur, chinese, russian, japanese, greek etc.)
2308
        // $data_location = "https://maps.google.com/maps/api/geocode/json?address=".urlencode(utf8_encode($address)); //Old One just for english
2309
	    $data_location = "https://maps.google.com/maps/api/geocode/json?address=".urlencode($address); // New One for every language.
2310
        if ($this->region != "" && strlen($this->region) == 2) {
2311
            $data_location .= "&region=".$this->region;
2312
        }
2313
        $data = file_get_contents($data_location);
2314
2315
        $data = json_decode($data);
2316
2317
        if ($data->status == "OK") {
2318
            $lat = $data->results[0]->geometry->location->lat;
2319
            $lng = $data->results[0]->geometry->location->lng;
2320
2321
            if ($this->geocodeCaching) { // if we to need to cache this result
2322
                if ($address != "" && $lat != 0 && $lng != 0) {
2323
                    $data = array(
2324
                        "address" => trim(strtolower($address)),
2325
                        "latitude" => $lat,
2326
                        "longitude" => $lng,
2327
                    );
2328
                    $CI->db->insert("geocoding", $data);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $CI does not seem to be defined for all execution paths leading up to this point.
Loading history...
2329
                }
2330
            }
2331
        } else {
2332
            if ($data->status == "OVER_QUERY_LIMIT") {
2333
                $error = $data->status;
2334
                if ($attempts < 2) {
2335
                    sleep(1);
2336
                    ++$attempts;
2337
                    list($lat, $lng, $error) = $this->get_lat_long_from_address($address, $attempts);
2338
                }
2339
            }
2340
        }
2341
2342
        return array($lat, $lng, $error);
2343
    }
2344
}
2345