ThinkGeo.com    |     Documentation    |     Premium Support

Clearing the icons in map

Hai all,


 am geitting the key not found exception when am trying to clear all my plotted icons in the map.


"The given key was not present in the dictionary."


 


the below is the function am using while loading maplayers in suite. 


        LayerOverlay layerOverlay = new LayerOverlay();
        InMemoryFeatureLayer pieMemoryLayer = new InMemoryFeatureLayer();
        ValueStyle valueStyle = new ValueStyle();

public void loadMap()
        { 
            wpfMap1.MapUnit = GeographyUnit.DecimalDegree;

            wpfMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);

            //map Layer
            GeoTiffRasterLayer tifMapLayer = new GeoTiffRasterLayer(@"C:\\map1.tif");
            tifMapLayer.LowerThreshold = 0;
            tifMapLayer.UpperThreshold = double.MaxValue;

            tifMapLayer.Open();
            wpfMap1.CurrentExtent = tifMapLayer.GetBoundingBox();
            tifMapLayer.Close();

            //icon layer
            InMemoryFeatureLayer pointLayer = new InMemoryFeatureLayer();

            pointLayer.Open();
            pointLayer.Columns.Add(new FeatureSourceColumn("PointType"));
            pointLayer.Close();

           
            // Draw features based on values
            //ValueStyle valueStyle = new ValueStyle();
            valueStyle.ColumnName = "PointType";
            //valueStyle.ColumnName = "LabelType";



            pointLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);
            pointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            //pie layer
            // InMemoryFeatureLayer pieMemoryLayer = new InMemoryFeatureLayer();
            pieMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.StandardColors.Black);
            pieMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.Black;
            pieMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen = new GeoPen(GeoColor.FromArgb(200, GeoColor.StandardColors.Black), 5);
            pieMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.SymbolPen = new GeoPen(GeoColor.FromArgb(255, GeoColor.StandardColors.Black), 8);           
            pieMemoryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

                       
            wpfMap1.MapClick += new EventHandler<MapClickWpfMapEventArgs>(wpfMap1_MapClick);




            layerOverlay.Layers.Add("MapLayer", tifMapLayer);
            layerOverlay.Layers.Add("PointLayer", pointLayer);
            layerOverlay.Layers.Add("PieLayer", pieMemoryLayer);

            wpfMap1.Overlays.Add("LayerOverlay", layerOverlay);

            wpfMap1.Refresh();
        }
 


the below is the one am using to clear my icons and label everything. i jus want to display the map alone.



 public void clearIcons()
        {
            InMemoryFeatureLayer im = (InMemoryFeatureLayer)wpfMap1.FindFeatureLayer("PointLayer");
            im.InternalFeatures.Clear();

            wpfMap1.Refresh(wpfMap1.Overlays["LayerOverlay"]);
        }


Deep, 
  
 Thanks for your post. 
  
 Unfortunately I did not find any problems with the code provided below, I doubt there is some else place cause this problem. If possible, could you paste out the stack trace for this exception? It would be very helpful if you could you provide a small application to show us your problem? 
  
 Thanks. 
  
 Yale 


when am trying to clear all the plotted icons in the map, am getting this error


System.Collections.Generic.KeyNotFoundException was unhandled

  Message="The given key was not present in the dictionary."

  Source="DesktopEdition"

  StackTrace:

       at ThinkGeo.MapSuite.DesktopEdition.Overlay.Draw(GeoCanvas canvas)

       at ThinkGeo.MapSuite.DesktopEdition.WpfMap.x03e3d48bcfe7bb6c(IEnumerable`1 xa6f0db4f183189f1)

       at ThinkGeo.MapSuite.DesktopEdition.WpfMap.xff5b27c00f9678c2(RectangleShape x178b193eec228e6e)

       at ThinkGeo.MapSuite.DesktopEdition.WpfMap.xe3cee4adb9c72451()

       at ThinkGeo.MapSuite.DesktopEdition.WpfMap.x9ac8c50f434f4b39(Int32 xb565f4681f05557a)

       at ThinkGeo.MapSuite.DesktopEdition.WpfMap.Refresh(IEnumerable`1 redrawOverlays)

       at ThinkGeo.MapSuite.DesktopEdition.WpfMap.Refresh(Overlay redrawOverlay)

       at sample.Window1.clearMap() in D:\sample\sample\Window1.xaml.cs:line 205

       at sample.Window1.button1_Click(Object sender, RoutedEventArgs e) in D:\sample\sample\Window1.xaml.cs:line 626

       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)

       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)

       at System.Windows.Controls.Button.OnClick()

       at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)

       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)

       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)

       at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)

       at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)

       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)

       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)

       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)

       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)

       at System.Windows.Input.InputManager.ProcessStagingArea()

       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)

       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)

       at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)

       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

       at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)

       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)

       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)

       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)

       at System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(MSG& msg)

       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)

       at System.Windows.Application.RunInternal(Window window)

       at sample.App.Main() in D:\sample\sample\obj\Debug\App.g.cs:line 0

       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

       at System.Threading.ThreadHelper.ThreadStart()

  InnerException: 

 



Deep, 
  
 When this method (clearIcons) was called? And are you using the MultiThreaded mode or single threaded mode? 
  
 Thanks. 
  
 Yale 


single thread only yale… am loading the map in page load. when we select location and click the view the icons will be ploted in the map, when we click i will call the clearicon method to clear all plotted icons in the map for next view.

Deep,


I finally dig out your problem, just replace into following code, hope it can fix your problem.

private void button1_Click(object sender, RoutedEventArgs e)
{
    InMemoryFeatureLayer im = (InMemoryFeatureLayer)wpfMap1.FindFeatureLayer("PointLayer");
    InMemoryFeatureLayer imp = (InMemoryFeatureLayer)wpfMap1.FindFeatureLayer("PieLayer");
    im.InternalFeatures.Clear();
    im.BuildIndex();
    imp.InternalFeatures.Clear();
    imp.BuildIndex();
 
    wpfMap1.Refresh(wpfMap1.Overlays["LayerOverlay"]);
 }

 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale