Add WMS layer

349 views
Skip to first unread message

Luca Santaniello

unread,
May 18, 2011, 3:41:41 AM5/18/11
to OpenTripPlanner Developers
Hi all,

Can I add wms layer to map? if yes, How can I do it?

Thanks

Vivien Deparday

unread,
May 18, 2011, 11:03:33 AM5/18/11
to opentripp...@googlegroups.com
Hi Luca,
to add a WMS layer, you have to edit the config.js file that is located in /opentripplanner-webapp/src/main/webapp/js/otp/
You will see there is an attribute called baseLayer (around line 60). I think by default there is only one OSM layer constructor. You can change that to an array and add your WMS layer, with something along those lines ( I have not tried the code):

baseLayer: [ new OpenLayers.Layer.OSM({
            url: [
                  "http://a.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png",
                  "http://b.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png",
                  "http://c.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png"
            ],
            numZoomLevels: 20
        }),
                new OpenLayers.Layer.WMS( "OpenLayers WMS,"http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basics'})
],

I have put some default WMS parameters but you can find more possibilities in the examples and the api docs sections of the OpenLayer website to find the ones you need for your WMS server. 

Also, if you want to be able to switch between the layer you have to add the LayerSwitcher control. To do that, still in the config.js file, you can find the controls array ( around line 53) and you can add this:

controls: [
                       new OpenLayers.Control.LayerSwitcher()
               ]

There might be small other things to modify but that should get you started.

Cheers,

Viv

Luca Santaniello

unread,
May 20, 2011, 10:20:55 AM5/20/11
to OpenTripPlanner Developers
Thank you very much!

Luca Santaniello

unread,
May 23, 2011, 5:33:18 AM5/23/11
to OpenTripPlanner Developers
I try this:

baseLayer: [

new OpenLayers.Layer.OSM({
url: [
"http://a.tah.openstreetmap.org/Tiles/tile/${z}/$
{x}/${y}.png",
"http://b.tah.openstreetmap.org/Tiles/tile/${z}/$
{x}/${y}.png",
"http://c.tah.openstreetmap.org/Tiles/tile/${z}/$
{x}/${y}.png"
],
numZoomLevels: 20
}),

new OpenLayers.Layer.WMS("NASA Global Mosaic", "http://
wms.jpl.nasa.gov/wms.cgi", {layers: "modis,global_mosaic"})
],


but I get js error...

Error: layer.div is undefined
Source: http://localhost:8081/opentripplanner-webapp/js/lib/openlayers/OpenLayers.js
Row: 825


On 18 Mag, 17:03, Vivien Deparday <vivien.depar...@gmail.com> wrote:

Vivien Deparday

unread,
May 23, 2011, 12:35:36 PM5/23/11
to opentripp...@googlegroups.com
Hi Luca,

as I thought, I forgot some other small changes. To support multiple
layers, you should also modify Map.js around line 84 to look like this
else {
this.map.addLayers(this.baseLayer);
}
this.map.setBaseLayer(this.baseLayer[0], true);

While looking into it, I also noticed that when you add the layer
switcher control in the config.js, you will no longer have the default
control (zoom,etc.) To solve that, one option is to add the
layerSwitcher as a default control near line 92 of Map.js and in the
OpenLayersUtil.js. Let me know if you need more detailed directions on this.

I may try to put a patch together to ease the configuration for single
and multiple layers.

Cheers,

Viv

Luca Santaniello

unread,
May 24, 2011, 5:19:42 AM5/24/11
to OpenTripPlanner Developers
Hi Vivien,

can you give me more detailed directions on this, please?

Thanks

On 23 Mag, 18:35, Vivien Deparday <vivien.depar...@gmail.com> wrote:
> Hi Luca,
>
> > Source:http://localhost:8081/opentripplanner-webapp/js/lib/openlayers/OpenLa...

Luca Santaniello

unread,
Sep 5, 2011, 3:56:43 AM9/5/11
to opentripp...@googlegroups.com
Can you help me please? I don't understand how add multiple layer. I want add geoserver layer to my map!

Thanks

Luca Santaniello

unread,
Sep 9, 2011, 10:38:09 AM9/9/11
to opentripp...@googlegroups.com
I add new OpenLayers.Control.LayerSwitcher() but when I switch base layer I don't see my geoserver layer

new OpenLayers.Layer.WMS("OSPEDALI", "http://xxxx/geoserver/wms", { layers: "myLayers:hospitals", transparent: false}, {visibility: false, singleTile: false})

Help me please

Frank Purcell

unread,
Sep 9, 2011, 11:35:34 AM9/9/11
to opentripp...@googlegroups.com
Hey Luca,

The entry point for adding map layers is in the Controller:


On line 50, the map controller is created: this.map = new otp.core.Map(this.config.map); Calling this.map.getMap(), will give you the OpenLayers object that you can further addLayers() to: http://dev.openlayers.org/releases/OpenLayers-2.10/doc/apidocs/files/OpenLayers/Map-js.html#OpenLayers.Map.addLayer

You're on your own from here, as we haven't really built api support for adding new layers to the map.

--Frank
Message has been deleted

Luca Santaniello

unread,
Sep 12, 2011, 3:26:57 AM9/12/11
to opentripp...@googlegroups.com
Thanks, I know OpenLayer very well.

I add my layer using this code:

var myLayer= new OpenLayers.Layer.WMS("LUCA", "http://xxxx/geoserver/wms", { layers: "prefix:layerName", transparent: false, styles: 'point'}, {visibility: true, singleTile: false});                   
myLayer.setIsBaseLayer(false);
                               
this.map.getMap().addLayers([myLayer]);

Layer is added to map but I dont see it well. If I zoom out I see that the layer is loaded, but it is not good. If I zoom in the layer I don't see it.

I attach screenshoot also.

Thanks

Luca
Immagine.JPG
Reply all
Reply to author
Forward
0 new messages