// (c) Copyright ESRI.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
using System;
using System.Windows;
using ESRI.ArcGIS.Client.Symbols;
using System.Collections.Generic;
namespace ESRI.ArcGIS.Client.Toolkit.DataSources
{
///
/// GeoRSS Layer.
///
///
///
/// Only GeoRSS-simple feeds are supported.
/// Geometries are returned in Geographic WGS84. If you are displaying the feed
/// on top of a map in a different projection, they must be reprojected manually
/// when the graphics collection gets features added.
///
///
/// The graphic will not have a symbol associated with them. You should specify
/// a renderer on this layer, or manually assign symbols to the graphics when
/// the graphics collection gets features added.
///
///
/// Recent earthquake's greater than M2.5 with map tips:
///
/// <esri:GeoRssLayer Source="http://earthquake.usgs.gov/earthquakes/catalogs/1day-M2.5.xml" >
/// <esri:GeoRssLayer.Renderer>
/// <esri:SimpleRenderer Brush="Red" />
/// </esri:GeoRssLayer.Renderer>
/// <esri:GeoRssLayer.MapTip>
/// <Border Padding="5" Background="White" esri:GraphicsLayer.MapTipHideDelay="0:0:0.5">
/// <StackPanel>
/// <TextBlock Text="{Binding [Title]}" FontWeight="Bold" FontSize="12" />
/// <TextBlock Text="{Binding [Summary]}" FontSize="10" />
/// <HyperlinkButton Content="Link" NavigateUri="{Binding [Link]}" Opacity=".5" FontSize="10" TargetName="_blank" />
/// </StackPanel>
/// </Border>
/// </esri:GeoRssLayer.MapTip>
/// </esri:GeoRssLayer>
///
///
///
/// If you require a proxy, simply prefix the layer URI with a proxy prefix:
///
/// <esri:GeoRssLayer Source="../proxy.ashx?url=http://earthquake.usgs.gov/earthquakes/catalogs/1day-M2.5.xml" />
///
///
///
/// The following attributes will be associated with each graphic:
///
///
/// - Title ()
/// - Summary ()
/// - PublishDate ()
/// - Id ()
/// - Link ()
/// - FeedItem ()
///
///
/// Optionally, if the item is using any of the simple-georss extensions,
/// these will also be included:
///
///
/// - elev ()
/// - floor ()
/// - radius ()
/// - featuretypetag ()
/// - relationshiptag ()
/// - featurename ()
///
///
/// The Graphic's property
/// will be set to a time instance matching the PublishDate.
///
///
public sealed class GeoRssLayer : GraphicsLayer
{
GeoRssLoader loader;
#region Constructor:
///
/// Initializes a new instance of the class.
///
public GeoRssLayer() : base()
{
loader = new GeoRssLoader();
loader.LoadCompleted += loader_LoadCompleted;
loader.LoadFailed += loader_LoadFailed;
}
private void loader_LoadFailed(object sender, GeoRssLoader.RssLoadFailedEventArgs e)
{
this.InitializationFailure = e.ex;
if (!IsInitialized)
base.Initialize();
}
private void loader_LoadCompleted(object sender, GeoRssLoader.RssLoadedEventArgs e)
{
this.Graphics = new GraphicCollection(e.Graphics);
// GeoRSS-Simple requires geometries in WGS84 hence; setting layer Spatial Reference to 4326:
this.SpatialReference = new Geometry.SpatialReference(4326);
if(!IsInitialized)
base.Initialize();
}
#endregion
#region Overriden Methods:
///
/// Initializes the resource.
///
///
/// Override this method if your resource requires asyncronous requests to initialize,
/// and call the base method when initialization is completed.
/// Upon completion of initialization, check the for any possible errors.
///
///
///
public override void Initialize()
{
Update();
}
///
/// Called when the GraphicsSource property changes.
///
/// Old value of the GraphicsSource property.
/// New value of the GraphicsSource property.
/// Thrown when property is changed on a .
protected override void OnGraphicsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
{
throw new InvalidOperationException(Properties.Resources.GraphicsLayer_GraphicsSourceCannotBeSetOnLayer);
}
#endregion
#region Dependency Properties:
#if !SILVERLIGHT
private System.Net.ICredentials credentials;
///
/// Gets or sets the network credentials that are sent to the host and used to authenticate the request.
///
/// The credentials used for authentication.
public System.Net.ICredentials Credentials
{
get { return credentials; }
set
{
if (credentials != value)
{
credentials = value;
OnPropertyChanged("Credentials");
}
}
}
#endif
///
/// Gets or sets the URI for the RSS feed.
///
public Uri Source
{
get { return ((Uri)GetValue(SourceProperty)); }
set { SetValue(SourceProperty, value); }
}
///
/// Identifies the dependency property.
///
public static readonly DependencyProperty SourceProperty =
DependencyProperty.Register("Source", typeof(Uri), typeof(GeoRssLayer), null);
#endregion
///
/// Reloads the RSS feed from the endpoint.
///
public void Update()
{
if (Source != null)
{
#if !SILVERLIGHT
loader.LoadRss(Source, Credentials);
#else
loader.LoadRss(Source);
#endif
}
}
}
}