[OpenLayers-Users] Loading WMC layers at overlays?

Bart van den Eijnden (OSGIS) bartvde at osgis.nl
Sat Aug 9 06:04:07 EDT 2008


Hi Joost,

unfortunately there is no easy way to override this at the moment in OL, 
see also:

http://trac.openlayers.org/ticket/1513

What you can do is loop over your layers and then set 
layer.params.TRANSPARENT to 'true', but it might be too late since the 
layer will have actually been drawn already.

Otherwise change the default WMS parameters of OpenLayers,

    /**
     * Constant: DEFAULT_PARAMS
     * {Object} Hashtable of default parameter key/value pairs
     */
    DEFAULT_PARAMS: { service: "WMS",
                      version: "1.1.1",
                      request: "GetMap",
                      styles: "",
                      exceptions: "application/vnd.ogc.se_inimage",
                      format: "image/jpeg"
                     },
 
to e.g. format "image/png" and transparent "true".

Best regards,
Bart

jvanulde wrote:
> Hi Bart,  thanks for that as I think I am half way there now.  The only issue
> now is that the layers are not transparent.  They are coming from Mapserver
> as PNG's.  Here is my code:
>
>         OpenLayers.IMAGE_RELOAD_ATTEMPTS = 2;
>         OpenLayers.Util.onImageLoadErrorColor = "transparent";
>         
>         var layerOptions = {
>             isBaseLayer: false,
>             singleTile: true,
>             buffer: 0,
>             ratio: 1
>             };
>         
>         var format = new OpenLayers.Format.WMC({'layerOptions':
> layerOptions});
>         var map, context;
>         
>         function initMap() 
>         {           
>             // parse wmc into context object            
>             var wmc = document.getElementById('<%= hidWMC.ClientID
> %>').value;
>             context = format.read(wmc, {map: map});                
>
>             // construct a map given the context
>             var mapOptions = {
>                 maxExtent: context.bounds,
>                 projection: context.srs
>                 };
>                 
>             map = new OpenLayers.Map("map", mapOptions);
>             
>             var baseLayerOptions = {
>                 isBaseLayer: true, 
>                 displayInLayerSwitcher: false
>                 };
>                 
>             var fake = new OpenLayers.Layer('fake', baseLayerOptions);
>             map.addLayer(fake);
>             
>             map.addLayers(context.layers);               
>             map.addControl(new OpenLayers.Control.LayerSwitcher());
>             map.zoomToMaxExtent();     
>         }
>
> Is there a way to make the layers transparent now that I have loaded them? 
> I think the problem is elsewhere but need some pointers on where to look.  I
> have loaded the context in another viewer and the layers come in as
> expected.
>
>
>
> Bart van den Eijnden wrote:
>   
>> Hi Joost,
>>
>> you can pass layerOptions to the Format.WMC constructor in order to do
>> this. Code example:
>>
>> mapfish.OGCUtil.readWMC = function(map, response, noZoom) {
>>     var format = new OpenLayers.Format.WMC({layerOptions: {isBaseLayer:
>> false, singleTile: true, buffer: 0,ratio: 1}});
>>
>>     // remove all layers except the baselayer
>>     for (var i = map.layers.length-1; i >= 0; i--) {
>>         if (!map.layers[i].isBaseLayer) {
>>             map.removeLayer(map.layers[i], false);
>>         }
>>     }
>>
>>     map = format.read(response.responseText, {map: map});
>>     ...
>> }
>>
>> Best regards,
>> Bart
>>
>>     
>>> Thanks John, that works.  Now I need to know how to convert all of the
>>> layers in my WMC to overlay's.  Any ideas?
>>>
>>> -----Original Message-----
>>> From: John Pulles [mailto:john.pulles at gmail.com]
>>> Sent: Wed 06/08/2008 2:49 PM
>>> To: Van Ulden, Joost
>>> Cc: users at openlayers.org
>>> Subject: Re: [OpenLayers-Users] Loading WMC layers at overlays?
>>>
>>> 2008/8/6 jvanulde <jvanulde at nrcan.gc.ca>
>>>
>>>       
>>>> Is this possible?  I want to add a fake base layer and load all the WMC
>>>> layers as overlays.  Any ideas on how one would go about doing this?
>>>>         
>>> You can add a fake base layer with
>>>
>>> map.addLayer(new OpenLayers.Layer('None', {isBaseLayer: true}));
>>>
>>> Regards,
>>> John
>>>
>>>
>>>       
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Loading-WMC-layers-at-overlays--tp18859376p18859376.html
>>>> Sent from the OpenLayers Users mailing list archive at Nabble.com.
>>>>
>>>> _______________________________________________
>>>> Users mailing list
>>>> Users at openlayers.org
>>>> http://openlayers.org/mailman/listinfo/users
>>>>
>>>>         
>>> _______________________________________________
>>> Users mailing list
>>> Users at openlayers.org
>>> http://openlayers.org/mailman/listinfo/users
>>>
>>>       
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>>
>>     
>
>   


-- 
Bart van den Eijnden
OSGIS, Open Source GIS
bartvde at osgis.nl
http://www.osgis.nl




More information about the Users mailing list