[Users] How to add array of layers / LayerStore to map
Matt Priour
mpriour at kestrelcomputer.com
Thu Feb 24 17:06:50 CET 2011
Yes GeoExt can do this all automatically. Instead of using nodeType:'gx_layer' use should simply use 'gx_baselayercontainer'. Define the text property and the children are auto-loaded with just base layers and they have radio buttons instead of checkboxes.
Make sure to define your mapPanel FIRST
So your layerList array would be more like this:
var layerList =[{
text: 'Background Layers',
leaf: false,
expanded: true,
nodeType:'gx_baselayercontainer'},
... other non-base layer nodes or a nodeType of 'gx_overlaylayercontainer' to load all non-base layers with checkboxes
]
You should see the examples and doc on the GeoExt website for more info. Specifically:
http://api.geoext.org/1.0/examples/tree.html
Ignore the JSON.write / read stuff, that is there so that people can edit the layer tree in the example.
You want the stuff inside the write function.
Matt Priour
From: Christian Gadge
Sent: Thursday, February 24, 2011 9:30 AM
To: Matt Priour
Cc: users at geoext.org
Subject: Re: [Users] How to add array of layers / LayerStore to map
Thank you Matt. This works.
Yes, I tried to use the TreePanel layers to be "added" to map. I have checkboxes for all layers.
Using an array of all available layers, all these layers are now visible within the map. But there should be only one layer visible at time.
So in that case I have to define a GeoExt.data.LayerStore of "checked" layers to be drawn in map? Can this be done automatically? Now all layers are visible and I have to uncheck them first.
regards,
Christian
Am 24.02.2011 16:16, schrieb Matt Priour:
first you don't need parenthesis
second I mis-typed that config below. And I mis-read what you wrote.
your variable layerList is a portion of TreePanel config. You can't use that as the layers parameter in MapPanel. The layers parameter is ONLY valid with a simple array of OpenLayers layers OR a GeoExt.data.LayerStore
I was thinking that you had something like:
var layerlist = [OLwms, USGSwms, NASAwms]
in that case the layers parameter should read:
...
layers:layerlist
...
layerlist is already an array so you don't need to enclose it in [ ]. That makes it an array of an array, which is not going to be read correctly by the MapPanel constructor
Sorry for the confusion
Matt Priour
From: Christian Gadge
Sent: Thursday, February 24, 2011 8:47 AM
To: users at geoext.org
Subject: Re: [Users] How to add array of layers / LayerStore to map
ok... when I try to add some layers like
layers: ([OLwms, USGSwms, NASAwms]) it works fine. But using layers:([layerlist]) it doesn't work at all. The browser is empty and firebug shows an error
map.layers is undefined
Christian
Am 24.02.2011 15:16, schrieb Matt Priour:
Your map panel config should be:
xtype: 'gx_mappanel',
title: 'Maps',
split: true,
map: mainMap,
layers: [layerList]}
it is layers not layer and zoomTo is not a valid config option. You can use zoom, center or nothing and the map will start at maxExtent
Matt Priour
Kestrel Computer Consulting
From: Christian Gadge
Sent: Thursday, February 24, 2011 7:53 AM
To: users at geoext.org
Subject: [Users] How to add array of layers / LayerStore to map
Hello all,
I tried to add an array of layers to my map object but it fails. First I have created some layers and added these to a layerlist (=array) which is also used for a layer tree. How can I add this array to the map? Do I have to create a GeoExt.data.layerStore?
Thank you for some sugestions...
Here the relevant code:
/*
* Layer
*/
var OLwms = new OpenLayers.Layer.WMS(
"Topographic map",
"http://labs.metacarta.com/wms/vmap0",
{layers: 'basic'},
{isBaseLayer: true}
);
var BMwms = new OpenLayers.Layer.WMS(
"Blue Marble Global Imagery",
"http://sigma.openplans.org/geoserver/wms?",
{layers: 'bluemarble'},
{isBaseLayer: true }
);
var NASAwms = new OpenLayers.Layer.WMS(
"NASA WMS",
"http://wms.jpl.nasa.gov/wms.cgi?",
{layers: 'BMNG', format: 'image/png'},
{isBaseLayer: true}
);
...
/*
* Array with layers
*/
var layerList =[{
text: 'Background Layers',
leaf: false,
expanded: true,
children: [{
nodeType: 'gx_layer',
layer: OLwms,
checked: false
}, {
nodeType: 'gx_layer',
layer: BMwms,
checked: false
}, {
nodeType: 'gx_layer',
layer: NASAwms,
checked: false
},
...
]
}];
...
/*
* the map panel
*/
var mainPanel = new Ext.Panel({
region: 'center',
deferredRender: false,
margins: '5 5 5 5',
activeTab: 2,
items:[
{
xtype: 'gx_mappanel',
title: 'Maps',
split: true,
map: mainMap,
layer: ([layerList]),
zoomTo: 'maxExtent',
}]
});
Best regards,
Christian
----------------------------------------------------------------------------
_______________________________________________
Users mailing list
Users at geoext.org
http://www.geoext.org/cgi-bin/mailman/listinfo/users
--
Christian Gadge
Department Urban and Environmental Sociology | Research Field Geomatics
Helmholtz Centre for Environmental Research - UFZ
Permoserstraße 15, 04318 Leipzig, Germany
phone +49 (0)341 - 235 1730
fax +49 (0)341 - 235 1834
email christian.gadge at ufz.de
Sitz der Gesellschaft: Leipzig | Vorsitzender des Aufsichtsrats: Wilfried Kraus
Registriergericht: Amtsgericht Leipzig | Wissenschaftlicher Geschäftsführer: Prof- Dr. Georg Teutsch
Handelsregister Nr. B4703 | Administrativer Geschäftsführer: Dr. Andreas Schmidt
http://www.ufz.de
------------------------------------------------------------------------------
_______________________________________________
Users mailing list
Users at geoext.org
http://www.geoext.org/cgi-bin/mailman/listinfo/users
--
Christian Gadge
Department Urban and Environmental Sociology | Research Field Geomatics
Helmholtz Centre for Environmental Research - UFZ
Permoserstraße 15, 04318 Leipzig, Germany
phone +49 (0)341 - 235 1730
fax +49 (0)341 - 235 1834
email christian.gadge at ufz.de
Sitz der Gesellschaft: Leipzig | Vorsitzender des Aufsichtsrats: Wilfried Kraus
Registriergericht: Amtsgericht Leipzig | Wissenschaftlicher Geschäftsführer: Prof- Dr. Georg Teutsch
Handelsregister Nr. B4703 | Administrativer Geschäftsführer: Dr. Andreas Schmidt
http://www.ufz.de
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20110224/d2afe397/attachment-0001.htm
More information about the Users
mailing list