issue #0001668 : Use the Google API for displaying streetview
This commit is contained in:
parent
1bde82bad3
commit
0bf27c4e86
@ -1146,8 +1146,12 @@ class IdentiteController extends Zend_Controller_Action
|
||||
|
||||
public function facadeAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
require_once 'Scores/Mappy.php';
|
||||
$infos = $this->getRequest()->getParam('infos');
|
||||
|
||||
$infos = $request->getParam('infos');
|
||||
$source = $request->getParam('source');
|
||||
$mappy = new Mappy();
|
||||
if ($mappy->villeCouverte($infos->Ville))
|
||||
{
|
||||
@ -1177,15 +1181,41 @@ class IdentiteController extends Zend_Controller_Action
|
||||
}
|
||||
else
|
||||
{
|
||||
require_once 'Scores/Google.php';
|
||||
$google = new Google();
|
||||
$googleKey = $google->getGoogleKey($_SERVER['SERVER_NAME']);
|
||||
$this->view->assign('googleKey', $googleKey);
|
||||
$this->view->assign('source', 'google');
|
||||
$this->view->assign('infos', $infos);
|
||||
}
|
||||
}
|
||||
|
||||
public function streetviewAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$lat = $request->getParam('lat', '');
|
||||
$lon = $request->getParam('lon', '');
|
||||
$heading = $request->getParam('heading', 0);
|
||||
|
||||
$streetview = new Scores_Streetview();
|
||||
if ( $lat != '' && $lon != '' ) {
|
||||
$streetview->setLocationGeo( $lat, $lon );
|
||||
$streetview->setHeading($heading);
|
||||
//$streetview->setLocationTxt($adresse);
|
||||
$this->view->assign('url', $streetview->urlImg());
|
||||
|
||||
$nbImg = $streetview->getNumDeg();
|
||||
$pagePrec = $heading-1;
|
||||
if ($pagePrec<reset($nbImg)) {
|
||||
$pagePrec = end($nbImg);
|
||||
}
|
||||
$pageSuiv = $heading+1;
|
||||
if($pageSuiv>end($nbImg)) {
|
||||
$pageSuiv = reset($nbImg);
|
||||
}
|
||||
$this->view->assign('pagePrec', $pagePrec);
|
||||
$this->view->assign('pageSuiv', $pageSuiv);
|
||||
}
|
||||
$this->view->assign('lat', $lat);
|
||||
$this->view->assign('lon', $lon);
|
||||
}
|
||||
|
||||
public function groupesarboAction()
|
||||
{
|
||||
$this->_helper->layout()->disableLayout();
|
||||
|
@ -1,70 +1,12 @@
|
||||
<?php if ($this->source == 'google'):?>
|
||||
|
||||
<div id="infogeo_photo">
|
||||
<div id="legende-photo" style="display: block;">
|
||||
Cliché à l'approche de l'adresse postale.
|
||||
</div>
|
||||
<div>
|
||||
<img id="pp-cb-thumb" src="http://cbk0.google.com/cbk?output=thumbnail&w=150&h=69&ll=<?=$this->infos->GeoLat.','.$this->infos->GeoLon?>" width="300px" height="128px" />
|
||||
</div>
|
||||
<?=$this->action('streetview', 'identite', null, array(
|
||||
'lat' => $this->infos->GeoLat,
|
||||
'lon' => $this->infos->GeoLon
|
||||
));?>
|
||||
</div>
|
||||
<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=<?=$this->googleKey?>"></script>
|
||||
<script type="text/javascript">
|
||||
function affichePhoto() {
|
||||
<?php if ($this->infos->GeoPrecis < 7) {?>
|
||||
var geoCoder = new GClientGeocoder;
|
||||
geoCoder.getLocations("<?=$this->infos->AdresseNum.' '.
|
||||
$this->infos->AdresseRue.' '.
|
||||
$this->infos->CP.' '.
|
||||
$this->infos->Ville?>", geoCodeCB);
|
||||
<?php } else { ?>
|
||||
var ll = new GLatLng(<?=$this->infos->GeoLat?>, <?=$this->infos->GeoLon?>);
|
||||
doShowPanoData(ll);
|
||||
<?php } ?>
|
||||
}
|
||||
|
||||
function geoCodeCB(reponse) {
|
||||
if (reponse &&
|
||||
reponse.Status.code == 200 &&
|
||||
reponse.Placemark.length == 1 &&
|
||||
reponse.Placemark[0].AddressDetails.Accuracy > 5) {
|
||||
var lat = reponse.Placemark[0].Point.coordinates[1];
|
||||
var lon = reponse.Placemark[0].Point.coordinates[0];
|
||||
var ll = new GLatLng(lat, lon);
|
||||
doShowPanoData(ll);
|
||||
}
|
||||
}
|
||||
|
||||
function showPanoData(panoData) {
|
||||
if (panoData.code != 200) {
|
||||
return;
|
||||
}
|
||||
$('#pp-cb-thumb').replaceWith(
|
||||
'<div id="pp-cb-thumb"><div class="left">' +
|
||||
'<img src="http://maps.google.fr/cbk?output=tile&panoid=' +
|
||||
panoData.location.panoId +
|
||||
'&zoom=1&x=0&y=0&cb_client=maps_sv" />' +
|
||||
'</div>' +
|
||||
'<div class="right">' +
|
||||
'<img src="http://maps.google.fr/cbk?output=tile&panoid=' +
|
||||
panoData.location.panoId +
|
||||
'&zoom=1&x=1&y=0&cb_client=maps_sv" />' +
|
||||
'</div></div>');
|
||||
|
||||
$('#legende-photo' ).css('display','block');
|
||||
$('#pp-cb-thumb' ).css('display','block');
|
||||
}
|
||||
|
||||
function doShowPanoData(ll) {
|
||||
var panoClient = new GStreetviewClient();
|
||||
panoClient.getNearestPanorama(ll, showPanoData);
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
if ($('#pp-cb-thumb').length) {
|
||||
affichePhoto();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<?php elseif ($this->source == 'mappy'):?>
|
||||
<div><img id="pp-cb-thumb" width="300px" /></div>
|
||||
<script src="<?=$this->lienJs?>"></script>
|
||||
|
@ -28,8 +28,8 @@
|
||||
<?php }?>
|
||||
</div>
|
||||
|
||||
<?php if($this->facade):?>
|
||||
<?=$this->action('facade', 'identite', null, array('infos' => $this->infos));?>
|
||||
<?php endif;?>
|
||||
<?php if($this->facade):?>
|
||||
<?=$this->action('facade', 'identite', null, array('infos' => $this->infos));?>
|
||||
<?php endif;?>
|
||||
</div>
|
||||
</div>
|
17
application/views/default/scripts/identite/streetview.phtml
Normal file
17
application/views/default/scripts/identite/streetview.phtml
Normal file
@ -0,0 +1,17 @@
|
||||
<?php if ($this->url) {?>
|
||||
<div id="legende-photo">Cliché à l'approche de l'adresse postale.</div>
|
||||
<img id="pp-cb-thumb" src="<?=$this->url?>" width="320" height="320" />
|
||||
<div>
|
||||
<a class="street-heading" href="<?=$this->url(array(
|
||||
'controller'=>'identite','action'=>'streetview', 'lat'=>$this->lat, 'lon'=>$this->lon, 'heading'=>$this->pagePrec))?>"><</a>
|
||||
-
|
||||
<a class="street-heading" href="<?=$this->url(array(
|
||||
'controller'=>'identite','action'=>'streetview', 'lat'=>$this->lat, 'lon'=>$this->lon, 'heading'=>$this->pageSuiv))?>">></a>
|
||||
</div>
|
||||
<script>
|
||||
$('a.street-heading').click(function(e){
|
||||
e.preventDefault();
|
||||
$('#infogeo_photo').load($(this).attr('href'));
|
||||
});
|
||||
</script>
|
||||
<?php }?>
|
@ -105,9 +105,6 @@ class Application_Controller_Plugin_Theme extends Zend_Controller_Plugin_Abstrac
|
||||
'identite-fichepc' => array(
|
||||
'identite-fiche.js' => 'inline',
|
||||
),
|
||||
'identite-geo' => array(
|
||||
'identite-geo.js' => 'file',
|
||||
),
|
||||
'identite-groupe' => array(
|
||||
'identite-groupe.js' => 'inline',
|
||||
),
|
||||
|
98
library/Scores/Streetview.php
Normal file
98
library/Scores/Streetview.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* Image de 640x640 max
|
||||
* Heading 0 à 360
|
||||
* 0, 45, 90, 135, 180, 225, 270, 315
|
||||
* Récup de chaque image enregistré SIRET-DEG
|
||||
*/
|
||||
class Scores_Streetview
|
||||
{
|
||||
|
||||
protected $url = 'http://maps.googleapis.com/maps/api/streetview?';
|
||||
|
||||
//Max size 640x640
|
||||
protected $size = '640x640';
|
||||
|
||||
//GPS ou Adresse
|
||||
protected $location = null;
|
||||
|
||||
//Defaut 90, Max 120, represents zoom, with smaller numbers indicating a higher level of zoom
|
||||
protected $fov = 90;
|
||||
|
||||
//(default is 0) Specifies the up or down angle of the camera relative to the Street View vehicle
|
||||
protected $pitch = 0;
|
||||
|
||||
//(optional) identifies your application for quota purposes
|
||||
protected $key = null;
|
||||
|
||||
protected $sensor = 'false';
|
||||
|
||||
// Indicates the compass heading of the camera (0 to 360)
|
||||
protected $heading = 0;
|
||||
|
||||
protected $nbImage = 8;
|
||||
|
||||
protected $extension = 'jpg';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->size = '320x320';
|
||||
}
|
||||
|
||||
public function setLocationGeo($lattitude, $longitude)
|
||||
{
|
||||
$this->location = $lattitude.','.$longitude;
|
||||
}
|
||||
|
||||
public function setLocationTxt($adresse){}
|
||||
|
||||
public function setHeading($num)
|
||||
{
|
||||
$this->heading = $num;
|
||||
}
|
||||
|
||||
public function getNumDeg()
|
||||
{
|
||||
$mark = array();
|
||||
$deg = 360/$this->nbImage;
|
||||
$i=$calc=0;
|
||||
while ($calc<360) {
|
||||
$mark[] = $i;
|
||||
$calc+=$deg;
|
||||
$i++;
|
||||
}
|
||||
return $mark;
|
||||
}
|
||||
|
||||
public function urlImg()
|
||||
{
|
||||
$url = '';
|
||||
|
||||
$params = array( 'size', 'location', 'fov', 'pitch', 'sensor', 'heading' );
|
||||
foreach ($params as $param) {
|
||||
if ( $this->{$param} !== null ) {
|
||||
$url.= '&'.$param.'='. $this->{$param};
|
||||
}
|
||||
}
|
||||
|
||||
return $this->url . substr($url,1);
|
||||
}
|
||||
|
||||
public function getImg()
|
||||
{
|
||||
require_once 'common/curl.php';
|
||||
$page = getUrl($this->url, '', '', '', false);
|
||||
|
||||
if ( !in_array($page['code'], array(400, 408, 403)) ) {
|
||||
$filename = $this->siret.'-'.$this->heading . '.' . $this->extension;
|
||||
$body = $page['body'];
|
||||
file_put_contents($this->path . DIRECTORY_SEPARATOR . $filename, $body);
|
||||
}
|
||||
}
|
||||
|
||||
public function pathImg()
|
||||
{
|
||||
$filename = $this->siret.'-'.$this->heading . '.' . $this->extension;
|
||||
return $this->path . DIRECTORY_SEPARATOR . $filename;
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
function showPanoData(panoData) {
|
||||
if (panoData.code != 200) {
|
||||
return;
|
||||
}
|
||||
$('#pp-cb-thumb').replaceWith(
|
||||
'<div id="pp-cb-thumb"><div class="left">' +
|
||||
'<img src="http://maps.google.fr/cbk?output=tile&panoid=' +
|
||||
panoData.location.panoId +
|
||||
'&zoom=1&x=0&y=0&cb_client=maps_sv" />' +
|
||||
'</div>' +
|
||||
'<div class="right">' +
|
||||
'<img src="http://maps.google.fr/cbk?output=tile&panoid=' +
|
||||
panoData.location.panoId +
|
||||
'&zoom=1&x=1&y=0&cb_client=maps_sv" />' +
|
||||
'</div></div>');
|
||||
|
||||
$('#legende-photo' ).css('display','block');
|
||||
$('#pp-cb-thumb' ).css('display','block');
|
||||
}
|
||||
|
||||
function doShowPanoData(ll) {
|
||||
var panoClient = new GStreetviewClient();
|
||||
panoClient.getNearestPanorama(ll, showPanoData);
|
||||
}
|
@ -518,10 +518,9 @@ ul.tabs li a.active {background-color:#ffffff;color:#282e32;border:1px solid #46
|
||||
|
||||
/* Géolocalisation
|
||||
----------------------------------*/
|
||||
#infogeo_txt {float:left;width:250px;padding:10px 0;}
|
||||
#infogeo_photo {float:left;margin:0;padding:0;width:340px;}
|
||||
#legende-photo {display:none;width:278px;margin:5px 0 10px 0;padding:10px;border:1px solid #0000ff;color:#0000ff;}
|
||||
#pp-cb-thumb {display:none;}
|
||||
#infogeo_txt {float:left;width:320px;padding:10px 0;}
|
||||
#infogeo_photo {float:left;margin:0;padding:0;width:320px;}
|
||||
#legende-photo {margin:5px 0; padding:10px;border:1px solid #0000ff;color:#0000ff;}
|
||||
#pp-cb-thumb div.left {float:left;position:relative;width:256px;height:128px;overflow:hidden;}
|
||||
#pp-cb-thumb div.right {float:left;position:relative;width:44px;height:128px;overflow:hidden;}
|
||||
#pp-cb-thumb div.left img{position:relative;left:-256px;top:-140px;}
|
||||
|
Loading…
Reference in New Issue
Block a user