Select to view content in your preferred language

GeoRSSLayer capture collection changed

795
3
Jump to solution
09-13-2012 12:55 PM
GregLutz
Emerging Contributor
Hi, I'm using GeoRSSLayer and I dynamically change the Source URI at runtime. I'm trying to capture when the Graphics.CollectionChanged. But it's not working. Here is my code:

On page load:

GeoRssLayer rssLayer = map1.Layers["GeoRSSLayer"] as GeoRssLayer;             rssLayer.Graphics.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Graphics_CollectionChanged);


In button click event:

GeoRssLayer rssLayer = map1.Layers["GeoRSSLayer"] as GeoRssLayer;                 rssLayer.ClearGraphics();                 rssLayer.Source = new Uri(source); // source is a new feed url                 rssLayer.Update();


Unfortunately, even though the graphics get updated successfully (I can watch during debug they go from 20 to 0, to 20, to 0, etc). the CollectionChanged event NEVER fires. I need to call ZoomTo method after the graphics layer is updated to zoom in wherever graphics are. If you have any other suggestions on how to perform a ZoomTo after the Source URI changes on a GeoRSSLayer that would work. Of course I can't just simply call ZoomTo in my code after I set the Source because it's asynchronous and I don't see any Completed type events on the GeoRSSLayer to know when it's done loading.

 void Graphics_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)         {             GeoRssLayer rssLayer = map1.Layers["GeoRSSLayer"] as GeoRssLayer;             map1.ZoomTo(rssLayer.FullExtent);         }
0 Kudos
1 Solution

Accepted Solutions
GregLutz
Emerging Contributor
Ok, I figured out my Zooming issue works if I listen for the FullExtent property to change, not the Graphics. I was afraid this code would result in an infinite loop (I thought ZoomTo changes the FullExtent property of the map control) but it apparently doesn't.

GeoRssLayer rssLayer = map1.Layers["GeoRSSLayer"] as GeoRssLayer; rssLayer.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(rssLayer_PropertyChanged);


void rssLayer_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) {     if (e.PropertyName == "FullExtent")     {         GeoRssLayer rssLayer = map1.Layers["GeoRSSLayer"] as GeoRssLayer;         map1.ZoomTo(rssLayer.FullExtent);     } }

Hopefully this won't result in other problems zooming in every time the full extent property changes. If I just listen for Graphics to change, then the ZoomTo method does not work. Probably because the Graphics layer hasn't updated its layout at that moment yet.

View solution in original post

0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
AS you assign a new collection of graphics, you can subscribe to rssLayer.PropertyChanged and, in the Handler, test that the changed property is called "Graphics".
0 Kudos
GregLutz
Emerging Contributor
Thank you, this does answer my question. Unfortunately it doesn't resolve my entire issue, but i'll create a new thread since the issue is unrelated now to the topic.
0 Kudos
GregLutz
Emerging Contributor
Ok, I figured out my Zooming issue works if I listen for the FullExtent property to change, not the Graphics. I was afraid this code would result in an infinite loop (I thought ZoomTo changes the FullExtent property of the map control) but it apparently doesn't.

GeoRssLayer rssLayer = map1.Layers["GeoRSSLayer"] as GeoRssLayer; rssLayer.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(rssLayer_PropertyChanged);


void rssLayer_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) {     if (e.PropertyName == "FullExtent")     {         GeoRssLayer rssLayer = map1.Layers["GeoRSSLayer"] as GeoRssLayer;         map1.ZoomTo(rssLayer.FullExtent);     } }

Hopefully this won't result in other problems zooming in every time the full extent property changes. If I just listen for Graphics to change, then the ZoomTo method does not work. Probably because the Graphics layer hasn't updated its layout at that moment yet.
0 Kudos