[OpenLayers-Users] TURN On layers Individually...
Paul james
pauljame at gmail.com
Wed Jul 1 17:16:18 EDT 2009
Thats It!
Thanks Andreas!
On Wed, Jul 1, 2009 at 6:11 PM, Andreas Hocevar <ahocevar at opengeo.org>wrote:
> Hi,
>
> On Wed, Jul 1, 2009 at 9:08 PM, Paul james<pauljame at gmail.com> wrote:
> > I have that layer on Openlayers :
> >
> > var _layer = new OpenLayers.Layer.MapServer(
> > "PointLayer",
> > _cgi,
> > {
> > map: _mapfile,
> > singleTile: true,
> > layers: ['Layer1', 'Layer2', 'Layer3'],
> > transparent: "true",
> > format: "image/png"
> > },
> > );
> >
> > If I use setVisibility on PointLayer, Layer1, 2 and 3 are turned ON...
> > How Can I turn on/off Layer1,Layer2,Layer3 individually on javascript?
>
> Many ways to do that, no big deal. How 'bout
>
> var _layer = new OpenLayers.Layer.WMS(
> "PointLayer",
> _cgi,
> {
> map: _mapfile,
> singleTile: true,
> layers: ['Layer1', 'Layer2', 'Layer3'],
> transparent: true,
> format: 'image/png',
> initialize: function(name, url, params, options) {
> this.layerMap = {};
> var layer;
> for(var i=0; i<params.layers.length; ++i) {
> layer = params.layers[i];
> this.layerMap[layer] = true;
> }
> OpenLayers.Layer.WMS.prototype.initialize.apply(this,
> arguments);
> },
> setLayerVisibility: function(layer, visibility) {
> this.layerMap[layer] = visibility;
> var layers = [];
> for(var l in this.layerMap) {
> this.layerMap[l] && layers.push(l);
> }
> this.mergeNewParams({"LAYERS": layers});
> }
> }
> );
>
> Now you can e.g. use _layer.setLayerVisibility('Layer1', false) to
> turn off Layer1. This would probably also work with Layer.MapServer,
> but I have never used that, and MapServer supports Layer.WMS as well.
>
> Regards,
> Andreas.
>
> >
> > Paul
> >
> > _______________________________________________
> > Users mailing list
> > Users at openlayers.org
> > http://openlayers.org/mailman/listinfo/users
> >
> >
>
>
>
> --
> Andreas Hocevar
> OpenGeo - http://opengeo.org/
> Expert service straight from the developers.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090701/4eee0dda/attachment.html
More information about the Users
mailing list