disableLog();
// =====================================================
// construction du tableau tab sur la base des
// enregistrements de la requete
// le tableau comprend :
// une zone titre
// une zone description dans lequel il y a le lien
// une zone idx
// ======================================================
$temp="select om_sql from ".DB_PREFIXE."om_sig_point where id ='".$obj."'";
$sql= $f -> db -> getOne($temp);
$sql=str_replace("&DB_PREFIXE",DB_PREFIXE,$sql);
$sql=str_replace("&idx",$idx,$sql); // restriction en sql
$temp="select url from ".DB_PREFIXE."om_sig_point where id ='".$obj."'";
$url= $f -> db -> getOne($temp);
$res = $f -> db -> query($sql);
if (database :: isError($res)){
die($res->getMessage()."erreur ".$sql);
}else{
while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
if($row["geom"]!='' or $row["geom"]!=null){
array_push($tab,
array('geom' => $row['geom'],
'titre' => $row['titre'],
'description' =>
"".
"".
$row['description']."",
'idx' => $row['idx'],
'delete' => 0
)
);
}
}
}
// ================================================================================
// traitement des doublons sur un meme point
// ce traitement permet de mettre l'ensemble des enregistrements sur un meme point
// la variable delete permet d eliminer les doublons
// ================================================================================
$archive=0;
$archive_i=0;
for($i=0;$i < sizeof($tab);$i++){
// echo $i." ".$tab[$i]['titre']." ".$tab[$i]['delete']."
";
if($i<>sizeof($tab)-1){ // ne pas traiter le dernier point (pb i+2)
if($tab[$i]['geom']==$tab[$i+1]['geom']){
if($archive==0){
$archive_i=$i;
$archive=1;
}
$tab[$archive_i]['description'].= '
'.$tab[$i+1]['description'];
$tab[$i+1]['delete']=1;
}else
$archive=0;
}
}
// ===========================================
// construction du tableau json en format json
// ===========================================
// entete
$json = '{ "type": "FeatureCollection",'."\n";
$json.= ' "features": ['."\n";
// corps
for($i=0;$i < sizeof($tab);$i++){
if($tab[$i]['delete']==0){ // elimine les doublons dans le tableau
$xy=$row['geom'];
$xy=substr($tab[$i]['geom'],6,strlen($tab[$i]['geom'])-7);
$xy=explode(' ',$xy);
$x=$xy[0];
$y=$xy[1];
$json.= '{ "type": "Feature",'."\n";
$json.= '"geometry":';
$json.= "{\"type\": \"Point\",";
$json.= "\"coordinates\": [".$x.", ".$y."]},";
$json.="\n";
$json.= '"properties": {'."\n";
$json.= '"titre": "'.$tab[$i]['titre'].'"'.",\n";
$json.= '"description": "'.$tab[$i]['description'].'"'."\n,";
$json.= '"idx": "'.$tab[$i]['idx'].'"'."\n"; // derniere champ (sans virgule)
$json.= "}\n";
$json.= "},\n";
}
}
// enpied
$json=substr($json,0, strlen($json)-2);
$json.= "]"."\n";
$json.="}";
// debug
if($debug==1){
$json=str_replace("\n","
",$json);
}
// envoi du tableau dans la couche json d'openlayer
echo $json;
?>