Commit b1712d973b0889e29345947c8aa64848192f3b7a

Authored by Edmar Moretti
1 parent 6d78cf48

Inclusão de projeto gvsig no testamapfile

Showing 1 changed file with 102 additions and 106 deletions   Show diff stats
testamapfile.php
... ... @@ -91,7 +91,7 @@ if ($tipo == "")
91 91 $combo = "<br><select onchange='roda()' id=nomemap ><option value=''>Escolha o arquivo para testar</option>";
92 92 foreach ($arqs["arquivos"] as $arq){
93 93 $temp = explode(".",$arq);
94   - if($temp[1] == "map"){
  94 + if($temp[1] == "map" || $temp[1] == "gvp"){
95 95 $combo .= "<option value='".$temp[0]."'>".$temp[0]."</option>";
96 96 }
97 97 }
... ... @@ -108,13 +108,9 @@ if (isset($map) &amp;&amp; $map != &quot;&quot;)
108 108 if (!isset($iniciar)){$iniciar = 0;}
109 109 foreach ($arqs["arquivos"] as $arq)
110 110 {
111   - if (($conta >= $iniciar) && ($conta < $iniciar+10))
112   - {
113   - $temp = explode(".",$arq);
114   - if($temp[1] == "map")
  111 + if (($conta >= $iniciar) && ($conta < $iniciar+10)){
  112 + //arquivos php so sao validos se estiverem em i3geo/temas
115 113 verifica($arq,$solegenda);
116   - else
117   - {echo "<br>Arquivo <i>$map</i> n&atilde;o &eacute; v&aacute;lido. <br>";}
118 114 }
119 115 $conta++;
120 116 }
... ... @@ -126,28 +122,25 @@ if (isset($map) &amp;&amp; $map != &quot;&quot;)
126 122 echo '</div>';
127 123 echo '<script>if(screen.availWidth > 700){document.getElementById("divGeral").style.width = "700px";}</script>';
128 124 echo '</body></html>';
129   -function verifica($map,$solegenda)
130   -{
  125 +function verifica($map,$solegenda){
131 126 global $tipo,$locaplic,$postgis_mapa,$versao,$base;
132 127 $mapUrl = $map;
133   - if ($tipo == "mini" && file_exists('temas/miniaturas/'.$map.".mini.png"))
134   - {
  128 + if ($tipo == "mini" && file_exists('temas/miniaturas/'.$map.".mini.png")){
135 129 Header("Content-type: image/png");
136 130 ImagePng(ImageCreateFromPNG('temas/miniaturas/'.$map.".mini.png"));
137 131 exit;
138 132 }
139   - if ($tipo == "grande" && file_exists('temas/miniaturas/'.$map.".grande.png"))
140   - {
  133 + if ($tipo == "grande" && file_exists('temas/miniaturas/'.$map.".grande.png")){
141 134 Header("Content-type: image/png");
142 135 ImagePng(ImageCreateFromPNG('temas/miniaturas/'.$map.".grande.png"));
143 136 exit;
144 137 }
145 138 ms_ResetErrorList();
146 139 $tema = "";
147   - if(file_exists($map))
148   - {$tema = $map;}
149   - else
150   - {
  140 + if(file_exists($map)){
  141 + $tema = $map;
  142 + }
  143 + else{
151 144 $map = str_replace("\\","/",$map);
152 145 $map = basename($map);
153 146 if (file_exists('temas/'.$map))
... ... @@ -156,21 +149,26 @@ function verifica($map,$solegenda)
156 149 {$tema = 'temas/'.$map.".map";}
157 150 if (file_exists('temas/'.$map.'.php'))
158 151 {$tema = 'temas/'.$map.".php";}
  152 + if (file_exists('temas/'.$map.'.gvp'))
  153 + {$tema = 'temas/'.$map.".gvp";}
159 154 }
160   - if(($tipo == "") || ($tipo == "todos"))
161   - {echo "<hr><br><br><span style='color:red' ><b>Testando: $tema </span><pre></b>";}
162   - if(!file_exists($tema))
163   - {$tema = $locaplic."/".$tema;}
164   - if(!file_exists($tema))
165   - {echo "Arquivo ".$map." n&atilde;o encontrado.";exit;}
166   - if ($tema != "")
167   - {
  155 + if(($tipo == "") || ($tipo == "todos")){
  156 + echo "<hr><br><br><span style='color:red' ><b>Testando: $tema </span><pre></b>";
  157 + }
  158 + if(!file_exists($tema)){
  159 + $tema = $locaplic."/".$tema;
  160 + }
  161 + if(!file_exists($tema)){
  162 + echo "Arquivo ".$map." n&atilde;o encontrado.";
  163 + exit;
  164 + }
  165 + if ($tema != ""){
168 166 if($base == "" or !isset($base)){
169 167 $base = "";
170   - if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN'))
171   - {$base = $locaplic."/aplicmap/geral1windowsv".$versao.".map";}
172   - else
173   - {
  168 + if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')){
  169 + $base = $locaplic."/aplicmap/geral1windowsv".$versao.".map";
  170 + }
  171 + else{
174 172 if($base == "" && file_exists('/var/www/i3geo/aplicmap/geral1debianv'.$versao.'.map')){
175 173 $base = "/var/www/i3geo/aplicmap/geral1debianv".$versao.".map";
176 174 }
... ... @@ -180,38 +178,35 @@ function verifica($map,$solegenda)
180 178 if($base == "" && file_exists('/opt/www/html/i3geo/aplicmap/geral1fedorav'.$versao.'.map')){
181 179 $base = "/opt/www/html/i3geo/aplicmap/geral1v".$versao.".map";
182 180 }
183   - if($base == "")
184   - {$base = $locaplic."/aplicmap/geral1v".$versao.".map";}
  181 + if($base == ""){
  182 + $base = $locaplic."/aplicmap/geral1v".$versao.".map";
  183 + }
185 184 }
186 185 }
187 186 else{
188   - if(!file_exists($base))
189   - {$base = $locaplic."/aplicmap/".$base;}
  187 + if(!file_exists($base)){
  188 + $base = $locaplic."/aplicmap/".$base;
  189 + }
190 190 }
191 191 //echo $base;exit;
192 192 $mapa = ms_newMapObj($base);
193   -
194 193 error_reporting(0);
195 194 $numlayers = $mapa->numlayers;
196   - for ($i=0;$i < $numlayers;$i++)
197   - {
  195 + for ($i=0;$i < $numlayers;$i++){
198 196 $layern = $mapa->getlayer($i);
199   - if (!empty($postgis_mapa))
200   - {
201   - if ($layern->connectiontype == MS_POSTGIS)
202   - {
  197 + if (!empty($postgis_mapa)){
  198 + if ($layern->connectiontype == MS_POSTGIS){
203 199 $lcon = $layern->connection;
204   - if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa))))
205   - {
  200 + if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))){
206 201 if(($lcon == " ") || ($lcon == "")) //para efeitos de compatibilidade
207 202 {$layern->set("connection",$postgis_mapa);}
208   - else
209   - {$layern->set("connection",$postgis_mapa[$lcon]);}
  203 + else{
  204 + $layern->set("connection",$postgis_mapa[$lcon]);
  205 + }
210 206 }
211 207 }
212 208 }
213 209 }
214   -
215 210 if(!stristr($tema, '.php') === FALSE){
216 211 echo "<br>Arquivo <i>$tema</i> &eacute; um programa PHP. O teste pode n&atilde;o funcionar.<br>";
217 212 include_once($locaplic."/".$tema);
... ... @@ -222,15 +217,15 @@ function verifica($map,$solegenda)
222 217 $pegarext = str_replace("temas/","",$pegarext);
223 218 eval($pegarext."(\$mapa);");
224 219 }
225   - else{
  220 + if(!stristr($tema, '.map') === FALSE){
226 221 if(file_exists($mapUrl)){
227   - if(@ms_newMapObj($mapUrl))
228   - {$nmapa = ms_newMapObj($mapUrl);}
  222 + if(@ms_newMapObj($mapUrl)){
  223 + $nmapa = ms_newMapObj($mapUrl);
  224 + }
229 225 else{
230 226 echo "Erro no arquivo $mapUrl <br>";
231 227 $error = ms_GetErrorObj();
232   - while($error && $error->code != MS_NOERR)
233   - {
  228 + while($error && $error->code != MS_NOERR){
234 229 printf("<br>Error in %s: %s<br>\n", $error->routine, $error->message);
235 230 $error = $error->next();
236 231 }
... ... @@ -238,17 +233,14 @@ function verifica($map,$solegenda)
238 233 }
239 234 }
240 235 else{
241   - if(@ms_newMapObj($locaplic."/".$tema))
242   - {
  236 + if(@ms_newMapObj($locaplic."/".$tema)){
243 237 $nmapa = ms_newMapObj($locaplic."/".$tema);
244 238 }
245   - else
246   - {
  239 + else{
247 240 echo "erro no arquivo $map <br>";
248 241 echo "Obs.: em alguns testes o mapfile pode falhar se o endere&ccedil;o dos arquivos de s&iacute;mbolos estiverem <br>definidos de forma relativa ao inv&eacute;s de absoluta. Nesses casos, ao abrir o i3Geo, <br>o mapfile poder&aacute; funcionar. <br>";
249 242 $error = ms_GetErrorObj();
250   - while($error && $error->code != MS_NOERR)
251   - {
  243 + while($error && $error->code != MS_NOERR){
252 244 printf("<br>Error in %s: %s<br>\n", $error->routine, $error->message);
253 245 $error = $error->next();
254 246 }
... ... @@ -257,18 +249,14 @@ function verifica($map,$solegenda)
257 249 }
258 250 $numlayers = $nmapa->numlayers;
259 251 $dados = "";
260   - for ($i=0;$i < $numlayers;$i++)
261   - {
  252 + for ($i=0;$i < $numlayers;$i++){
262 253 $layern = $mapa->getlayer($i);
263 254 $layern->set("status",MS_DEFAULT);
264   - if (!empty($postgis_mapa))
265   - {
266   - if ($layern->connectiontype == MS_POSTGIS)
267   - {
  255 + if (!empty($postgis_mapa)){
  256 + if ($layern->connectiontype == MS_POSTGIS){
268 257 $lcon = $layern->connection;
269 258 error_reporting(0);
270   - if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa))))
271   - {
  259 + if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))){
272 260 if(($lcon == " ") || ($lcon == "")) //para efeitos de compatibilidade
273 261 {$layern->set("connection",$postgis_mapa);}
274 262 else
... ... @@ -282,51 +270,69 @@ function verifica($map,$solegenda)
282 270 $tipotemp = $layern->type;
283 271 $tiporep = $layern->getmetadata("tipooriginal");
284 272 $layern->set("type",MS_LAYER_POLYGON);
285   - if ($tiporep == "linear")
286   - {$layern->set("type",MS_LAYER_LINE);}
287   - if ($tiporep == "pontual")
288   - {$layern->set("type",MS_LAYER_POINT);}
  273 + if ($tiporep == "linear"){
  274 + $layern->set("type",MS_LAYER_LINE);
  275 + }
  276 + if ($tiporep == "pontual"){
  277 + $layern->set("type",MS_LAYER_POINT);
  278 + }
289 279 $sld = $layern->generateSLD();
290   - if($sld != "")
291   - $layern->setmetadata("wms_sld_body",str_replace('"',"'",$sld));
  280 + if($sld != ""){
  281 + $layern->setmetadata("wms_sld_body",str_replace('"',"'",$sld));
  282 + }
292 283 $layern->set("type",$tipotemp);
293 284 }
294 285 ms_newLayerObj($mapa, $layern);
295   - if ($layern->data == "")
296   - $dados = $layern->connection;
297   - else
298   - $dados = $layern->data;
299   - $pegarext = $teman;
  286 + if ($layern->data == ""){
  287 + $dados = $layern->connection;
  288 + }
  289 + else{
  290 + $dados = $layern->data;
  291 + }
  292 + $pegarext = $layern->name;
300 293 }
  294 + zoomTema($pegarext,$mapa);
301 295 }
302   - zoomTema($pegarext,$mapa);
303   - if ($tipo == "mini")
304   - {
  296 + if(!stristr($tema, '.gvp') === FALSE){
  297 + if(file_exists($mapUrl)){
  298 + $gvsiggvp = $mapUrl;
  299 + }
  300 + else{
  301 + $gvsiggvp = $locaplic."/".$tema;
  302 + }
  303 + include_once($locaplic."/pacotes/gvsig/gvsig2mapfile/class.gvsig2mapfile.php");
  304 + $gm = new gvsig2mapfile($gvsiggvp);
  305 + $gvsigview = $gm->getViewsNames();
  306 + $gvsigview = $gvsigview[0];
  307 + $dataView = $gm->getViewData($gvsigview);
  308 + $numlayers = $mapn->numlayers;
  309 + $next = $dataView["extent"];
  310 + $ext = $mapa->extent;
  311 + $ext->setextent($next[0],$next[1],$next[2],$next[3]);
  312 + $mapa = $gm->addLayers($mapa,$gvsigview,$dataView["layerNames"]);
  313 + }
  314 + if ($tipo == "mini"){
305 315 $mapa->setsize(50,50);
306 316 $sca = $mapa->scalebar;
307 317 $sca->set("status",MS_OFF);
308 318 }
309   - if ($tipo == "grande")
310   - {
  319 + if ($tipo == "grande"){
311 320 $mapa->setsize(300,300);
312 321 $sca = $mapa->scalebar;
313 322 $sca->set("status",MS_OFF);
314 323 }
315   - if($tipo == "todos")
316   - {
  324 + if($tipo == "todos"){
317 325 $mapa->setsize(150,150);
318 326 $sca = $mapa->scalebar;
319 327 $sca->set("status",MS_OFF);
320 328 }
321 329 $objImagem = @$mapa->draw();
322 330 $objImagemLegenda = @$mapa->drawLegend();
323   - if (!$objImagem)
324   - {
  331 + if (!$objImagem){
325 332 echo "Problemas ao gerar o mapa<br>";
326 333 $error = "";
327 334 $error = ms_GetErrorObj();
328   - while($error && $error->code != MS_NOERR)
329   - {
  335 + while($error && $error->code != MS_NOERR){
330 336 echo "<br>Error in %s: %s<br>", $error->routine, $error->message;
331 337 $error = $error->next();
332 338 }
... ... @@ -341,38 +347,32 @@ function verifica($map,$solegenda)
341 347 $nomel = ($objImagemLegenda->imagepath).nomeRandomico()."testel.png";
342 348 $objImagemLegenda->saveImage($nomel);
343 349 $nomerl = ($objImagemLegenda->imageurl).basename($nomel);
344   - if(($tipo == "") || ($tipo == "todos"))
345   - {
  350 + if(($tipo == "") || ($tipo == "todos")){
346 351 if($solegenda == "nao")
347 352 {echo "<img src=".$nomer." /><br>";}
348 353 echo "<img src=".$nomerl." />";
349   - if($tipo == "todos")
350   - {
351   - echo "<br>".$dados."<br>";
  354 + if($tipo == "todos"){
  355 + echo "<br>".$dados."<br>";
352 356 }
353   - if($map != "todos")
354   - {
  357 + if($map != "todos"){
355 358 echo "<br>Erros:<br>";
356 359 $error = "";
357 360 $error = ms_GetErrorObj();
358   - while($error && $error->code != MS_NOERR)
359   - {
  361 + while($error && $error->code != MS_NOERR){
360 362 echo "<br>Error in %s: %s<br>", $error->routine, $error->message;
361 363 $error = $error->next();
362 364 }
363 365 }
364 366  
365 367 }
366   - else
367   - {
  368 + else{
368 369 Header("Content-type: image/png");
369 370 ImagePng(ImageCreateFromPNG($nomec));
370 371 }
371 372 //$objImagem->free();
372 373 }
373 374 }
374   -function zoomTema($nomelayer,&$mapa)
375   -{
  375 +function zoomTema($nomelayer,&$mapa){
376 376 $layer = $mapa->getlayerbyname($nomelayer);
377 377 if($layer->data == "" && $layer->connection == "")
378 378 {return;}
... ... @@ -385,23 +385,19 @@ function zoomTema($nomelayer,&amp;$mapa)
385 385 $ct = $layer->connectiontype;
386 386 if(($ret == "") && ($ct != 1))
387 387 {return;}
388   - if ($ret == "")
389   - {
  388 + if ($ret == ""){
390 389 $ret = $layer->getextent();
391 390 //reprojeta o retangulo
392   - if (($prjTema != "") && ($prjMapa != $prjTema))
393   - {
  391 + if (($prjTema != "") && ($prjMapa != $prjTema)){
394 392 $projInObj = ms_newprojectionobj($prjTema);
395 393 $projOutObj = ms_newprojectionobj($prjMapa);
396 394 $ret->project($projInObj, $projOutObj);
397 395 }
398 396 $extatual->setextent($ret->minx,$ret->miny,$ret->maxx,$ret->maxy);
399 397 }
400   - else
401   - {
  398 + else{
402 399 $ret = explode(" ",$ret);
403 400 $extatual->setextent($ret[0],$ret[1],$ret[2],$ret[3]);
404 401 }
405 402 }
406   -
407 403 ?>
... ...