Select to view content in your preferred language

GeoRSS Layer

1471
9
09-07-2010 08:29 AM
MichaelMacDonald
Emerging Contributor
I'm trying to add a GeoRSSLayer to my project and I'm getting the following error. 

A value of type 'GeoRssLayer' cannot be added to a collection or dictionary of type 'LayerCollection'.

I've checked all of my references to ensure everything is at the latest version (build 314 of the v2 Silverlight API).

Any idea what I'm doing wrong?

Thanks.
0 Kudos
9 Replies
dotMorten_esri
Esri Notable Contributor
Did you add a reference to ESRI.ArcGIS.Client.Toolkit.DataSources ?
0 Kudos
MichaelMacDonald
Emerging Contributor
Did you add a reference to ESRI.ArcGIS.Client.Toolkit.DataSources ?


Thanks, very much for the help.  I ended up uninstalling everything and reinstalling and I think it's fine now (at least the reference is fine).

However, I'm having trouble matching up two different coordinate systems.  All of my layers are in web mercator and I'm importing a GeoRSS feed in LAT/LONG.  I understand that I have to use the GraphicsLayer to transform each of the points to the new projected coordinate system but how do I access each of the points ? in GraphicsLayer_Initialized?  or is there some event on the GeoRSS layer?

Thanks much,
0 Kudos
RandallBrown
Emerging Contributor
Michael,
I put the following in the the initialized event for the GeoRSS layer.  I set the GeoRSS layer visible property to "False" and added another Graphics layer ("TransformLayer") to hold the converted points.

It works, but I am wondering if there is a simpler solution, maybe a method to grab the points directly from the RSS feed without having to add the service as a hidden layer (although maybe that is not a problem, I don't know -- I have about 2 days experience with the ArcGIS siliverlight API):

    Private Sub GeoRSS_Initailized(ByVal sender As Object, ByVal e As EventArgs)
        Dim tranGraphic As ESRI.ArcGIS.Client.Graphic = Nothing
        Dim tansformLayer As ESRI.ArcGIS.Client.GraphicsLayer = TryCast(MyMap.Layers("TransformLayer"), GraphicsLayer)
        Dim mapPt As ESRI.ArcGIS.Client.Geometry.MapPoint = Nothing
        Dim transformPt As ESRI.ArcGIS.Client.Geometry.MapPoint = Nothing
        Dim grLayer As ESRI.ArcGIS.Client.GraphicsLayer = TryCast(sender, ESRI.ArcGIS.Client.GraphicsLayer)
        For Each graphic As ESRI.ArcGIS.Client.Graphic In grLayer.Graphics
            If TypeOf graphic.Geometry Is ESRI.ArcGIS.Client.Geometry.MapPoint Then
                mapPt = graphic.Geometry
                transformPt = ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(mapPt)
                tranGraphic = New ESRI.ArcGIS.Client.Graphic()
                tranGraphic.Geometry = transformPt
                tansformLayer.Graphics.Add(tranGraphic)
            End If
        Next (graphic)


    End Sub
0 Kudos
dotMorten_esri
Esri Notable Contributor
This is unfortunately a limitation of the GeoRSS layer, since data always comes back in lat/long.
You could use the layer.Graphics.CollectionChanged event. If the event tells you a feature got added, check it's spatial reference and verify if you need to project it by checking its graphic.Geometry.SpatialReference property.
0 Kudos
adamestrada
Emerging Contributor
You'll need to define that the map is Web Mercator like this

public partial class Home : Page
{
private static ESRI.ArcGIS.Client.Projection.WebMercator _mercator =
new ESRI.ArcGIS.Client.Projection.WebMercator();

Then in your method for parsing the RSS feed, you need to add the following

#region Parse GeoRSS with Linq
private void RSS(Stream s)
{
try
{
GraphicsLayer graphicsLayer = Map.Layers["GeoRSSFeed"] as GraphicsLayer;
graphicsLayer.ClearGraphics();

XDocument doc = XDocument.Load(s);
XNamespace geo = "http://www.w3.org/2003/01/geo/wgs84_pos#";
XNamespace dc = "http://purl.org/dc/elements/1.1/";

var rssGraphics = from rssgraphic in doc.Descendants("item")
select new RssGraphic
{
Geometry = new MapPoint(
Convert.ToDouble(rssgraphic.Element(geo + "long").Value, System.Globalization.CultureInfo.InvariantCulture),
Convert.ToDouble(rssgraphic.Element(geo + "lat").Value, System.Globalization.CultureInfo.InvariantCulture)),
Symbol = LayoutRoot.Resources["QuakePictureSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol,
RssAttributes = new Dictionary<string, object>() { { "Title", rssgraphic.Element("title").Value },
{ "Link", rssgraphic.Element("link").Value } }
};

foreach (RssGraphic rssGraphic in rssGraphics)
{
  rssGraphic.Geometry = _mercator.FromGeographic(rssGraphic.Geometry);
foreach (KeyValuePair<string, object> rssAttribute in rssGraphic.RssAttributes)
{
rssGraphic.Attributes.Add(rssAttribute.Key, rssAttribute.Value);
}
graphicsLayer.Graphics.Add((Graphic)rssGraphic);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
#endregion
0 Kudos
DarkoRadiceski
Emerging Contributor
Has anyone played with adding the geoRss layer all programatically let say in C# or VB? I have tried accessing the geoRss feed and i can see in my code behind there are number of features.

No map points shown on the map.

Do i need to add them manualy and if need be reproject them to web mercator to show?

My points on the map dont show 😞 and no error messages shown.

A bit confused on how to add the map tips programaticaly. I found an example but all the map tips and icons are defined in xaml code.

Also has anyone been able to display images that could be part of the feed on hover over the pin?

Any advice would be greatly appreciated.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
0 Kudos
DarkoRadiceski
Emerging Contributor
Hi dbroux,

I had a look at the example but it also has elements placed in xaml.

I was more hoping to find an example that will create all the elements in code behind and load the georss layer.

Any thoughts?
0 Kudos
dotMorten_esri
Esri Notable Contributor
If you read the comments at the end of the blogpost, there's a snippet on how to assign the reprojector to the map from code.
Remember: ANYTHING you can do in Xaml, you can also do in code.
0 Kudos