Select to view content in your preferred language

Clear Layer Cache

899
2
12-21-2010 03:56 AM
BrianLeroux
Frequent Contributor
I am looking to clear the cache on the selected layer. I am able to get it to work on either a Service Layer or a Feature layer. What I am trying to do now is have it detect which type the layer is so that it can refresh using the corrct code. I am stuck on trying to detect the layer type. Any thoughts? TIA.

Public Overrides Sub OnClick()
        Dim slayer As ServiceLayer
        Dim flayer As FeatureLayer

        If ESRI.ArcGISExplorer.Application.Application.SelectedItems(0).GetType = ServiceLayer Then
            slayer = TryCast(ESRI.ArcGISExplorer.Application.Application.SelectedItems(0), ServiceLayer)
            slayer.ClearCache()
            System.Windows.Forms.MessageBox.Show("The cache for the selected layer has been cleared!", "CACHE", Windows.Forms.MessageBoxButtons.OK)

        ElseIf ESRI.ArcGISExplorer.Application.Application.SelectedItems(0).GetType = FeatureLayer Then
            flayer = TryCast(ESRI.ArcGISExplorer.Application.Application.SelectedItems(0), FeatureLayer)
            flayer.ClearCache()
            System.Windows.Forms.MessageBox.Show("The cache for the selected layer has been cleared!", "CACHE", Windows.Forms.MessageBoxButtons.OK)

        Else : System.Windows.Forms.MessageBox.Show("The cache for the selected layer could not be cleared due to incorrect layer type!", "CACHE", Windows.Forms.MessageBoxButtons.OK)
        End If

    End Sub
0 Kudos
2 Replies
AndreiIvanov
Deactivated User
Brian,

ServiceLayer, FeatureLayer, RasterLayer and etc are all inherit from Layer class. So the easiest way to clear the cache is to cast selected mapitem to Layer, and if it is valid call layer.ClearCache();
0 Kudos
BrianLeroux
Frequent Contributor
aivanov -
That simplifies things a bit. For some reason I thought i tried that. Guess not. Thank you..

Public Overrides Sub OnClick()

        Dim xlayer As Layer = TryCast(ESRI.ArcGISExplorer.Application.Application.SelectedItems(0), Layer)
        xlayer.ClearCache()
        System.Windows.Forms.MessageBox.Show("The cache for the selected layer has been cleared!", "Layer Cache", Windows.Forms.MessageBoxButtons.OK)

    End Sub
0 Kudos