-
Notifications
You must be signed in to change notification settings - Fork 6
/
EGmap3Marker.php
90 lines (85 loc) · 2.58 KB
/
EGmap3Marker.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
<?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
*
*/
/**
* A map marker.
* @link http://code.google.com/intl/fr/apis/maps/documentation/javascript/reference.html#Marker
*/
class EGmap3Marker extends EGmap3OverlayBase
{
protected $action = 'addMarker';
/**
* Address to set marker on
* @var string
*/
public $address;
/**
* Coordinates to set marker on
* @var array
*/
public $latLng;
/**
* @var EGmap3MarkerOptions
*/
protected $options;
/**
* An info window associated to this marker.
* @var EGmap3InfoWindow
*/
protected $infowindow;
/**
* Capture the latitude and longitude of the marker to a model.
*
* @param CModel $model Model object
* @param string $lat Attribute name for latitude
* @param string $lng Attribute name for longitude
* @param array $options Options to set :<ul>
* <li>'visible' - show the input fields
* <li>'nocallback' - do not update on callback
* <li>'nodragend' - do not update on dragend
* <li>'drag' - update on drag
* </ul>
*/
public function capturePosition(CModel $model, $lat, $lng, array $options=array())
{
// field options
if (in_array('visible', $options)) {
echo CHtml::activeLabelEx($model, $lat), CHtml::activeTextField($model, $lat);
echo '<br>';
echo CHtml::activeLabelEx($model, $lng), CHtml::activeTextField($model, $lng);
}
else {
echo CHtml::activeHiddenField($model, $lat), CHtml::activeHiddenField($model, $lng);
}
$latId = CHtml::activeId($model, $lat);
$lngId = CHtml::activeId($model, $lng);
// update function
$jsFunction = "function captureMarkerPosition(marker){\$('#$latId').val(marker.getPosition().lat());\$('#$lngId').val(marker.getPosition().lng());}";
Yii::app()->getClientScript()->registerScript(__CLASS__.'#capturePosition', $jsFunction, CClientScript::POS_END);
// event options
if (!in_array('nocallback', $options)){
$this->addCallback('function(result){captureMarkerPosition(result);}');
}
if (!in_array('nodragend', $options)){
$this->addEvent('dragend', 'function(result){captureMarkerPosition(result);}');
}
if (in_array('drag', $options)){
$this->addEvent('drag', 'function(result){captureMarkerPosition(result);}');
}
$this->addEvent('position_changed', 'function(result){captureMarkerPosition(result);}');
}
public function addInfoWindow(EGmap3InfoWindow $infoWindow)
{
$infoWindow->attachToMarker();
$this->infowindow = $infoWindow;
}
}