summaryrefslogtreecommitdiff
path: root/protected/extensions/egmap/EGMapKeyDragZoom.php
blob: 272efa07702ce5fa3e8a25ad739f99380be1dc4f (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
/**
 * 
 * EGMapKeyDragZoom Class
 * 
 * @link http://google-maps-utility-library-v3.googlecode.com/svn/tags/keydragzoom/2.0.5/docs/reference.html
 * from utility library KeyDragZoom Google Maps V3
 * 
 * @author Antonio Ramirez Cobos
 *
 * 
 * @copyright 
 * 
 * Copyright (c) 2010 Antonio Ramirez Cobos
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 
 * subject to the following conditions:
 * The above copyright notice and this permission notice shall be included in all copies or substantial 
 * portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
 * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */
class EGMapKeyDragZoom extends EGMapBase
{
	/**
	 * 
	 * key trigger definitions
	 * @var string 
	 */
	const KEY_SHIFT = '"shift"';
	const KEY_ALT	= '"alt"';
	/**
	 * 
	 * Supported events
	 * @var string
	 */
	const EVENT_ACTIVATE 	= 'activate';
	const EVENT_DEACTIVATE 	= 'deactivate';
	const EVENT_DRAGSTART	= 'dragstart';
	const EVENT_DRAG		= 'drag';
	const EVENT_DRAGEND		= 'dragend';
	
	protected $options = array(
		// An object literal or named array defining the css styles of the zoom box. The default 
		// is {border: "4px solid #736AFF"}. Border widths must be specified in pixel units 
		// (or as thin, medium, or thick).
		'boxStyle' => null,
		// The hot key to hold down to activate a drag zoom, shift | ctrl | alt. The default 
		// is shift. NOTE: Do not use Ctrl as the hot key with Google Maps JavaScript API V3 since, 
		// unlike with V2, it causes a context menu to appear when running on the Macintosh. Also 
		// note that the alt hot key refers to the Option key on a Macintosh.
		'key' => self::KEY_SHIFT,
		// An object literal or named array defining the css styles of the veil pane which covers the map when a 
		// drag zoom is activated. The previous name for this property was paneStyle but the use of 
		// this name is now deprecated. The default is {backgroundColor: "gray", opacity: 0.25, cursor: "crosshair"}.
		'veilStyle' => null,
		// The name of the CSS class defining the styles for the visual control. To prevent the visual control 
		// from being printed, set this property to the name of a class, defined inside a @media print rule, 
		// which sets the CSS display style to none.
		'visualClass' => null,
		// A flag indicating whether a visual control is to be used. The default is false.
		'visualEnabled' => null,
		// The position of the visual control. The default position is on the left side of the map below other 
		// controls in the top left  i.e., a position of google.maps.ControlPosition.LEFT_TOP.
		'visualPosition' => EGMapControlPosition::LEFT_TOP,
		// The index of the visual control. The index is for controlling the placement of the control relative 
		// to other controls at the position given by visualPosition; controls with a lower index are placed 
		// first. Use a negative value to place the control before any default controls. No index is generally 
		// required; the default is null.
		'visualPositionIndex'=> null,
		// The width and height values provided by this property are the offsets (in pixels) from the location 
		// at which the control would normally be drawn to the desired drawing location. The default is (35,0).
		'visualPositionOffset'=>null,
		// The width and height values provided by this property are the size (in pixels) of each of the images 
		// within visualSprite. The default is (20,20).
		'visualSize'=>null,
		// The URL of the sprite image used for showing the visual control in the on, off, and hot (i.e., when 
		// the mouse is over the control) states. The three images within the sprite must be the same size and 
		// arranged in on-hot-off order in a single row with no spaces between images. The default is 
		// http://maps.gstatic.com/mapfiles/ftr/controls/dragzoom_btn.png.
		'visualSprite'=>null,
		// An object literal defining the help tips that appear when the mouse moves over the visual control. 
		// The off property is the tip to be shown when the control is off and the on property is the tip to be 
		// shown when the control is on. The default values are "Turn on drag zoom mode" and "Turn off drag zoom mode", respectively.
		'visualType'=> null
	);
	/**
	 * 
	 * Collection of events
	 * @var array
	 */
	protected $events = array();
	
	/**
	 * 
	 * Class constructor
	 * @param array options
	 */
	public function __construct( $options = array() )
	{
		$this->setOptions($options);
	}
  	/**
  	 * 
  	 * Sets plugin options
  	 * @param array $options
  	 * @throws CException
  	 */
	public function setOptions( $options ){
		if(!is_array( $options )) 
			throw new CException( Yii::t('EGMap', 'KeyDrEGMapKeyDragZoomagZoom options must be of type array!'));
		$this->options = CMap::mergeArray($this->options, $options);
		
	}
	public function setVeilStyle( $options ){
		if(!is_array($options))
			throw new CException(Yii::t('EGMap', 'Property "{class}.{property}" {e}.',
				array('{class}'=>get_class($this), '{property}'=>'veilStyle','{e}'=>'must be of type array')));
	}
	public function setBoxStyle( $options ){
		if(!is_array($options))
			throw new CException(Yii::t('EGMap', 'Property "{class}.{property}" {e}.',
				array('{class}'=>get_class($this), '{property}'=>'boxStyle','{e}'=>'must be of type array')));
	}
	public function setVisualSize( EGMapSize $size ){
		$this->options['visualSize'] = $size;
	}
	public function setVisualPositionOffset( EGMapSize $offset ){
		$this->options['visualPositionOffset'] = $offset;
	}
	
	/**
	 * 
	 * Adds an event to the plugin
	 * Note that the event must be a supported one
	 * @param string $trigger
	 * @param string $function
	 * @param boolean $encapsulate_function
	 * @throws CException
	 */
	public function addEvent( $trigger,$function,$encapsulate_function=true ){
		if(	$trigger != self::EVENT_ACTIVATE && 
			$trigger != self::EVENT_DEACTIVATE && 
			$trigger != self::EVENT_DRAG && 
			$trigger != self::EVENT_DRAGEND && 
			$trigger != self::EVENT_DRAGSTART )
			throw new CException( Yii::t('EGMap', 'Unrecognized EGMapKeyDragZoom event!'));
			
		$this->events[] = new EGMapEvent( $trigger, $function, $encapsulate_function );
		
	}
	/**
	 * @return string Javascript code to return the Point
	 */
	public function toJs( $map_js_name = 'map' )
	{
		foreach(array('veilStyle','boxStyle','visualClass','visualType') as $key)
			if(isset($this->options[$key])) $this->options[$key] = CJavaScript::encode($this->options[$key]);
			
		$return = $map_js_name.'.enableKeyDragZoom('.EGMap::encode($this->options).');';
		
		if (count($this->events)){
			$return .= 'var '.$this->getJsName().'='.$map_js_name.'.getDragZoomObject();';
			foreach($this->events as $e){
				$return .= $e->toJs($this->getJsName());
			}
		}
		return  $return;
  	}
}