Changeset 16301
- Timestamp:
- 03/13/09 15:44:57 (4 years ago)
- Files:
-
- plugins/sfEasyGMapPlugin/trunk/README (modified) (1 diff)
- plugins/sfEasyGMapPlugin/trunk/config/app.yml (modified) (1 diff)
- plugins/sfEasyGMapPlugin/trunk/lib/GMap.class.php (modified) (12 diffs)
- plugins/sfEasyGMapPlugin/trunk/lib/GMapBounds.class.php (added)
- plugins/sfEasyGMapPlugin/trunk/lib/GMapCoord.class.php (added)
- plugins/sfEasyGMapPlugin/trunk/lib/GMapMarker.class.php (modified) (5 diffs)
- plugins/sfEasyGMapPlugin/trunk/lib/external (added)
- plugins/sfEasyGMapPlugin/trunk/lib/external/RenderTag.class.php (added)
- plugins/sfEasyGMapPlugin/trunk/lib/helper/GMapHelper.php (modified) (3 diffs)
- plugins/sfEasyGMapPlugin/trunk/modules/sfEasyGMapPlugin/actions/actions.class.php (modified) (2 diffs)
- plugins/sfEasyGMapPlugin/trunk/modules/sfEasyGMapPlugin/templates/indexSuccess.php (added)
- plugins/sfEasyGMapPlugin/trunk/package.xml (modified) (3 diffs)
- plugins/sfEasyGMapPlugin/trunk/test (added)
- plugins/sfEasyGMapPlugin/trunk/test/bootstrap (added)
- plugins/sfEasyGMapPlugin/trunk/test/bootstrap/functional.php (added)
- plugins/sfEasyGMapPlugin/trunk/test/bootstrap/unit.php (added)
- plugins/sfEasyGMapPlugin/trunk/test/unit (added)
- plugins/sfEasyGMapPlugin/trunk/test/unit/GMapBoundsTest.php (added)
- plugins/sfEasyGMapPlugin/trunk/test/unit/GMapCoordTest.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfEasyGMapPlugin/trunk/README
r16292 r16301 48 48 49 49 All samples are available in the sfEasyGMapPlugin module of the plugin 50 51 IMPORTANT ! The javascript in the samples will not work unless you put the js files in your web directory. 52 53 $ ln -s ../plugins/sfEasyGMapPlugin/web web/sfEasyGMapPlugin 50 54 51 55 * Sample 1 plugins/sfEasyGMapPlugin/trunk/config/app.yml
r11741 r16301 6 6 localhost: 'ABQIAAAAR8dhgMmvaR96TE0zbrZpPhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTigwPNwH8mpUzCtNyXEc8wof8pQQ' 7 7 127.0.0.1: 'ABQIAAAAR8dhgMmvaR96TE0zbrZpPhRi_j0U6kJrkFvY4-OX2XYmEAa76BSBf4cexehBD0A_7x8IHGqyru1L-w' 8 myfriendsmap.allomatch.amlocal: 'ABQIAAAAR8dhgMmvaR96TE0zbrZpPhTen_Kr4BPibvG7BpUai5kZ9loSrRQWMSxzmHsjgRny_cdmLnAughm8zQ'8 theodo.allomatch.amlocal: 'ABQIAAAAR8dhgMmvaR96TE0zbrZpPhQYmdh2C4WZ52ITKaz16nRTTNfCjxTaZAKZH5i3EYw_WobyL5iIG6Hurg' plugins/sfEasyGMapPlugin/trunk/lib/GMap.class.php
r12374 r16301 8 8 class GMap 9 9 { 10 11 protected $default_options = array( 12 'double_click_zoom' => true, 13 'control' => 'new google.maps.LargeMapControl()', 14 'zoom' => 10, 15 'center_lat' => 48.845398, 16 'center_lng' => 2.34258, 17 'js_name' => 'map' 18 ); 10 19 // The API key provided by Google 11 20 protected $api_key; 12 // the name of the javascript Google Map object 13 protected $js_name = 'map'; 14 // Starting zoom and center parameters. 15 protected $zoom = 1; 16 protected $center_lat=26.43; 17 protected $center_lng=0; 21 18 22 // id of the Google Map div container 19 protected $container_id='map'; 23 protected $container_attributes = array( 24 'id' =>'map' 25 ); 20 26 // style of the container 21 27 protected $container_style=array('width'=>'512px','height'=>'512px'); … … 36 42 * Constructs a Google Map PHP object 37 43 * 38 * @param Integer $zoom39 * @param Decimal $lat40 * @param Decimal $lng41 44 * @param array $options 42 */ 43 public function __construct($zoom=null,$lat=null,$lng=null,$options=array()) 44 { 45 * @param array $attributes 46 */ 47 public function __construct($options=array(),$container_attributes=array()) 48 { 49 $this->options = array_merge($this->default_options,$options); 50 $this->container_attributes = array_merge($this->container_attributes,$container_attributes); 45 51 // sets the starting zoom and center parameters 46 if (!is_null($zoom)) 47 { 48 $this->zoom=$zoom; 49 } 50 if (!is_null($lat) && !is_null($lng)) 51 { 52 $this->setCenter($lat, $lng); 53 } 52 $this->zoom = $this->options['zoom']; 53 $this->setCenter($this->options['center_lat'], $this->options['center_lng']); 54 54 55 55 // delcare the Google Map Javascript object as global … … 57 57 58 58 // set the Google Map API key for the current domain 59 $this->guessAPIKey(); 60 61 $default_options = array( 62 'double_click_zoom'=>true, 63 'control'=>'new google.maps.LargeMapControl()' 64 ); 65 $this->options = array_merge($default_options,$options); 66 67 } 68 69 /** 70 * Guesses the GoogleMap key for the current domain 71 * 72 */ 73 protected function guessAPIKey() 74 { 75 if (isset($_SERVER['SERVER_NAME'])) 76 { 77 $this->setAPIKeyByDomain($_SERVER['SERVER_NAME']); 78 } 79 else if (isset($_SERVER['HTTP_HOST'])) 80 { 81 $this->setAPIKeyByDomain($_SERVER['HTTP_HOST']); 82 } 83 else 84 { 85 $this->setAPIKeyByDomain('default'); 86 } 87 } 88 59 $this->guessAndSetAPIKey(); 60 61 } 62 63 /** 64 * Guesses and sets the API Key 65 * @author Fabrice 66 * 67 */ 68 protected function guessAndSetAPIKey() 69 { 70 $this->setAPIKey(self::guessAPIKey()); 71 } 72 89 73 /** 90 74 * Sets the Google Map API Key using the array_google_keys defined in the app.yml of your application 91 75 * @param String $domain The domaine name 76 * @author Fabrice 77 * 92 78 */ 93 79 public function setAPIKeyByDomain($domain) 80 { 81 $this->setAPIKey(self::getAPIKeyByDomain($domain)); 82 } 83 84 /** 85 * Guesses the GoogleMap key for the current domain 86 * @return String $api_key 87 * @author Fabrice 88 * 89 */ 90 public static function guessAPIKey() 91 { 92 if (isset($_SERVER['SERVER_NAME'])) 93 { 94 return self::getAPIKeyByDomain($_SERVER['SERVER_NAME']); 95 } 96 else if (isset($_SERVER['HTTP_HOST'])) 97 { 98 return self::getAPIKeyByDomain($_SERVER['HTTP_HOST']); 99 } 100 101 return self::getAPIKeyByDomain('default'); 102 } 103 104 /** 105 * Static method to retrieve API key 106 * 107 * @param unknown_type $domain 108 * @return unknown 109 */ 110 public static function getAPIKeyByDomain($domain) 94 111 { 95 112 $api_keys = sfConfig::get('app_google_maps_api_keys'); 96 113 if (is_array($api_keys) && array_key_exists($domain,$api_keys)) 97 114 { 98 $ this->api_key=$api_keys[$domain];115 $api_key=$api_keys[$domain]; 99 116 } 100 117 else … … 102 119 if (array_key_exists('default',$api_keys)) 103 120 { 104 $ this->api_key=$api_keys['default'];121 $api_key=$api_keys['default']; 105 122 } 106 123 else … … 109 126 } 110 127 } 111 } 128 129 return $api_key; 130 } 131 112 132 113 133 /** … … 139 159 140 160 /** 141 * @return String $ js_nameJavascript name of the googlemap161 * @return String $this->options['js_name'] Javascript name of the googlemap 142 162 */ 143 163 public function getJsName() 144 164 { 145 165 146 return $this-> js_name;166 return $this->options['js_name']; 147 167 } 148 168 … … 199 219 200 220 return $this->container_style[$style_tag]; 221 } 222 223 public function getContainerId() 224 { 225 226 return $this->container_attributes['id']; 201 227 } 202 228 … … 207 233 * @author Fabrice Bernhard 208 234 */ 209 public function getContainer($options=array()) 210 { 211 if (count($options)>0) 212 { 213 $this->setContainerStyles($options); 214 } 235 public function getContainer($styles=array(),$attributes=array()) 236 { 237 $this->container_style = array_merge($this->container_style,$styles); 238 $this->container_attributes = array_merge($this->container_attributes,$attributes); 239 215 240 $style=""; 216 241 foreach ($this->container_style as $tag=>$val) … … 218 243 $style.=$tag.":".$val.";"; 219 244 } 220 return 221 ' 222 <div id="'.$this->container_id.'" style="'.$style.'"> 223 </div> 224 '; 225 } 245 246 $attributes = $this->container_attributes; 247 $attributes['style'] = $style; 248 249 return RenderTag::renderContent('div',null,$attributes); 250 } 251 226 252 227 253 /** … … 239 265 $return =''; 240 266 $init_events = array(); 241 $init_events[] = $this->getJsName().' = new google.maps.Map2(document.getElementById("'.$this-> container_id.'"));';267 $init_events[] = $this->getJsName().' = new google.maps.Map2(document.getElementById("'.$this->getContainerId().'"));'; 242 268 $init_events[] = $this->getJsName().'.setCenter(new google.maps.LatLng('.$this->getCenterLat().', '.$this->getCenterLng().'), '.$this->getZoom().');'; 243 269 if ($options['double_click_zoom']) … … 305 331 $this->icons[$icon->getName()]=$icon; 306 332 } 333 334 /** 335 * Retourne l'objet GMapIcon à partir du nom de l'icone 336 * 337 * @param String $name 338 * @return GMapIcon 339 * 340 * @author Vincent 341 * @since 2008-12-02 342 */ 343 public function getIconByName($name) 344 { 345 346 return $this->icons[$name]; 347 } 348 307 349 /** 308 350 * @param GMapMarker $marker a marker to be put on the map … … 400 442 } 401 443 402 public function getContainerId()403 {404 return $this->container_id;405 }406 444 public function addGlobalVariable($name, $value='null') 407 445 { plugins/sfEasyGMapPlugin/trunk/lib/GMapMarker.class.php
r16292 r16301 82 82 } 83 83 84 public function getIconName() 85 { 86 if ($this->getIcon() instanceof GMapIcon) 87 { 88 89 return $this->getIcon()->getName(); 90 } 91 92 return $this->getIcon(); 93 } 84 94 /** 85 95 * @return String Javascript code to create the marker … … 88 98 public function getMarkerJs() 89 99 { 90 if ($this->getIcon () instanceof GMapIcon)100 if ($this->getIconName() != '') 91 101 { 92 $markerOptionsJs = ', { icon:'.$this->getIcon ()->getName().' }';102 $markerOptionsJs = ', { icon:'.$this->getIconName().' }'; 93 103 } 94 104 else … … 124 134 * 125 135 * @param String $html_text 126 * @since Mar 13, 2009 fabriceb replaced the escape_javascript of the TagHelper by plain code to ensure 1.2 compatibility 136 * @author fabriceb 137 * @since Feb 20, 2009 fabriceb removed the escape_javascript function which made the plugin incompatible with symfony 1.2 127 138 */ 128 139 public function addHtmlInfoWindow($html_text) … … 130 141 $javascript = preg_replace('/\r\n|\n|\r/', "\\n", $html_text); 131 142 $javascript = preg_replace('/(["\'])/', '\\\\\1', $javascript); 132 143 133 144 $this->addEvent(new GMapEvent('click',"this.openInfoWindowHtml('".$javascript."')")); 134 145 } … … 137 148 * Returns the code for the static version of Google Maps 138 149 * @TODO Add support for color and alpha-char 150 * @author laurentb 139 151 */ 140 152 public function getMarkerStatic() plugins/sfEasyGMapPlugin/trunk/lib/helper/GMapHelper.php
r11741 r16301 6 6 * @param GMap $gMap 7 7 * @param array style options of the container 8 * @author fabriceb 8 9 */ 9 10 function include_map($gMap,$options=array()) … … 17 18 * @param GMap $gMap 18 19 * @param array style options of the container 20 * @author fabriceb 19 21 */ 20 22 function include_map_javascript($gMap) … … 25 27 function include_search_location_form() 26 28 { 27 sfContext::getInstance()->getResponse()->addJavascript('/sf GMaps2Plugin/js/sfGMaps2Plugin.js');29 sfContext::getInstance()->getResponse()->addJavascript('/sfEasyGMapPlugin/js/sfEasyGMapPlugin.js'); 28 30 ?> 29 31 <form onsubmit="geocode_and_show(document.getElementById('search_location_input').value);return false;"> plugins/sfEasyGMapPlugin/trunk/modules/sfEasyGMapPlugin/actions/actions.class.php
r11741 r16301 3 3 class sfEasyGMapPluginActions extends sfActions 4 4 { 5 6 public function executeIndex() 7 { 8 9 } 5 10 6 11 /** … … 69 74 public function executeSample3() 70 75 { 71 $this->gMap = new GMap(4,45,8,array('control'=>'new google.maps.SmallMapControl()')); 76 $this->gMap = new GMap( 77 array( 78 'zoom'=>4, 79 'center_lat'=>45, 80 'center_lng'=>8, 81 'control'=>'new google.maps.SmallMapControl()' 82 ) 83 ); 72 84 73 85 // some places in the world plugins/sfEasyGMapPlugin/trunk/package.xml
r11741 r16301 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <package packagerversion="1.4.6" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> 3 <name>sfEasyGMapPlugin</name> <channel>plugins.symfony-project.org</channel>4 3 <name>sfEasyGMapPlugin</name> 4 <channel>plugins.symfony-project.org</channel> 5 5 <summary>An easy, object-oriented, PHP abstraction of the Google Maps API</summary> 6 6 <description>The sfEasyGMap plugin provides helpers and an objet-oriented PHP abstraction to the Google Maps API to ease the process of adding a Google Map and customising it in your symfony projects.</description> … … 11 11 <active>yes</active> 12 12 </lead> 13 14 15 <date>2008-09-21</date> 16 <time>01:15:35</time> 13 <contributor> 14 <name>Laurent BACHELIER</name> 15 <user>laurentb</user> 16 <email>laurent@bachelier.name</email> 17 <active>yes</active> 18 </contributor> 19 <date>2009-03-13</date> 20 <time>10:34:00</time> 17 21 <version> 18 <release>0.9. 0</release>19 <api>0.9. 0</api>22 <release>0.9.4</release> 23 <api>0.9.4</api> 20 24 </version> 21 25 <stability> … … 75 79 <min>1.0.0</min> 76 80 <max>1.2.0</max> 77 <exclude>1.2.0</exclude>78 81 </package> 79 82 </required> 80 83 </dependencies> 81 84 <phprelease /> 82 <changelog /> 85 <changelog> 86 <release> 87 <version> 88 <release>0.9.4</release> 89 <api>0.9.4</api> 90 </version> 91 <stability> 92 <release>beta</release> 93 <api>beta</api> 94 </stability> 95 <license uri="http://www.symfony-project.org/license">MIT license</license> 96 <notes> 97 * removed the call to the Helper Tag to use the escape_javascript function to ensure symfony 1.2 compatibility 98 </notes> 99 </release> 100 </changelog> 83 101 </package>