# Cluster point problem

**URL:** <https://community.thinkgeo.com/t/cluster-point-problem/9621>\
**Category:** WPF\
**Created:** [October 8, 2019, 3:21am UTC](https://community.thinkgeo.com/t/cluster-point-problem/9621 "2019-10-08T03:21:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard6](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/r/f9ae1b/32.png) [@Richard6](https://community.thinkgeo.com/u/Richard6)\
**Post date:** [October 8, 2019, 3:21am UTC](https://community.thinkgeo.com/t/cluster-point-problem/9621/1 "2019-10-08T03:21:08Z")

</div>

I am currently using version 10.5 code – all up to the latest 10.5 release with VS 2015.

I have an in-memory layer that gets populated with search results I am using a cluster style that is defined as below.

```
            bitmapObject = MethodHelpers.GetBitmapResource("bluemarker");
            PointStyle ps = new PointStyle(new GeoImage(bitmapObject));
            ps.YOffsetInPixel = -1 * (ps.Image.Height / 2);

            // Set up the cluster style. 
            ClusterPointStyle clusterPointStyle = new ClusterPointStyle();
            clusterPointStyle.Styles.Add(ps);
            clusterPointStyle.TextStyle = new TextStyle("FeatureCount", new GeoFont("Arial", 10), GeoBrushes.Black);
            clusterPointStyle.TextStyle.OverlappingRule = LabelOverlappingRule.AllowOverlapping;
            clusterPointStyle.TextStyle.XOffsetInPixel = -9;
            clusterPointStyle.TextStyle.YOffsetInPixel = 26;
            clusterPointStyle.DrawingLevel = DrawingLevel.LabelLevel;
            clusterPointStyle.PointType = PointType.Bitmap;
            bitmapObject = MethodHelpers.GetBitmapResource("bluemarker");
            clusterPointStyle.Image = new GeoImage(bitmapObject);
            clusterPointStyle.YOffsetInPixel = -1 * (ps.Image.Height / 2);
            
            // Set the minimum features in per cell. If the count is less than the value it will invisible.
            clusterPointStyle.MinimumFeaturesPerCellToCluster = 5;

            ZoomLevel lzl = SearchResultsLayer.ZoomLevelSet.ZoomLevel01;
            lzl.CustomStyles.Add(clusterPointStyle);
            lzl.ApplyUntilZoomLevel = (ApplyUntilZoomLevel)GlobalProperties.totalZoomLevels;

            SearchResultsLayer.Open();
            searchResultsOverlay.Layers.Add(SearchResultsLayer);
            searchResultsOverlay.Layers.Add(SearchHighlightResultsLayer);
            searchResultsOverlay.TileType = TileType.SingleTile;

```

The searhResultsLayer is an inMemoryLayer. This is actually working as expected until I have somewhere over 700 features in the InMemoryLayer. Once that occurs I get an exception when the layer gets drawn.

{“An item with the same key has already been added.”}

at ThinkGeo.MapSuite.Wpf.Tile.DrawException(GeoCanvas geoCanvas, Exception exception)  
at ThinkGeo.MapSuite.Wpf.Tile.Draw(GeoCanvas geoCanvas)  
at ThinkGeo.MapSuite.Wpf.LayerOverlay.DrawTileCore(Tile tile, RectangleShape targetExtent)  
at ThinkGeo.MapSuite.Wpf.TileOverlay.DrawTile(Tile tile, RectangleShape targetExtent)  
at ThinkGeo.MapSuite.Wpf.TileOverlay.ZEU=(RectangleShape targetExtent)  
at ThinkGeo.MapSuite.Wpf.TileOverlay.DrawCore(RectangleShape targetExtent, OverlayRefreshType overlayRefreshType)  
at ThinkGeo.MapSuite.Wpf.LayerOverlay.DrawCore(RectangleShape targetExtent, OverlayRefreshType refreshType)  
at ThinkGeo.MapSuite.Wpf.Overlay.Draw(RectangleShape targetExtent, OverlayRefreshType refreshType)  
at ThinkGeo.MapSuite.Wpf.TileOverlay.RefreshCore()  
at ThinkGeo.MapSuite.Wpf.Overlay.Refresh()  
at ByersOneView.Core.MapTools.SearchHandler2.showSearchPins() in C:\projects\OneViewClient\ByersOneView\ByersOneView.Core\MapTools\SearchHandler2.cs:line 267

I have absolutely no idea what I am doing wrong. I can’t exclude the possibility this is being caused by something else in my code, but I only encounter this with the clusterPointStyle. If I simply use a pointstyle instead I get a big mass of markers but no exception.

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [October 8, 2019, 10:46am UTC](https://community.thinkgeo.com/t/cluster-point-problem/9621/2 "2019-10-08T10:46:06Z")

</div>

Hi Richard,

It looks I hadn’t reproduced your exception, here is a simple sample, it render 2000 features.

Could you please check the code and modify it to reproduce your problem? So we can look into it.

[9621.zip](https://community.thinkgeo.com/uploads/short-url/7FSFv2vSsWuEtPWjqLz5wrisXo1.zip) (12.3 KB)

Regards,

Ethan

---

<div class="post-metadata">

**Author:** ![Richard6](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/r/f9ae1b/32.png) [@Richard6](https://community.thinkgeo.com/u/Richard6)\
**Post date:** [October 9, 2019, 3:41am UTC](https://community.thinkgeo.com/t/cluster-point-problem/9621/3 "2019-10-09T03:41:10Z")

</div>

Ultimately what is causing the exception is a duplicate feature id in the inmemorylayer. The feature I create to put in the inmemoryLayer retains the feature id from the original feature. Since the results can encompass multiple feature layers I am getting duplicate ids.

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [October 9, 2019, 8:52am UTC](https://community.thinkgeo.com/t/cluster-point-problem/9621/4 "2019-10-09T08:52:56Z")

</div>

Hi Richard,

Yes if the feature with same id it will met this problem.

You can loop your feature in your inmemory layer and reset it for example:

feature.Id = Guid.NewGuid().ToString();

Regards,

Ethan
