summaryrefslogtreecommitdiff
path: root/misc/openlayers/tests/Layer/Vector/RootContainer.html
blob: aa92923412ca8f74c47724207d915d1532f63814 (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
<html>
<head>
  <script src="../../OLLoader.js"></script>
  <script type="text/javascript">
    var layer, map; 

    function test_RootContainer_collectResetRoots(t) {
        
        map = new OpenLayers.Map("map");
        var layer1 = new OpenLayers.Layer.Vector("layer1");
        var layer2 = new OpenLayers.Layer.Vector("layer2");
        layer = new OpenLayers.Layer.Vector.RootContainer("layer_1_2", {
            layers: [layer1, layer2]
        });
        
        // we cannot test this with a renderer that does not hava a rendererRoot
        var plan = layer.renderer.rendererRoot ? 4 : 0;
        t.plan(plan);
        if(plan == 0) {
            return;
        }

        var numRoots = layer.renderer.rendererRoot.childNodes.length;

        // addLayers will call setMap() for layer, which will call collectRoots()
        map.addLayers([layer1, layer2, layer]);
        t.eq(layer.renderer.rendererRoot.childNodes.length, numRoots * 3, "layer has correct number of renderer roots");        
        t.eq(layer1.renderer.rendererRoot.childNodes.length, 0, "layer1 has no own renderer root");
        
        layer.resetRoots();
        t.eq(layer.renderer.rendererRoot.childNodes.length, numRoots, "roots removed from container");
        t.eq(layer1.renderer.rendererRoot.childNodes.length, numRoots, "root re-added to original layer");
    }
    
    function test_RootContainer_getFeatureFromEvent(t) {
        t.plan(2);
        var map = new OpenLayers.Map("map");
        var layer1 = new OpenLayers.Layer.Vector("layer1");
        var layer2 = new OpenLayers.Layer.Vector("layer2");
        layer = new OpenLayers.Layer.Vector.RootContainer("layer_1_2", {
            layers: [layer1, layer2]
        });
        map.addLayers([layer1, layer2, layer]);
        var feature1 = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(0,1));
        var feature2 = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1,0));
        layer1.addFeatures(feature1);
        layer2.addFeatures(feature2);
        t.eq(layer.getFeatureFromEvent({
            srcElement: {
                _featureId: feature1.id
            }
        }).id, feature1.id, "feature from layer1 found");
        t.eq(layer.getFeatureFromEvent({srcElement: {
            _featureId: feature2.id
        }}).id, feature2.id, "feature from layer2 found");
    }

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