ThinkGeo.com    |     Documentation    |     Premium Support

Control Individual feature visibility on a layer

Hello, 



I have a layer and I can control its visibility. I now need to be able to control the individual features visibility of a layer. I have tried the following with no success. How can I accomplish this without removing the feature from the layer? I don’t want to remove the feature from the layer because I would like to allow the user to toggle the features visibility on the map. 





public void HideFeatureOnLayer(string layerName, ObservableCollection<string> featureIds)
        {
            FeatureLayer connectingFeatureLayer = GetFeatureLayerByName(layerName);
            connectingFeatureLayer.FeatureSource.FeatureIdsToExclude.Clear();
 
            foreach (string featureId in featureIds)
            {
                connectingFeatureLayer.FeatureSource.FeatureIdsToExclude.Add(featureId);
            }
             
            RefreshFeatureLayersGroup(layerName);
        }



Hi Scott, 
  
 In fact I tested your code and it works for me. 
  
 I think if there are some problem, that should because you use incorrect feature id. 
  
 Could you please test my code and add some your code in it for reproduce your problem? 
  
  
 <Button x:Name="btnStop"
                        Content="test"
                        Height="20"
                        FontSize="10"
                        Width="80"
                        Click="btnHide_Click"></Button>



  LayerOverlay LayerOverlay = new LayerOverlay();
            InMemoryFeatureLayer InMemoryFeatureLayer = new InMemoryFeatureLayer();
            LayerOverlay.Layers.Add(InMemoryFeatureLayer);
            Map1.Overlays.Add(LayerOverlay);

            InMemoryFeatureLayer.InternalFeatures.Add(new Feature(Map1.CurrentExtent.GetCenterPoint()));
            InMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.Capital1;
            InMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;





 private void btnHide_Click(object sender, RoutedEventArgs e)
        {
            HideFeatureOnLayer();
        }

        public void HideFeatureOnLayer()
        {
            FeatureLayer connectingFeatureLayer = GetFeatureLayerByName();
            connectingFeatureLayer.FeatureSource.FeatureIdsToExclude.Clear();

            connectingFeatureLayer.FeatureSource.FeatureIdsToExclude.Add(connectingFeatureLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.NoColumns)[0].Id);

            RefreshFeatureLayersGroup();
        }

        private void RefreshFeatureLayersGroup()
        {
            Map1.Refresh((Map1.Overlays[0]));
        }

 
  
 Regards, 
  
 Don