Description = (item.Element("description") != null) item.Element("description").Value : null,
PubData = (item.Element("pubDate") != null) item.Element("pubDate").Value : null,
Locatios = ParserLocations(XElement.Parse(item.LastNode.ToString().Replace(":", "X")).Value)
};
if (DownloadGeoRssCompleted.Method != null)
{
DownloadGeoRssCompleted.Invoke(items.ToList());
}
}
catch (Exception ex)
{
if (DownloadGeoRssException.Method != null)
{
DownloadGeoRssException.Invoke(ex);
}
else
{
throw;
}
}
}
private LocationCollection ParserLocations(string points)
{
LocationCollection lc = new LocationCollection();
string[] ps = points.Split(' ');
for (int i = 0; i < ps.Length; i+=2)
{
lc.Add(new Location(double.Parse(ps[i]), double.Parse(ps[i + 1])));
}
return lc;
}
#endregion
}
}
三、基于SLBM呈现GeoRss数据
引入Bing Maps Silverlight Control的控件库,定义一个专门的MapLayer图层来呈现GeoRss数据,其Silverlight前台的代码如下。
CopyrightVisibility="Collapsed">
应用程序加载的过程中使用上面所开发完成的GeoRss阅读器进行数据读取并解析,随后将结果呈现在Bing Maps Silverlight Control的应用中。代码如下:
public MainPage()
{
InitializeComponent();
string url = "http://localhost:32484/SHBuildingGeoHandler.ashx";
GeoRssReader reader = new GeoRssReader(new Uri(url, UriKind.RelativeOrAbsolute));
reader.DownloadGeoRssCompleted+=new DownloadGeoRssCompletedEventHandler(reader_DownloadGeoRssCompleted);
reader.ReadAsync();
}
void reader_DownloadGeoRssCompleted(List
{
//System.Diagnostics.Debug.WriteLine(items.Count);
foreach (var item in items)
{
MapPolygon mp = new MapPolygon();
mp.Locations = item.Locatios;
mp.Fill = new SolidColorBrush(Colors.Red);
this.mlayer.Children.Add(mp);
}
}

作者:“beniao”