classe_atlas.php
6.63 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
/*
Title: classe_atlas.php
Manipulação da interface Atlas.
Licenca:
GPL2
i3Geo Interface Integrada de Ferramentas de Geoprocessamento para Internet
Direitos Autorais Reservados (c) 2006 Ministério do Meio Ambiente Brasil
Desenvolvedor: Edmar Moretti edmar.moretti@gmail.com
Este programa é software livre; você pode redistribuí-lo
e/ou modificá-lo sob os termos da Licença Pública Geral
GNU conforme publicada pela Free Software Foundation;
Este programa é distribuído na expectativa de que seja útil,
porém, SEM NENHUMA GARANTIA; nem mesmo a garantia implícita
de COMERCIABILIDADE OU ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA.
Consulte a Licença Pública Geral do GNU para mais detalhes.
Você deve ter recebido uma cópia da Licença Pública Geral do
GNU junto com este programa; se não, escreva para a
Free Software Foundation, Inc., no endereço
59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
Arquivo:
i3geo/classesphp/classe_atlas.php
*/
/*
Classe: Atlas
*/
class Atlas
{
public $atlas;
/*
Function: __construct
Cria um objeto atlas
parameters:
$atlasxml - Objeto xml com o atlas.
*/
function __construct($xml)
{
//error_reporting(0);
$this->xml = $xml;
}
/*
Method: pegaListaDeAtlas
Pega a lista de atlas existentes e as informações básicas sobre cada um
Parametros:
tituloinstituicao - é utilizado para montar o cabeçalho HTML com a lista de atlas. Pode ser obtido do ms_configura.php
*/
function pegaListaDeAtlas($tituloinstituicao="")
{
$tituloinstituicao = mb_convert_encoding($tituloinstituicao,"HTML-ENTITIES","auto");
$atlas = array();
foreach($this->xml->ATLAS as $s)
{
$atlas[] = array("PUBLICADO"=>ixml($s,"PUBLICADO"),"ID"=>ixml($s,"ID"),"TITULO"=>ixml($s,"TITULO"),"DESCRICAO"=>ixml($s,"DESCRICAO"),"ICONE"=>ixml($s,"ICONE"),"W"=>ixml($s,"WABERTURA"),"H"=>ixml($s,"HABERTURA"),"TEMPLATEHTML"=>ixml($s,"TEMPLATEHTML"));
}
return (array("atlas"=>$atlas,"tituloinstituicao"=>$tituloinstituicao));
}
/*
Method: criaAtlas
Lê os parâmetros necessários para abrir um atlas no i3geo
Parametros:
atlasId - id do atlas desejado, conforme existente em atlas.xml
*/
function criaAtlas($atlasId)
{
foreach($this->xml->ATLAS as $s)
{
$id = ixml($s,"ID");
if ($id == $atlasId)
{
$interface = ixml($s,"TEMPLATEHTML");
$base = ixml($s,"BASEMAPFILE");
}
}
return (array("interface"=>$interface,"base"=>$base));
}
/*
Method: pegaListaDePranchas
Pega a lista de pranchas existentes em um atlas específico e as informações básicas sobre cada uma
Parametros:
atlasId - identificador do Atlas desejado
*/
function pegaListaDePranchas($atlasId)
{
$p = array();
foreach($this->xml->ATLAS as $s)
{
$id = ixml($s,"ID");
if ($id == $atlasId)
{
$titulo = ixml($s,"TITULO");
$link = ixml($s,"LINKMAISINFO");
$w = ixml($s,"WABERTURA");
$h = ixml($s,"HABERTURA");
$icone = ixml($s,"ICONE");
$tipoguias = ixml($s,"TIPOGUIAS");
$pdefault = ixml($s,"PRANCHADEFAULT");
foreach($s->PRANCHAS as $pranchas)
{
foreach($pranchas->PRANCHA as $prancha)
{
$p[] = array("id"=>ixml($prancha,"ID"),"titulo"=>ixml($prancha,"TITULO"),"icone"=>ixml($prancha,"ICONE"));
}
}
}
}
return (array("tipoguias"=>$tipoguias,"pranchadefault"=>$pdefault,"icone"=>$icone,"titulo"=>$titulo,"w"=>$w,"h"=>$h,"link"=>$link,"pranchas"=>$p));
}
/*
Method: abrePrancha
Ativa uma prancha do atlas.
Inclui os temas definidos na configuração da prancha.
Os layers que não são oriundos de uma prancha recebe o metadata "ATLAS" igual a "nao". Isso é feito na inicialização do Atlas.
Parametros:
atlasId - id do atlas
pranchaId - identificador da prancha de um atlas
map_file - nome do mapfile do mapa atual
locaplic - localização do i3geo no servidor
*/
function abrePrancha($atlasId,$pranchaId,$map_file,$locaplic)
{
$p = array();
$temasa = array();
$layers = array();
$mapa = ms_newMapObj($map_file);
$numlayers = $mapa->numlayers;
for ($i=0;$i < $numlayers;++$i)
{
$l = $mapa->getlayer($i);
if (($l->getmetadata("ATLAS")) != "nao")
{$l->set("status",MS_DELETE);}
}
$mapa->save(str_replace(".map","",$map_file).".map");
$mp = "";
foreach($this->xml->ATLAS as $s)
{
$ida = ixml($s,"ID");
if ($ida == $atlasId)
{
foreach($s->PRANCHAS as $pranchas)
{
foreach($pranchas->PRANCHA as $prancha)
{
if($pranchaId == ixml($prancha,"ID"))
{
$link = ixml($prancha,"LINKMAISINFO");
$w = ixml($prancha,"WABERTURA");
$h = ixml($prancha,"HABERTURA");
$mp = ixml($prancha,"MAPEXT");
//pega os temas
foreach($prancha->TEMAS as $temas)
{
foreach($temas->TEMA as $tema)
{
$codigo = ixml($tema,"CODIGO");
$ligado = ixml($tema,"LIGADO");
if ($codigo != "")
{
$temasa[] = $codigo;
if (strtolower($ligado) == "sim")
{$layers[] = $codigo;}
}
}
}
}
}
}
}
}
if(count($temasa) > 0)
{
include_once("classe_mapa.php");
$mapa = "";
$m = new Mapa($map_file);
$m->adicionaTema((implode(",",$temasa)),$locaplic,"nao");
$m->salva();
$mapa = ms_newMapObj($map_file);
$numlayers = $mapa->numlayers;
for ($i=0;$i < $numlayers;++$i)
{
$l = $mapa->getlayer($i);
if (($l->getmetadata("ATLAS")) != "nao")
{$l->set("status",MS_OFF);}
}
foreach($layers as $t)
{
$layer = $mapa->getlayerbyname($t);
$layer->set("status",MS_DEFAULT);
}
$mapa->save(str_replace(".map","",$map_file).".map");
}
//verifica extensão geográfica
$newext = array();
if ($mp != "")
{
$ext = $mapa->extent;
$newext = array();
$temp = explode(",",$mp);
foreach ($temp as $t)
{
if ($t != "")
{$newext[] = $t;}
}
if (count($newext) == 4)
{$ext->setextent($newext[0], $newext[1], $newext[2], $newext[3]);}
$mapa->save(str_replace(".map","",$map_file).".map");
}
if(!function_exists("sobeAnno")){
include_once("funcoes_gerais.php");
}
sobeAnno($map_file);
if ($w == ""){$w = 300;}
if($h == ""){$h = 300;}
return (array("link"=>$link,"w"=>$w,"h"=>$h,"mapexten"=>implode(" ",$newext)));
}
}
?>