├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json └── src ├── Facades └── Map.php ├── Map.php └── Providers └── Service.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | ## [0.7.0] - 2020-02-29 3 | ### Added 4 | - Laravel 7 compatibility 5 | 6 | ## [0.5.7] - 5 Oct 2018 7 | ### Added 8 | - Laravel 5.7 compatibility. 9 | 10 | ## [0.5.1] - 10 Feb 2018 11 | ### Added 12 | - Laravel 5.6 compatibility. 13 | 14 | ## [0.5.0] - 14 Oct 2017 15 | ### Added 16 | - test stubs and required dependencies. 17 | - badges to README. 18 | 19 | ### Changed 20 | - package namespace to genealabs/laravel-maps. 21 | - and cleaned up code, did some refactoring. 22 | 23 | ## [0.3.8 - 0.3.9] - 2016-08-07 24 | ### Added 25 | - automatic setting of apiKey from `config('services.google.maps.api-key')`. 26 | 27 | ### Removed 28 | - deprectated 'sensor' querystring parameter, which would trigger a "SensorNotRequired" warning. 29 | 30 | ## [0.3.5 - 0.3.7] - 2016-01-11 31 | ### Added 32 | - clusterstyles (thanks to @MichaelGollinski). 33 | 34 | ### Changed 35 | - script tag 'src' attributes to always referr to 'https' targets. 36 | 37 | ### Removed 38 | - options to manually choose http or https. 39 | 40 | ## [0.3.4] - 2015-12-11 41 | ### Fixed 42 | - class name conflicts. 43 | 44 | ### Removed 45 | - auto-loading of Facade to avoid conflicts. 46 | 47 | ## 0.3.0 - 0.3.3: 25 Jun 2015 48 | ### Added 49 | - License 50 | - Change Log 51 | 52 | ### Changed 53 | - Namespace from Appitventures to GeneaLabs. 54 | - Installation instructions, affected areas of README. 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 GeneaLabs, LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # laravel-maps 2 | 3 | [](https://travis-ci.org/GeneaLabs/laravel-maps) 4 | [](https://scrutinizer-ci.com/g/GeneaLabs/laravel-maps) 5 | [](https://coveralls.io/github/GeneaLabs/laravel-maps) 6 | [](https://github.com/GeneaLabs/laravel-maps) 7 | [](https://packagist.org/packages/genealabs/laravel-maps) 8 | [](https://raw.githubusercontent.com/GeneaLabs/laravel-maps/master/LICENSE) 9 | 10 | ## Prerequisites 11 | - PHP >= 7.3 12 | - Laravel >= 8.0 13 | 14 | **This package is the continuation of `GeneaLabs/Phpgmaps`. The move to the more appropriately-named package namespace is in preparation for a complete rewrite of the package, optimizing it for Laravel.** 15 | 16 | # PhpGmaps 17 | This repo aims to keep appitventures/phpgmaps alive, hopefully filling in temporarily until they make their repo 18 | available again, or else continuing its maintenance going forward and keeping it working with future versions of 19 | Laravel. 20 | 21 | ## Installation 22 | Add the repo to composer.json under this new namespace: 23 | ```sh 24 | composer require genealabs/laravel-maps 25 | ``` 26 | 27 | Add an environment variable with your Google Maps API Key in your `.env` file: 28 | ``` 29 | GOOGLE_MAPS_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 30 | ``` 31 | 32 | Lastly, add the following entry to your `\config\services.php` config file: 33 | ```php 34 | 'google' => [ 35 | 'maps' => [ 36 | 'api-key' => env('GOOGLE_MAPS_API_KEY'), 37 | ], 38 | ], 39 | ``` 40 | 41 | ### Example 42 | The following code will prompt the user for access to their geolocation and then creates a map centered on their lat/lng 43 | 44 | Route::get('/', function(){ 45 | $config = array(); 46 | $config['center'] = 'auto'; 47 | $config['onboundschanged'] = 'if (!centreGot) { 48 | var mapCentre = map.getCenter(); 49 | marker_0.setOptions({ 50 | position: new google.maps.LatLng(mapCentre.lat(), mapCentre.lng()) 51 | }); 52 | } 53 | centreGot = true;'; 54 | 55 | app('map')->initialize($config); 56 | 57 | // set up the marker ready for positioning 58 | // once we know the users location 59 | $marker = array(); 60 | app('map')->add_marker($marker); 61 | 62 | $map = app('map')->create_map(); 63 | echo "
".$map['js']."".$map['html'].""; 64 | }); 65 | 66 | ### More Examples 67 | BIOINSTALL has a great website showing how to do all the things with the class. No reason to reinvent the wheel, so [here](http://biostall.com/demos/google-maps-v3-api-codeigniter-library/) it is. The only thing to note is that `$this->googlemaps` is now either the facade `Map::` or the app variable `app('map')`. 68 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "genealabs/laravel-maps", 3 | "description": "Eay - peasy map integration for Laravel.", 4 | "license": "MIT", 5 | "keywords": [ 6 | "laravel", 7 | "phpgmaps", 8 | "googlemaps", 9 | "biostall" 10 | ], 11 | "authors": [ 12 | { 13 | "name": "Mike Bronner", 14 | "email": "mike@genealabs.com", 15 | "role": "developer" 16 | } 17 | ], 18 | "require": { 19 | "illuminate/support": "^8.0|^9.0|^10.0" 20 | }, 21 | "suggest": { 22 | "geocoder-php/GeocoderLaravel": "If you need to geocode addresses and don't already have marker coordinates, use this package. It provides geocoding functionality optimized for Laravel." 23 | }, 24 | "autoload": { 25 | "psr-4": { 26 | "GeneaLabs\\LaravelMaps\\": "src/" 27 | } 28 | }, 29 | "require-dev": { 30 | "orchestra/testbench-browser-kit": "^6.0", 31 | "orchestra/testbench-dusk": "^6.0", 32 | "orchestra/testbench": "^6.0", 33 | "php-coveralls/php-coveralls" : "*", 34 | "phpmd/phpmd": "^2.7", 35 | "phpunit/phpunit": "^9.0", 36 | "sebastian/phpcpd": "^5.0", 37 | "symfony/thanks": "^1.2" 38 | }, 39 | "autoload-dev": { 40 | "psr-4": { 41 | "GeneaLabs\\LaravelMaps\\Tests\\": "tests/" 42 | } 43 | }, 44 | "extra": { 45 | "laravel": { 46 | "providers": [ 47 | "GeneaLabs\\LaravelMaps\\Providers\\Service" 48 | ], 49 | "aliases": { 50 | "Map": "GeneaLabs\\LaravelMaps\\Facades\\Map" 51 | } 52 | } 53 | }, 54 | "minimum-stability": "dev", 55 | "prefer-stable": true 56 | } 57 | -------------------------------------------------------------------------------- /src/Facades/Map.php: -------------------------------------------------------------------------------- 1 | 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 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 | public $placesAutocompleteOptionsAppend = ''; 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 .= '®ion='.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 | '; 1185 | } 1186 | 1187 | if ($this->cluster) { 1188 | $this->output_js .= ' 1189 | 1190 | 1191 | '; 1192 | } 1193 | } 1194 | if ($this->jsfile == "") { 1195 | $this->output_js .= ' 1196 | '; 2244 | } 2245 | } 2246 | } 2247 | 2248 | if ($this->jsfile == "") { 2249 | $this->output_js .= ' 2250 | //]]> 2251 | '; 2252 | } 2253 | 2254 | // set height and width 2255 | if (is_numeric($this->map_width)) { // if no width type set 2256 | $this->map_width = $this->map_width.'px'; 2257 | } 2258 | if (is_numeric($this->map_height)) { // if no height type set 2259 | $this->map_height = $this->map_height.'px'; 2260 | } 2261 | // 2262 | 2263 | $this->output_html .= '