ThinkGeo.com    |     Documentation    |     Premium Support

Image Animation Code - Review & Comment

I have created a sample below of the way I am implementing image animation.  I am looking for feedback on whether there are better ways.  Also, and error when I zoom while the animation is running:


System.Windows.Media.Animation Warning: 6 : Unable to perform action because the specified Storyboard was never applied to this object for interactive control.; Action='Stop'; Storyboard='System.Windows.Media.Animation.Storyboard'; Storyboard.HashCode='4002278'; Storyboard.Type='System.Windows.Media.Animation.Storyboard'; TargetElement='System.Windows.Media.Animation.Storyboard'; TargetElement.HashCode='4002278'; TargetElement.Type='System.Windows.Media.Animation.Storyboard'


 You can download the solution at: bocafallsweather.com/images/...xample.zip


 



Imports ThinkGeo.MapSuite.WpfDesktopEdition
Imports ThinkGeo.MapSuite.Core
Class MainWindow
    'Images located at bocafallsweather.com/images/thinkgeo/image1.png replace "1" with 1 through 15 and put in "data" directory under app
    'On MainWindow.xaml add map named "WpfMap1" and button named butSatAnimate w/ content "Animate"

    Private Shared _listGDIs As New List(Of GdiPlusRasterLayer)
    Private Shared _continueAnamation As Boolean = True

    Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        WpfMap1.MapUnit = GeographyUnit.DecimalDegree
        WpfMap1.BackgroundOverlay.BackgroundBrush = New GeoSolidBrush(GeoColor.GeographicColors.DeepOcean)

        Dim worldOverlay As WorldMapKitWmsWpfOverlay = New WorldMapKitWmsWpfOverlay()
        WpfMap1.Overlays.Add("WMK", worldOverlay)

        Dim SatAnimationOverlay As LayerOverlay = New LayerOverlay()
        WpfMap1.Overlays.Add("SatAnimationOverlay", SatAnimationOverlay)

        WpfMap1.CurrentExtent = New RectangleShape(-91.132653, 35.743055, -38.613148, 3.837897)

        WpfMap1.Refresh()
    End Sub

    Private Sub GetAnimationFileList()
        Dim DataList As New ArrayList
        For i As Integer = 1 To 15
            Dim gdi As GdiPlusRasterLayer = New GdiPlusRasterLayer("Data/Image" & i.ToString & ".png", New RectangleShape(-91.132653, 35.743055, -38.613148, 3.837897))
            gdi.IsVisible = False
            _listGDIs.Add(gdi)
        Next
    End Sub

    Private Sub butSatAnimate_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles butSatAnimate.Click
        If butSatAnimate.Content.ToString = "Animate" Then
            Dim th As System.Threading.Thread = New System.Threading.Thread(AddressOf Anamate)
            butSatAnimate.Content = "Stop"
            th.Start()
        Else
            butSatAnimate.Content = "Animate"
            _continueAnamation = False
        End If
    End Sub

    Private Delegate Sub RefreshThdDelegate()
    Public Sub Anamate()
        GetAnimationFileList()
        _continueAnamation = True
        Dim SatelliteOverlay As LayerOverlay = DirectCast(WpfMap1.Overlays("SatAnimationOverlay"), LayerOverlay)

        For Each gd As GdiPlusRasterLayer In _listGDIs
            SatelliteOverlay.Layers.Add(gd)
        Next

        SatelliteOverlay.TileType = TileType.SingleTile

        While _continueAnamation
            For i As Integer = 0 To SatelliteOverlay.Layers.Count - 1
                If _continueAnamation = False Then Exit For
                SatelliteOverlay.Layers(i).IsVisible = True
                Me.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, New RefreshThdDelegate(AddressOf RefreshMap))
                System.Threading.Thread.Sleep(300)   '????????? CHANGE TO TIMERS.TIMER implementation
                If i < SatelliteOverlay.Layers.Count - 1 Then
                    SatelliteOverlay.Layers(i).IsVisible = False
                End If
            Next
            If _continueAnamation = True Then System.Threading.Thread.Sleep(500) '????????? CHANGE TO TIMERS.TIMER implementation
            SatelliteOverlay.Layers(SatelliteOverlay.Layers.Count - 1).IsVisible = False
        End While
        While SatelliteOverlay.Layers.Count > 0
            SatelliteOverlay.Layers.RemoveAt(0)
        End While
        _listGDIs.Clear()
        Me.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, New RefreshThdDelegate(AddressOf RefreshMap))
    End Sub

    Public Sub RefreshMap()
        Try
            WpfMap1.Overlays("SatAnimationOverlay").Refresh()
        Catch eg As System.Collections.Generic.KeyNotFoundException
            Debug.Print("MainWindow:RefreshMap:Eg:" & eg.Message.ToString)
        Catch ex As Exception
            Debug.Print("MainWindow:RefreshMap:Ex:" & ex.Message.ToString)
        End Try
    End Sub

    Private Sub butExit_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles butExit.Click
        _continueAnamation = False
        Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown
        Application.Current.Shutdown()
    End Sub
End Class



 I have tested your sample code with latest code, it works properly, no exception thrown, could you let me know which file version of DLL you used? and you also can try to get the latest version from helpdesk and try it again.


Thanks,


James