|
|
@@ -3,6 +3,7 @@ namespace Tools\View\Helper;
|
|
|
|
|
|
use Cake\View\Helper;
|
|
|
use Cake\Utility\Hash;
|
|
|
+use Cake\Core\Configure;
|
|
|
|
|
|
/**
|
|
|
* This is a CakePHP helper that helps users to integrate GoogleMap v3
|
|
|
@@ -190,7 +191,7 @@ class GoogleMapV3Helper extends Helper {
|
|
|
),
|
|
|
'autoCenter' => false, // try to fit all markers in (careful, all zooms values are omitted)
|
|
|
'autoScript' => false, // let the helper include the necessary js script links
|
|
|
- 'inline' => false, // for scripts
|
|
|
+ 'block' => false, // for scripts
|
|
|
'localImages' => false,
|
|
|
'https' => null // auto detect
|
|
|
);
|
|
|
@@ -203,6 +204,7 @@ class GoogleMapV3Helper extends Helper {
|
|
|
|
|
|
public function __construct($View = null, $config = array()) {
|
|
|
$google = (array)Configure::read('Google');
|
|
|
+
|
|
|
$defaults = $this->_defaultOptions;
|
|
|
if (!empty($google['api'])) {
|
|
|
$defaults['map']['api'] = $google['api'];
|
|
|
@@ -243,7 +245,7 @@ class GoogleMapV3Helper extends Helper {
|
|
|
$defaults['localImages'] = $google['localImages'];
|
|
|
}
|
|
|
|
|
|
- $this->settings = $defaults;
|
|
|
+ $config = Hash::merge($defaults, $config);
|
|
|
parent::__construct($View, $config);
|
|
|
}
|
|
|
|
|
|
@@ -269,10 +271,10 @@ class GoogleMapV3Helper extends Helper {
|
|
|
$url .= '&language=' . $language;
|
|
|
}
|
|
|
if (!empty($api)) {
|
|
|
- $this->settings['map']['api'] = $api;
|
|
|
+ $this->_config['map']['api'] = $api;
|
|
|
}
|
|
|
- if (!empty($this->settings['map']['api'])) {
|
|
|
- $url .= '&v=' . $this->settings['map']['api'];
|
|
|
+ if (!empty($this->_config['map']['api'])) {
|
|
|
+ $url .= '&v=' . $this->_config['map']['api'];
|
|
|
}
|
|
|
if (!empty($append)) {
|
|
|
$url .= $append;
|
|
|
@@ -292,7 +294,7 @@ class GoogleMapV3Helper extends Helper {
|
|
|
* @return string currentContainerId
|
|
|
*/
|
|
|
public function id() {
|
|
|
- return $this->settings['div']['id'];
|
|
|
+ return $this->_config['div']['id'];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -305,7 +307,7 @@ class GoogleMapV3Helper extends Helper {
|
|
|
static::$markerCount = static::$infoWindowCount = 0;
|
|
|
$this->markers = $this->infoWindows = array();
|
|
|
if ($full) {
|
|
|
- $this->settings = $this->_defaultOptions;
|
|
|
+ $this->_config = $this->_defaultOptions;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -324,19 +326,19 @@ class GoogleMapV3Helper extends Helper {
|
|
|
*/
|
|
|
public function setControls($options = array()) {
|
|
|
if (isset($options['streetView'])) {
|
|
|
- $this->settings['map']['streetViewControl'] = $options['streetView'];
|
|
|
+ $this->_config['map']['streetViewControl'] = $options['streetView'];
|
|
|
}
|
|
|
if (isset($options['zoom'])) {
|
|
|
- $this->settings['map']['scaleControl'] = $options['zoom'];
|
|
|
+ $this->_config['map']['scaleControl'] = $options['zoom'];
|
|
|
}
|
|
|
if (isset($options['scrollwheel'])) {
|
|
|
- $this->settings['map']['scrollwheel'] = $options['scrollwheel'];
|
|
|
+ $this->_config['map']['scrollwheel'] = $options['scrollwheel'];
|
|
|
}
|
|
|
if (isset($options['keyboardShortcuts'])) {
|
|
|
- $this->settings['map']['keyboardShortcuts'] = $options['keyboardShortcuts'];
|
|
|
+ $this->_config['map']['keyboardShortcuts'] = $options['keyboardShortcuts'];
|
|
|
}
|
|
|
if (isset($options['type'])) {
|
|
|
- $this->settings['map']['type'] = $options['type'];
|
|
|
+ $this->_config['map']['type'] = $options['type'];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -349,32 +351,32 @@ class GoogleMapV3Helper extends Helper {
|
|
|
*/
|
|
|
public function map($options = array()) {
|
|
|
$this->reset();
|
|
|
- $this->settings = Hash::merge($this->settings, $options);
|
|
|
- $this->settings['map'] = array_merge($this->settings['map'], array('zoom' => $this->settings['zoom'], 'lat' => $this->settings['lat'], 'lng' => $this->settings['lng'], 'type' => $this->settings['type']), $options);
|
|
|
- if (!$this->settings['map']['lat'] || !$this->settings['map']['lng']) {
|
|
|
- $this->settings['map']['lat'] = $this->settings['map']['defaultLat'];
|
|
|
- $this->settings['map']['lng'] = $this->settings['map']['defaultLng'];
|
|
|
- $this->settings['map']['zoom'] = $this->settings['map']['defaultZoom'];
|
|
|
- } elseif (!$this->settings['map']['zoom']) {
|
|
|
- $this->settings['map']['zoom'] = $this->settings['map']['defaultZoom'];
|
|
|
+ $this->_config = Hash::merge($this->_config, $options);
|
|
|
+ $this->_config['map'] = array_merge($this->_config['map'], array('zoom' => $this->_config['zoom'], 'lat' => $this->_config['lat'], 'lng' => $this->_config['lng'], 'type' => $this->_config['type']), $options);
|
|
|
+ if (!$this->_config['map']['lat'] || !$this->_config['map']['lng']) {
|
|
|
+ $this->_config['map']['lat'] = $this->_config['map']['defaultLat'];
|
|
|
+ $this->_config['map']['lng'] = $this->_config['map']['defaultLng'];
|
|
|
+ $this->_config['map']['zoom'] = $this->_config['map']['defaultZoom'];
|
|
|
+ } elseif (!$this->_config['map']['zoom']) {
|
|
|
+ $this->_config['map']['zoom'] = $this->_config['map']['defaultZoom'];
|
|
|
}
|
|
|
|
|
|
$result = '';
|
|
|
|
|
|
// autoinclude js?
|
|
|
- if (!empty($this->settings['autoScript']) && !$this->_apiIncluded) {
|
|
|
- $res = $this->Html->script($this->apiUrl(), array('inline' => $this->settings['inline']));
|
|
|
+ if (!empty($this->_config['autoScript']) && !$this->_apiIncluded) {
|
|
|
+ $res = $this->Html->script($this->apiUrl(), array('block' => $this->_config['block']));
|
|
|
|
|
|
- if ($this->settings['inline']) {
|
|
|
+ if (!$this->_config['block']) {
|
|
|
$result .= $res . PHP_EOL;
|
|
|
}
|
|
|
// usually already included
|
|
|
//http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
|
|
|
}
|
|
|
// still not very common: http://code.google.com/intl/de-DE/apis/maps/documentation/javascript/basics.html
|
|
|
- if (false && !empty($this->settings['autoScript']) && !$this->_gearsIncluded) {
|
|
|
- $res = $this->Html->script($this->gearsUrl(), array('inline' => $this->settings['inline']));
|
|
|
- if ($this->settings['inline']) {
|
|
|
+ if (false && !empty($this->_config['autoScript']) && !$this->_gearsIncluded) {
|
|
|
+ $res = $this->Html->script($this->gearsUrl(), array('block' => $this->_config['block']));
|
|
|
+ if (!$this->_config['block']) {
|
|
|
$result .= $res . PHP_EOL;
|
|
|
}
|
|
|
}
|
|
|
@@ -391,30 +393,30 @@ class GoogleMapV3Helper extends Helper {
|
|
|
";
|
|
|
|
|
|
#rename "map_canvas" to "map_canvas1", ... if multiple maps on one page
|
|
|
- while (in_array($this->settings['div']['id'], $this->_mapIds)) {
|
|
|
- $this->settings['div']['id'] .= '-1'; //TODO: improve
|
|
|
+ while (in_array($this->_config['div']['id'], $this->_mapIds)) {
|
|
|
+ $this->_config['div']['id'] .= '-1'; //TODO: improve
|
|
|
}
|
|
|
- $this->_mapIds[] = $this->settings['div']['id'];
|
|
|
+ $this->_mapIds[] = $this->_config['div']['id'];
|
|
|
|
|
|
$map .= "
|
|
|
- var " . $this->name() . " = new google.maps.Map(document.getElementById(\"" . $this->settings['div']['id'] . "\"), myOptions);
|
|
|
+ var " . $this->name() . " = new google.maps.Map(document.getElementById(\"" . $this->_config['div']['id'] . "\"), myOptions);
|
|
|
";
|
|
|
$this->map = $map;
|
|
|
|
|
|
- $this->settings['div']['style'] = '';
|
|
|
- if (is_numeric($this->settings['div']['width'])) {
|
|
|
- $this->settings['div']['width'] .= 'px';
|
|
|
+ $this->_config['div']['style'] = '';
|
|
|
+ if (is_numeric($this->_config['div']['width'])) {
|
|
|
+ $this->_config['div']['width'] .= 'px';
|
|
|
}
|
|
|
- if (is_numeric($this->settings['div']['height'])) {
|
|
|
- $this->settings['div']['height'] .= 'px';
|
|
|
+ if (is_numeric($this->_config['div']['height'])) {
|
|
|
+ $this->_config['div']['height'] .= 'px';
|
|
|
}
|
|
|
|
|
|
- $this->settings['div']['style'] .= 'width: ' . $this->settings['div']['width'] . ';';
|
|
|
- $this->settings['div']['style'] .= 'height: ' . $this->settings['div']['height'] . ';';
|
|
|
- unset($this->settings['div']['width']); unset($this->settings['div']['height']);
|
|
|
+ $this->_config['div']['style'] .= 'width: ' . $this->_config['div']['width'] . ';';
|
|
|
+ $this->_config['div']['style'] .= 'height: ' . $this->_config['div']['height'] . ';';
|
|
|
+ unset($this->_config['div']['width']); unset($this->_config['div']['height']);
|
|
|
|
|
|
- $defaultText = isset($this->settings['content']) ? $this->settings['content'] : __d('tools', 'Map cannot be displayed!');
|
|
|
- $result .= $this->Html->tag('div', $defaultText, $this->settings['div']);
|
|
|
+ $defaultText = isset($this->_config['content']) ? $this->_config['content'] : __d('tools', 'Map cannot be displayed!');
|
|
|
+ $result .= $this->Html->tag('div', $defaultText, $this->_config['div']);
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
@@ -425,10 +427,10 @@ class GoogleMapV3Helper extends Helper {
|
|
|
* @return string
|
|
|
*/
|
|
|
protected function _initialLocation() {
|
|
|
- if ($this->settings['map']['lat'] && $this->settings['map']['lng']) {
|
|
|
- return "new google.maps.LatLng(" . $this->settings['map']['lat'] . ", " . $this->settings['map']['lng'] . ")";
|
|
|
+ if ($this->_config['map']['lat'] && $this->_config['map']['lng']) {
|
|
|
+ return "new google.maps.LatLng(" . $this->_config['map']['lat'] . ", " . $this->_config['map']['lng'] . ")";
|
|
|
}
|
|
|
- $this->settings['autoCenter'] = true;
|
|
|
+ $this->_config['autoCenter'] = true;
|
|
|
return 'false';
|
|
|
}
|
|
|
|
|
|
@@ -447,7 +449,7 @@ class GoogleMapV3Helper extends Helper {
|
|
|
* @throws CakeException
|
|
|
*/
|
|
|
public function addMarker($options) {
|
|
|
- $defaults = $this->settings['marker'];
|
|
|
+ $defaults = $this->_config['marker'];
|
|
|
if (isset($options['icon']) && is_array($options['icon'])) {
|
|
|
$defaults = array_merge($defaults, $options['icon']);
|
|
|
unset($options['icon']);
|
|
|
@@ -533,19 +535,19 @@ function geocodeAddress(address) {
|
|
|
}
|
|
|
|
|
|
// Fill popup windows
|
|
|
- if (!empty($options['content']) && $this->settings['infoWindow']['useMultiple']) {
|
|
|
+ if (!empty($options['content']) && $this->_config['infoWindow']['useMultiple']) {
|
|
|
$x = $this->addInfoWindow(array('content' => $options['content']));
|
|
|
$this->addEvent(static::$markerCount, $x, $options['open']);
|
|
|
|
|
|
} elseif (!empty($options['content'])) {
|
|
|
- if (!isset($this->settings['marker']['infoWindow'])) {
|
|
|
- $this->settings['marker']['infoWindow'] = $this->addInfoWindow();
|
|
|
+ if (!isset($this->_config['marker']['infoWindow'])) {
|
|
|
+ $this->_config['marker']['infoWindow'] = $this->addInfoWindow();
|
|
|
}
|
|
|
|
|
|
$x = $this->addInfoContent($options['content']);
|
|
|
$event = "
|
|
|
- gInfoWindows" . static::$mapCount . "[" . $this->settings['marker']['infoWindow'] . "]. setContent(gWindowContents" . static::$mapCount . "[" . $x . "]);
|
|
|
- gInfoWindows" . static::$mapCount . "[" . $this->settings['marker']['infoWindow'] . "].open(" . $this->name() . ", gMarkers" . static::$mapCount . "[" . $x . "]);
|
|
|
+ gInfoWindows" . static::$mapCount . "[" . $this->_config['marker']['infoWindow'] . "]. setContent(gWindowContents" . static::$mapCount . "[" . $x . "]);
|
|
|
+ gInfoWindows" . static::$mapCount . "[" . $this->_config['marker']['infoWindow'] . "].open(" . $this->name() . ", gMarkers" . static::$mapCount . "[" . $x . "]);
|
|
|
";
|
|
|
$this->addCustomEvent(static::$markerCount, $event);
|
|
|
|
|
|
@@ -646,11 +648,11 @@ function geocodeAddress(address) {
|
|
|
$color = 'red';
|
|
|
}
|
|
|
|
|
|
- if (!empty($this->settings['localImages'])) {
|
|
|
- $this->setIcons['color'] = $this->settings['localImages'] . 'marker%s.png';
|
|
|
- $this->setIcons['alpha'] = $this->settings['localImages'] . 'marker%s%s.png';
|
|
|
- $this->setIcons['numeric'] = $this->settings['localImages'] . '%s%s.png';
|
|
|
- $this->setIcons['special'] = $this->settings['localImages'] . '%s.png';
|
|
|
+ if (!empty($this->_config['localImages'])) {
|
|
|
+ $this->setIcons['color'] = $this->_config['localImages'] . 'marker%s.png';
|
|
|
+ $this->setIcons['alpha'] = $this->_config['localImages'] . 'marker%s%s.png';
|
|
|
+ $this->setIcons['numeric'] = $this->_config['localImages'] . '%s%s.png';
|
|
|
+ $this->setIcons['special'] = $this->_config['localImages'] . '%s.png';
|
|
|
}
|
|
|
|
|
|
if (!empty($char)) {
|
|
|
@@ -777,7 +779,7 @@ var iconShape = {
|
|
|
* @return int windowCount
|
|
|
*/
|
|
|
public function addInfoWindow($options = array()) {
|
|
|
- $defaults = $this->settings['infoWindow'];
|
|
|
+ $defaults = $this->_config['infoWindow'];
|
|
|
$options += $defaults;
|
|
|
|
|
|
if (!empty($options['lat']) && !empty($options['lng'])) {
|
|
|
@@ -866,7 +868,7 @@ var iconShape = {
|
|
|
*/
|
|
|
public function addDirections($from, $to, $options = array()) {
|
|
|
$id = 'd' . static::$markerCount++;
|
|
|
- $defaults = $this->settings['directions'];
|
|
|
+ $defaults = $this->_config['directions'];
|
|
|
$options += $defaults;
|
|
|
$travelMode = $this->travelModes[$options['travelMode']];
|
|
|
|
|
|
@@ -936,7 +938,7 @@ var iconShape = {
|
|
|
$to = '\'' . h($to) . '\'';
|
|
|
}
|
|
|
|
|
|
- $defaults = $this->settings['polyline'];
|
|
|
+ $defaults = $this->_config['polyline'];
|
|
|
$options += $defaults;
|
|
|
|
|
|
$id = 'p' . static::$markerCount++;
|
|
|
@@ -987,7 +989,7 @@ var iconShape = {
|
|
|
* @return string
|
|
|
*/
|
|
|
public function script() {
|
|
|
- $script = '<script type="text/javascript">
|
|
|
+ $script = '<script>
|
|
|
' . $this->finalize(true) . '
|
|
|
</script>';
|
|
|
return $script;
|
|
|
@@ -1008,15 +1010,15 @@ var iconShape = {
|
|
|
';
|
|
|
|
|
|
$script .= $this->map;
|
|
|
- if ($this->settings['geolocate']) {
|
|
|
+ if ($this->_config['geolocate']) {
|
|
|
$script .= $this->_geolocate();
|
|
|
}
|
|
|
|
|
|
- if ($this->settings['showMarker'] && !empty($this->markers) && is_array($this->markers)) {
|
|
|
+ if ($this->_config['showMarker'] && !empty($this->markers) && is_array($this->markers)) {
|
|
|
$script .= implode($this->markers, " ");
|
|
|
}
|
|
|
|
|
|
- if ($this->settings['autoCenter']) {
|
|
|
+ if ($this->_config['autoCenter']) {
|
|
|
$script .= $this->_autoCenter();
|
|
|
}
|
|
|
$script .= '
|
|
|
@@ -1038,10 +1040,10 @@ var iconShape = {
|
|
|
*/
|
|
|
public function geolocateCallback($js) {
|
|
|
if ($js === false) {
|
|
|
- $this->settings['callbacks']['geolocate'] = false;
|
|
|
+ $this->_config['callbacks']['geolocate'] = false;
|
|
|
return;
|
|
|
}
|
|
|
- $this->settings['callbacks']['geolocate'] = $js;
|
|
|
+ $this->_config['callbacks']['geolocate'] = $js;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1088,7 +1090,7 @@ var iconShape = {
|
|
|
}
|
|
|
|
|
|
protected function _geolocationCallback() {
|
|
|
- if (($js = $this->settings['callbacks']['geolocate']) === false) {
|
|
|
+ if (($js = $this->_config['callbacks']['geolocate']) === false) {
|
|
|
return '';
|
|
|
}
|
|
|
if ($js === null) {
|
|
|
@@ -1116,7 +1118,7 @@ var iconShape = {
|
|
|
* @return json like js string
|
|
|
*/
|
|
|
protected function _mapOptions() {
|
|
|
- $options = array_merge($this->settings, $this->settings['map']);
|
|
|
+ $options = array_merge($this->_config, $this->_config['map']);
|
|
|
|
|
|
$mapOptions = array_intersect_key($options, array(
|
|
|
'streetViewControl' => null,
|
|
|
@@ -1523,7 +1525,7 @@ var iconShape = {
|
|
|
* @return string protocol base (including ://)
|
|
|
*/
|
|
|
protected function _protocol() {
|
|
|
- if (($https = $this->settings['https']) === null) {
|
|
|
+ if (($https = $this->_config['https']) === null) {
|
|
|
$https = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on';
|
|
|
}
|
|
|
return ($https ? 'https' : 'http') . '://';
|