Skip to content

Commit d8e22c4

Browse files
committed
1 parent 6157132 commit d8e22c4

8 files changed

Lines changed: 360 additions & 199 deletions

File tree

SharpMap.Serialization/MapSerialization.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public static Map LoadMapFromStream(Stream s)
5252
}
5353
lay = wmsl;
5454
}
55+
//And some simple tiled layers
5556
else if (l is OsmLayer)
5657
{
5758
lay = new Layers.TileLayer(new BruTile.Web.OsmTileSource(), l.Name);

SharpMap.Serialization/MapServerMapFileLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ private static void ApplyStyling(ILayer lay, List<ClassElement> classes, string
235235
styleMap.Add(c.Expression, CreateStyle(c.Styles.ToArray(), type));
236236
}
237237

238-
(lay as VectorLayer).Theme = new SharpMap.Rendering.Thematics.CategoriesTheme<string>(classItem, styleMap, new VectorStyle());
238+
(lay as VectorLayer).Theme = new SharpMap.Rendering.Thematics.UniqueValuesTheme<string>(classItem, styleMap, new VectorStyle());
239239
}
240240
}
241241

SharpMap.Serialization/SharpMap.Serialization.csproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,17 @@
5656
<Compile Include="SharpMapSerializationClasses.cs" />
5757
</ItemGroup>
5858
<ItemGroup>
59-
<ProjectReference Include="..\SharpMap.Extensions\SharpMap.Extensions.VS2010.csproj">
59+
<ProjectReference Include="..\SharpMap.Extensions\SharpMap.Extensions.csproj">
6060
<Project>{A4140C12-53F5-438C-8D24-9E48C504FECF}</Project>
6161
<Name>SharpMap.Extensions.VS2010</Name>
6262
</ProjectReference>
63-
<ProjectReference Include="..\SharpMap\SharpMap.VS2010.csproj">
63+
<ProjectReference Include="..\SharpMap\SharpMap.csproj">
6464
<Project>{C83777FC-AABB-47D9-911F-D76255D4D541}</Project>
6565
<Name>SharpMap.VS2010</Name>
6666
</ProjectReference>
6767
</ItemGroup>
6868
<ItemGroup>
6969
<None Include="packages.config" />
70-
<None Include="ShapMapMapFile.xsd">
71-
<SubType>Designer</SubType>
72-
</None>
7370
</ItemGroup>
7471
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7572
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

SharpMap.sln

Lines changed: 212 additions & 190 deletions
Large diffs are not rendered by default.

SharpMap/Rendering/Thematics/CategoriesTheme.cs renamed to SharpMap/Rendering/Thematics/UniqueValuesTheme.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
namespace SharpMap.Rendering.Thematics
2222
{
2323
/// <summary>
24-
/// CategoriesTheme is a theme each rendered feature is matched against at category that have a different style
24+
/// UniqueValuesTheme is a theme each rendered feature is matched against at category that have a different style
2525
/// </summary>
2626
/// <typeparam name="T">Type of the featureattribute to match</typeparam>
27-
public class CategoriesTheme<T> : ITheme
27+
public class UniqueValuesTheme<T> : ITheme
2828
{
2929
IStyle _default = null;
3030

@@ -38,7 +38,7 @@ public class CategoriesTheme<T> : ITheme
3838
/// <param name="attributeName">the featureattribute to categorize by</param>
3939
/// <param name="styleMap">the map of attributevalue to style</param>
4040
/// <param name="defaultStyle">the default style to map features that does not exist in the stylemap with</param>
41-
public CategoriesTheme(string attributeName, Dictionary<T,IStyle> styleMap, IStyle defaultStyle)
41+
public UniqueValuesTheme(string attributeName, Dictionary<T, IStyle> styleMap, IStyle defaultStyle)
4242
{
4343
_attributeName = attributeName;
4444
_styleMap = new Dictionary<string, IStyle>();

SharpMap/SharpMap.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
<Compile Include="Rendering\Symbolizer\CohenSutherlandLineClipping.cs" />
190190
<Compile Include="Rendering\Symbolizer\Utility.cs" />
191191
<Compile Include="Rendering\TextOnPath.cs" />
192+
<Compile Include="Rendering\Thematics\UniqueValuesTheme.cs" />
192193
<Compile Include="Rendering\Thematics\ColorBlend.cs" />
193194
<Compile Include="Rendering\Thematics\CustomTheme.cs" />
194195
<Compile Include="Rendering\Thematics\GradientTheme.cs" />
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using NUnit.Framework;
6+
using System.Drawing;
7+
using System.Xml.Serialization;
8+
using SharpMap.Serialization;
9+
using System.IO;
10+
using System.Net;
11+
12+
namespace UnitTests.Serialization
13+
{
14+
[TestFixture]
15+
class MapDocSerializationTests
16+
{
17+
[Test]
18+
public void TestSerializeWmsLayer()
19+
{
20+
SharpMap.Map m = new SharpMap.Map();
21+
SharpMap.Layers.WmsLayer l = new SharpMap.Layers.WmsLayer("testwms", "http://mapus.jpl.nasa.gov/wms.cgi?");
22+
l.AddChildLayers(l.RootLayer, false);
23+
m.Layers.Add(l);
24+
MemoryStream ms = new MemoryStream();
25+
SharpMap.Serialization.MapSerialization.SaveMapToStream(m, ms);
26+
string txt = System.Text.ASCIIEncoding.ASCII.GetString(ms.ToArray());
27+
Console.WriteLine(txt);
28+
Assert.IsTrue(txt.Contains(@"<Layers>
29+
<MapLayer xsi:type=""WmsLayer"">
30+
<Name>testwms</Name>
31+
<MinVisible>0</MinVisible>
32+
<MaxVisible>1.7976931348623157E+308</MaxVisible>
33+
<OnlineURL>http://mapus.jpl.nasa.gov/wms.cgi?</OnlineURL>
34+
<WmsLayers>global_mosaic,global_mosaic_base,us_landsat_wgs84,srtm_mag,daily_planet,daily_afternoon,BMNG,modis,huemapped_srtm,srtmplus,worldwind_dem,us_ned,us_elevation,us_colordem,gdem</WmsLayers>
35+
</MapLayer>
36+
</Layers>"));
37+
ms.Close();
38+
}
39+
40+
[Test]
41+
public void TestDeSerializeWmsLayer()
42+
{
43+
44+
MemoryStream ms = new MemoryStream(System.Text.ASCIIEncoding.ASCII.GetBytes(@"<?xml version=""1.0""?>
45+
<MapDefinition xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
46+
<BackGroundColor>Transparent</BackGroundColor>
47+
<Extent>
48+
<Xmin>-0.5</Xmin>
49+
<Ymin>-0.375</Ymin>
50+
<Xmax>0.5</Xmax>
51+
<Ymax>0.375</Ymax>
52+
</Extent>
53+
<Layers>
54+
<MapLayer xsi:type=""WmsLayer"">
55+
<Name>testwms</Name>
56+
<MinVisible>0</MinVisible>
57+
<MaxVisible>1.7976931348623157E+308</MaxVisible>
58+
<OnlineURL>http://mapus.jpl.nasa.gov/wms.cgi?</OnlineURL>
59+
</MapLayer>
60+
</Layers>
61+
<SRID>4326</SRID>
62+
</MapDefinition>
63+
"));
64+
SharpMap.Map m = SharpMap.Serialization.MapSerialization.LoadMapFromStream(ms);
65+
Assert.AreEqual(4326, m.SRID);
66+
Assert.AreEqual(1, m.Layers.Count);
67+
Assert.IsInstanceOfType(typeof(SharpMap.Layers.WmsLayer), m.Layers[0]);
68+
Assert.AreEqual("http://mapus.jpl.nasa.gov/wms.cgi?", (m.Layers[0] as SharpMap.Layers.WmsLayer).CapabilitiesUrl);
69+
ms.Close();
70+
}
71+
72+
[Test]
73+
public void TestDeSerializeWmsLayerWithCredentials()
74+
{
75+
76+
MemoryStream ms = new MemoryStream(System.Text.ASCIIEncoding.ASCII.GetBytes(@"<?xml version=""1.0""?>
77+
<MapDefinition xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
78+
<BackGroundColor>Transparent</BackGroundColor>
79+
<Extent>
80+
<Xmin>-0.5</Xmin>
81+
<Ymin>-0.375</Ymin>
82+
<Xmax>0.5</Xmax>
83+
<Ymax>0.375</Ymax>
84+
</Extent>
85+
<Layers>
86+
<MapLayer xsi:type=""WmsLayer"">
87+
<Name>testwms</Name>
88+
<MinVisible>0</MinVisible>
89+
<MaxVisible>1.7976931348623157E+308</MaxVisible>
90+
<OnlineURL>http://mapus.jpl.nasa.gov/wms.cgi?</OnlineURL>
91+
<WmsUser>test</WmsUser>
92+
<WmsPassword>pw</WmsPassword>
93+
</MapLayer>
94+
</Layers>
95+
<SRID>4326</SRID>
96+
</MapDefinition>
97+
"));
98+
SharpMap.Map m = SharpMap.Serialization.MapSerialization.LoadMapFromStream(ms);
99+
Assert.AreEqual(4326, m.SRID);
100+
Assert.AreEqual(1, m.Layers.Count);
101+
Assert.IsInstanceOfType(typeof(SharpMap.Layers.WmsLayer), m.Layers[0]);
102+
Assert.AreEqual("http://mapus.jpl.nasa.gov/wms.cgi?", (m.Layers[0] as SharpMap.Layers.WmsLayer).CapabilitiesUrl);
103+
Assert.IsNotNull((m.Layers[0] as SharpMap.Layers.WmsLayer).Credentials);
104+
Assert.IsInstanceOfType(typeof(NetworkCredential), (m.Layers[0] as SharpMap.Layers.WmsLayer).Credentials);
105+
Assert.AreEqual("test", ((m.Layers[0] as SharpMap.Layers.WmsLayer).Credentials as NetworkCredential).UserName);
106+
Assert.AreEqual("pw", ((m.Layers[0] as SharpMap.Layers.WmsLayer).Credentials as NetworkCredential).Password);
107+
ms.Close();
108+
}
109+
110+
111+
[Test]
112+
public void TestSerializeWmsLayerWithCredentials()
113+
{
114+
SharpMap.Map m = new SharpMap.Map();
115+
SharpMap.Layers.WmsLayer l = new SharpMap.Layers.WmsLayer("testwms", "http://mapus.jpl.nasa.gov/wms.cgi?", TimeSpan.MaxValue,
116+
System.Net.WebRequest.DefaultWebProxy, new NetworkCredential("test", "pw"));
117+
m.Layers.Add(l);
118+
MemoryStream ms = new MemoryStream();
119+
SharpMap.Serialization.MapSerialization.SaveMapToStream(m, ms);
120+
string txt = System.Text.ASCIIEncoding.ASCII.GetString(ms.ToArray());
121+
Assert.IsTrue(txt.Contains(@"<Layers>
122+
<MapLayer xsi:type=""WmsLayer"">
123+
<Name>testwms</Name>
124+
<MinVisible>0</MinVisible>
125+
<MaxVisible>1.7976931348623157E+308</MaxVisible>
126+
<OnlineURL>http://mapus.jpl.nasa.gov/wms.cgi?</OnlineURL>
127+
<WmsLayers>global_mosaic,global_mosaic_base,us_landsat_wgs84,srtm_mag,daily_planet,daily_afternoon,BMNG,modis,huemapped_srtm,srtmplus,worldwind_dem,us_ned,us_elevation,us_colordem,gdem</WmsLayers>
128+
<WmsUser>test</WmsUser>
129+
<WmsPassword>pw</WmsPassword>
130+
</MapLayer>
131+
</Layers>"));
132+
ms.Close();
133+
}
134+
}
135+
}

UnitTests/UnitTests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<Compile Include="Rendering\GroupStyle\GroupStyleTests.cs" />
125125
<Compile Include="Rendering\Symbolizer\CohenSutherlandLineClippingTest.cs" />
126126
<Compile Include="Rendering\Thematics\ColorBlendTest.cs" />
127+
<Compile Include="Serialization\MapDocSerializationTests.cs" />
127128
<Compile Include="TestWmsCapabilityParser.cs" />
128129
<Compile Include="WMS\Encoding.cs" />
129130
</ItemGroup>
@@ -132,6 +133,10 @@
132133
<Project>{A4140C12-53F5-438C-8D24-9E48C504FECF}</Project>
133134
<Name>SharpMap.Extensions.VS2010</Name>
134135
</ProjectReference>
136+
<ProjectReference Include="..\SharpMap.Serialization\SharpMap.Serialization.csproj">
137+
<Project>{75E9B9FF-D04E-4F4F-8D06-8CD310F5F2DB}</Project>
138+
<Name>SharpMap.Serialization</Name>
139+
</ProjectReference>
135140
<ProjectReference Include="..\SharpMap.SqlServerSpatialObjects\SharpMap.SqlServerSpatialObjects.csproj">
136141
<Project>{6D681045-8EF1-44EA-A19D-C7A63A6D0F76}</Project>
137142
<Name>SharpMap.SqlServerSpatialObjects.VS2010</Name>

0 commit comments

Comments
 (0)