Skip to content

Commit 592ecd1

Browse files
committed
[Branches/1.0] bugfix: LayerGroup.Envelope supports inner layers with null envelope. Workitem: #35091
git-tfs-id: [https://tfs.codeplex.com/tfs/TFS01]$/SharpMap/Branches/1.0;C105578
1 parent e517f19 commit 592ecd1

2 files changed

Lines changed: 51 additions & 6 deletions

File tree

SharpMap/Layers/LayerGroup.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,19 @@ public override Envelope Envelope
7575
{
7676
get
7777
{
78-
if (Layers.Count == 0)
79-
return null;
80-
var bbox = new Envelope(Layers[0].Envelope);
81-
for (int i = 1; i < Layers.Count; i++)
82-
bbox.ExpandToInclude(Layers[i].Envelope);
78+
Envelope bbox = null;
79+
for (int i = 0; i < Layers.Count; i++)
80+
{
81+
var layerEnvelope = Layers[i].Envelope;
82+
if (layerEnvelope != null)
83+
{
84+
if(bbox == null)
85+
bbox = new Envelope(layerEnvelope);
86+
else
87+
bbox.ExpandToInclude(layerEnvelope);
88+
}
89+
}
90+
8391
return bbox;
8492
}
8593
}

UnitTests/Layers/LayerGroupTest.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ private class DummyLayer : Layer
1313
{
1414
public override Envelope Envelope
1515
{
16-
get { throw new NotImplementedException(); }
16+
get { return null; }
17+
}
18+
}
19+
#endregion
20+
21+
#region FooLayer class
22+
private class FooLayer : Layer
23+
{
24+
public override Envelope Envelope
25+
{
26+
get { return new Envelope(5, 10, 5, 10); }
1727
}
1828
}
1929
#endregion
@@ -91,5 +101,32 @@ public void ReverseCoordinateTransformation_SettingValueWhenSkipIsOn_DoesNotProp
91101
"LayerGroup.ReverseCoordinateTransformation should NOT propagate to inner layers because SkipTransformationPropagation was true");
92102
}
93103
#endif
104+
105+
[Test(Description = "Envelope returns null when the inner layer Envelope is null")]
106+
public void Envelope_WhenInnerLayerEnvelopeIsNull_ReturnsNull()
107+
{
108+
var group = new LayerGroup("group");
109+
group.Layers.Add(new DummyLayer());
110+
111+
Assert.That(group.Envelope, Is.Null,
112+
"LayerGroup envelope should be null since we added a layer with a null envelope");
113+
}
114+
115+
[Test(Description = "Envelope returns null when there are no layers")]
116+
public void Envelope_NoInnerLayers_ReturnsNull()
117+
{
118+
var group = new LayerGroup("group");
119+
Assert.IsNull(group.Envelope);
120+
}
121+
122+
[Test(Description = "Envelope skips inner layers which return null envelope")]
123+
public void Envelope_SomeInnerLayerWithNullEnvelope_SkipNulls()
124+
{
125+
var group = new LayerGroup("group");
126+
group.Layers.Add(new DummyLayer());
127+
group.Layers.Add(new FooLayer());
128+
129+
Assert.That(group.Envelope, Is.EqualTo(new Envelope(5, 10, 5, 10)));
130+
}
94131
}
95132
}

0 commit comments

Comments
 (0)