Overlays only at specific zoom levels

3 messages Options
Embed this post
Permalink
Derek Watling

Overlays only at specific zoom levels

Reply Threaded More More options
Print post
Permalink
I am using Google base layers in OpenLayers 2.8 with a my own WMS overlay that is only avalilable at at the top 3 zoom levels. My bounding box is set to cover South Africa. I have the Google zoom levels limited to between 5 and 18 with the following code:

    ...
    var bbox = new OpenLayers.Bounds(bbox = 1780677, -4180188, 3683653, -2512026);
    var mapOptions = {
        projection: new OpenLayers.Projection("EPSG:900913"),
        units: 'm',
        maxResolution: 156543.0339,
        maxExtent: bbox,
        restrictedExtent: bbox
    };
    var map = new OpenLayers.Map('divMap', mapOptions);
    map.addControl(new OpenLayers.Control.LayerSwitcher());

    var gmap = new OpenLayers.Layer.Google("Google Streets", { "sphericalMercator": true });
    gmap.MIN_ZOOM_LEVEL = 5;
    gmap.MAX_ZOOM_LEVEL = 18;

    var myOverlay = new OpenLayers.Layer.WMS(
        "Custom Overlay",
        "http://dev/Tilecache/tilecache.py?",
        { layers: "Custom", 'maxExtent': bbox, format: "image/png" }
    );
    myOverlay.setIsBaseLayer(false);
    myOverlay.displayOutsideMaxExtent = 0;
    myOverlay.transitionEffect = "resize";

    map.addLayers([gmap, myOverlay]);
    ....

How do I tell OpenLayers that myOverlay only exists for the following resolutions?
2.38865713348388, 1.19432856674194, 0.597164283370971
Currently I get "pink" tiles overlayed where the tiles do not exist!

My tilecache.cfg is set up as follows:
[cache]
type=Disk
base=C:\Inetpub\TileCache\Cache

[Custom]
type=WMSLayer
bbox=-20037508.3427892,-20037508.3427892,20037508.3427892,20037508.3427892
#maxResolution=156543.0339
resolutions=2.38865713348388, 1.19432856674194, 0.597164283370971
srs=EPSG:900913
layers=Overlay,OverlayLabels
url=http://localhost/Mapping/WMS.aspx?Transparent=True&
extension=png
metaTile=yes
metaSize=5,5
mettaBuffer=0
Eric Lemoine-2-2

Re: Overlays only at specific zoom levels

Reply Threaded More More options
Print post
Permalink
On Wednesday, October 21, 2009, Derek Watling <[hidden email]> wrote:

>
> I am using Google base layers in OpenLayers 2.8 with a my own WMS overlay
> that is only avalilable at at the top 3 zoom levels. My bounding box is set
> to cover South Africa. I have the Google zoom levels limited to between 5
> and 18 with the following code:
>
>     ...
>     var bbox = new OpenLayers.Bounds(bbox = 1780677, -4180188, 3683653,
> -2512026);
>     var mapOptions = {
>         projection: new OpenLayers.Projection("EPSG:900913"),
>         units: 'm',
>         maxResolution: 156543.0339,
>         maxExtent: bbox,
>         restrictedExtent: bbox
>     };
>     var map = new OpenLayers.Map('divMap', mapOptions);
>     map.addControl(new OpenLayers.Control.LayerSwitcher());
>
>     var gmap = new OpenLayers.Layer.Google("Google Streets", {
> "sphericalMercator": true });
>     gmap.MIN_ZOOM_LEVEL = 5;
>     gmap.MAX_ZOOM_LEVEL = 18;
>
>     var myOverlay = new OpenLayers.Layer.WMS(
>         "Custom Overlay",
>         "http://dev/Tilecache/tilecache.py?",
>         { layers: "Custom", 'maxExtent': bbox, format: "image/png" }
>     );
>     myOverlay.setIsBaseLayer(false);
>     myOverlay.displayOutsideMaxExtent = 0;
>     myOverlay.transitionEffect = "resize";
>
>     map.addLayers([gmap, myOverlay]);
>     ....
>
> How do I tell OpenLayers that myOverlay only exists for the following
> resolutions?
> 2.38865713348388, 1.19432856674194, 0.597164283370971

have you tried passing these resolutions to youe WMS layer, through
the "resolutions" config option. It should make OpenLayers "stop" the
layer when it's out of range.

Cheers,

--
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : [hidden email]
http://www.camptocamp.com
_______________________________________________
Users mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/users
Derek Watling

Re: Overlays only at specific zoom levels

Reply Threaded More More options
Print post
Permalink
Hi Eric

I had tried setting the resolutions as part of the "params" in the constructor:

     var myOverlay = new OpenLayers.Layer.WMS(
         "Custom Overlay",
         "http://dev/Tilecache/tilecache.py?",
         { layers: "Custom",
            'maxExtent': bbox,
            format: "image/png",
            resolutions: [2.388657133483887, 1.19432856674194, 0.597164283370971]
         }
     );

However, if I move it to the "options" it works:

     var myOverlay = new OpenLayers.Layer.WMS(
         "Custom Overlay",
         "http://dev/Tilecache/tilecache.py?",
         { layers: "Custom",
            'maxExtent': bbox,
            format: "image/png"
         },
         { resolutions: [2.388657133483887, 1.19432856674194, 0.597164283370971] }
     );

but this introduces an issue with IE 8 in that the "Google" image doesn't update when changing base layers!

I have found a hack that makes it work: By changing the size of the map when the base layer changes IE 8 renders the new layer:

        map.events.register('changebaselayer', null, function(e) {
            var pnlMap = document.getElementById("pnlMap");
            pnlMap.style.height = (parseInt(pnlMap.style.height) - 1) + 'px';
            setTimeout("pnlMap.style.height = (parseInt(pnlMap.style.height) + 1) + 'px'", 500);
        });

where "pnlMap" is a <div> around my "mapDiv".

If anyone has a more elegant solution, it would be appreciated.

Eric Lemoine-2-2 wrote:
have you tried passing these resolutions to youe WMS layer, through
the "resolutions" config option. It should make OpenLayers "stop" the
layer when it's out of range.