[OpenLayers-Users] switch Layers by resolution/zoom

Eric Lemoine eric.c2c at gmail.com
Mon Aug 25 11:38:24 EDT 2008


Hi. I'm not too familiar with TMS and I don't why you get png instead
of gif. But it seems to me that could simplify your code a lot by
giving each layer a one-entry resolutions array instead of setting the
resolutions at the map level. With this OpenLayers should take care of
showing/hiding the layers based on the zoom level. Hope this helps.
Eric

2008/8/25, crinolium <wengerter at gmail.com>:
>
> Hello List!
>
> I have got a map of 4 layers and 4 resolutions. Each layer for one
> resolution. But I've got a problem in switching between the layers by
> zooming. It works for the resolutions 40, 16 and 8 but not for 4.There the
> URL (f. e. http://localhost/uk500/400/.../ .png) isn't correct. It must be
> http://localhost/tk50/400/.../.gif.
>
> What I have to do to request with the right URL?
>
> What's wrong with the code? Or is there another, better way to switch
> between the layers than with setVisibility?
>
> I hope, someone can help me.
>
>
> Here is the code:
>
> function get_url (bounds) {
>        var res = this.map.getResolution();
>        var x = bounds.left;
>        var y = bounds.bottom;
>        var z = res*100;
>
>        var path = z + "/" + x + "/" + x + y + "." + this.type;
>        var url = this.url;
>        if (url instanceof Array) {
>            url = this.selectUrl(path, url);
>        }
>        return url + path;
> }
>
> var options = {resolutions: [40,16,8,4],...};
>
> var map = new OpenLayers.Map("map", options);
>
> tms_uk500 = new OpenLayers.Layer.TMS("TMS
> UK500","http://localhost/uk500/4000/", 'type':'png', 'getURL':get_url});
> tms_tk50_16 = new OpenLayers.Layer.TMS("TMS TK50
> 16","http://localhost/tk50/", {'type':'gif', 'getURL':get_url});
> tms_tk50_8 = new OpenLayers.Layer.TMS("TMS TK50 8","http://localhost/tk50/",
> {'type':'gif', 'getURL':get_url});
> tms_tk50_4 = new OpenLayers.Layer.TMS("TMS TK50 4","http://localhost/tk50/",
> {'type':'gif', 'getURL':get_url});
>
> map.addLayers([tms_uk500,tms_tk50_16,tms_tk50_8, tms_tk50_4]);
>
> map.events.register("zoomend", map, function() {
>        switch(map.getResolution()) {
>           case 40:
>                        tms_tk50_16.setVisibility(false);
>                        tms_tk50_8.setVisibility(false);
>                        tms_tk50_4.setVisibility(false);
>                        tms_uk500.setVisibility(true);
>           case 16:
>                        tms_uk500.setVisibility(false);
>                        tms_tk50_8.setVisibility(false);
>                        tms_tk50_4.setVisibility(false);
>                        tms_tk50_16.setVisibility(true);
>           case 8:
>                        tms_uk500.setVisibility(false);
>                        tms_tk50_16.setVisibility(false);
>                        tms_tk50_4.setVisibility(false);
>                        tms_tk50_8.setVisibility(true);
>           case 4:
>                        tms_uk500.setVisibility(false);
>                        tms_tk50_16.setVisibility(false);
>                        tms_tk50_8.setVisibility(false);
>                        tms_tk50_4.setVisibility(true);
> }});
>
> --
> View this message in context:
> http://n2.nabble.com/switch-Layers-by-resolution-zoom-tp781199p781199.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
>



More information about the Users mailing list