# Custom InMemoryFeatureLayer

**URL:** <https://community.thinkgeo.com/t/custom-inmemoryfeaturelayer/784>\
**Category:** WinForms\
**Created:** [October 22, 2009, 4:58pm UTC](https://community.thinkgeo.com/t/custom-inmemoryfeaturelayer/784 "2009-10-22T16:58:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chad](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@Chad](https://community.thinkgeo.com/u/Chad)\
**Post date:** [October 22, 2009, 4:58pm UTC](https://community.thinkgeo.com/t/custom-inmemoryfeaturelayer/784/1 "2009-10-22T16:58:24Z")

</div>

Has&nbsp;anyone&nbsp;tried&nbsp;implementing&nbsp;a&nbsp;custom&nbsp;InMemoryFeatureLayer&nbsp;in&nbsp;the&nbsp;Release&nbsp;Candidate&nbsp;2&nbsp;version?&nbsp;&nbsp;I&nbsp;have&nbsp;a&nbsp;custom&nbsp;layer&nbsp;that&nbsp;was&nbsp;working&nbsp;in&nbsp;previous&nbsp;versions,&nbsp;but&nbsp;it&nbsp;no&nbsp;longer&nbsp;works&nbsp;in&nbsp;the&nbsp;latest&nbsp;release.&nbsp;&nbsp;By&nbsp;not&nbsp;works&nbsp;I&nbsp;mean&nbsp;it&nbsp;no&nbsp;longer&nbsp;has&nbsp;spatial&nbsp;query&nbsp;ability&nbsp;via&nbsp;the&nbsp;QueryTools&nbsp;because&nbsp;QueryTools&nbsp;is&nbsp;null.&nbsp;&nbsp;I&nbsp;am&nbsp;overriding&nbsp;SetupToolsCore&nbsp;to&nbsp;setup&nbsp;QueryTools&nbsp;for&nbsp;the&nbsp;layer&nbsp;as&nbsp;well&nbsp;as&nbsp;collumns&nbsp;for&nbsp;the&nbsp;underlying&nbsp;FeatureSourece.&nbsp;&nbsp;The&nbsp;SetupToolsCore&nbsp;method&nbsp;is&nbsp;no&nbsp;longer&nbsp;executing&nbsp;when&nbsp;the&nbsp;layer&nbsp;is&nbsp;initialized.&nbsp;&nbsp;Any&nbsp;ideas?&nbsp;&nbsp;Thanks,

Chad

&nbsp;

`	class FcdInMemoryLayer : InMemoryFeatureLayer    {        private Dictionary<Feature, Style> features;        public FcdInMemoryLayer()            : this(new Dictionary<Feature, Style>())        {            base.QueryTools = new QueryTools(FeatureSource);        }        public FcdInMemoryLayer(Dictionary<Feature, Style> features) : base()        {            this.features = features;        }        public Dictionary<Feature, Style> Features        {            get { return features; }        }        public override bool HasBoundingBox        {            get            {                return features.Count > 0;            }        }        protected override RectangleShape GetBoundingBoxCore()        {            if (features == null || features.Count == 0)                    return null;            double minX = features.Select(a => a.Key.GetBoundingBox().UpperLeftPoint.X).Min();            double maxY = features.Select(a => a.Key.GetBoundingBox().UpperLeftPoint.Y).Max();            double maxX = features.Select(a => a.Key.GetBoundingBox().LowerRightPoint.X).Max();            double minY = features.Select(a => a.Key.GetBoundingBox().LowerRightPoint.Y).Min();            return new RectangleShape(minX, maxY, maxX, minY);        }        protected override void SetupToolsCore()        {	    // This doesn't execute            Collection<FeatureSourceColumn> newColumns = new Collection<FeatureSourceColumn>();            newColumns.Add(new FeatureSourceColumn(Strings.TrackingNameColumn));            newColumns.Add(new FeatureSourceColumn(Strings.StripNumberColumn));            newColumns.Add(new FeatureSourceColumn(Strings.TickerColumn));            newColumns.Add(new FeatureSourceColumn(Strings.CleanColumn));            FeatureSource = new InMemoryFeatureSource(newColumns, features.Keys);            base.QueryTools = new QueryTools(FeatureSource);            base.SetupToolsCore();        }        protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)        {            Collection<SimpleCandidate> labelInThisLayer = new Collection<SimpleCandidate>();            Collection<SimpleCandidate> labelInAllLayers = new Collection<SimpleCandidate>();            foreach (Feature feature in features.Keys)            {                //string drawPoint = feature.ColumnValues[Strings.DrawPointColumn];                Style style = features[feature];                style.Draw(new Feature[] { feature }, canvas, labelInThisLayer, labelInAllLayers);            }        }    }`

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [October 23, 2009, 1:18am UTC](https://community.thinkgeo.com/t/custom-inmemoryfeaturelayer/784/2 "2009-10-23T01:18:04Z")

</div>

&nbsp;

Chad,  
&nbsp;  
Thanks&nbsp;for&nbsp;your&nbsp;post&nbsp;and&nbsp;codes&nbsp;showing&nbsp;your&nbsp;problem.&nbsp;Yes,&nbsp;as&nbsp;you&nbsp;said,&nbsp;we&nbsp;changed&nbsp;some&nbsp;logic&nbsp;for&nbsp;the&nbsp;Open&nbsp;stuff&nbsp;during&nbsp;the&nbsp;2&nbsp;release.  
&nbsp;  
Just&nbsp;try&nbsp;the&nbsp;following&nbsp;code&nbsp;for&nbsp;the&nbsp;SetupToolCore,&nbsp;hope&nbsp;it&nbsp;fixs&nbsp;your&nbsp;problem.  
`         protectedoverridevoid SetupToolsCore()        {            base.SetupToolsCore();        // This doesn't execute            Collection<FeatureSourceColumn> newColumns = new Collection<FeatureSourceColumn>();            newColumns.Add(new FeatureSourceColumn(Strings.TrackingNameColumn));            newColumns.Add(new FeatureSourceColumn(Strings.StripNumberColumn));            newColumns.Add(new FeatureSourceColumn(Strings.TickerColumn));            newColumns.Add(new FeatureSourceColumn(Strings.CleanColumn));                        bool isOpen = FeatureSource.IsOpen;                                FeatureSource = new InMemoryFeatureSource(newColumns, features.Keys);                if (isOpen)                                {                                                FeatureSource.Open();                                }            base.QueryTools = new QueryTools(FeatureSource);         }`  
&nbsp;  
Let&nbsp;me&nbsp;know&nbsp;if&nbsp;any&nbsp;more&nbsp;questions.  
&nbsp;  
Thanks.  
&nbsp;  
Yale
