Good day, I am trying to filter a shapefilefeaturelayer and display only certain features. The values i want to filter by will be selected from a dropdownlist on the page. From the samples i can see how to only draw certain features like so
Private Sub worldLayer_DrawingFeatures(ByVal sender As Object, ByVal e As DrawingFeaturesEventArgs) Dim featuresToDrawn As New Collection(Of Feature)() For Each feature As Feature In e.FeaturesToDraw Dim population As Double = Convert.ToDouble(feature.ColumnValues("POP_CNTRY")) If population > pop Then featuresToDrawn.Add(feature) End If Next
e.FeaturesToDraw.Clear() For Each feature As Feature In featuresToDrawn e.FeaturesToDraw.Add(feature) Next End Sub
However this sample uses Map1.StaticOverlay.Layers.Add() to add the layer. When i try to apply this logic to my project that is using Map1.Customoverlays.Add to add the feature layer this event is no longer triggered. I am still very new to Thinkgeo. Any help will be greatly appreciated. Thanks
I try to recreate your issue but didn’t work. Both staticOverlay or CustomerOverlay can trigger this event, would you please let me know which version you are using? or a contain-self sample would be great. Thanks, Troy
Hi Troy , thank you very much for the reply. You are correct it seems the event is triggered by both Map1.StaticOverlay.Layers.Add() and Map1.Customoverlays.Add() so that is not the problem. However i am still unable to filter the features that are displayed on the map.
Dim ddlvalue As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Page.IsPostBack Then ddlvalue = "2-Good" Map1.MapBackground.BackgroundBrush = New GeoSolidBrush(GeoColor.FromHtml("#E5E3DF")) Map1.CurrentExtent = New RectangleShape(-140, 60, 140, -60) Map1.MapUnit = GeographyUnit.DecimalDegree
Dim worldMapKitOverlay As New WorldMapKitWmsWebOverlay() Map1.CustomOverlays.Add(worldMapKitOverlay)
’ The following two lines of code enable the client and server caching. ’ If you enable these features it will greatly increase the scalability of your ’ mapping application however there some side effects that may be counter intuitive. ’ Please read the white paper on web caching or the documentation regarding these methods.
Dim staticOverlay As New LayerOverlay("StaticOverlay") staticOverlay.IsBaseOverlay = False staticOverlay.Layers.Add("WorldLayer", worldLayer)
Map1.CustomOverlays.Add(staticOverlay)
End If End Sub
Private Sub worldLayer_DrawingFeatures(ByVal sender As Object, ByVal e As DrawingFeaturesEventArgs) Dim featuresToDrawn As New Collection(Of Feature)() For Each feature As Feature In e.FeaturesToDraw Dim population As String = Convert.ToString(feature.ColumnValues("Surface_Co")) If population = ddlvalue Then featuresToDrawn.Add(feature) End If Next
e.FeaturesToDraw.Clear() For Each feature As Feature In featuresToDrawn e.FeaturesToDraw.Add(feature) Next End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Map1.CustomOverlays.RemoveAt(1) ddlvalue = "3-Fair" Dim worldLayer As New ShapeFileFeatureLayer(MapPath("~\SampleData\World\20140527_Amajuba_PT_Routes_rev7.shp")) worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 243, 239, 228), GeoColor.FromArgb(255, 218, 193, 163), 1) worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.RequiredColumnNames.Add("Surface_Co") worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20 AddHandler worldLayer.DrawingFeatures, AddressOf worldLayer_DrawingFeatures 'Map1.StaticOverlay.Layers.Add(worldLayer)
Dim staticOverlay As New LayerOverlay("StaticOverlay") staticOverlay.IsBaseOverlay = False staticOverlay.Layers.Add("WorldLayer", worldLayer)
Map1.CustomOverlays.Add(staticOverlay)
End Sub
At this point I am just simulating the dropdownlist value with a button click but the effect should be the same. As it stands the map load the layer geometry on the first page load but fails to filter the features that are selected when the button is clicked.
I might have some insights on your problem.I guess this is because the ddlvalue doesn’t be changed in the DrawingFeature event after you click the button. You may try to declare the ddlvalue as Shared or using session to store the value after setting the vlaue.
Besides, I think there is an enhancement in your click event. I don’t think we need to remove the original layeroverlay and then add a new one. you can just get the layer overlay with its key value and find the shape file layer from it. after find the layer, then we can do any style changes on the layer.
Hope it helps and any question please let me know.
Hi troy thank you very much for the response. I have changed my ddl variable to be shared and verified that the value does indeed change by placing a breakpoint within the worldLayer_DrawingFeatures event. However the layer still comes up blank after the event executed.
From your reply it seems that you are suggesting I keep the original layeroverlay and rather do style changes on selected features. I can get this right by slightly modifying the FindFeaturesWithinDistance sample. Would this not become inefficent when displaying large amounts of data?
I think you can try to just change the ddlvalue in the button1 click event and comment out the other logic to see if it works? Btw, do you means the filter works fine in the first page load but the layer doesn’t change after the ddlvalue changed?
I attached a sample for your case and it works fine with "cntry02.shp" file which you can find it in the installation folder. I am not sure if there is any thing I miss.
If still not help, would you mind to send us your sample to recreate the issue? if the shape data is large, I think you can try to replace it with cntry02.shp in the sample. Any way, a contain-self sample is better for us to debug.