classe_toponimia.php
12.4 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
<?php
/*
* Title: classe_toponimia.php
*
* Processa a toponímia de um tema.
*
* Adiciona, remove, altera, etc.
*
* Cria camadas com a toponímia e gerencia o status das etiquetas mostradas no mapa.
*
* 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_toponimia.php
*/
/*
* Classe: Toponimia
*/
class Toponimia
{
/*
* Variavel: $mapa
*
* Objeto mapa
*/
protected $mapa;
/*
* Variavel: $map_file
*
* Arquivo map file
*/
protected $map_file;
/*
* Variavel: $layer
*
* Objeto layer
*/
public $layer;
/*
* Variavel: $nome
*
* Nome do layer
*/
protected $nome;
/*
* Variavel: $v
*
* Versão atual do Mapserver (primeiro dígito)
*/
public $v;
/*
* Variavel: $vi
*
* Versão atual do Mapserver (valor inteiro)
*
* Returns the MapServer version number (x.y.z) as an integer (x*10000 + y*100 + z). (New in v5.0) e.g. V5.4.3 would return 50403
*/
public $vi;
/*
* function __construct
*
* Cria um objeto map e seta a variavel tema
*
* parameters:
* $map_file - Endereço do mapfile no servidor.
*
* $tema - nome do tema que será processado
*/
function __construct($map_file, $tema = "", $locaplic = "")
{
include (dirname(__FILE__) . "/../ms_configura.php");
$this->postgis_mapa = $postgis_mapa;
if (file_exists($locaplic . "/funcoes_gerais.php"))
include_once ($locaplic . "/funcoes_gerais.php");
else
include_once ("funcoes_gerais.php");
$this->v = versao();
$this->vi = $this->v["inteiro"];
$this->v = $this->v["principal"];
$this->mapa = ms_newMapObj($map_file);
substituiConObj($this->mapa, $postgis_mapa);
$this->arquivo = str_replace(".map", "", $map_file) . ".map";
if ($tema != "" && @$this->mapa->getlayerbyname($tema))
$this->layer = $this->mapa->getlayerbyname($tema);
$this->nome = $tema;
}
/*
* function: salva
*
* Salva o mapfile atual
*/
function salva()
{
restauraConObj($this->mapa, $this->postgis_mapa);
$this->mapa->save($this->arquivo);
}
/*
* function: criaToponimia
*
* Cria a toponímia de um tema
*
* parameter:
*
* $item Item que será utilizado.
*
* $position Posição da âncora do texto.
*
* $partials Corta texto nas bordas do mapa.
*
* $offsetx Deslocamento em X.
*
* $offsety Deslocamento em Y.
*
* $minfeaturesize Tamanho mínimo que o texto deve ter.
*
* $mindistance Distância mínima entre os textos.
*
* $force Força colisão.
*
* $shadowcolor Cor da sombra.
*
* $shadowsizex Tamanho em X da sombra.
*
* $shadowsizey Tamanho em Y da sombra.
*
* $outlinecolor Cor do contorno.
*
* $cor Cor do texto.
*
* $sombray Deslocamento Y da sombra.
*
* $sombrax Deslocamento X da sombra.
*
* $sombra string Inclui sombra.
*
* $fundo Cor do fundo.
*
* $angulo Ângulo do texto.
*
* $tamanho Tamanho do texto.
*
* $fonte Fonte.
*
* $tipo Tipo teste|
*
* $wrap
*
* $novotema sim|nao Cria um novo tema ou não, nesse último caso, a toponímia é inserida em todas as classes
*
* Retorno:
*
* {string} - codigo do layer criado
*/
function criaToponimia($item, $position, $partials, $offsetx, $offsety, $minfeaturesize, $mindistance, $force, $shadowcolor, $shadowsizex, $shadowsizey, $outlinecolor, $cor, $sombray, $sombrax, $sombra, $fundo, $angulo, $tamanho, $fonte, $tipo, $wrap, $novotema = "sim")
{
// error_reporting(0);
if (! $this->layer) {
return false;
}
$this->removeToponimia();
if (! isset($tipo)) {
$tipo = "";
}
if ($item != "") // o layer nao tem tabela mas tem toponimia
{
if ($novotema == "sim") {
$nome = pegaNome($this->layer);
$novolayer = ms_newLayerObj($this->mapa, $this->layer);
$nomer = nomeRandomico();
$novolayer->set("name", $nomer);
$novolayer->set("group", "");
$novolayer->set("type", $this->layer->type);
$nclasses = $novolayer->numclasses;
for ($i = 0; $i < $nclasses; ++ $i) {
$c = $novolayer->getclass($i);
$c->set("status", MS_DELETE);
}
$novac = ms_newClassObj($novolayer);
$novolayer->set("status", MS_DEFAULT);
$novolayer->setmetadata("tema", "texto de " . $nome);
$novolayer->setmetadata("tip", "");
$novolayer->setmetadata("tiles", "nao");
$novolayer->setmetadata("identifica", "nao");
$novolayer->set("labelitem", $item);
} else {
$nomer = $this->layer->name;
$novolayer = $this->mapa->getlayerbyname($nomer);
}
$novolayer->setmetadata("cache", "");
$this->layer = $novolayer;
} else {
$nomer = $this->layer->name;
}
if (! ($this->vi >= 60200)) {
$this->layer->set("labelitem", $item);
}
$nclasses = $this->layer->numclasses;
for ($i = 0; $i < $nclasses; ++ $i) {
$novac = $this->layer->getclass($i);
if ($this->vi >= 60200) {
$s = "CLASS LABEL TEXT '[" . $item . "]' END END";
$novac->updateFromString($s);
$label = $novac->getLabel($indiceLabel);
} else {
$label = $novac->label;
}
if ($wrap != "") {
$label->set("maxlength", 1);
$s = $novac->getTextString;
$s = "CLASS LABEL WRAP '$wrap' END END";
$novac->updateFromString($s);
}
if ($this->vi >= 60200) {
$label = $novac->getLabel($indiceLabel);
} else {
$label = $novac->label;
}
if ($fonte != "bitmap") {
// $label->set("type",MS_TRUETYPE);
$label->updatefromstring("LABEL TYPE TRUETYPE END");
$label->set("font", $fonte);
$label->set("size", $tamanho);
} else {
// $label->set("type",MS_BITMAP);
$label->updatefromstring("LABEL TYPE BITMAP END");
// $label->set("font",$fonte);
$t = MS_TINY;
if ($tamanho > 5) {
$t = MS_TINY;
}
if ($tamanho >= 7) {
$t = MS_SMALL;
}
if ($tamanho >= 10) {
$t = MS_MEDIUM;
}
if ($tamanho >= 12) {
$t = MS_LARGE;
}
if ($tamanho >= 14) {
$t = MS_GIANT;
}
$label->set("size", $t);
}
if ($angulo > 0) {
$label->set("angle", $angulo);
}
if ($angulo == "AUTO") {
$label->updatefromstring("LABEL ANGLE AUTO END");
}
if (strtoupper($angulo) == "CURVO" || strtoupper($angulo) == "FOLLOW") {
$label->updatefromstring("LABEL ANGLE FOLLOW END");
}
corE($label, $cor, "color");
corE($label, $fundo, "backgroundcolor");
corE($label, $sombra, "backgroundshadowcolor", $sombrax, $sombray);
corE($label, $outlinecolor, "outlinecolor");
corE($label, $shadowcolor, "shadowcolor");
$label->set("shadowsizex", $shadowsizex);
$label->set("shadowsizey", $shadowsizey);
$label->set("force", $force);
$label->set("mindistance", $mindistance);
$label->set("minfeaturesize", $minfeaturesize);
$label->set("offsetx", $offsetx);
$label->set("offsety", $offsety);
$label->set("partials", $partials);
$p = array(
"MS_AUTO" => MS_AUTO,
"MS_UL" => MS_UL,
"MS_LR" => MS_LR,
"MS_UR" => MS_UR,
"MS_LL" => MS_LL,
"MS_CR" => MS_CR,
"MS_CL" => MS_CL,
"MS_UC" => MS_UC,
"MS_LC" => MS_LC,
"MS_CC" => MS_CC
);
$label->set("position", $p[$position]);
}
if ($tipo == "teste") {
$this->layer->set("maxscaledenom", 0);
$this->layer->set("minscaledenom", 0);
$i = gravaImagemMapa($this->mapa);
return ($i["url"]);
} else {
return true;
}
}
function removeToponimia()
{
$nclasses = $this->layer->numclasses;
if ($this->vi >= 60200) {
for ($i = 0; $i < $nclasses; ++ $i) {
$classe = $this->layer->getclass($i);
while ($classe->numlabels > 0) {
$classe->removeLabel(0);
}
}
}
if ($this->layer) {
$this->layer->setMetaData("cache", "");
}
return true;
}
/*
* function: ativaEtiquetas
*
* ativa a inclusão de etiquetas em um tema
*
* parameter:
* $item Lista de Itens separados por vírgula que serão utilizados.
*/
function ativaEtiquetas($item)
{
if (! $this->layer) {
return "erro";
}
$this->layer->setmetadata("IDENTIFICA", "");
$this->layer->setmetadata("TIP", $item);
return ("ok");
}
/*
* function: pegaDadosEtiquetas
*
* ativa a inclusão de etiquetas em um tema
*
* parameter:
* $item Lista de Itens separados por vírgula que serão utilizados.
*/
function pegaDadosEtiquetas()
{
if (! $this->layer) {
return "erro";
}
$itens = $this->layer->getmetadata("ITENS");
$itens = explode(",", $itens);
$itensdesc = mb_convert_encoding($this->layer->getmetadata("ITENSDESC"), "UTF-8", "ISO-8859-1");
$itensdesc = explode(",", $itensdesc);
$itenslink = $this->layer->getmetadata("ITENSLINK");
$itenslink = explode(",", $itenslink);
$tips = $this->layer->getmetadata("TIP");
$res = array(
"itens" => $itens,
"itensdesc" => array_combine($itens, $itensdesc),
"itenslink" => array_combine($itens, $itenslink),
"tips" => explode(",", $tips),
"itembuscarapida" => $this->layer->getmetadata("itembuscarapida"),
"utfdata" => $this->layer->getmetadata("UTFDATA")
);
return ($res);
}
/*
* function: removeEtiquetas
*
* remove a inclusão de etiquetas em um tema.
*
*/
function removeEtiquetas()
{
if (! $this->layer) {
return "erro";
}
$this->layer->setmetadata("TIP", "");
$this->layer->setmetadata("UTFDATA", "");
return ("ok");
}
}
?>