forked from digitick/yii-jquery-gmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EGmap3OverlayBase.php
94 lines (86 loc) · 1.89 KB
/
EGmap3OverlayBase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* EGmap3 Yii extension
*
* Object oriented PHP interface to GMAP3 Javascript library for
* Google Maps.
*
* @copyright © Digitick <www.digitick.net> 2011
* @license GNU Lesser General Public License v3.0
* @author Ianaré Sévi
*
*/
/**
* Base class for all actions.
*/
abstract class EGmap3OverlayBase extends EGmap3ActionBase
{
/**
* @var EGmap3MapOptions
*/
protected $map;
/**
* Free-form field, it is available as the third parameter in a function
* called.
* @var string
*/
public $data;
/**
* Center the map on the element.
*/
public function centerOnMap()
{
$this->initMapOptions();
$this->map->center = true;
}
/**
* Set the map zoom. Overrides the initial map zoom.
*
* @param int $zoom
*/
public function setMapZoom($zoom)
{
$this->initMapOptions();
$this->map->zoom = $zoom;
}
protected function initMapOptions()
{
if (!is_object($this->map)) {
$this->map = new EGmap3MapOptions();
}
}
/**
* Convert the overlay object into a Javascript string.
* @return string
*/
public function toJS()
{
// set elements into the storage object
if ($this->options || $this->events || $this->onces || $this->callback) {
// transform class name into gmap3 storage name
$name = strtolower(str_replace('EGmap3', null, get_class($this)));
$this->$name = new EGmap3ObjectBase();
if ($this->options) {
$this->$name->options = $this->options;
$this->options = null;
}
if ($this->events) {
$this->$name->events = $this->eventsToJS($this->events);
$this->events = null;
}
if ($this->onces) {
$this->$name->onces = $this->eventsToJS($this->onces);
$this->onces = null;
}
if ($this->callback) {
$this->$name->callback = $this->callback;
$this->callback = null;
}
if ($this->data) {
$this->$name->data = $this->data;
$this->data = null;
}
}
return parent::toJS();
}
}