# Image Animation Code - Review & Comment

**URL:** <https://community.thinkgeo.com/t/image-animation-code-review-comment/3060>\
**Category:** WPF\
**Created:** [September 4, 2011, 9:10am UTC](https://community.thinkgeo.com/t/image-animation-code-review-comment/3060 "2011-09-04T09:10:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael4](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/michael4/32/24915_2.png) [@Michael4](https://community.thinkgeo.com/u/Michael4)\
**Post date:** [September 4, 2011, 9:10am UTC](https://community.thinkgeo.com/t/image-animation-code-review-comment/3060/1 "2011-09-04T09:10:47Z")

</div>

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

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

&nbsp;You&nbsp;can&nbsp;download&nbsp;the&nbsp;solution&nbsp;at:&nbsp;[bocafallsweather.com/images/...xample.zip](http://bocafallsweather.com/images/thinkgeo/ThinkGeoImageAnimationExample.zip)

&nbsp;

`Imports ThinkGeo.MapSuite.WpfDesktopEditionImports ThinkGeo.MapSuite.CoreClass 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 SubEnd Class`

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [September 5, 2011, 12:21pm UTC](https://community.thinkgeo.com/t/image-animation-code-review-comment/3060/2 "2011-09-05T12:21:49Z")

</div>

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

Thanks,

James
