Author: vincentg
Date: 2010-03-04 17:07:05 +0100 (Thu, 04 Mar 2010)
New Revision: 28377
Modified:
plugins/sfEasyGMapPlugin/branches/v3/lib/GMapClient.class.php
plugins/sfEasyGMapPlugin/branches/v3/lib/GMapDirection.class.php
plugins/sfEasyGMapPlugin/branches/v3/lib/GMapEvent.class.php
plugins/sfEasyGMapPlugin/branches/v3/lib/GMapGeocodedAddress.class.php
plugins/sfEasyGMapPlugin/branches/v3/lib/GMapInfoWindow.class.php
plugins/sfEasyGMapPlugin/branches/v3/lib/GMapMarker.class.php
plugins/sfEasyGMapPlugin/branches/v3/modules/sfEasyGMapPlugin/actions/actions.class.php
plugins/sfEasyGMapPlugin/branches/v3/modules/sfEasyGMapPlugin/templates/sample1Success.php
plugins/sfEasyGMapPlugin/branches/v3/web/css/sfEasyGMapPlugin.sample.css
plugins/sfEasyGMapPlugin/branches/v3/web/js/sfEasyGMapPlugin.sample.js
Log:
[sfEasyGMapPlugin] Add Reverse geocoding an fix some bugs
Modified: plugins/sfEasyGMapPlugin/branches/v3/lib/GMapClient.class.php
===================================================================
--- plugins/sfEasyGMapPlugin/branches/v3/lib/GMapClient.class.php
2010-03-04 12:45:08 UTC (rev 28376)
+++ plugins/sfEasyGMapPlugin/branches/v3/lib/GMapClient.class.php
2010-03-04 16:07:05 UTC (rev 28377)
@@ -255,5 +255,20 @@
$js_url = self::JS_URL;
return $js_url;
- }
+ }
+
+ /**
+ * Reverse geocoding info
+ *
+ * @return string
+ * @author Vincent Guillon <[email protected]>
+ * @since 2010-03-04
+ */
+ public function getReverseGeocodingInfo($lat, $lng)
+ {
+ $apiURL = 'http://maps.google.com/maps/geo?ll='.$lat.','.$lng;
+ $raw_data = file_get_contents($apiURL);
+
+ return $raw_data;
+ }
}
Modified: plugins/sfEasyGMapPlugin/branches/v3/lib/GMapDirection.class.php
===================================================================
--- plugins/sfEasyGMapPlugin/branches/v3/lib/GMapDirection.class.php
2010-03-04 12:45:08 UTC (rev 28376)
+++ plugins/sfEasyGMapPlugin/branches/v3/lib/GMapDirection.class.php
2010-03-04 16:07:05 UTC (rev 28377)
@@ -193,7 +193,7 @@
throw new sfException('$name can\'t be "null" !');
}
- $this->option[$name] = $value;
+ $this->options[$name] = $value;
}
/**
Modified: plugins/sfEasyGMapPlugin/branches/v3/lib/GMapEvent.class.php
===================================================================
--- plugins/sfEasyGMapPlugin/branches/v3/lib/GMapEvent.class.php
2010-03-04 12:45:08 UTC (rev 28376)
+++ plugins/sfEasyGMapPlugin/branches/v3/lib/GMapEvent.class.php
2010-03-04 16:07:05 UTC (rev 28377)
@@ -46,7 +46,7 @@
else
{
- return 'function() {
+ return 'function(event) {
'.$this->function.'
}';
}
Modified: plugins/sfEasyGMapPlugin/branches/v3/lib/GMapGeocodedAddress.class.php
===================================================================
--- plugins/sfEasyGMapPlugin/branches/v3/lib/GMapGeocodedAddress.class.php
2010-03-04 12:45:08 UTC (rev 28376)
+++ plugins/sfEasyGMapPlugin/branches/v3/lib/GMapGeocodedAddress.class.php
2010-03-04 16:07:05 UTC (rev 28377)
@@ -68,6 +68,36 @@
}
/**
+ * Reverse geocoding
+ *
+ * @return integer
+ * @author Vincent Guillon <[email protected]>
+ * @since 2010-03-04
+ */
+ public function reverseGeocode($gmap_client)
+ {
+ $raw_data = $gmap_client->getReverseGeocodingInfo($this->getLat(),
$this->getLng());
+ $geocoded_array = json_decode($raw_data, true);
+
+ if ($geocoded_array['Status']['code'] != 200)
+ {
+
+ return false;
+ }
+
+ $this->raw_address = $geocoded_array['Placemark'][0]['address'];
+ $this->accuracy =
$geocoded_array['Placemark'][0]['AddressDetails']['Accuracy'];
+ $this->geocoded_city =
$geocoded_array['Placemark'][0]['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['LocalityName'];
+ $this->geocoded_country_code =
$geocoded_array['Placemark'][0]['AddressDetails']['Country']['CountryNameCode'];
+ $this->geocoded_country =
$geocoded_array['Placemark'][0]['AddressDetails']['Country']['CountryName'];
+ $this->geocoded_address = $geocoded_array['Placemark'][0]['address'];
+ $this->geocoded_street =
$geocoded_array['Placemark'][0]['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['Thoroughfare']['ThoroughfareName'];
+ $this->geocoded_postal_code =
$geocoded_array['Placemark'][0]['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['PostalCode']['PostalCodeNumber'];
+
+ return $this->accuracy;
+ }
+
+ /**
* Geocodes the address using the Google Maps XML webservice, which has more
information.
* Unknown values will be set to NULL.
* @param GMapClient $gmap_client
Modified: plugins/sfEasyGMapPlugin/branches/v3/lib/GMapInfoWindow.class.php
===================================================================
--- plugins/sfEasyGMapPlugin/branches/v3/lib/GMapInfoWindow.class.php
2010-03-04 12:45:08 UTC (rev 28376)
+++ plugins/sfEasyGMapPlugin/branches/v3/lib/GMapInfoWindow.class.php
2010-03-04 16:07:05 UTC (rev 28377)
@@ -179,9 +179,9 @@
}
}
$tab = ' ';
- $separator = "\n".$tab.$tab;
+ $separator = "\n ".$tab.$tab;
- return '{'.$separator.$tab.implode(','.$separator.$tab,
$options_array).$separator.'}';
+ return "\n {".$separator.$tab.implode(','.$separator.$tab,
$options_array).$separator.'}';
}
/**
@@ -197,12 +197,15 @@
{
$this->setOption('content', $content);
}
+
$return = '';
$return .= $this->getName().' = new
google.maps.InfoWindow('.$this->optionsToJs().");\n";
+
foreach ($this->custom_properties as $attribute=>$value)
{
$return .= $this->getName().".".$attribute." = '".$value."';";
}
+
foreach ($this->events as $event)
{
$return .= ' '.$event->getEventJs($this->getName());
Modified: plugins/sfEasyGMapPlugin/branches/v3/lib/GMapMarker.class.php
===================================================================
--- plugins/sfEasyGMapPlugin/branches/v3/lib/GMapMarker.class.php
2010-03-04 12:45:08 UTC (rev 28376)
+++ plugins/sfEasyGMapPlugin/branches/v3/lib/GMapMarker.class.php
2010-03-04 16:07:05 UTC (rev 28377)
@@ -53,8 +53,10 @@
* @param GmapEvent[] array of GoogleMap Events linked to the marker
* @author Fabrice Bernhard
*/
- public function __construct($lat,$lng,$options =
array(),$js_name='marker',$events=array())
+ public function __construct($lat,$lng,$options = array(), $js_name =
null,$events=array())
{
+ $js_name = $js_name ? $js_name : 'marker_'.uniqid();
+
$this->js_name = $js_name;
$this->setOptions($options);
$this->setGMapCoord(new GMapCoord($lat,$lng));
@@ -238,11 +240,15 @@
}
$return = '';
+
if($this->info_window instanceof GMapInfoWindow)
{
- $this->addEvent(new
GMapEvent('click',$this->info_window->getName().".open(".$map_js_name.",".$this->getName().");"));
- $return .= $this->info_window->toJs();
+ $this->addEvent(new GMapEvent(
+ 'click',
+ $this->info_window->toJs()."\n
".$this->info_window->getName().".open(".$map_js_name.", ".$this->getName().");"
+ ));
}
+
$return .= $this->getName().' = new
google.maps.Marker('.$this->optionsToJs().");\n";
foreach ($this->custom_properties as $attribute=>$value)
{
@@ -252,7 +258,7 @@
{
$return .= ' '.$event->getEventJs($this->getName())."\n";
}
-
+
return $return;
}
Modified:
plugins/sfEasyGMapPlugin/branches/v3/modules/sfEasyGMapPlugin/actions/actions.class.php
===================================================================
---
plugins/sfEasyGMapPlugin/branches/v3/modules/sfEasyGMapPlugin/actions/actions.class.php
2010-03-04 12:45:08 UTC (rev 28376)
+++
plugins/sfEasyGMapPlugin/branches/v3/modules/sfEasyGMapPlugin/actions/actions.class.php
2010-03-04 16:07:05 UTC (rev 28377)
@@ -6,14 +6,16 @@
public function executeIndex()
{
$this->available_samples = array(
- '1' => array('url' => 'sfEasyGMapPlugin/sample1', 'name' => 'Sample 1',
'message' => 'Simple map with some markers, using longitudes and latitudes.'),
- '2' => array('url' => 'sfEasyGMapPlugin/sample2', 'name' => 'Sample 2',
'message' => 'Basic events on marker and map.'),
- '3' => array('url' => 'sfEasyGMapPlugin/sample3', 'name' => 'Sample 3',
'message' => 'Basic GMapInfoWindow sample.'),
- '4' => array('url' => 'sfEasyGMapPlugin/sample4', 'name' => 'Sample 4',
'message' => 'How to center the map on a tag cloud.'),
- '5' => array('url' => 'sfEasyGMapPlugin/sample5', 'name' => 'Sample 5',
'message' => 'Center the map on a given map and display inside markers.'),
- '6' => array('url' => 'sfEasyGMapPlugin/sample6', 'name' => 'Sample 6',
'message' => 'How to set a custom marker.'),
- '7' => array('url' => 'sfEasyGMapPlugin/sample7', 'name' => 'Sample 7',
'message' => 'GMapGeocodedAddress sample.'),
- '8' => array('url' => 'sfEasyGMapPlugin/sample8', 'name' => 'Sample 8',
'message' => 'GMapDirection sample.'),
+ '1' => array('url' => 'sfEasyGMapPlugin/sample1', 'name' => 'Sample 1',
'message' => 'Simple map with some markers, using longitudes and latitudes.'),
+ '2' => array('url' => 'sfEasyGMapPlugin/sample2', 'name' => 'Sample 2',
'message' => 'Basic events on marker and map.'),
+ '3' => array('url' => 'sfEasyGMapPlugin/sample3', 'name' => 'Sample 3',
'message' => 'Basic GMapInfoWindow sample.'),
+ '4' => array('url' => 'sfEasyGMapPlugin/sample4', 'name' => 'Sample 4',
'message' => 'How to center the map on a marker cloud.'),
+ '5' => array('url' => 'sfEasyGMapPlugin/sample5', 'name' => 'Sample 5',
'message' => 'Center the map on a given map and display inside markers.'),
+ '6' => array('url' => 'sfEasyGMapPlugin/sample6', 'name' => 'Sample 6',
'message' => 'How to set a custom marker.'),
+ '7' => array('url' => 'sfEasyGMapPlugin/sample7', 'name' => 'Sample 7',
'message' => 'GMapGeocodedAddress sample.'),
+ '8' => array('url' => 'sfEasyGMapPlugin/sample8', 'name' => 'Sample 8',
'message' => 'GMapDirection sample.'),
+ '9' => array('url' => 'sfEasyGMapPlugin/sample9', 'name' => 'Sample 9',
'message' => 'Reverse geocoding sample.'),
+ '10' => array('url' => 'sfEasyGMapPlugin/sample10', 'name' => 'Sample
10', 'message' => 'Multiple info windows'),
);
}
@@ -50,7 +52,6 @@
// END OF ACTION
$this->message = 'Simple google map with markers';
$this->action_source = $this->functionToString('executeSample1');
- $this->generated_js = str_replace(' ', ' ', preg_replace('/^\n(.*)/',
'$1', $this->gMap->getJavascript()));
}
@@ -86,7 +87,6 @@
// END OF ACTION
$this->message = 'Simple events : <br /> - click marker to focus on<br />
- click on the map for test map event';
$this->action_source = $this->functionToString('executeSample2');
- $this->generated_js = str_replace(' ', ' ', preg_replace('/^\n(.*)/',
'$1', $this->gMap->getJavascript()));
}
@@ -118,7 +118,6 @@
// END OF ACTION
$this->message = 'Simple GMapInfoWindow : click marker to open info
window';
$this->action_source = $this->functionToString('executeSample3');
- $this->generated_js = str_replace(' ', ' ', preg_replace('/^\n(.*)/',
'$1', $this->gMap->getJavascript()));
}
/**
@@ -155,7 +154,6 @@
// END OF ACTION
$this->message = 'Center the map on the markers.';
$this->action_source = $this->functionToString('executeSample4');
- $this->generated_js = str_replace(' ', ' ', preg_replace('/^\n(.*)/',
'$1', $this->gMap->getJavascript()));
}
/**
@@ -195,7 +193,6 @@
// END OF ACTION
$this->message = 'Center the map on a given place and display only inside
markers.';
$this->action_source = $this->functionToString('executeSample5');
- $this->generated_js = str_replace(' ', ' ', preg_replace('/^\n(.*)/',
'$1', $this->gMap->getJavascript()));
}
/**
@@ -231,7 +228,6 @@
// END OF ACTION
$this->message = 'Custom marker.';
$this->action_source = $this->functionToString('executeSample6');
- $this->generated_js = str_replace(' ', ' ', preg_replace('/^\n(.*)/',
'$1', $this->gMap->getJavascript()));
}
/**
@@ -267,7 +263,6 @@
// END OF ACTION
$this->message = 'Display a marker on geocoded address
"'.$sample_address.'" and center the map.';
$this->action_source = $this->functionToString('executeSample7');
- $this->generated_js = str_replace(' ', ' ', preg_replace('/^\n(.*)/',
'$1', $this->gMap->getJavascript()));
}
/**
@@ -311,8 +306,102 @@
$this->view_panel = true;
$this->message = 'GMapDirection sample from Paris to Bordeaux';
$this->action_source = $this->functionToString('executeSample8');
- $this->generated_js = str_replace(' ', ' ', preg_replace('/^\n(.*)/',
'$1', $this->gMap->getJavascript()));
}
+
+ /**
+ * Reverse geocoding sample
+ *
+ * @param sfWebRequest $request
+ * @author Vincent Guillon <[email protected]>
+ * @since 2009-10-30 17:30:11
+ */
+ public function executeSample9()
+ {
+ // Initialize the google map
+ $this->gMap = new GMap();
+ $this->gMap->setWidth(512);
+ $this->gMap->setHeight(400);
+ $this->gMap->setZoom(16);
+ $this->gMap->setCenter(48.857939, 2.346611);
+
+ // Marker
+ $marker = new GMapMarker($this->gMap->getCenterLat(),
$this->gMap->getCenterLng());
+ $this->gMap->addMarker($marker);
+
+ // Reverse geocoding of the center of the map
+ $geocoded_addr = new GMapGeocodedAddress(null);
+ $geocoded_addr->setLat($this->gMap->getCenterLat());
+ $geocoded_addr->setLng($this->gMap->getCenterLng());
+ $geocoded_addr->reverseGeocode($this->gMap->getGMapClient());
+
+ $this->setTemplate('sample1');
+
+ // END OF ACTION
+ $this->message = 'Reverse geocoding sample';
+ $this->action_source = $this->functionToString('executeSample9');
+
+ // Construct console message
+ $values = array(
+ 'Reverse geocoding of coordinates \"'.$this->gMap->getCenterLat().',
'.$this->gMap->getCenterLng().'\" : ',
+ '<i>raw_address : </i>'.$geocoded_addr->getRawAddress(),
+ '<i>accuracy : </i>'.$geocoded_addr->getAccuracy(),
+ '<i>geocoded_city : </i>'.$geocoded_addr->getGeocodedCity(),
+ '<i>geocoded_country_code :
</i>'.$geocoded_addr->getGeocodedCountryCode(),
+ '<i>geocoded_country : </i>'.$geocoded_addr->getGeocodedCountry(),
+ '<i>geocoded_address : </i>'.$geocoded_addr->getGeocodedAddress(),
+ '<i>geocoded_street : </i>'.$geocoded_addr->getGeocodedStreet(),
+ '<i>geocoded_postal_code : </i>'.$geocoded_addr->getGeocodedPostalCode(),
+ );
+
+ foreach ($values as $value)
+ {
+ $this->gMap->addAfterInitJs('gmapSample_AddConsoleLine("'.$value.'");');
+ }
+ }
+
+ /**
+ * Multiple GMapInfoWindow sample
+ *
+ * @author Vincent Guillon <[email protected]>
+ * @since 2010-03-04
+ */
+ public function executeSample10()
+ {
+ // Initialize the google map
+ $gMap = new GMap();
+
+ $markers = array(
+ new GMapMarker(51.245475, 6.821373),
+ new GMapMarker(46.262248, 6.115969),
+ new GMapMarker(48.848959, 2.341577),
+ new GMapMarker(48.718952, 2.219180),
+ new GMapMarker(47.376420, 8.547995),
+ );
+
+ foreach($markers as $marker)
+ {
+ // Reverse geocoding of the center of the map
+ $geocoded_addr = new GMapGeocodedAddress(null);
+ $geocoded_addr->setLat($marker->getLat());
+ $geocoded_addr->setLng($marker->getLng());
+ $geocoded_addr->reverseGeocode($gMap->getGMapClient());
+
+ $info_window = new
GMapInfoWindow('<div>'.$geocoded_addr->getRawAddress().'</div>');
+ $marker->addHtmlInfoWindow($info_window);
+ $gMap->addMarker($marker);
+ }
+
+ // Center the map on marker width 0.3 margin
+ $gMap->centerAndZoomOnMarkers(0.3);
+
+ $this->gMap = $gMap;
+
+ $this->setTemplate('sample1');
+
+ // END OF ACTION
+ $this->message = 'Multiple info window : click marker to open info window';
+ $this->action_source = $this->functionToString('executeSample10');
+ }
function functionToString($function_name)
{
Modified:
plugins/sfEasyGMapPlugin/branches/v3/modules/sfEasyGMapPlugin/templates/sample1Success.php
===================================================================
---
plugins/sfEasyGMapPlugin/branches/v3/modules/sfEasyGMapPlugin/templates/sample1Success.php
2010-03-04 12:45:08 UTC (rev 28376)
+++
plugins/sfEasyGMapPlugin/branches/v3/modules/sfEasyGMapPlugin/templates/sample1Success.php
2010-03-04 16:07:05 UTC (rev 28377)
@@ -1,5 +1,3 @@
-<?php use_helper('Javascript','GMap') ?>
-
<div class="sample-message">
<a href="/sfEasyGMapPlugin/index">Samples list</a> > <?php echo $message ?>
</div>
@@ -31,18 +29,10 @@
<a href="#" onclick="gmapSample_Toggle('action_source'); return
false;">• <?php echo "Display/Hide action source" ?></a>
<div id="action_source">
- <?php echo preg_replace('/.*(\/\/.*)<br \/>.*/', '<span
class="sample-comment">$0</span>', nl2br($action_source)) ?>
+ <?php echo preg_replace('/.*(\/\/.*)<br \/>.*/', '<span
class="sample-comment">$0</span>',
htmlspecialchars_decode(nl2br($action_source))) ?>
</div>
</div>
- <div id="sample-source-js">
- <a href="#" onclick="gmapSample_Toggle('generated-js'); return
false;">• <?php echo "Display/Hide generated javascript" ?></a>
-
- <div id="generated-js">
- <?php echo preg_replace('/.*(\/\/.*)<br \/>.*/', '<span
class="sample-comment">$0</span>', nl2br($generated_js)) ?>
- </div>
- </div>
-
<?php if (isset($view_panel)): ?>
<div id="sample-direction-pane">
<div id="direction_pane">
Modified:
plugins/sfEasyGMapPlugin/branches/v3/web/css/sfEasyGMapPlugin.sample.css
===================================================================
--- plugins/sfEasyGMapPlugin/branches/v3/web/css/sfEasyGMapPlugin.sample.css
2010-03-04 12:45:08 UTC (rev 28376)
+++ plugins/sfEasyGMapPlugin/branches/v3/web/css/sfEasyGMapPlugin.sample.css
2010-03-04 16:07:05 UTC (rev 28377)
@@ -84,7 +84,7 @@
margin-top: 5px;
border: #000000 solid 1px;
padding: 2px;
- height: 100px;
+ height: 150px;
overflow: auto;
width: 505px;
}
Modified: plugins/sfEasyGMapPlugin/branches/v3/web/js/sfEasyGMapPlugin.sample.js
===================================================================
--- plugins/sfEasyGMapPlugin/branches/v3/web/js/sfEasyGMapPlugin.sample.js
2010-03-04 12:45:08 UTC (rev 28376)
+++ plugins/sfEasyGMapPlugin/branches/v3/web/js/sfEasyGMapPlugin.sample.js
2010-03-04 16:07:05 UTC (rev 28377)
@@ -33,7 +33,7 @@
var inner_console = document.getElementById('console_div').innerHTML;
var line = '<div class="line">' + time + ' <span
class="begin-line">></span>' + content + '</div>';
- console.innerHTML = line + inner_console;
+ console.innerHTML = inner_console + line;
return false;
}
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.