Changeset 3179 for trunk/modules
- Timestamp:
- 07/21/2008 11:44:36 AM (4 months ago)
- Files:
-
- 1 modified
-
trunk/modules/gmaps/libraries/Gmap.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/gmaps/libraries/Gmap.php
r3163 r3179 13 13 14 14 /** 15 * Return GMap javascript url 16 * 17 * @param string API component 18 * @param array API parameters 19 * @return string 20 */ 21 public static function api_uri($component = 'jsapi', $parameters = NULL) 22 { 23 if (empty($parameters['key'])) 24 { 25 // Set the API key 26 $parameters['key'] = Kohana::config('gmaps.api_key'); 27 } 28 29 if (empty($parameters['ie'])) 30 { 31 // Set input encoding to UTF-8 32 $parameters['ie'] = 'utf-8'; 33 } 34 35 if (empty($parameters['oe'])) 36 { 37 // Set ouput encoding to input encoding 38 $parameters['oe'] = $parameters['ie']; 39 } 40 41 return html::specialchars('http://www.google.com/'.$component.'?'.http_build_query($parameters), FALSE); 42 } 43 44 /** 15 45 * Retrieves the latitude and longitude of an address. 16 46 * … … 87 117 return $xml; 88 118 } 89 119 90 120 /** 91 121 * Returns an image map … … 99 129 * @return string 100 130 */ 101 public static function static_map($lat = 0, $lon = 0, $zoom = 6, $type = 'roadmap', $width = 300, $height = 300) 102 { 103 $api_url = 'http://maps.google.com/staticmap?key='.Kohana::config('gmaps.api_key'); 104 131 public static function static_map($lat = 0, $lon = 0, $zoom = 6, $type = NULL, $width = 300, $height = 300) 132 { 133 // Valid map types 105 134 $types = array('roadmap', 'mobile'); 106 135 107 $width = min(640, (int) $width); 108 $height = min(640, (int) $height); 109 110 if ($width <= 0 OR $height <= 0) 111 throw new Kohana_Exception('gmaps.invalid_dimensions', $width, $height); 112 113 $api_url = $api_url.'&size='.$width.'x'.$height; 114 136 // Maximum width and height are 640px 137 $width = min(640, abs($width)); 138 $height = min(640, abs($height)); 139 140 $parameters['size'] = $width.'x'.$height; 141 142 // Minimum zoom = 0, maximum zoom = 19 143 $parameters['zoom'] = min(0, max(19, abs($zoom))); 144 115 145 if (in_array($type, $types)) 116 $api_url = $api_url.'&maptype='.$type; 117 146 { 147 // Set map type 148 $parameters['maptype'] = $type; 149 } 150 118 151 if (is_array($lat)) 119 152 { 120 foreach ($lat as $key => $value) 121 $markers[] = $key.','.$value; 122 123 $api_url = $api_url.'&markers='.implode('|', $markers); 153 foreach ($lat as $_lat => $_lon) 154 { 155 $parameters['markers'][] = $_lat.','.$_lon; 156 } 157 158 $parameters['markers'] = implode('|', $parameters['markers']); 124 159 } 125 160 else 126 161 { 127 $ api_url = $api_url.'&center='.$lat.','.$lon.'&zoom='.$zoom;128 } 129 130 return $api_url;162 $parameters['center'] = $lat.','.$lon; 163 } 164 165 return Gmap::api_url('staticmap', $parameters); 131 166 } 132 167 … … 138 173 protected $overview_control; 139 174 protected $type_control = FALSE; 140 175 141 176 // Map types 142 177 protected $types = array(); … … 158 193 $this->options = new Gmap_Options((array) $options); 159 194 } 160 161 /**162 * Return GMap javascript url163 *164 * @return string165 */166 public function api_uri()167 {168 return 'http://www.google.com/jsapi?key='.Kohana::config('gmaps.api_key').'&oe=utf-8';169 }170 195 171 196 /** … … 196 221 { 197 222 // Set the control type 198 $this->control = (strtolower($size) == ='small') ? 'Small' : 'Large';199 200 return $this; 201 } 202 223 $this->control = (strtolower($size) == 'small') ? 'Small' : 'Large'; 224 225 return $this; 226 } 227 203 228 /** 204 229 * Set the GMap overview map. … … 213 238 $size = (is_int($width) AND is_int($height)) ? 'new GSize('.$width.','.$height.')' : ''; 214 239 $this->overview_control = 'map.addControl(new google.maps.OverviewMapControl('.$size.'));'; 215 216 return $this; 217 } 218 240 241 return $this; 242 } 243 219 244 /** 220 245 * Set the GMap type controls. … … 229 254 { 230 255 $this->type_control = TRUE; 231 256 232 257 $types = array 233 258 ( 234 259 'G_NORMAL_MAP','G_SATELLITE_MAP','G_HYBRID_MAP','G_PHYSICAL_MAP' 235 260 ); 236 261 237 262 if ($type !== NULL and in_array($type, $types, true)) 238 263 { … … 240 265 $this->types[$type] = (strtolower($action) === 'remove') ? 'remove' : 'add'; 241 266 } 242 267 243 268 return $this; 244 269 } … … 274 299 // Map 275 300 $map = 'var map = new google.maps.Map2(document.getElementById("'.$this->id.'"));'; 276 301 277 302 // Map controls 278 303 $controls[] = empty($this->control) ? '' : 'map.addControl(new google.maps.'.$this->control.'MapControl());'; … … 281 306 if ($this->type_control === TRUE) 282 307 { 283 if (count($this->types) > 0) 308 if (count($this->types) > 0) 284 309 { 285 310 foreach($this->types as $type => $action) 286 311 $controls[] = 'map.'.$action.'MapType('.$type.');'; 287 312 } 288 313 289 314 $controls[] = 'map.addControl(new google.maps.MapTypeControl());'; 290 315 } 291 316 292 317 if ( ! empty($this->overview_control)) 293 318 $controls[] = $this->overview_control;
