First, you have to include the the GoogleMapsPHP/Classes/Core/Bootstrap.php
file.
include_once('../../GoogleMapsPHP/Classes/Core/Bootstrap.php');
If you want to deactivate the autoloader call \AdGrafik\GoogleMapsPHP\Core\ClassLoader::unregisterAutoloader();
after including.
Next step is to create an instance of the class \AdGrafik\GoogleMapsPHP\MapBuilder
.
The constructor accepts two parameters. The first parameter can be the map ID or the map options. If it's an array or instance of \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
the constructor set the map options, else if it's a string the map ID.
$map = \AdGrafik\GoogleMapsPHP\Utility\ClassUtility::makeInstance('AdGrafik\\GoogleMapsPHP\\MapBuilder', 'myMap'); $map = \AdGrafik\GoogleMapsPHP\Utility\ClassUtility::makeInstance('AdGrafik\\GoogleMapsPHP\\MapBuilder', 'myMap', $mapOptions); $map = \AdGrafik\GoogleMapsPHP\Utility\ClassUtility::makeInstance('AdGrafik\\GoogleMapsPHP\\MapBuilder', $mapOptions);
If no parameter is set, the map ID will be calculated automatically and the default map options will be used.
$map = \AdGrafik\GoogleMapsPHP\Utility\ClassUtility::makeInstance('AdGrafik\\GoogleMapsPHP\\MapBuilder');
To set options after initialization you can use the object setters or set them by array access.
The canvas node is a simple PHP DOMElement
object, so you can configure it according to your needs.
$map->getCanvasNode()->setAttribute('style', 'height: 300px;');
Every layer, every function and even the map itself is a plug-in for the JavaScript MapBuilder. Therefore you can extend it easily.
To add a plug-in to the map use the add()
method of your map instance.
The first parameter will always be the plug-in name. Depending on the created plug-in you can define more parameters to set the options. Currently all provided plug-ins accept only one parameter for their options.
If the first parameter is an array, than this array contains multiple plug-in settings like in this example.
$map->add('InfoWindow', $options); $map->add('Marker', $options); $map->add('Polygon', $options); $map->add('Polyline', $options); $map->add('KmlLayer', $options); $map->add('StyledMapType', $options); $map->add('Loader', $options);
Consult the Plug-in Options Reference for supported options.
For printing the map in HTML there are several functions available.
If you print multiply maps on one page, you must not care if some tags already printed. Unique tags like jQuery or the Google Maps API will be marked as "printed" when they delivered. So if you call echo $map1;
and echo $map2;
these tags just printed the first time.
To print all just call:
echo $map;
To print just a part use one of the functions:
echo $map->printJavaScriptConstruction();
google.maps.event.addDomListener(window, 'load', function(){ GoogleMapsPhpMap1 = new GoogleMapsPHP.MapBuilder( GoogleMapsPhpOptionsMap1 ); });
The default settings are located in the file GoogleMapsPHP/Configuration/Settings.yml
. Check the reference table for available properties.
To get or set settings in PHP just write:
$settings = \AdGrafik\GoogleMapsPHP\Utility\ClassUtility::makeInstance('AdGrafik\\GoogleMapsPHP\\Configuration\\Settings') ->set('debug', TRUE) ->set('view.node.jQuery.source', 'http://code.jquery.com/jquery-1.10.1.min.js') ->set('view.node.jQuery.external', TRUE) ; $jQuerySource = $settings->get('view.node.jQuery.source');
The OptionSplit function is a powerful function from the TYPO3 inventor Kasper Skårhøj. With this function you can define configurations for defined parts of an array. It can be applied to every plug-in option (but only if it makes sense :) ).
A useful implementation can be found in the section Multiply markers with info windows.
Please read the official documentation, to see how it works.
Use the full power of the PHP ArrayAccess object! Setting options can be done in various ways.
Set options at initialization:
$map = \AdGrafik\GoogleMapsPHP\Utility\ClassUtility::makeInstance('AdGrafik\\GoogleMapsPHP\\MapBuilder', array( 'center' => '48.208202, 16.373749', 'backgroundColor' => 'yellow', 'mapTypeId' => \AdGrafik\GoogleMapsPHP\API\Map\MapTypeId::TERRAIN, 'zoom' => 15, ));
Set options by array access:
$map = \AdGrafik\GoogleMapsPHP\Utility\ClassUtility::makeInstance('AdGrafik\\GoogleMapsPHP\\MapBuilder'); $map['center'] = '48.208202, 16.373749'; $map['backgroundColor'] = 'yellow'; $map['mapTypeId'] = \AdGrafik\GoogleMapsPHP\API\Map\MapTypeId::TERRAIN; $map['zoom'] = 15;
Set options by object access:
$map = \AdGrafik\GoogleMapsPHP\Utility\ClassUtility::makeInstance('AdGrafik\\GoogleMapsPHP\\MapBuilder'); $map->setCenter('48.208202, 16.373749'); $map->setBackgroundColor('yellow'); $map->setMapTypeId(\AdGrafik\GoogleMapsPHP\API\Map\MapTypeId::TERRAIN); $map->setZoom(15);