From ec6ddfc09a5ea6ce2cd9322a941fe0c036d04fab Mon Sep 17 00:00:00 2001 From: Edmar Moretti Date: Mon, 19 Sep 2016 18:46:22 -0300 Subject: [PATCH] Correção no template da legenda utilizado no mashup, pois não estava montando corretamente a legenda de camadas WMS --- aplicmap/legendaOgc.html | 8 ++++++-- classesjs/classe_editorol.js | 1 + mashups/openlayersdebug.php | 813 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 820 insertions(+), 2 deletions(-) create mode 100755 mashups/openlayersdebug.php diff --git a/aplicmap/legendaOgc.html b/aplicmap/legendaOgc.html index 2f9f6d1..db384fa 100755 --- a/aplicmap/legendaOgc.html +++ b/aplicmap/legendaOgc.html @@ -1,12 +1,16 @@ diff --git a/classesjs/classe_editorol.js b/classesjs/classe_editorol.js index 4a2a43e..f7a4977 100755 --- a/classesjs/classe_editorol.js +++ b/classesjs/classe_editorol.js @@ -623,6 +623,7 @@ i3GEO.editorOL = { i3GEO.editorOL.mapa.zoomToExtent(b); }, mostraLegenda: function(){ + console.info(i3GEO.editorOL.layersLigados()) var layers = i3GEO.editorOL.layersLigados(), nlayers = layers.length, ins = "",i, icone = "", diff --git a/mashups/openlayersdebug.php b/mashups/openlayersdebug.php new file mode 100755 index 0000000..d08fc13 --- /dev/null +++ b/mashups/openlayersdebug.php @@ -0,0 +1,813 @@ +web; + $w->set("imagepath",dirname($w->imagepath)."/"); + $w->set("imageurl",dirname($w->imageurl)."/"); + // apaga algumas camadas + $l = $m->getlayerbyname("rosadosventos"); + if($l != ""){ + $l->set("status",MS_DELETE); + } + $l = $m->getlayerbyname("copyright"); + if($l != ""){ + $l->set("status",MS_DELETE); + } + $m->save($xbase); + $temas = $xbase; + if (!isset($mapext)){ + $mapext = $m->extent->minx." ".$m->extent->miny." ".$m->extent->maxx." ".$m->extent->maxy; + } +} +if(!isset($mapext)){ + $versao = versao(); + $versao = $versao["principal"]; + if(isset($base) && $base != ""){ + if(file_exists($base)){ + $f = $base; + } + else{ + $f = $locaplic."/aplicmap/".$base.".map"; + } + } + else + { + $f = ""; + if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')){ + $f = $locaplic."/aplicmap/geral1windowsv".$versao.".map"; + } + else{ + if($f == "" && file_exists('/var/www/i3geo/aplicmap/geral1debianv'.$versao.'.map')){ + $f = "/var/www/i3geo/aplicmap/geral1debianv".$versao.".map"; + } + if($f == "" && file_exists('/var/www/html/i3geo/aplicmap/geral1fedorav'.$versao.'.map')){ + $f = "/var/www/html/i3geo/aplicmap/geral1fedorav".$versao.".map"; + } + if($f == "" && file_exists('/opt/www/html/i3geo/aplicmap/geral1fedorav'.$versao.'.map')){ + $f = "/opt/www/html/i3geo/aplicmap/geral1v".$versao.".map"; + } + if($f == "") + { + $f = $locaplic."/aplicmap/geral1v".$versao.".map"; + } + } + } + if(@ms_newMapObj($f)){ + $mapae = ms_newMapObj($f); + $c = $mapae->extent; + $mapext = $c->minx.",".$c->miny.",".$c->maxx.",".$c->maxy; + } +} +// +// imprime na tela a ajuda ao usuário +// +if(!isset($temas) && isset($layers)){ + $temas = $layers; +} +if(!isset($temas)){ + ajuda(); +} +// problema na versão 211 do OpenLayers. Tamanho em % não é +// aceito +// if(!isset($largura)) + // {$largura = 500;} +if(isset($largura) && !isset($altura)){ + $altura = $largura; +} +if(isset($altura) && !isset($largura)){ + $largura = $altura; +} +// +// define quais controles serão mostrados no mapa +// +$objControles = array(); +if(isset($controles)){ + $controles = str_replace(" ",",",$controles); + $controles = strtolower($controles); + $controles = explode(",",$controles); + if(in_array("navigation",$controles)){ + $objControles[] = "new OpenLayers.Control.Navigation()"; + } + if(in_array("panzoombar",$controles)){ + $objControles[] = "new OpenLayers.Control.PanZoomBar()"; + } + if(in_array("layerswitcher",$controles)){ + $objControles[] = "new OpenLayers.Control.LayerSwitcher({'ascending':false})"; + } + if(in_array("scaleline",$controles)){ + $objControles[] = "new OpenLayers.Control.ScaleLine()"; + } + if(in_array("mouseposition",$controles)) + { + $objControles[] = "new OpenLayers.Control.MousePosition({'separator':' '})"; + } + if(in_array("overviewmap",$controles)){ + $objControles[] = "new OpenLayers.Control.OverviewMap()"; + } + if(in_array("keyboarddefaults",$controles)){ + $objControles[] = "new OpenLayers.Control.KeyboardDefaults()"; + } +} +// +// define quais botoes serão mostrados no mapa +// +$objBotoes = array(); +if(isset($botoes)){ + $botoes = str_replace(" ",",",$botoes); + $botoes = strtolower($botoes); + $botoes = explode(",",$botoes); + if(in_array("pan",$botoes)){ + $objBotoes[] = "'pan':true"; + } + if(in_array("zoombox",$botoes)){ + $objBotoes[] = "'zoombox':true"; + } + if(in_array("zoomtot",$botoes)){ + $objBotoes[] = "'zoomtot':true"; + } + if(in_array("zoomout",$botoes)){ + $objBotoes[] = "'zoomout':true"; + } + if(in_array("zoomin",$botoes)) + { + $objBotoes[] = "'zoomin':true"; + } + if(in_array("legenda",$botoes)){ + $objBotoes[] = "'legenda':true"; + } + if(in_array("distancia",$botoes)){ + $objBotoes[] = "'distancia':true"; + } + if(in_array("area",$botoes)){ + $objBotoes[] = "'area':true"; + } + if(in_array("identifica",$botoes)){ + $objBotoes[] = "'identifica':true"; + } + if(in_array("linha",$botoes)){ + $objBotoes[] = "'linha':true"; + } + if(in_array("ponto",$botoes)){ + $objBotoes[] = "'ponto':true"; + } + if(in_array("poligono",$botoes)){ + $objBotoes[] = "'poligono':true"; + } + if(in_array("edita",$botoes)){ + $objBotoes[] = "'edita':true"; + } + if(in_array("listag",$botoes)){ + $objBotoes[] = "'listag':true"; + } + if(in_array("corta",$botoes)){ + $objBotoes[] = "'corta':true"; + } + if(in_array("apaga",$botoes)){ + $objBotoes[] = "'apaga':true"; + } + if(in_array("procura",$botoes)){ + $objBotoes[] = "'procura':true"; + } + if(in_array("salva",$botoes)){ + $objBotoes[] = "'salva':true"; + } + if(in_array("ajuda",$botoes)){ + $objBotoes[] = "'ajuda':true"; + } + if(in_array("fecha",$botoes)){ + $objBotoes[] = "'fecha':true"; + } + if(in_array("tools",$botoes)){ + $objBotoes[] = "'tools':true"; + } + if(in_array("undo",$botoes)){ + $objBotoes[] = "'undo':true"; + } + if(in_array("propriedades",$botoes)){ + $objBotoes[] = "'propriedades':true"; + } + if(in_array("frente",$botoes)){ + $objBotoes[] = "'frente':true"; + } + if(in_array("texto",$botoes)){ + $objBotoes[] = "'texto':true"; + } + if(in_array("novaaba",$botoes)){ + $objBotoes[] = "'novaaba':true"; + } + $botoes = "{".implode(",",$objBotoes)."}"; +} + +// +// define a lista de layers do tipo baselayers +// $fundo é um array com a lista dos nomes possíveis ou passados +// pela url +// cada um deve ser definido em openlayers.js.php +// +if(isset($fundo) && $fundo != ""){ + $fundo = str_replace(","," ",$fundo); + $fundo = explode(" ",$fundo); +} +// +// define quais os layers que comporão o mapa +// +//$objOpenLayers guarda a string javascript que sera usada para criar os objetos +//layer do OpenLayers +if(isset($temas)){ + $objOpenLayers = array(); +} +if($temas != ""){ + $temas = str_replace(" ",",",$temas); + // $temas = strtolower($temas); + $temas = explode(",",$temas); + if(!isset($visiveis)){ + $visiveis = $temas; + } + else{ + $visiveis = str_replace(" ",",",$visiveis); + $visiveis = explode(",",$visiveis); + } + $objOpenLayers = array(); + if(!isset($servidor)){ + $servidor = "../ogc.php"; + } + // + //lista de ferramentas + //lista os nomes de metadados que contem os parametros das + //ferramentas customizaveis e que seraco incluidas na propriedade do layer + // + $listaFerramentas = array("tme","storymap","animagif"); + $dadosTemas = pegaDadosAdminKey("SELECT codigo_tema,link_tema FROM __esq__i3geoadmin_temas WHERE codigo_tema IN('".implode($temas,',')."')","__esq__"); + foreach($temas as $tema){ + // + //utilzado para obter os parametros de ferramentas especificas indicadas nos metadados do LAYER + // + $ferramentas = array(); + if(file_exists($locaplic."/temas/".$tema.".gvp")){ + include_once($locaplic."/pacotes/gvsig/gvsig2mapfile/class.gvsig2mapfile.php"); + $gm = new gvsig2mapfile($locaplic."/temas/".$tema.".gvp"); + $gvsigview = $gm->getViewsNames(); + $objOpenLayers[] = 'new OpenLayers.Layer.WMS( "'.$gvsigview[0].'", "'.$servidor.'?'.$nocache.'tema='.$tema.'&DESLIGACACHE='.$DESLIGACACHE.'&",{layers:"'.$tema.'",transparent: "true", format: "image/png"},{singleTile:false,visibility:true,isBaseLayer:false, ferramentas :'.$ferramentas.')'; + } + else{ + $nomeMap = ""; + if(file_exists($locaplic."/temas/".$tema.".map")){ + $nomeMap = $locaplic."/temas/".$tema.".map"; + } + else{ + if(file_exists($tema)){ + $nomeMap = $tema; + } + else{ + // acontece caso o mapfile tenha sido gerado na pasta + // temporaria por algum sistema + if(file_exists($dir_tmp."/".$tema.".map")){ + $nomeMap = $dir_tmp."/".$tema.".map"; + } + } + } + if($nomeMap != ""){ + $layersNomes = array(); + $layers = array(); + $maptemp = @ms_newMapObj($nomeMap); + if($maptemp){ + $nlayers = $maptemp->numlayers; + for($i=0;$i<($nlayers);++$i) { + $layern = $maptemp->getLayer($i); + // + //verifica se o layer contem ferramentas parametrizadas + // + foreach($listaFerramentas as $lf){ + $meta = $layern->getmetadata($lf); + if($meta != ""){ + $ferramentas[] = "'".$lf."':".$meta; + } + } + $ferramentas = '{'.implode(",",$ferramentas).'}'; + if($layern->getmetadata("PLUGINI3GEO") != ""){ + //obtem os dados necessarios para iniciar o plugin + //os objetos layer (openLayers) sao criados apenas no final + //do processo, pois necessitam usar javascript e nao apenas PHP + $temasPluginI3Geo[] = array( + "name"=>$layern->name, + "tema"=>$layern->getmetadata("tema"), + "plugin"=>$layern->getmetadata("PLUGINI3GEO"), + "cache"=>strtoupper($layern->getmetadata("cache")), + "transitioneffect"=>strtoupper($layern->getmetadata("transitioneffect")), + "tiles"=>strtoupper($layern->getmetadata("tiles")), + "posicaoLayer"=>count($objOpenLayers), + "ferramentas"=>$ferramentas + ); + $objOpenLayers[] = ""; + } + else{ + $layersNomes[] = $layern->name; + $layers[] = $layern; + } + } + $nomeLayer = implode(",",$layersNomes); + $tituloLayer = $layern->getmetadata("tema"); + $ebase = "false"; + if(isset($fundo) && $fundo != ""){ + if(in_array($tema,$fundo)){ + $ebase = "true"; + } + } + $visivel = "false"; + if(in_array($tema,$visiveis)){ + $visivel = "true"; + } + if(strtolower($DESLIGACACHE) != "sim" && $nlayers == 1 && strtoupper($layern->getmetadata("cache")) == "SIM" && $layern->getmetadata("PLUGINI3GEO") == ""){ + // + //obtem a fonte + // + $link_tema = $dadosTemas[$layern->name]; + $link_tema = $link_tema["link_tema"]; + if($layern->type != 2 && $layern->type != 3){ + $opacidade = 1; + } + // + //verifica se deve aplicar filtro + // + $filtro = $_GET["map_layer_".$layern->name."_filter"]; + if(!empty($filtro)){ + $DESLIGACACHE = "sim"; + $nocache = "map_layer_".$layern->name."_filter=".$filtro."&".$nocache; + } + $teffect = 'transitionEffect: "resize",'; + if(strtoupper($layern->getmetadata("transitioneffect")) == "NAO"){ + $teffect = 'transitionEffect: null,'; + } + // nesse caso o layer e adicionado como TMS + // tms leva os parametros do TMS + if($layern->getmetadata("extensao") == ""){ + $objOpenLayers[] = 'new OpenLayers.Layer.TMS("'.$tituloLayer.'", "'.$servidor.'?'.$nocache.'tema='.$tema.'&DESLIGACACHE='.$DESLIGACACHE.'",{'.$teffect.' tileOrigin: new OpenLayers.LonLat(-180, -90),opacity:'.$opacidade.',serviceVersion:"&tms=",visibility:'.$visivel.',isBaseLayer:'.$ebase.',layername:"'.$nomeLayer.'",type:"png", ferramentas :'.$ferramentas.',link_tema:"'.$link_tema.'"})'; + } + else{ + $objOpenLayers[] = 'new OpenLayers.Layer.TMS("'.$tituloLayer.'", "'.$servidor.'?'.$nocache.'tema='.$tema.'&DESLIGACACHE='.$DESLIGACACHE.'",{'.$teffect.' tileOrigin: new OpenLayers.LonLat(-180, -90),maxExtent:['.str_replace(" ",",",$layern->getmetadata("extensao")).'],opacity:'.$opacidade.',serviceVersion:"&tms=",visibility:'.$visivel.',isBaseLayer:'.$ebase.',layername:"'.$nomeLayer.'",type:"png", ferramentas :'.$ferramentas.',link_tema:"'.$link_tema.'"})'; + } + // cria um clone WMS para efeitos de getfeatureinfo + $objOpenLayers[] = 'new OpenLayers.Layer.WMS( "'.$tituloLayer.'", "'.$servidor.'?'.$nocache.'tema='.$tema.'&DESLIGACACHE='.$DESLIGACACHE.'&",{cloneTMS:"'.$nomeLayer.'",layers:"'.$nomeLayer.'",transparent: "true", format: "image/png"},{displayInLayerSwitcher:false,transitionEffect : null,singleTile:true,visibility:false,isBaseLayer:false, ferramentas :'.$ferramentas.',link_tema:"'.$link_tema.'"})'; + } + else{ + foreach($layers as $l){ + $singleTile = "false"; + if(strtoupper($l->getmetadata("TILES")) == "NAO"){ + $singleTile = "true"; + } + $tituloLayer = $l->getmetadata("tema"); + $nomeLayer = $l->name; + $link_tema = $dadosTemas[$nomeLayer]; + $link_tema = $link_tema["link_tema"]; + $visivel = "false"; + if($l->status == MS_DEFAULT || in_array($tema,$visiveis)){ + $visivel = "true"; + } + if($l->type != 2 && $l->type != 3){ + $opacidade = 1; + } + // + //verifica se deve aplicar filtro + // + $filtro = $_GET["map_layer_".$l->name."_filter"]; + if(!empty($filtro)){ + $DESLIGACACHE = "sim"; + $nocache = "map_layer_".$l->name."_filter=".$filtro."&".$nocache; + } + $teffect = 'transitionEffect: "resize",'; + if(strtoupper($l->getmetadata("transitioneffect")) == "NAO"){ + $teffect = 'transitionEffect: null,'; + } + if($tituloLayer != ""){ + $objOpenLayers[] = 'new OpenLayers.Layer.WMS( "'.$tituloLayer.'", "'.$servidor.'?'.$nocache.'tema='.$tema.'&DESLIGACACHE='.$DESLIGACACHE.'&",{opacity:'.$opacidade.',layers:"'.$nomeLayer.'",transparent: "true", format: "image/png"},{'.$teffect.' singleTile:'.$singleTile.',visibility:'.$visivel.',isBaseLayer:'.$ebase.', ferramentas :'.$ferramentas.',link_tema:"'.$link_tema.'"})'; + } + else{ + $objOpenLayers[] = 'new OpenLayers.Layer.WMS( "'.$tituloLayer.'", "'.$servidor.'?'.$nocache.'tema='.$tema.'&DESLIGACACHE='.$DESLIGACACHE.'&",{opacity:'.$opacidade.',layers:"'.$nomeLayer.'",transparent: "true", format: "image/png"},{'.$teffect.' displayInLayerSwitcher:false,singleTile:'.$singleTile.',visibility:'.$visivel.',isBaseLayer:'.$ebase.', ferramentas :'.$ferramentas.',link_tema:"'.$link_tema.'"})'; + } + } + } + } + } + else{ + echo $tema." não foi encontrado.
"; + } + } + } +} +function nomeRandomicoM($n=10){ + $nomes = ""; + $a = 'azertyuiopqsdfghjklmwxcvbnABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $max = 51; + for($i=0; $i < $n; ++$i) + { + $nomes .= $a{mt_rand(0, $max)}; + } + return $nomes; +} +function ajuda(){ + echo " +

+	Mashup OpenLayers
+	Parâmetros:
+	restauramapa - id do mapa armazenado no sistema de administracao e que será restaurado para ser aberto novamente (veja em i3geo/admin/html/mapas.html)
+	opacidade - opacidade (de 0 a 1) aplicada aos temas do tipo poligonal ou raster (default 1)
+	kml - lista de endereços (url) de um arquivos kml que serão adicionados ao mapa. Separado por ','
+	servidor - por default é ../ogc.php o que força o uso do i3geo local. Esse é o programa que será utilizado em conjunto com a lista definida no parâmetro 'temas'
+	temas - lista com os temas (mapfiles) do i3Geo que serão incluídos no mapa. Pode ser incluído um arquivo mapfile que esteja fora da pasta i3geo/temas. Nesse caso, deve-se definir o caminho completo do arquivo e também o parâmetro &layers
+	visiveis - lista de temas (mesmos nomes do parâmetro temas) que iniciarão como visíveis no mapa. Se não for definido, todos os temas serão visíveis.
+	numzoomlevels - número de níveis de zoom, default=12
+	minresolution - resolução mínima. Utilizada para definir o primeiro nível de zoom. Default=0.703125
+	maxextent - extensão geográfica máxima do mapa (xmin,ymin,xmax,ymax)
+	mapext - extensão geográfica inicial do mapa (xmin,ymin,xmax,ymax)
+	largura - lagura do mapa em pixels
+	altura - altura do mapa em pixels
+	pontos - lista de coordenadas x e y que serão incluídas como marcas no mapa
+	marca - nome do arquivo que contém a imagem que será utilizada para mostrar as coordenadas
+	tiles (true|false) - indica se o modo tile será usado ou não (true por default). O modo tile pode tornar o mashup mais lento em algumas situações.
+	incluilayergrafico (true|false) - indica se o layer que recebe elementos gráficos será adicionado ou não ao mapa
+	ativalayerswicther (true|false) - inicia o mapa com a caixa de escolha das camadas (layerSwitcher) aberta ou não. Por default, inicia fechada
+	ativarodadomouse (true|false) - ativa ou não o zoom com base na roda do mouse (default é true)
+	legendahtml (true|false) - ativa ou não (default é false) a geração de legenda do tipo HTML no lugar de imagem png. Legendas HTML podem ser modificadas com base em CSS. A legenda é construída com o template i3geo/aplicmap/legendaOgc.html.
+	desligacache (sim|nao) - desativa o uso do cache de imagens em disco do lado do servidor, forçando a renderização dos tiles de cada camada em cada requisição
+	nocache (sim) - evita o uso de imagens em cache existentes no navegador do usuário
+
+	Filtros
+
+	filtros podem ser adicionados incluindo o parametro da seguinte forma: &map_layer__filter=
+
+	Exemplo de filtro
+
+	?map_layer__lbiomashp_filter=(('[CD_LEGENDA]'='CAATINGA'))
+
+	no caso de camadas Postgis basta usar map_layer__lbiomashp_filter=cd_legenda='CAATINGA'
+
+	fundo - lista com os nomes, separados por ',' dos layers que serão usados como fundo para o mapa. Se não for definido,
+	será usado o default. O primeiro da lista será o fundo ativo. Se na lista de temas de fundo estiver algum
+	tema incluido com o parametro 'temas', esses serão incluídos como temas de fundo.
+	Quando for vazio, o ultimo layer sera considerado como o layer de fundo
+	Os seguintes fundos podem usados nessa lista:
+
+	e_oce - ESRI Ocean Basemap
+	e_ims - ESRI Imagery World 2D
+	e_wsm - ESRI World Street Map
+	ol_mma - base cartográfica do Brasil
+	ol_wms - base mundial da Meta Carta
+	top_wms - toponímia do servidor do MMA usado no mapa de referência
+	est_wms - estados do Brasil
+
+	controles - lista com os nomes dos controles que serão adicionados ao mapa. Se não for definido, todos os controles serão adicionados
+	navigation
+	panzoombar
+	layerswitcher
+	scaleline
+	mouseposition
+	overviewmap
+	keyboarddefaults
+	botoes - lista com os nomes dos botoes que serão adicionados ao mapa. Se não for definido, todos os botões serão adicionados
+	pan
+	zoombox
+	zoomtot
+	zoomin
+	zoomout
+	distancia
+	area
+	identifica
+	ponto
+	linha
+	poligono
+	texto
+	edita
+	listag (lista geometrias)
+	apaga
+	captura
+	procura
+	frente
+	propriedades
+	tools
+	undo
+	salva
+	ajuda
+	fecha
+	corta
+	legenda
+	novaaba
+
+	Para ver a lista de códigos de temas, que podem ser utilizados no parâmetro 'temas', acesse:
+	lista de temas. Os códigos são mostrados em vermelho.
+
+	Exemplo:
+
+	<iframe height='400px' src='http://mapas.mma.gov.br/i3geo/mashups/openlayers.php?temas=bioma&altura=350&largura=350' style='border: 0px solid white;' width='400px'></iframe>
+
+	";
+	exit;
+}
+?>
+
+
+
+
+
+
+
+ 0){
+	echo ''."\n";
+	//echo ''."\n";
+	echo ''."\n";
+}
+?>
+
+
+
+
+
+	';
+	}
+	else{
+		echo '
'; + } + + ?> + + + + -- libgit2 0.21.2