[Portugal] duvidas sobre openlayers
Jorge de Jesus
jmdj pml.ac.uk
Sexta-Feira, 2 de Dezembro de 2011 - 07:36:33 EST
On 02/12/11 11:26, Pedro Costa wrote:
>
> Obrigado Jorge. Já eliminei os erros no entanto o openlayers não está
> a carregar o layer ruas, a página abre mas sem eu conseguir ver o layer.
>
> Tentei wms_ruas.getExtent() no firebug e obtenho o seguinte erro:
> ReferenceError: wms_ruas is not defined.
> Penso que não está a conseguir ir buscar o layer ao geoserver, alguma
> segestão do que poderá ser?
>
>
> Obrigado pelas repostas de todos
>
Oi
Como nao tens o wms_ruas como variable global o firebug nao consegue ver
a variable, tens duas opcoes:
1)wms_ruas declarado fora do init() do genero
var map=null;
var wms_ruas=null;
Ou entao dentro da funcao init() fares um dump do objecto depois de criado
console.log(wms_ruas)
Outra coisa ve na seccao "Net" se o browser esta a contactar o servico
WMS e se esta a receber alguma coisa
Jorge
>
>
>
>
>
>
>
> On 02-12-2011 09:32, Jorge de Jesus wrote:
>> On 02/12/11 00:37, Pedro Costa wrote:
>>> Pessoal podem ajudar-me também nas seguintes dúvidas:
>>>
>>>
>>> Eu tenho o html que segue em baixo, quando o abro, o firebug indica
>>> um erro assim:
>>>
>>> OpenLayers is not defined
>>> var bounds = new OpenLayers.Bounds(
>>>
>>>
>> "OpenLayers is not defined" acho que este e' o error que tens, parece
>> que a pagina nao carregou o OpenLayers.js. Ve no tab "Net">js do
>> firefox se ele carregou o OpenLayers, experimenta usar a versao online:
>>
>>
>> <script type="text/javascript"
>> src="http://openlayers.org/dev/OpenLayers.js"></script>
>>
>>
>> Eu experimentei: var bounds = new OpenLayers.Bounds(-23941,
>> 208039,-21480, 210148);
>>
>> E esta tudo OK
>>
>> Quanto aos bounds, experimenta meter os bounds iguais aos descritos
>> no WMS (faz um pedido getCapabilites), depois de teres adicionado o a
>> layer wms_ruas, podes usar wms_ruas.getExtent():
>>
>> map.zoomToExtent(wms_ruas.getExtent());
>>
>> So uma chamada de atencao o object wms_ruas so esta totalmante
>> operacional depois de adicionado ao mapa e depois de feito o pedido
>> ao servico pelo openlayers, ate teres o objecto totalmente criado
>> certas variaveis e metodos dao error.
>>
>> Jorge
>>
>>> Penso que seja porque os bounds estão mal definidos. A minha dúvida
>>> é o seguinte, como posso saber os bounds correctos? E em que src
>>> tenho de os escrever?Igual ao src do layer que quero ir buscar?Será
>>> que funciona se eu executar no firebug map.zoomToMaxExtent e
>>> map.getExtent no layer preview do geoserver?
>>>
>>> Tentei isso e dá-me os valores: topp right left e bottom, mas porque
>>> ordem os escrevo?
>>>
>>>
>>> Podem tirar-me estas dúvidas?
>>>
>>> Obrigado
>>>
>>>
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
>>> "DTD/xhtml1-strict.dtd">
>>> <html xmlns="http://www.w3.org/1999/xhtml">
>>> <head>
>>> <title>O meu primeiro mapa</title>
>>> <meta http-equiv="Content-Type" content="text/html;
>>> charset=UTF-8" />
>>> <script src="/openlayers/lib/OpenLayers.js"
>>> type="text/javascript"></script>
>>> <script type="text/javascript">
>>> var map;
>>> function init() {
>>>
>>> var bounds = new OpenLayers.Bounds(
>>> -23941, 208039,
>>> -21480, 210148
>>> );
>>>
>>> var options = {
>>> controls: [ new OpenLayers.Control.Navigation(),
>>> new
>>> OpenLayers.Control.PanZoom(),
>>> new
>>> OpenLayers.Control.LayerSwitcher()],
>>> maxExtent: bounds,
>>> maxResolution: 9.61328125,
>>> projection: "EPSG:27492",
>>> units: 'm'
>>>
>>> };
>>>
>>> map = new OpenLayers.Map('map', options);
>>> var wms = new OpenLayers.Layer.WMS(
>>> 'OpenLayers WMS',
>>> 'http://localhost:8080/geoserver/wms', {
>>> layers: 'topp:ruas'
>>> }, {} );
>>> map.addLayer(wms);
>>> if(!map.getCenter()) {
>>> map.zoomToMaxExtent();
>>> }
>>> }
>>> </script>
>>> </head>
>>> <body onload='init();'>
>>> <h1>Mapa mundo</h1>
>>> <div id='map' style='width: 500px; height: 500px;'>
>>> </div>
>>> </body>
>>> </html>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On 01-12-2011 13:22, Jorge de Jesus wrote:
>>>> Algumas respostas peco desculpas pelo email meio algarviado
>>>>
>>>>
>>>> On 01/12/11 12:41, Pedro Costa wrote:
>>>>> Pessoal será que podiam ajudar-me com as seguintes dúvidas do
>>>>> openlayeres, as dúvidas são relativas ao exemplo disponivel aqui:
>>>>>
>>>>> http://geobox.geospot.pt/pt/index.php/Edi%C3%A7%C3%A3o_com_OpenLayers
>>>>>
>>>>>
>>>>> *1) O que sgnificam estas diferentes partes do código:*
>>>>> <link rel="stylesheet" href="/openlayers/theme/default/style.css" type="text/css" />
>>>>>
>>>> Isto e' un link pro CSS (cascade style sheet) que define como
>>>> varios elementos vao ser rendizados (rendered), ou seja cores,
>>>> tipos de letras icons, e onde os menus (exemplo: LayerSwitcher) vao
>>>> aparecer etc. Da uma vista de olhos ao ficheiro e experimenta a
>>>> fazer alteracoes :) .Se nao sabes trabalhar com CSS da uma vista de
>>>> olhos a: http://www.w3schools.com/css/
>>>>> OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
>>>>>
>>>> Aiiiiiii a santa bendita proxy !!! Da uma vista de olhos aqui:
>>>> http://trac.osgeo.org/openlayers/wiki/FrequentlyAskedQuestions#ProxyHost
>>>>
>>>>
>>>> Basicamente em Javascript tu nao podes chamar um URL que nao esteja
>>>> no mesmo dominio, por exemplo se o teu site esta em
>>>> http://localhost mas o WFS esta em http://WFSsite.pt o codigo de
>>>> javascipript nao pode aceder a http://WFSsite.pt, esta situacao eh
>>>> conhecida por "cross domain" da uma vista de olhos na internet
>>>>
>>>> Actualmente os browsers mais recentes podem contactar outros
>>>> dominios se o servidor no outro dominio suportar a norma CORS:
>>>> http://www.leggetter.co.uk/2010/03/12/making-cross-domain-javascript-requests-using-xmlhttprequest-or-xdomainrequest.html
>>>>
>>>> Basicamente, a melhor estrategia eh de instalar a proxy no teu
>>>> servidor e deixar que o openlayers trate do assunto.
>>>>
>>>> Normalmente, o firebug manda-te um erro quando tens cross-domain
>>>> (normalmente o browser nao diz nada e nao faz nada quando tens
>>>> cross-domain)
>>>>> *2) Porquê é que aqui a classe map é nula?*
>>>>>
>>>>
>>>> var map=null; Bem uns gostam cozido outros gosta de assado :0 eh
>>>> so um estilo de programacao, se usares var map; vai dar ao mesmo.
>>>> Uma chamada de atencao, o var map=null; esta fora da funcao init(),
>>>> quer dizer que eh uma variable global, que pode ser acedida por
>>>> qualquer funcao. Normalmente um erro comum e' meter "var map"
>>>> dentro do init()
>>>>
>>>> Pessoalmente meto o map e as layers sempre fora da funcao de
>>>> inicializacao, ja que variaveis globais parecem logo no firebug.
>>>>
>>>>
>>>>> var map = null;
>>>>>
>>>>> *3) NO exemplo em questão que segue em baixo, temos de por o schema para o layer do geoserver em questão, trata-se de
>>>>> um url? Como posso descobrir url para o layer que pretendo? Tentei trocar o nome deste exemplo (participante)
>>>>> por um layer que tenho e colar no browser mas não abre nada...
>>>>> POdem dar-me uma dicas?
>>>>>
>>>>> *
>>>>
>>>> Eu raramente trabalho com WFS e estive a ver no codigo do
>>>> openlayers (Protocol/WFS/v1.js) temos a seguinte definicao da
>>>> propriedade schema:
>>>>
>>>> /**
>>>> * Property: schema
>>>> * {String} Optional schema location that will be included in the
>>>> * schemaLocation attribute value. Note that the feature
>>>> type schema
>>>> * is required for a strict XML validator (on transactions
>>>> with an
>>>> * insert for example), but is *not* required by the WFS
>>>> specification
>>>> * (since the server is supposed to know about feature type
>>>> schemas).
>>>> */
>>>> schema: null,
>>>>
>>>>
>>>> Basicamente e' um URL que define o schema dos dados em XML e que
>>>> pode ser usado para validar os conteudos, no exemplo passas um
>>>> DescribeFeatureType que gera un esquema que define a estrutura do
>>>> XML dos teus dados. Em varios exemplos nunca vi o uso do schema:
>>>>
>>>> http://workshops.opengeo.org/stack-intro/openlayers.html
>>>>
>>>> Eu uso mais mapserver, ja que nao me dou muito bem com o JAVA
>>>> (serei demasiado calhau?)
>>>>
>>>>> *
>>>>> 4)Quando devo utilizar a livraria do openlayers no localhost e quando devo utilizar a online?Tanto faz ou quais as vantagens
>>>>> de um e de outro?
>>>>>
>>>>>
>>>>> Obrigado
>>>>> Bom feriado a todos
>>>>> *
>>>> uma livraria no localhost e' mais rapida para fazer o upload e nao
>>>> estas dependente de "terceiros"
>>>>
>>>> E para concluir: O firebug e' o melhor amigo do Homem (depois do
>>>> cao e' claro)
>>>>
>>>>
>>>> Bom feriado, eu vou marfar
>>>>
>>>> Jorge
>>>>
>>>> --
>>>> PGP public key: 0x595FF9D3
>>>>
>>>> ------------------------------------------------------------------------
>>>>
>>>> Plymouth Marine Laboratory
>>>> Registered Office:
>>>> Prospect Place
>>>> The Hoe
>>>> Plymouth PL1 3DH
>>>>
>>>> Website: www.pml.ac.uk <http://www.pml.ac.uk>
>>>> Click here for PML Annual Review
>>>> <http://www.pml.ac.uk/pdf/PMLAR2010.pdf>
>>>> Registered Charity No. 1091222
>>>> PML is a company limited by guarantee
>>>> registered in England & Wales
>>>> company number 4178503
>>>>
>>>> Please think before you print.
>>>>
>>>> ------------------------------------------------------------------------
>>>>
>>>> This e-mail, its content and any file attachments are confidential.
>>>>
>>>> If you have received this e-mail in error please do not copy,
>>>> disclose it to any third party or use the contents or attachments
>>>> in any way. Please notify the sender by replying to this e-mail or
>>>> e-mail forinfo at pml.ac.uk and then delete the email without making
>>>> any copies or using it in any other way.
>>>>
>>>> The content of this message may contain personal views which are
>>>> not the views of Plymouth Marine Laboratory unless specifically stated.
>>>>
>>>> You are reminded that e-mail communications are not secure and may
>>>> contain viruses. Plymouth Marine Laboratory accepts no liability
>>>> for any loss or damage which may be caused by viruses.
>>>>
>>>> ------------------------------------------------------------------------
>>>>
>>>>
>>>
>>
>>
>> --
>> PGP public key: 0x595FF9D3
>>
>> ------------------------------------------------------------------------
>>
>> Plymouth Marine Laboratory
>> Registered Office:
>> Prospect Place
>> The Hoe
>> Plymouth PL1 3DH
>>
>> Website: www.pml.ac.uk <http://www.pml.ac.uk>
>> Click here for PML Annual Review
>> <http://www.pml.ac.uk/pdf/PMLAR2010.pdf>
>> Registered Charity No. 1091222
>> PML is a company limited by guarantee
>> registered in England & Wales
>> company number 4178503
>>
>> Please think before you print.
>>
>> ------------------------------------------------------------------------
>>
>> This e-mail, its content and any file attachments are confidential.
>>
>> If you have received this e-mail in error please do not copy,
>> disclose it to any third party or use the contents or attachments in
>> any way. Please notify the sender by replying to this e-mail or
>> e-mail forinfo at pml.ac.uk and then delete the email without making any
>> copies or using it in any other way.
>>
>> The content of this message may contain personal views which are not
>> the views of Plymouth Marine Laboratory unless specifically stated.
>>
>> You are reminded that e-mail communications are not secure and may
>> contain viruses. Plymouth Marine Laboratory accepts no liability for
>> any loss or damage which may be caused by viruses.
>>
>> ------------------------------------------------------------------------
>>
>>
>
--
PGP public key: 0x595FF9D3
--------------------------------------------------------------------------------
Plymouth Marine Laboratory
Registered Office:
Prospect Place
The Hoe
Plymouth PL1 3DH
Website: www.pml.ac.uk
Click here for PML Annual Review
Registered Charity No. 1091222
PML is a company limited by guarantee
registered in England & Wales
company number 4178503
Please think before you print
--------------------------------------------------------------------------------
This e-mail, its content and any file attachments are confidential.
If you have received this e-mail in error please do not copy, disclose it to any third party or use the contents or attachments in any way. Please notify the sender by replying to this e-mail or e-mail forinfo at pml.ac.uk and then delete the email without making any copies or using it in any other way.
The content of this message may contain personal views which are not the views of Plymouth Marine Laboratory unless specifically stated.
You are reminded that e-mail communications are not secure and may contain viruses. Plymouth Marine Laboratory accepts no liability for any loss or damage which may be caused by viruses.
--------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/portugal/attachments/20111202/bce30fcc/attachment-0001.html
Mais informações acerca da lista Portugal