3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
7 function test_Layer_FixedZoomLevels (t) {
10 var layer = { 'MIN_ZOOM_LEVEL': 5,
11 'MAX_ZOOM_LEVEL': 10 };
16 layer = p_createLayer(layer);
17 p_minMaxNum(t, layer, layer.MIN_ZOOM_LEVEL, layer.MAX_ZOOM_LEVEL, "nothing specified");
23 layer = p_createLayer(layer, {}, { minZoomLevel: 3, numZoomLevels: 12});
24 p_minMaxNum(t, layer, layer.MIN_ZOOM_LEVEL, layer.MAX_ZOOM_LEVEL, "min too low num too high(layer.options)");
26 layer = p_createLayer(layer, {}, { minZoomLevel: 6, numZoomLevels: 3 });
27 p_minMaxNum(t, layer, 6, 8, "valid min,num(layer.options)");
31 layer = p_createLayer(layer, {}, { maxZoomLevel: 9 });
32 p_minMaxNum(t, layer, layer.MIN_ZOOM_LEVEL, 9, "valid max(layer.options)");
34 layer = p_createLayer(layer, {}, { maxZoomLevel: 12 });
35 p_minMaxNum(t, layer, layer.MIN_ZOOM_LEVEL, layer.MAX_ZOOM_LEVEL, "invalid max(layer.options)");
42 layer = p_createLayer(layer, { minZoomLevel: 3, numZoomLevels: 12});
43 p_minMaxNum(t, layer, layer.MIN_ZOOM_LEVEL, layer.MAX_ZOOM_LEVEL, "min too low num too high(map)");
45 layer = p_createLayer(layer, { minZoomLevel: 6, numZoomLevels: 3 });
46 p_minMaxNum(t, layer, 6, 8, "valid min,num(map)");
50 layer = p_createLayer(layer, { maxZoomLevel: 9 });
51 p_minMaxNum(t, layer, layer.MIN_ZOOM_LEVEL, 9, "valid max(map)");
53 layer = p_createLayer(layer, { maxZoomLevel: 12 });
54 p_minMaxNum(t, layer, layer.MIN_ZOOM_LEVEL, layer.MAX_ZOOM_LEVEL, "invalid max(map)");
58 layer = p_createLayer(layer, {minZoomLevel: 6, numZoomLevels: 2}, { minZoomLevel: 7, numZoomLevels: 3});
59 p_minMaxNum(t, layer, 7, 9, "min,num(layer.options) wins over (map)");
61 layer = p_createLayer(layer, {minZoomLevel: 6, maxZoomLevel: 8}, { minZoomLevel: 7, maxZoomLevel: 9});
62 p_minMaxNum(t, layer, 7, 9, "min,max(layer.options) wins over (map)");
65 // numZoomLevels vs. maxZoomLevel
67 layer = p_createLayer(layer, {maxZoomLevel: 8, numZoomLevels: 6});
68 p_minMaxNum(t, layer, layer.MIN_ZOOM_LEVEL, 10, "min,max(layer.options) wins over (map)");
72 var resolutions = Array(20);
73 for (var i = 0; i < 20; i++) {
74 resolutions[i] = Math.random();
76 OpenLayers.Util.extend(layer, {RESOLUTIONS:resolutions});
78 var numZoomLevels = 2;
79 layer = p_createLayer(layer, {}, {minZoomLevel: minZoomLevel, numZoomLevels: numZoomLevels});
80 t.eq( layer.resolutions.length, numZoomLevels, "length of resolutions array ok");
81 for (var i = 0; i < numZoomLevels; i++) {
82 t.eq( layer.resolutions[i], resolutions[i + minZoomLevel], "resolutions array at index " + i + " ok");
86 function p_createLayer(layer, mapOptions, layerOptions) {
88 layer.map = mapOptions || {};
89 layer.options = layerOptions || {};
90 OpenLayers.Layer.FixedZoomLevels.prototype.initResolutions.apply(layer);
95 function p_minMaxNum(t, layer, min, max, msg) {
97 t.eq( layer.minZoomLevel, min, "min zoom level inherited from layer constant: " + msg);
98 t.eq( layer.maxZoomLevel, max, "max zoom level inherited from layer constant: " + msg);
99 t.eq( layer.numZoomLevels, max - min + 1, "num zoom levels correctly calcuated: " + msg);