I have 2 Overlays, each with a client side opacity slider. OpenLayers allows me to change the opacity of a GoogleOverlay.olMap.getLayersByName(‘GoogleMapsOverlayName’)[0].setOpacity(opacity);
So the user can change the opacity of GoogleMaps and my custom overlay independently.
I’d like to duplicate these opacity settings when the user wants to export an image. I need to be able to set the transparency / opacity of a GoogleMapsLayer. Is there a way to do this by inheriting from GoogleMapsLayer? Or is this something that I’d have to wait for a new dll?
Also, is there a way to change the opacity of a LayerOverlay? or FeatureLayers?
GoogleMapsLayer Transparency / Opacity
Rob,
Currently, GoogleMapsLayer doesn’t support alpha channel; to satisfy your requirement, please see my new class AlphaGoogleMapsLayer in the attachement. Also here is the code how to use it.AlphaGoogleMapsLayer googleLayer = new AlphaGoogleMapsLayer(133);
On the other hand, the alpha channel is depending on the layer, so if you are using FeatureLayer, please set the alpha on the style etc. If you are using RasterLayer, please set the Transparency property. Please have a try and let me know if you have any more questions.
Thanks,
Howard
1627-AlphaGoogleMapsLayer.cs.txt (2.99 KB)
I love how extending Classes can solve so many problems! This is exactly what I needed. Thanks again Howard.
For the second problem, here is a little background. I have many Layers in the dynamic overlay, each with their own styles per ZoomLevel. Many styles have some sort of Alpha set. After all the server side rendering, the user is able to change the opacity of the overlay as a whole. So I am trying to make the image export resemble the OpenLayers map as much as possible. I'd like to apply an opacity to the already rendered styles, which may already have some sort of alpha set. And have that only apply for the call to Map1.GetBitmap(), without loosing the original styles. Is the only way to loop through them all, calc and use currentOpacity *= overlayOpacity, GetBitmap(), loop through, calc and use currentOpacity /= overlayOpacity ?
UPDATE: I noticed that LayerOverlay does have an Opacity field, but it seems to only work on the client side, not GetBitmap()
Thanks,
Rob
Rob,
I see; if you don’t like to reset the alpha again and again; I recommend you to maintain two layers set. We have a class names GroupLayer which maintains all the layers. So we’ll add two GroupLayer objects into the overlay. One maintains the original setting while the other one maintains the layers with alpha settings. So we can easily use its IsVisible property to turn the setting on and off. Hope it makes sense.
Please let me know if you have more queries.
Thanks,
Howard