If I want a data driven map that updates live data, I would need to add and remove line elements all the time. I can certainly add lines but I see no way to search the elements list so I can remove them.
So my specific questions:
-- What is the best practice for tagging elements so they can be found for subsequent removal?
-- Is removal as simple as deleting an element from the Elements list? Am I that lucky?
thanks
Roger
Just a short follow up. I found the name field which I can hijack for my purposes of identifying and tying multiple elements together for subsequent removal.
I tried removing an element by simply removing it from the element list but the screen went blank. hmmm... I will play around more today.
Another short follow up. I just found the stuff about adding custom propertyies. Very nice and more than adequate for my purposes.
Now if I can just remove an element....
try this:
private void MapLayer_Imported(object sender, MapLayerImportEventArgs e) { if (e.Action == MapLayerImportAction.End) { MapLayer layer = sender as MapLayer; MapElement france = layer.Elements.FindElement("Name", "France").FirstOrDefault(); layer.Elements.Remove(france); } }
<igMap:XamWebMap x:Name="xamWebMap1"> <igMap:XamWebMap.Layers> <igMap:MapLayer Imported="MapLayer_Imported"> <igMap:MapLayer.Reader> <igMap:ShapeFileReader Uri="world" DataMapping="Name=CNTRY_NAME" /> </igMap:MapLayer.Reader> </igMap:MapLayer> </igMap:XamWebMap.Layers> </igMap:XamWebMap>
Also, all map elements have a custom property system to enable binding of ad-hoc data coming in from shape files etc. If you need to tag elements with various data, one way would be to use this system. As an added bonus, you could then also bind against that data for visualization purposes, see these methods:
SetProperty
GetProperty
HasCustomProperty
-Graham
Roger,
I've created a small sample to show map elements being added and removed from the map. Let me know if you have any questions about it.
<UserControl x:Class="SilverlightApplication12.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
xmlns:igMap="clr-namespace:Infragistics.Silverlight.Map;assembly=Infragistics.Silverlight.DataVisualization.Map.v9.2">
<Grid x:Name="LayoutRoot">
<StackPanel>
<igMap:XamWebMap x:Name="map"
Loaded="TheMap_Loaded"
GridDisplayMode="Back">
<igMap:XamWebMap.Layers>
<igMap:MapLayer x:Name="theLayer"
WorldRect="0,0,100,100" />
</igMap:XamWebMap.Layers>
</igMap:XamWebMap>
<TextBlock x:Name="textBox"
Text="" />
</StackPanel>
</Grid>
</UserControl>
Code behind:
public partial class MainPage : UserControl
{
public MainPage()
InitializeComponent();
}
private DispatcherTimer _timer;
private void TheMap_Loaded(object sender, RoutedEventArgs e)
_timer = new DispatcherTimer();
_timer.Interval = new TimeSpan(0, 0, 4);
_timer.Tick += new EventHandler(Timer_Tick);
_timer.Start();
private double _currTop = 0;
private double _currLeft = 0;
private Queue<MapElement> _addedElements = new Queue<MapElement>();
void Timer_Tick(object sender, EventArgs e)
MapElement _ele = CreateElement(_currTop, _currLeft);
_addedElements.Enqueue(_ele);
map.Layers[0].Elements.Add(_ele);
if (map.Layers[0].Elements.Count == 1)
map.WindowFit();
if (_addedElements.Count > 5)
MapElement _toRemove = _addedElements.Dequeue();
map.Layers[0].Elements.Remove(_toRemove);
_currLeft += 10;
if (_currLeft > 100)
_currTop += 10;
_currLeft = 0;
private MapElement CreateElement(double _currTop, double _currLeft)
SurfaceElement el = new SurfaceElement();
MapPolyline oly = new MapPolyline();
oly.Add(new Point(_currLeft, _currTop));
oly.Add(new Point(_currLeft + 10, _currTop));
oly.Add(new Point(_currLeft + 10, _currTop + 10));
oly.Add(new Point(_currLeft, _currTop + 10));
el.Polylines = new MapPolylineCollection();
el.Polylines.Add(oly);
el.WorldRect = new Rect(_currLeft, _currTop, 10, 10);
return el;
MapElementCollection derives from ObservableCollection<MapElement>, so yes, there is a Remove method in Map.v9.2.
if you have any trouble trying to use this method, please describe the problem, providing error messages if there are any.
Fuelogic:
I submitted that question a while back. I was able to write code to get elements to go away but I never got the consistent behavior I wanted. As I remember, I was able to create and remove paths (lines). I was not able to reliably create and remove symbols or images. I moved on and haven't touched the map control for some time.
Keep in mind that I am a rank beginner to GUIs in general. I ignored Windows Forms while I spent 22 years writing low level communications drivers in C and assembly. Now, I have been abruptly yanked into the 21st century and have a lot of catching up to do. I must leapfrog Windows forms into WPF and C++ into C#.
That's all a long winded way to say that the problem may have been me and that you shouldn't get too excited.
Best of luck
There is no MapLayer.Elements.Remove(Element) in
DataVisualization.Map.v9.2
Are you telling me infragistics forgot to add a method for removing rendered elements, this is a major oversight, I am building a map with my branch customer footprints and want to only display ones I select and then remove the items from the map if I am not interested in viewing that branches specific data set, I need some kind of a patch for this ASAP