Bonjour,
J'ai un souci pour afficher une couche WFS dans l'API Géoportail. Ce problème a déjà été posé dans un autre sujet (http://www.developpez.net/forums/d11...wfs-invisible/) mais je n'ai pas compris comment il a été résolu et me casse les dents depuis plusieurs jours déjà...
Je réexpose donc le souci : ma couche WFS s'affiche dans ma liste de couches, mais lorsque je clique pour la visualiser, il ne se passe rien. D'après Firebug, le problème viendrait du proxy, mais comme je ne suis pas une pro, je ne sais pas du tout où se situe le problème exactement.
Voici mon code, qui permet d'ajouter une couche WMS et une WFS représentant la même chose. La WMS marche bien mais la WFS ne s'affiche pas :
Et le code du proxy php, copié-collé depuis le site du Géoportail sans aucune modification (https://api.ign.fr/geoportail/api/do...proxy_wfs.html) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139 <!--DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"--> <html> <head> <title>Page test</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <!--Style de texte et de Carte--> <link rel="stylesheet" type="text/css" href="testcss.css" /> <link rel="stylesheet" type="test/css" href="http://api.ign.fr/geoportail/api/js/VERSION/theme/geoportail/style.css" /> <script type="text/javascript" src="http://api.ign.fr/geoportail/api?v=1.2-e&key=XXXXXXXXXXXXXXXX&instance=maCarte&"> <!--Bien entendu, ici je met normalement la bonne clé --> </script> <script type="text/javascript"> //Fonctions pour l'affichage WFS //-------------------------------- function overRiver(feature) { if (feature) { if (!feature.popup) { var ll= feature.geometry.getBounds().getCenterLonLat(); var me= maCarte.getMap().getExtent(); var inView= me.containsLonLat(ll,false); if (!inView) {//hors de la visualisation ll= me.getCenterLonLat(); } feature.popup= new OpenLayers.Popup.FramedCloud( "chicken", ll, null, // on affiche l'attribut 'NAME' dans l'info-bulle : "<div style='font-size:.75em'>" + feature.attributes['NAME']+ "</div>", null, false); } if (feature.popup) { maCarte.getMap().addPopup(feature.popup,true); } } } function outRiver(feature) { if (feature && feature.popup) { feature.popup.destroy(); feature.popup= null; } } //Initialisation de la Carte //--------------------------- function initGeoportalMap() { //Cette fonction sera exécutée au chargement de la page HTML //La carte doit y être créée et paramétrée geoportalLoadmaCarte("Carte","normal"); if (maCarte) { //Ajout des Couches Geoportail dans le contrat maCarte.addGeoportalLayers(); } //Définition des coordonnées du centre de l'image (Lon,Lat,Altitude) maCarte.getMap().setCenterAtLonLat(0.11, 49.5, 9); //Test ajout WMS //--------------- maCarte.getMap().addLayer( "WMS", "Geolittoral WMS", "http://geolittoral.application.equipement.gouv.fr/wms/metropole?", {layers:'Sentiers_littoraux'}, { //projection:'EPSG:27582', projection:'EPSG:4326', isBaseLayer:false, visibility: false } ); //Test ajout WFS //--------------- var rwbodyStyle= new OpenLayers.StyleMap({ "default": new OpenLayers.Style({ strokeColor:'#0000ff', strokeWidth:3 }), "select": new OpenLayers.Style({ strokeColor:'#3399ff', strokeWidth:3 }) }); var sandre = maCarte.getMap().addLayer( "WFS", "Sentiers Littoraux", "http://geolittoral.application.equipement.gouv.fr/wfs/metropole?", { typename: 'Sentiers_littoraux' }, { projection: 'EPSG:27582', units:'degrees', // maxExtent est exprimée en EPSG:27582 : maxExtent: new OpenLayers.Bounds(47538.8,1.62262e+06,1.18164e+06,2.67764e+06), minZoomLevel:8, maxZoomLevel:15, isBaseLayer: false, visibility: false, extractAttributes:true, styleMap:rwbodyStyle, onSelect: overRiver, onUnselect: outRiver, hover: true } ); // Proxy //------- maCarte.getMap().setProxyUrl('proxy/proxy.php'); } </script> </head> <body> <h1>Test Carto</h1> <div id="Carte"></div> </body> </html>
Auriez-vous une idée de ce qui résoudrait ce problème?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201 <?php // proxy http // auteur: Marc Gauthier // 02/09/2009 // les erreurs dans les log du serveur // http://www.papygeek.com/download/53/ // Transfer-Encoding: chunked // // Didier Richard - IGN - dérivation pour publication // (c) IGN 2010 // License : http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ // ---------------------------------------------------------- // global variables : $debug= 0; $debug_html= 0; $sUrl= ''; $sReponse= ''; // via un proxy d'entreprise/IP $proxy_host= ''; $proxy_port= 80; $content_types= array( 'application/vnd.google-earth.kml+xml', 'application/vnd.google-earth.kml', //'application/vnd.google-earth.kmz', # TODO needs to unzip response ... 'application/vnd.ogc.se_xml', 'application/vnd.ogc.wms_xml', 'application/vnd.ogc.wfs_xml', 'application/vnd.ogc.gml', 'application/soap+xml', 'application/xml', 'text/xml', 'text/plain', 'text/html'); // ---------------------------------------------------------- // // écriture d'un message de log function carp($msg) { global $debug; global $debug_html; if ($debug) { if ($debug_html) { print "__FILE__.:$msg.<br>\n"; } error_log(__FILE__.": $msg", 0); } } // // écriture d'un message de log et erreur http function confess($msg) { carp($msg); header("HTTP/1.0 500 $msg"); exit; } // // mode chunk function unchunk($result) { return preg_replace_callback( '/(?:(?:\r\n|\n)|^)([0-9A-F]+)(?:\r\n|\n){1,2}(.*?)'. '((?:\r\n|\n)(?:[0-9A-F]+(?:\r\n|\n))|$)/si', create_function( '$matches', 'return hexdec($matches[1]) == strlen($matches[2]) ? $matches[2] : $matches[0];' ), $result ); } // // la fonction proxy // 2 grandes étapes: // - émission de la requête // - réception de la réponse function proxy($sUrl) { global $proxy_host, $proxy_port, $chunked, $content_types; // // analyse de l'url et construction de la requête $sUrl= urldecode($sUrl); $referrer= (isset($_SERVER["HTTP_REFERER"])? $_SERVER["HTTP_REFERER"] : ""); $userAgent= (isset($_SERVER["HTTP_USER_AGENT"])? $_SERVER["HTTP_USER_AGENT"] : ""); $aUrl= @parse_url($sUrl); if (!isset($aUrl['scheme'])) { //try absolute and relative path: confess("proxy scheme missing"); } // construction de la requete $acceptH= (isset($_SERVER['HTTP_ACCEPT'])? $_SERVER['HTTP_ACCEPT'] : ""); #$pragmaH= (isset($_SERVER['HTTP_PRAGMA'])? $_SERVER['HTTP_PRAGMA'] : ""); #$cacheControlH= (isset($_SERVER['HTTP_CACHE_CONTROL'])? $_SERVER['HTTP_CACHE_CONTROL'] : ""); $acceptLanguageH= (isset($_SERVER['HTTP_ACCEPT_CHARSET'])? $_SERVER['HTTP_ACCEPT_CHARSET'] : ""); $keepAliveH= (isset($_SERVER['HTTP_KEEP_ALIVE'])? $_SERVER['HTTP_KEEP_ALIVE'] : ""); #$acceptEncodingH= (isset($_SERVER['HTTP_ACCEPT_ENCODING'])? $_SERVER['HTTP_ACCEPT_ENCODING'] : "");//TODO decompression #$connectionH= (isset($_SERVER['HTTP_CONNECTION'])? $_SERVER['HTTP_CONNECTION'] : ""); #$SOAPActionH= (isset($_SERVER['HTTP_SOAPACTION'])? $_SERVER['HTTP_SOAPACTION'] : ""); $acceptCharsetH= (isset($_SERVER['HTTP_ACCEPT_CHARSET'])? $_SERVER['HTTP_ACCEPT_CHARSET'] : ""); #$gppKeyH= (isset($_SERVER['gppkey'];#if gppKey in HTTP Header $Hs= "Host: ".$aUrl['host'].(isset($aUrl['port']) && !empty($aUrl['port']) ? ":".$aUrl['port'] : "")."\r\n" . (strlen($acceptH)>0? "Accept: ".$acceptH : join(",", $content_types))."\r\n" #. (strlen($pragmaH)>0? "Pragma: ".$pragmaH."\r\n" : "") #. (strlen($cacheControlH)>0? "Cache-Control: ".$cacheControlH."\r\n" : "") . (strlen($acceptLanguageH)>0? "Accept-Language: ".$acceptLanguageH."\r\n" : "") . (strlen($keepAliveH)>0? "Keep-Alive: ".$keepAliveH."\r\n" : "") #. (strlen($acceptEncodingH)>0? "Accept-Encoding: ".$acceptEncodingH."\r\n" : "") #. (strlen($connectionH)>0? "Connection: ".$connectionH."\r\n" : "") #. (strlen($SOAPActionH)>0? "SOAPAction: ".$SOAPActionH."\r\n" : "") . (strlen($acceptCharsetH)>0? "Accept-Charset: ".$acceptCharsetH."\r\n" : "") #. (strlen($gppKeyH)>0? "gppkey: ".$gppKeyH."\r\n" : "") . (strlen($referrer)>0? "Referer: ".$referrer."\r\n" : "") . (strlen($userAgent)>0? "User-Agent: ".$userAgent."\r\n" : "") ; carp($Hs); if ($_SERVER["REQUEST_METHOD"]==='GET') { $sReq= "GET $sUrl HTTP/1.0\r\n" . $Hs ; } else { if ($_SERVER["REQUEST_METHOD"]==='POST') { $data= ''; if (count($_POST)){ while (list($key, $val)= each($_POST)){ $data.="$key : $val\n"; } } else { $data= trim(file_get_contents('php://input')); } $sReq= "POST $sUrl HTTP/1.0\r\n" . $Hs . "Content-Type: text/xml\r\n" . "Content-length: ".strlen($data)."\r\n" . "\r\n" . $data ; } } $sReq.= "\r\n"; if (empty($proxy_host)) { $host= $aUrl["host"]; $port= (isset($aUrl["port"]) && !empty($aUrl["port"])? $aUrl["port"] : 80); } else { $host= $proxy_host; $port= $proxy_port; } // envoi de la requête carp("host:$host port:$port url:$sUrl"); $fp= @fsockopen($host, $port, $errno, $errstr, 5); if (!$fp) { confess("fsockopen failed: $errstr ($errno)"); } carp("sReq:$sReq"); fwrite($fp, $sReq); // attente de la réponse $headers= ''; $sReponse= ''; ob_start(); while (!feof($fp)) { $sReponse.= fread($fp, 4096); } fclose ($fp); $eoh= strpos($sReponse, "\r\n\r\n"); $headers= substr($sReponse, 0, $eoh); $sReponse= substr($sReponse, $eoh+4); $Hs= preg_split('/(?:\r\n|\n)/', $headers); carp("Hs=[".count($hs)."]"); for ($i= 0, $l= count($hs); $i<$l; $i++) { if (preg_match('/^Content-Length/i', $hs[$i])) { continue; } if (preg_match('/^Transfer-Encoding: chunked/i', $hs[$i])) { // Transfer-Encoding: chunked carp("chunked response"); $sReponse= unchunck($sReponse); continue; } #carp("header=[$hs[$i]]"); header($hs[$i]); } header("Content-Length: ".strlen($sReponse)); print $sReponse; } // ---------------------------------------------------------- // programme principal: // on accept que GET/POST (pour l'instant) if (($_SERVER["REQUEST_METHOD"]==='GET' or $_SERVER["REQUEST_METHOD"]==='POST') && (isset($_REQUEST["url"]) && strlen($_REQUEST["url"])>0)) { $sUrl= substr($_SERVER["QUERY_STRING"],4); carp("Proxying:$sUrl"); proxy($sUrl); exit; } // on ne traite pas la demande : carp("REQUEST_METHOD:".$_SERVER["REQUEST_METHOD"]." QUERY_STRING:".$_SERVER["QUERY_STRING"] ); if ($debug) { phpinfo(INFO_VARIABLES); } exit; // ---------------------------------------------------------- ?>
Partager