[Portugal] duvidas sobre openlayers
Pedro Costa
pedrocostaarma sapo.pt
Sexta-Feira, 2 de Dezembro de 2011 - 07:51:03 EST
Jorge ajuda-me também no seguinte sff, estou a tentar agora adicionar um
layer osm no código em baixo:
<?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="http://openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function init() {
var bounds = new OpenLayers.Bounds(
-15699, 188532, -13689, 190828);
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_ruas = new OpenLayers.Layer.WMS(
"ruas",
"http://localhost:8080/geoserver/wms",
{'layers': 'Vizela:ruas', 'format':'image/png',
'transparent':'true',strategies:[new OpenLayers.Strategy.Fixed()]},
{'opacity': 1.0, 'isBaseLayer': true, 'visibility': true}
);
map.addLayer(wms_ruas);
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>
Mas sinceramente não sei bem onde o inserir, já tentei em vários locais
e não funciona.POdes ajudar?
Estava a tentar adicionando o seguinte:
var osm_layer = new OpenLayers.Layer.OSM(
'OpenStreetMap Layer'
);
Abraço
On 02-12-2011 12:37, Jorge de Jesus wrote:
> Ok parece que o assunto esta resolvido
>
> On 02/12/11 11:42, Pedro Costa wrote:
>> Consegui resolver...Tinha de mudar postgis para o nome da store que
>> tinha e já funciona:-)
>>
>> Obrigado pessoal
>> Vou continuar o estudo
>>
>> ABraço
>>
>>
>>
>> -------- Original Message --------
>> Subject: Re: [Portugal] duvidas sobre openlayers
>> Date: Fri, 02 Dec 2011 11:26:55 +0000
>> From: Pedro Costa <pedrocostaarma sapo.pt>
>> To: Jorge de Jesus <jmdj pml.ac.uk>
>>
>>
>>
>>
>> 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
>>
>>
>>
>>
>>
>>
>>
>>
>> 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 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 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.
>>>
>>> ------------------------------------------------------------------------
>>>
>>>
>>
>>
>>
>> _______________________________________________
>> Portugal mailing list
>> Portugal lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/portugal
>
>
> --
> 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 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.
>
> ------------------------------------------------------------------------
>
>
-------------- próxima parte ----------
Um anexo em HTML foi limpo...
URL: http://lists.osgeo.org/pipermail/portugal/attachments/20111202/0a6a698a/attachment-0001.html
Mais informações acerca da lista Portugal