summaryrefslogtreecommitdiff
path: root/misc/openlayers/tests/Layer/Bing.html
blob: 89bbba7584c985c112804c877ef1bbcfa0368f70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<html>
<head>
  <script src="../OLLoader.js"></script>
  <script type="text/javascript">
    var map, layer; 

    var layerType = 'Aerial';
    var key = "AqTGBsziZHIJYYxgivLBf0hVdrAk9mWO5cQcb8Yux8sW5M8c8opEC2lZqKR1ZZXf";
    
    var options = {
        type: layerType,
        key: key
    };

    function test_constructor(t) {
        t.plan(3);
                       
        var origProcessMetadata = OpenLayers.Layer.Bing.processMetadata;
        var log = [];
        OpenLayers.Layer.Bing.processMetadata = function(metadata) {
            var script = document.getElementById(this._callbackId);
            log.push(script.src);
            origProcessMetadata.apply(this, arguments);
        };
        layer = new OpenLayers.Layer.Bing(OpenLayers.Util.extend({
            metadataParams: {foo: "bar"}
        }, options));
        t.ok(layer instanceof OpenLayers.Layer.Bing, "returns OpenLayers.Layer.Bing object" );
        t.delay_call(5, function() {
            t.eq(log.length, 1, "processMetadata called");
            t.eq(OpenLayers.Util.getParameters(log[0]).foo, "bar", "metadataParams passed to url correctly.");
            OpenLayers.Layer.Bing.processMetadata = origProcessMetadata;
            layer.destroy();
        });
    }
    
    function test_initLayer(t) {
        t.plan(2);

        var meta = [];
        var origProcessMetadata = OpenLayers.Layer.Bing.processMetadata;
        OpenLayers.Layer.Bing.processMetadata = function(metadata) {
            meta.push(metadata);
        };
        map = new OpenLayers.Map("map");
        layer = new OpenLayers.Layer.Bing(options);
        var extent;
        map.addLayers([layer, new OpenLayers.Layer(null, {
            moveTo: function(bounds, changed) {
                extent = bounds;
            }
        })]);
        map.zoomToMaxExtent();
        
        var map2 = new OpenLayers.Map("map");
        var layer2 = new OpenLayers.Layer.Bing(OpenLayers.Util.extend({
            initLayer: function() {
                // pretend we have a zoomMin of 2
                this.metadata.resourceSets[0].resources[0].zoomMin = 2;
                OpenLayers.Layer.Bing.prototype.initLayer.apply(this, arguments);
            }
        }, options));
        var extent2;
        map2.addLayers([layer2, new OpenLayers.Layer(null, {
            moveTo: function(bounds, changed) {
                extent2 = bounds;
            }
        })]);
        map2.zoomToMaxExtent();
        
        t.delay_call(5, function() {
            origProcessMetadata.call(layer, meta[0]);
            t.eq(extent.toBBOX(), map.getExtent().toBBOX(), "layer extent correct for base layer with zoomMin == 1.");
            map.destroy();
        });

        t.delay_call(6, function() {
            origProcessMetadata.call(layer2, meta[1]);
            t.eq(extent2.toBBOX(), map2.getExtent().toBBOX(), "layer extent correct for base layer with zoomMin == 2.");
            map2.destroy();
            OpenLayers.Layer.Bing.processMetadata = origProcessMetadata;
        });
    }
    
    function test_initLayer_notempty(t) {
        t.plan(1);
        
        map = new OpenLayers.Map("map", {
            projection: "EPSG:3857",
            layers: [new OpenLayers.Layer("dummy", {isBaseLayer: true})]
        });
        map.zoomToExtent([-14768652, 4492113, -12263964, 5744457]);
        var layer = new OpenLayers.Layer.Bing(OpenLayers.Util.extend({
            isBaseLayer: false
        }, options));
        map.addLayer(layer);
        
        t.delay_call(5, function() {
            t.ok(layer.grid[0][0].url, "Tile not empty");
            map.destroy();
        });
    }
    
    function test_attribution(t) {
        t.plan(3);
        
        var log = [];
        var map = new OpenLayers.Map("map");
        layer = new OpenLayers.Layer.Bing(options);
        map.addLayer(layer);
        map.zoomToMaxExtent();
        
        t.delay_call(2, function() {
            t.ok(OpenLayers.Util.indexOf(layer.attribution, 'olBingAttribution aerial') !== -1, "Attribution has the correct css class");
            t.ok(OpenLayers.Util.indexOf(layer.attribution, '<img src="">') == -1, "Attribution contains a logo");
            t.ok(OpenLayers.Util.indexOf(layer.attribution, '</img></div></a><a style=') == -1 , "Attribution contains a copyright");
            map.destroy();
        });
    }

    function test_attribution_notempty(t) {
        t.plan(1);
        
        var log = [];
        var map = new OpenLayers.Map("map");
        layer = new OpenLayers.Layer.Bing(OpenLayers.Util.applyDefaults({type: 'Road'}, options));
        map.addLayer(layer);
        var format = OpenLayers.String.format;
        OpenLayers.String.format = function(tpl, options) {
            log.push(options.copyrights);
        }
        map.zoomToExtent(new OpenLayers.Bounds(-14768652, 4492113, -12263964, 5744457));
        t.delay_call(2, function() {
            t.ok(log.join("") !== "", "Copyright not empty");
            OpenLayers.String.format = format;
            map.destroy();
        });
    }
    
    function test_getXYZ(t) {
        t.plan(1);
        
        var map = new OpenLayers.Map("map", {allOverlays: true});
        var osm = new OpenLayers.Layer.OSM();
        map.addLayer(osm);
        map.zoomToExtent(new OpenLayers.Bounds(11373579,-2445208,13628777,680760));
        layer = new OpenLayers.Layer.Bing(options);
        map.addLayer(layer);
        
        t.delay_call(2, function() {
            var xyz = layer.getXYZ(layer.getTileBounds(new OpenLayers.Pixel(1,1)));
            t.eq(xyz.z, OpenLayers.Util.indexOf(layer.serverResolutions, map.getResolution()), "zoom level correct");
        });
    }

    function test_clone(t) {
        t.plan(1);
        
        var clone;
        
        layer = new OpenLayers.Layer.Bing(options);
        clone = layer.clone();
        t.ok(clone instanceof OpenLayers.Layer.Bing, "clone is a Layer.Bing instance");
    }

    function test_protocol(t)
    {
        t.plan(5);

        var map = new OpenLayers.Map("map");
        layer = new OpenLayers.Layer.Bing(options);
        map.addLayer(layer);
        map.zoomToMaxExtent();
        
        t.delay_call(5, function() {
            t.ok(OpenLayers.Util.indexOf(layer.attribution, '<img src="//') != -1, "Attribution contains a logo with protocol //");
            t.ok(OpenLayers.Util.indexOf(layer.attribution, '<img src="http://') == -1, "Attribution logo does not have http:// protocol");
            t.ok(layer.grid[1][1].url.indexOf('http:') == -1, "Tile url does not contain http:");

            map.destroy();
        });

        var map2 = new OpenLayers.Map("map");
        layer_https = new OpenLayers.Layer.Bing(OpenLayers.Util.applyDefaults({protocol: 'https:'}, options));
        map2.addLayer(layer_https);
        map2.zoomToMaxExtent();

        t.delay_call(5, function() {
            t.ok(OpenLayers.Util.indexOf(layer_https.attribution, '<img src="https://') != -1, "Attribution logo has https:// protocol");
            t.ok(layer_https.grid[1][1].url.indexOf('https:') == 0, "Tile url contains https:");
            map2.destroy();
        });
    }

  </script>
</head>
<body>
<div id="map" style="width:500px;height:550px"></div>
</body>
</html>