summaryrefslogtreecommitdiff
path: root/misc/openlayers/tests/Renderer/VML.html
blob: 2bdc876dfc24d79b9e296d65877ca4442bd08240 (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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
<html>
<head>
<script src="../OLLoader.js"></script>
  <script type="text/javascript">

    var geometry = null, node = null;

    function test_VML_constructor(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }
        
        t.plan(1);
        var r = new OpenLayers.Renderer.VML(document.body);
        t.ok(r instanceof OpenLayers.Renderer.VML, "new OpenLayers.Renderer.VML returns VML object" );
    }
    
    function test_VML_destroy(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }
        
        t.plan(1);
        
        var g_Destroy = false;
        
        OpenLayers.Renderer.Elements.prototype._destroy = 
            OpenLayers.Renderer.Elements.prototype.destroy;
            
        OpenLayers.Renderer.prototype.destroy = function() {
            g_Destroy = true;
        }
        
        var r = new OpenLayers.Renderer.VML(document.body);
        r.destroy();
        
        t.eq(g_Destroy, true, "OpenLayers.Renderer.Elements.destroy() called");
        
        OpenLayers.Renderer.prototype.destroy = 
            OpenLayers.Renderer.prototype._destroy;
    }
    
    function test_VML_setextent(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }
        
        t.plan(4);
        
        OpenLayers.Renderer.Elements.prototype._setExtent =
            OpenLayers.Renderer.Elements.prototype.setExtent;
        
        var g_SetExtent = false;
        OpenLayers.Renderer.Elements.prototype.setExtent = function() {
            g_SetExtent = true;
        }
                
        var r = new OpenLayers.Renderer.VML(document.body);
        r.setSize(new OpenLayers.Size(4,4));
        r.map = {
            getResolution: function() {
                return 0.5;
            }
        }
        
        var extent = new OpenLayers.Bounds(1,2,3,4);
        r.setExtent(extent);
        
        t.eq(g_SetExtent, true, "Elements.setExtent() called");
        
        t.ok(r.root.coordorigin == "0,0", "coordorigin is correct");
        t.ok(r.root.coordsize == "4,4", "coordsize is correct");
        t.eq(r.offset, {x:2, y:4}, "offset is correct");
        
        OpenLayers.Renderer.Elements.prototype.setExtent =
            OpenLayers.Renderer.Elements.prototype._setExtent;
    }

    function test_VML_setsize(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }
        
        t.plan(4);
                
        var r = new OpenLayers.Renderer.VML(document.body);
        
        var size = new OpenLayers.Size(1,2);
        r.setSize(size);
        t.eq(r.rendererRoot.style.width, "1px", "rendererRoot width is correct");
        t.eq(r.rendererRoot.style.height, "2px", "rendererRoot height is correct");
        
        t.eq(r.root.style.width, "1px", "root width is correct");
        t.eq(r.root.style.height, "2px", "root height is correct");
    }
    
    function test_VML_drawText(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }
        
        t.plan(2);

        var r = new OpenLayers.Renderer.VML(document.body);
        r.offset = {x: 0, y: 0};
        
        r.LABEL_ID_SUFFIX = "";
        r.getResolution = function() {
            return 1;
        };

        var style = {
            label: "myText",
            fontColor: "blue"
        }
        
        r.drawText("feature1", style, new OpenLayers.Geometry.Point(1,1));
        
        var textbox = document.getElementById("feature1_textbox");
        
        t.eq(textbox.innerText, style.label, "label set correctly");
        t.eq(textbox.style.color, style.fontColor, "font color of label set correctly");
    }

    function test_VML_drawpoint(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }
    
        t.plan(1);

        var r = new OpenLayers.Renderer.VML(document.body);
        
        var properDraw = false;
        var g_Radius = null;
        r.drawCircle = function(n, g, r) {
            properDraw = true;
            g_Radius = 1;
        }
        r.drawPoint();
        
        t.ok(properDraw && g_Radius == 1, "drawPoint called drawCircle with radius set to 1");
    }

    function test_VML_drawcircle(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }
        
        t.plan(4);
        
        var r = new OpenLayers.Renderer.VML(document.body);
        r.offset = {x: 0, y: 0};
        r.resolution = 0.5;
        
        var node = document.createElement('div');
        
        var geometry = {
            x: 1,
            y: 2
        }
        
        var radius = 3;
        r.drawCircle(node, geometry, radius);
        
        t.eq(node.style.left, '-1px', "left is correct");
        t.eq(node.style.top, '1px', "top is correct");
        t.eq(node.style.width, (2 * radius) + "px", "width is correct");
        t.eq(node.style.height, (2 * radius) + "px", "height is correct");
    }
    
    function test_VML_drawGraphic(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }
        
        t.plan(6);
        
        var r = new OpenLayers.Renderer.VML(document.body);
        r.offset = {x: 0, y: 0};
        r.resolution = 1;
        
        var node = document.createElement('div');
        node.id = "test"
        node._geometryClass = "OpenLayers.Geometry.Point";
        
        var geometry = {
            x: 1,
            y: 2
        }
        
        var style = {
            externalGraphic: "foo.png",
            graphicWidth: 7,
            graphicHeight: 10
        }
        
        r.drawGeometryNode(node, geometry, style);

        t.eq(node.childNodes[0].id, "test_fill", "fill child node correctly created");
        t.eq(node.style.left, "-2px", "x of insertion point with calculated xOffset correct");
        t.eq(node.style.top, "-3px", "y of insertion point with calculated yOffset correct");
        
        style.rotation = 90;
        
        r.drawGeometryNode(node, geometry, style);
        
        t.eq(node.childNodes[1].id, "test_image", "image child node correctly created");
        t.eq(node.style.left, "-3px", "x of insertion point of rotated image correct");
        t.eq(node.style.top, "-4px", "y of insertion point of rotated image correct");
    }

    function test_VML_drawlinestring(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }
        
        t.plan(1);
        
        var r = new OpenLayers.Renderer.VML(document.body);
        
        g_DrawLine = false;
        r.drawLine = function(c) {
            g_DrawLine = true;
        }
        
        r.drawLineString(node, geometry);
        
        t.ok(g_DrawLine, "drawLine is called");
    }
    
    function test_VML_drawlinearring(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }
        
        t.plan(1);
        
        var r = new OpenLayers.Renderer.VML(document.body);
        
        g_DrawLine = false;
        r.drawLine = function(c) {
            g_DrawLine = true;
        }
        
        r.drawLinearRing(node, geometry);
        
        t.ok(g_DrawLine, "drawLine is called");
    }

    function test_VML_drawline(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }
        
        t.plan(8);
        
        var r = new OpenLayers.Renderer.VML(document.body);
        r.offset = {x: 0, y: 0};
        r.resolution = 0.5;
        
        var node = document.createElement('div');
        
        var geometry = {
            components: [{
                x: 1,
                y: 2
            },{
                x: 3,
                y: 4
            }],
            getBounds: function() {
                return new OpenLayers.Bounds(5,6,7,8);
            }
        };
        
        r.drawLine(node, geometry, true);
        t.ok(node.path.indexOf("x") != -1, "path attribute is correct when passed closeLine = true");
        
        
        r.drawLine(node, geometry, false);
        t.eq(node.path, "m 2,4 l  6,8 l  e", "path attribute is correct");
        t.eq(node.style.left, "10px", "node.style.left is correct");
        t.eq(node.style.top, "16px", "node.style.top is correct");
        t.eq(node.style.width, "4px", "node.style.width is correct");
        t.eq(node.style.height, "4px", "node.style.height is correct");
        t.eq(node.coordorigin, "10 16", "node.coordorigin is correct");
        t.eq(node.coordsize, "4 4", "node.coordsize is correct");
    }
    
    function test_VML_drawpolygon(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }
        
        t.plan(3);
        
        var r = new OpenLayers.Renderer.VML(document.body);
        r.offset = {x: 0, y: 0};
        r.resolution = 0.5;
        
        g_SetNodeDimension = false;
        r.setNodeDimension = function(){
            g_SetNodeDimension = true;
        };
        
        var node = document.createElement('div');
        
        var geometry = OpenLayers.Geometry.fromWKT(
            "POLYGON((1 2, 3 4), (5 6, 7 8))"
        );
        r.drawPolygon(node, geometry, true);
        t.ok(g_SetNodeDimension, "setNodeDimension is called");
        t.eq(node.path, "m 2,4 l 6,8 2,4 x m 10,12 l 14,16 10,12 e", "path attribute is correct - inner ring has no area and is not closed");

        geometry.components[1].addComponent(new OpenLayers.Geometry.Point(8, 7));
        r.drawPolygon(node, geometry, true);
        t.eq(node.path, "m 2,4 l 6,8 2,4 x m 10,12 l 14,16 16,14 10,12 x e", "path attribute is correct - inner ring has an area and is closed");        
    }
    
    function test_VML_drawrectangle(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }
        
        t.plan(4);
        
        var r = new OpenLayers.Renderer.VML(document.body);
        r.offset = {x: 0, y: 0};
        r.resolution = 0.5;
        
        var node = document.createElement('div');
        
        var geometry = {
            x: 1,
            y: 2,
            width: 3,
            height: 4
        }
        
        r.drawRectangle(node, geometry);
        
        t.eq(node.style.left, "2px", "node.style.left is correct");
        t.eq(node.style.top, "4px", "node.style.top is correct");
        t.eq(node.style.width, "6px", "node.style.width is correct");
        t.eq(node.style.height, "8px", "node.style.height is correct");
    }
    
    function test_vml_getnodetype(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }

        t.plan(1);
        
        var r = new OpenLayers.Renderer.VML(document.body);

        var g = {CLASS_NAME: "OpenLayers.Geometry.Point"}
        var s = {graphicName: "square"};
        
        t.eq(r.getNodeType(g, s), "olv:shape", "Correct node type for well known symbols");
    }

    function test_vml_importsymbol(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }

        t.plan(4);
        
        OpenLayers.Renderer.symbol.rect1 = [0,0, 10,0, 10,4, 0,4, 0,0];
        OpenLayers.Renderer.symbol.rect2 = [0,0, 4,0, 4,10, 0,10, 0,0];

        var r = new OpenLayers.Renderer.VML(document.body);

        var cache = r.importSymbol("square");

        t.eq(cache.path, "m 0 0 l 0 1 1 1 1 0 0 0 x e", "Square symbol rendered correctly");
        t.ok(r.symbolCache["-square"], "Symbol has been cached correctly.");
        
        cache = r.importSymbol("rect1");
        t.eq(cache.bottom, -3, "coordorigin bottom of landscape symbol set to -3 to move topmost part to the bottom (we are flipping y!)");
        
        cache = r.importSymbol("rect2");
        t.eq(cache.left, -3, "coordorigin left of portrait symbol set to -3 to move leftmost part to the right");
        
        delete OpenLayers.Renderer.symbol.rect1;
        delete OpenLayers.Renderer.symbol.rect2;
        
    }
    
    function test_vml_dashstyle(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }
        
        t.plan(5);
        
        var r = new OpenLayers.Renderer.VML(document.body);
        
        t.eq(r.dashStyle({strokeDashstyle: "1 4"}), "dot", "dot pattern recognized correctly.");
        t.eq(r.dashStyle({strokeDashstyle: "4 4"}), "dash", "dash pattern recognized correctly.");
        t.eq(r.dashStyle({strokeDashstyle: "8 4"}), "longdash", "longdash pattern recognized correctly.");
        t.eq(r.dashStyle({strokeDashstyle: "4 4 1 4"}), "dashdot", "dashdot pattern recognized correctly.");
        t.eq(r.dashStyle({strokeDashstyle: "8 4 1 4"}), "longdashdot", "longdashdot pattern recognized correctly.");
    }
    
    function test_vml_moveRoot(t) {
        if (!OpenLayers.Renderer.VML.prototype.supported() || OpenLayers.Renderer.SVG.prototype.supported()) {
            t.plan(0);
            return;
        }
        t.plan(2);
        
        var map = new OpenLayers.Map("map");
        var l1 = new OpenLayers.Layer.Vector("vector");
        map.addLayer(l1);
        var l2 = new OpenLayers.Layer.Vector.RootContainer("rootcontainer", {layers: [l1]});
        
        var clear = l1.renderer.clear;
        l1.renderer.clear = function() {
            // this should be called twice, once when l2 is added to the map,
            // and once when removed from the map.
            t.ok(true, "Clearing original layer");
        };
        map.addLayer(l2);
        map.removeLayer(l2);
        l1.renderer.clear = clear;
        
        map.removeLayer(l1);
    }
        
  </script>
</head>
<body>
<div id="map" style="width:500px;height:550px"></div>
</body>
</html>