issue #0001801 : New Streetview

This commit is contained in:
Michael RICOIS 2013-12-03 15:04:38 +00:00
parent ce0ca8bb68
commit f662f25a5e
5 changed files with 164 additions and 76 deletions

View File

@ -1091,13 +1091,14 @@ class IdentiteController extends Zend_Controller_Action
}
}
/**
*
*/
public function geoAction()
{
$infos = $this->getRequest()->getParam('infos');
$user = new Scores_Utilisateur();
$this->view->assign('facade', $user->checkPref('mappy'));
// Text
$google = new Scores_Google_Maps();
$decLat = $google->dec2dms($infos->GeoLat);
$decLon = $google->dec2dms($infos->GeoLon);
@ -1110,27 +1111,25 @@ class IdentiteController extends Zend_Controller_Action
$this->view->assign('decLat', $decLat);
$this->view->assign('decLon', $decLon);
$this->view->assign('infos', $infos);
}
public function facadeAction()
{
$request = $this->getRequest();
// Img
$user = new Scores_Utilisateur();
$this->view->assign('facade', $user->checkPref('mappy'));
require_once 'Scores/Mappy.php';
$infos = $request->getParam('infos');
$source = $request->getParam('source');
$mappy = new Mappy();
if ($mappy->villeCouverte($infos->Ville))
{
$this->view->assign('source', 'mappy');
$adresse = '';
$adresse.= $infos->AdresseNum;
//Corriger la voie pour Mappy
$adresse.= ' '.strtr($infos->AdresseVoie, array(
'R' => 'RUE',
'AV' => 'AVENUE',
'RLE' => 'RUELLE',
'R' => 'RUE',
'AV' => 'AVENUE',
'RLE' => 'RUELLE',
));
$adresse.= ' '.$infos->AdresseRue;
@ -1144,7 +1143,6 @@ class IdentiteController extends Zend_Controller_Action
}
$this->view->assign('adresse', $adresse);
$this->view->assign('source', 'mappy');
$this->view->assign('lienJs', $mappy->getJs());
}
else
@ -1153,26 +1151,65 @@ class IdentiteController extends Zend_Controller_Action
}
}
/**
* Display streetview image
*/
public function streetviewAction()
{
$request = $this->getRequest();
$siret = $request->getParam('siret');
$this->view->assign('siret', $siret);
if ( $request->isXmlHttpRequest() ) {
$this->_helper->layout()->disableLayout();
$this->_helper->layout()->disableLayout();
$siret = $request->getParam('siret');
$lat = $request->getParam('lat', '');
$lon = $request->getParam('lon', '');
$address = $request->getParam('address');
} else {
$infos = $request->getParam('infos');
$siret = $infos->Siret;
$lat = $infos->GeoLat;
$lon = $infos->GeoLon;
$adresse = '';
if (intval($infos->AdresseNum)>0) {
$adresse.= intval($infos->AdresseNum).' ';
}
//Corriger la voie
$adresse.= strtr($infos->AdresseVoie, array(
'R' => 'RUE',
'AV' => 'AVENUE',
'RLE' => 'RUELLE',
));
$adresse.= ' '.$infos->AdresseRue;
$adresse.= ', '.$infos->Ville;
//Définir le pays
if ($infos->Pays == '') {
$adresse.= ', FRANCE';
} else {
$adresse.= ', '.$infos->Pays;
}
}
$adresse = $request->getParam('adresse');
$lat = $request->getParam('lat', '');
$this->view->assign('lat', $lat);
$lon = $request->getParam('lon', '');
$this->view->assign('lon', $lon);
$num = $request->getParam('heading', 0);
if ( intval($siret)>100 && $lat != '' && $lon != '' ) {
$this->view->assign('siret', $siret);
$this->view->assign('lat', $lat);
$this->view->assign('lon', $lon);
$mode = 'address';
$this->view->assign('streetviewMode', $mode);
if ( $mode == 'address' && $adresse !== null ) {
$streetview = new Scores_Google_Streetview($siret);
$streetview->setLocationTxt($adresse);
$url = $streetview->serveUrl();
$this->view->assign('url', $url);
}
if ( $mode == 'GPS' && intval($siret)>100 && $lat != '' && $lon != '' ) {
$streetview = new Scores_Google_Streetview($siret);
$deg = $streetview->getNumDeg();
$nbImg = count($deg);
@ -1186,13 +1223,14 @@ class IdentiteController extends Zend_Controller_Action
}
$this->view->assign('pagePrec', $pagePrec);
$this->view->assign('pageSuiv', $pageSuiv);
$streetview->setLocationGeo( $lat, $lon );
$heading = $deg[$num];
$streetview->setHeading($heading);
//$streetview->setLocationTxt($adresse);
$img = $streetview->display();
$img = $streetview->serveImg();
if ( $img!==false ) {
$url = '/fichier/streetview/'.$streetview->display();
$url = '/fichier/streetview/'.$img;
$this->view->assign('url', $url);
}
}

View File

@ -1,34 +0,0 @@
<?php if ($this->source == 'google') {?>
<div id="infogeo_photo">
<?=$this->action('streetview', 'identite', null, array(
'lat' => $this->infos->GeoLat,
'lon' => $this->infos->GeoLon,
'siret' => $this->infos->Siret,
));?>
</div>
<?php } elseif ($this->source == 'mappy') {?>
<div><img id="pp-cb-thumb" width="300px" /></div>
<script src="<?=$this->lienJs?>"></script>
<script type="text/javascript">
$(document).ready(function() {
var serviceHandler = function(result) {
if (result instanceof Mappy.api.visiocity.Frontage) {
var current = result.getCurrent();
var img = $('<img src="' + current.getURL(320, null) +
'" alt="' + current.getDescription() +
'" width="300px" />');
$('#pp-cb-thumb').replaceWith(img);
}
};
var address = "<?=$this->adresse?>";
var geo = new Mappy.api.geolocation.Geocoder();
var photoService = new Mappy.api.visiocity.PhotoService();
geo.geocode(address, function(result) {
photoService.search(result[0], 'f', serviceHandler);
}, function(error) {});
});
</script>
<?php }?>

View File

@ -17,7 +17,7 @@
<?php
if (count($this->infos->InfosIris)>0){
$InfosIris = $this->infos->InfosIris;
$codComIris = str_replace($InfosIris->codIris, '', $InfosIris->codComIris);
$codComIris = str_replace($InfosIris->codIris, '', $InfosIris->codComIris);
?>
<br/><br/><b>Iris :</b>
<?php if (intval($InfosIris->codIris) == 0){ ?>
@ -27,11 +27,42 @@
<br/>Libellé : <a title="Consulter le plan d'assemblage de la commune" href="<?=$this->url(array('controller'=>'identite', 'action'=>'iris', 'code'=>$codComIris), null, true)?>" target="_blank"><?=$InfosIris->libIris?></a>
<img title="<?=$InfosIris->typIris?>" style="vertical-align:middle;" src="/themes/default/images/info.gif">
<?php }?>
<?php }?>
<?php }?>
</div>
<?php if($this->facade):?>
<?=$this->action('facade', 'identite', null, array('infos' => $this->infos));?>
<?php endif;?>
<?php if ($this->source == 'google') {?>
<div id="infogeo_photo">
<?=$this->action('streetview', 'identite', null, array(
'infos' => $this->infos,
));?>
</div>
<?php } elseif ($this->source == 'mappy') {?>
<div><img id="pp-cb-thumb" width="300px" /></div>
<script src="<?=$this->lienJs?>"></script>
<script type="text/javascript">
$(document).ready(function() {
var serviceHandler = function(result) {
if (result instanceof Mappy.api.visiocity.Frontage) {
var current = result.getCurrent();
var img = $('<img src="' + current.getURL(320, null) +
'" alt="' + current.getDescription() +
'" width="300px" />');
$('#pp-cb-thumb').replaceWith(img);
}
};
var address = "<?=$this->adresse?>";
var geo = new Mappy.api.geolocation.Geocoder();
var photoService = new Mappy.api.visiocity.PhotoService();
geo.geocode(address, function(result) {
photoService.search(result[0], 'f', serviceHandler);
}, function(error) {});
});
</script>
<?php }?>
</div>
</div>

View File

@ -1,6 +1,9 @@
<?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" />
<?php if ($this->streetviewMode == 'gps') {?>
<div>
<a class="street-heading" href="<?=$this->url(array(
'controller'=>'identite','action'=>'streetview', 'siret'=> $this->siret,
@ -17,3 +20,5 @@ $('a.street-heading').click(function(e){
});
</script>
<?php }?>
<?php }?>

View File

@ -22,7 +22,7 @@ class Scores_Google_Streetview
/**
* GPS ou Adresse
* @var strign
* @var string
*/
protected $location = null;
@ -53,7 +53,7 @@ class Scores_Google_Streetview
/**
* Indicates the compass heading of the camera (0 to 360)
*/
protected $heading = 0;
protected $heading = null;
/**
* Number of image by the circle (360°)
@ -78,8 +78,38 @@ class Scores_Google_Streetview
*/
protected $siret;
/**
* Maximum request per day
* @var int
*/
protected $maxRequestPerDay = 25000;
/**
*
* @var unknown
*/
protected $mode;
/**
* Mode GPS
* @var unknown
*/
const MODE_GPS = 1;
/**
* Mode Adresse
* @var unknown
*/
const MODE_ADDRESS = 2;
/**
* Google Streetview
* Get image by GPS coord or by adresse
* Save image reference in a database
* GpsLat, GpsLong, Adresse, Image, Date
* Save request that give no imagery
* Siren, Nic, Date
* Save in database, with a counter the number of request by day
*/
public function __construct($siret)
{
@ -98,18 +128,23 @@ class Scores_Google_Streetview
*/
public function setLocationGeo($lattitude, $longitude)
{
$this->mode = self::MODE_GPS;
$this->location = $lattitude.','.$longitude;
}
/**
*
* @param unknown $adresse
* @param string $adresse
*/
public function setLocationTxt($adresse){}
public function setLocationTxt($adresse)
{
$this->mode = self::MODE_ADDRESS;
$this->location = $adresse;
}
/**
*
* @param unknown $num
* @param int $num
*/
public function setHeading($num)
{
@ -134,7 +169,7 @@ class Scores_Google_Streetview
}
/**
*
* Construct the image URL
* @return string
*/
public function urlImg()
@ -144,7 +179,7 @@ class Scores_Google_Streetview
$params = array( 'size', 'location', 'fov', 'pitch', 'sensor', 'heading' );
foreach ($params as $param) {
if ( $this->{$param} !== null ) {
$url.= '&'.$param.'='. $this->{$param};
$url.= '&'.$param.'='. urlencode($this->{$param});
}
}
@ -178,7 +213,11 @@ class Scores_Google_Streetview
*/
public function pathImg()
{
$filename = $this->siret.'-'.$this->heading . '.' . $this->extension;
if ($this->mode == self::MODE_GPS) {
$filename = $this->siret.'-'.$this->heading . '.' . $this->extension;
} else if ($this->mode == self::MODE_ADDRESS) {
$filename = $this->siret.'-ADDRESS' . $this->extension;
}
return $this->path . DIRECTORY_SEPARATOR . $filename;
}
@ -186,7 +225,16 @@ class Scores_Google_Streetview
*
* @return string
*/
public function display()
public function serveUrl()
{
return $this->urlImg();
}
/**
*
* @return string
*/
public function serveImg()
{
$this->url = $this->urlImg();
Zend_Registry::get('firebug')->info('URL = '.$file);