Commit 8b17f02908fc2d44c44c0f515015e729ab301473
1 parent
c0623121
Exists in
master
and in
7 other branches
Reengenharia do mashup OpenLayers para permitir o uso do javascript dentro do i3geo
Showing
2 changed files
with
99 additions
and
84 deletions
Show diff stats
mashups/openlayers.js.php
... | ... | @@ -21,7 +21,6 @@ i3GEOOL = { |
21 | 21 | {layers: 'basic'} |
22 | 22 | ), |
23 | 23 | jpl_wms: new OpenLayers.Layer.WMS( "NASA Global Mosaic", "http://wms.jpl.nasa.gov/wms.cgi", {layers: "modis,global_mosaic"},{singleTile:true}), |
24 | - | |
25 | 24 | osm_wms: new OpenLayers.Layer.WMS( |
26 | 25 | "Open Street Map", |
27 | 26 | "http://full.wms.geofabrik.de/std/demo_key?", |
... | ... | @@ -36,45 +35,63 @@ i3GEOOL = { |
36 | 35 | "Estados do Brasil", |
37 | 36 | "http://mapas.mma.gov.br/i3geo/ogc.php?tema=estadosl&", |
38 | 37 | {layers: "estadosl",FORMAT:'image/png'} |
39 | - ), | |
38 | + ), | |
39 | + fundo: "ol_mma,ol_wms,jpl_wms,osm_wms,top_wms,est_wms", | |
40 | 40 | layergrafico: new OpenLayers.Layer.Vector("Edição",{displayInLayerSwitcher:true,visibility:true}), |
41 | - layersIniciais: [<?php | |
42 | - if(isset($objOpenLayers) && $objOpenLayers != "") | |
43 | - {echo implode(",",$objOpenLayers);} | |
44 | - else | |
45 | - {echo "''";} | |
46 | - ?>], | |
47 | - botoes: <?php echo $botoes; ?>, | |
48 | - pontos: [<?php | |
49 | - if(isset($pontos)){ | |
50 | - $pontos = str_replace(" ",",",$pontos); | |
51 | - echo $pontos; | |
52 | - } | |
53 | - ?>], | |
54 | - marca: "<?php | |
55 | - if(isset($marca)){echo $marca;} | |
56 | - else | |
57 | - {echo "../pacotes/openlayers/img/marker-gold.png";} | |
58 | - ?>", | |
59 | - mapa: new OpenLayers.Map('i3geoMapa', { | |
60 | - controls: [ | |
61 | - <?php echo implode(",",$objControles); ?> | |
62 | - ], | |
63 | - numZoomLevels: <?php echo $numzoomlevels;?>, | |
64 | - maxExtent: new OpenLayers.Bounds(<?php echo $maxextent;?>) | |
65 | - }), | |
41 | + layersIniciais: [], | |
42 | + botoes: { | |
43 | + 'pan':true, | |
44 | + 'zoombox':true, | |
45 | + 'zoomtot':true, | |
46 | + 'legenda':true, | |
47 | + 'distancia':true, | |
48 | + 'area':true, | |
49 | + 'identifica':true, | |
50 | + 'linha':true, | |
51 | + 'ponto':true, | |
52 | + 'poligono':true, | |
53 | + 'edita':true, | |
54 | + 'apaga':true, | |
55 | + 'procura':true, | |
56 | + 'salva':true | |
57 | + }, | |
58 | + pontos: [], | |
59 | + marca: "../pacotes/openlayers/img/marker-gold.png", | |
60 | + controles: [ | |
61 | + new OpenLayers.Control.Navigation(), | |
62 | + new OpenLayers.Control.PanZoomBar(), | |
63 | + new OpenLayers.Control.LayerSwitcher({'ascending':false}), | |
64 | + new OpenLayers.Control.ScaleLine(), | |
65 | + new OpenLayers.Control.MousePosition({'separator':' '}), | |
66 | + new OpenLayers.Control.OverviewMap(), | |
67 | + new OpenLayers.Control.KeyboardDefaults() | |
68 | + ], | |
69 | + numzoom: 12, | |
70 | + maxext: new OpenLayers.Bounds(-76.5125927,-39.3925675209,-29.5851853,9.49014852081), | |
71 | + mapa: "", | |
66 | 72 | inicia: function(){ |
67 | - var alayers = []; | |
68 | - <?php | |
69 | - foreach($fundo as $f){ | |
70 | - echo "try{"; | |
71 | - echo "i3GEOOL.".$f.".transitionEffect = 'resize';"; | |
72 | - echo "i3GEOOL.".$f.".setVisibility(false);"; | |
73 | - echo "alayers.push(i3GEOOL.".$f.");"; | |
74 | - echo "}catch(e){}"; | |
73 | + var alayers = [], | |
74 | + fundo = (i3GEOOL.fundo).split(","), | |
75 | + nfundo = fundo.length, | |
76 | + ncontroles = i3GEOOL.controles.length, | |
77 | + i; | |
78 | + if(i3GEOOL.mapa === "") | |
79 | + {alert("O objeto i3GEOOL.mapa precisa ser criado com new OpenLayers.Map()");return;} | |
80 | + i3GEOOL.mapa.setOptions({ | |
81 | + numZoomLevels: i3GEOOL.numzoom, | |
82 | + maxExtent: i3GEOOL.maxext | |
83 | + }); | |
84 | + for(i=0;i<ncontroles;i++){ | |
85 | + i3GEOOL.mapa.addControl(i3GEOOL.controles[i]); | |
86 | + } | |
87 | + for(i=nfundo-1;i>=0;i--){ | |
88 | + try{ | |
89 | + eval("i3GEOOL."+fundo[i]+".transitionEffect = 'resize';"); | |
90 | + eval("i3GEOOL."+fundo[i]+".setVisibility(false);"); | |
91 | + eval("alayers.push(i3GEOOL."+fundo[i]+");"); | |
92 | + } | |
93 | + catch(e){alayers[0].setVisibility(true);} | |
75 | 94 | } |
76 | - echo "try{alayers[0].setVisibility(true);}catch(e){}"; | |
77 | - ?> | |
78 | 95 | i3GEOOL.mapa.addLayers(alayers); |
79 | 96 | |
80 | 97 | if(i3GEOOL.layersIniciais != ""){ | ... | ... |
mashups/openlayers.php
... | ... | @@ -13,30 +13,10 @@ if(!isset($largura)) |
13 | 13 | if(!isset($altura)) |
14 | 14 | {$altura = 400;} |
15 | 15 | // |
16 | -//define o nível de zoom | |
17 | -// | |
18 | -if(!isset ($numzoomlevels)) | |
19 | -{$numzoomlevels = "6";} | |
20 | -// | |
21 | -//define a extensão geográfica que será aplicada | |
22 | -// | |
23 | -if(!isset($maxextent)) | |
24 | -{$maxextent = "-76.5125927 -39.3925675209 -29.5851853 9.49014852081";} | |
25 | -$maxextent = str_replace(" ",",",$maxextent); | |
26 | -// | |
27 | 16 | //define quais controles serão mostrados no mapa |
28 | 17 | // |
29 | 18 | $objControles = array(); |
30 | -if(!isset($controles)){ | |
31 | - $objControles[] = "new OpenLayers.Control.Navigation()"; | |
32 | - $objControles[] = "new OpenLayers.Control.PanZoomBar()"; | |
33 | - $objControles[] = "new OpenLayers.Control.LayerSwitcher({'ascending':false})"; | |
34 | - $objControles[] = "new OpenLayers.Control.ScaleLine()"; | |
35 | - $objControles[] = "new OpenLayers.Control.MousePosition({'separator':' '})"; | |
36 | - $objControles[] = "new OpenLayers.Control.OverviewMap()"; | |
37 | - $objControles[] = "new OpenLayers.Control.KeyboardDefaults()"; | |
38 | -} | |
39 | -else{ | |
19 | +if(isset($controles)){ | |
40 | 20 | $controles = str_replace(" ",",",$controles); |
41 | 21 | $controles = strtolower($controles); |
42 | 22 | $controles = explode(",",$controles); |
... | ... | @@ -59,23 +39,7 @@ else{ |
59 | 39 | //define quais botoes serão mostrados no mapa |
60 | 40 | // |
61 | 41 | $objBotoes = array(); |
62 | -if(!isset($botoes)){ | |
63 | - $objBotoes[] = "'pan':true"; | |
64 | - $objBotoes[] = "'zoombox':true"; | |
65 | - $objBotoes[] = "'zoomtot':true"; | |
66 | - $objBotoes[] = "'legenda':true"; | |
67 | - $objBotoes[] = "'distancia':true"; | |
68 | - $objBotoes[] = "'area':true"; | |
69 | - $objBotoes[] = "'identifica':true"; | |
70 | - $objBotoes[] = "'linha':true"; | |
71 | - $objBotoes[] = "'ponto':true"; | |
72 | - $objBotoes[] = "'poligono':true"; | |
73 | - $objBotoes[] = "'edita':true"; | |
74 | - $objBotoes[] = "'apaga':true"; | |
75 | - $objBotoes[] = "'procura':true"; | |
76 | - $objBotoes[] = "'salva':true"; | |
77 | -} | |
78 | -else{ | |
42 | +if(isset($botoes)){ | |
79 | 43 | $botoes = str_replace(" ",",",$botoes); |
80 | 44 | $botoes = strtolower($botoes); |
81 | 45 | $botoes = explode(",",$botoes); |
... | ... | @@ -107,8 +71,9 @@ else{ |
107 | 71 | {$objBotoes[] = "'procura':false";} |
108 | 72 | if(in_array("salva",$botoes)) |
109 | 73 | {$objBotoes[] = "'salva':false";} |
74 | + $botoes = "{".implode(",",$objBotoes)."}"; | |
110 | 75 | } |
111 | -$botoes = "{".implode(",",$objBotoes)."}"; | |
76 | + | |
112 | 77 | // |
113 | 78 | //define a lista de layers do tipo baselayers |
114 | 79 | //$fundo é um array com a lista dos nomes possíveis ou passados pela url |
... | ... | @@ -118,9 +83,6 @@ if(isset($fundo) && $fundo != ""){ |
118 | 83 | $fundo = str_replace(","," ",$fundo); |
119 | 84 | $fundo = explode(" ",$fundo); |
120 | 85 | } |
121 | -else{ | |
122 | - $fundo = array("est_wms","ol_mma","ol_wms","jpl_wms","osm_wms","top_wms"); | |
123 | -} | |
124 | 86 | // |
125 | 87 | //define quais os layers que comporão o mapa |
126 | 88 | // |
... | ... | @@ -147,10 +109,8 @@ if($temas != "") |
147 | 109 | $layers[] = $layern->name; |
148 | 110 | } |
149 | 111 | $ebase = "false"; |
150 | - if(in_array($tema,$fundo)) | |
151 | - { | |
152 | - $ebase = "true"; | |
153 | - } | |
112 | + if(isset($fundo) && in_array($tema,$fundo)) | |
113 | + {$ebase = "true";} | |
154 | 114 | $objOpenLayers[] = 'new OpenLayers.Layer.WMS( "'.($layern->getmetadata("tema")).'", "../ogc.php?tema='.$tema.'&",{layers:"'.implode(",",$layers).'",transparent: "true", format: "image/png"},{isBaseLayer:'.$ebase.'})'; |
155 | 115 | } |
156 | 116 | else |
... | ... | @@ -231,6 +191,7 @@ Parâmetros: |
231 | 191 | <script type="text/javascript" src="../pacotes/yui270/build/container/container-min.js"></script> |
232 | 192 | <script type="text/javascript" src="../classesjs/compactados/classe_calculo_compacto.js"></script> |
233 | 193 | <script type="text/javascript" src="../pacotes/openlayers/OpenLayers.js.php"></script> |
194 | +<script type="text/javascript" src="openlayers.js.php"></script> | |
234 | 195 | <link rel="stylesheet" href="theme/default/style.css" type="text/css" /> |
235 | 196 | <link rel="stylesheet" href="openlayers.css" type="text/css" /> |
236 | 197 | </head> |
... | ... | @@ -238,7 +199,44 @@ Parâmetros: |
238 | 199 | <div id=i3geoMapa style="width:<?php echo $largura;?>px;height:<?php echo $altura;?>px;"></div> |
239 | 200 | <div id=i3geoSelTemaAtivo style="height:15em;z-index:3000" class=" yui-skin-sam"></div> |
240 | 201 | <script> |
241 | -<?php include("openlayers.js.php");?> | |
202 | +i3GEOOL.layersIniciais = [<?php | |
203 | + if(isset($objOpenLayers) && $objOpenLayers != "") | |
204 | + {echo implode(",",$objOpenLayers);} | |
205 | + else | |
206 | + {echo "''";} | |
207 | +?>]; | |
208 | +<?php if(isset($botoes)){ | |
209 | + echo "i3GEOOL.botoes = $botoes ;"; | |
210 | +} | |
211 | +?> | |
212 | +i3GEOOL.pontos = [<?php | |
213 | + if(isset($pontos)){ | |
214 | + $pontos = str_replace(" ",",",$pontos); | |
215 | + echo $pontos; | |
216 | + } | |
217 | +?>]; | |
218 | +i3GEOOL.marca = "<?php | |
219 | + if(isset($marca)){echo $marca;} | |
220 | + else | |
221 | + {echo "../pacotes/openlayers/img/marker-gold.png";} | |
222 | +?>"; | |
223 | +<?php if(isset($fundo)){ | |
224 | + echo "i3GEOOL.fundo = '".implode(",",$fundo)."';"; | |
225 | +} | |
226 | +?> | |
227 | +<?php if(isset($controles)){ | |
228 | + echo "i3GEOOL.controle = [".implode(",",$objControles)."];"; | |
229 | +} | |
230 | +?> | |
231 | +<?php if(isset($numzoomlevels)){ | |
232 | + echo "i3GEOOL.numzoom = ".$numzoomlevels.";"; | |
233 | +} | |
234 | +?> | |
235 | +<?php if(isset($maxextent)){ | |
236 | + echo "i3GEOOL.maxext = new OpenLayers.Bounds(".$maxextent.");"; | |
237 | +} | |
238 | +?> | |
239 | +i3GEOOL.mapa = new OpenLayers.Map('i3geoMapa',{controls:[]}) | |
242 | 240 | i3GEOOL.inicia(); |
243 | 241 | </script> |
244 | 242 | </body> | ... | ... |