none
Geo Located image is clipping when zoomed RRS feed

  • Question

  • I am adding an image (radar overlay) and keep it positioned in the ViewChanged event and things seem to work except I get image clipping from the bottom and right side as I zoom in.  The more I zoom, the more it clips (clip is defined a space from the right/bottom of the map to where the image starts to show up).  Not sure what is causing it... can someone point me in the right direction?  Thanks!

     Complete sample code-behind below that should reproduce the problem:

    Public NotInheritable Class MainPage
        Inherits Page
    
        Private _MarkerLayerRadar As New Bing.Maps.MapLayer
        Private _locs As New Bing.Maps.LocationCollection
        Private _ptList As New List(Of Windows.Foundation.Point)
        Private _img As New Image
    
        ''' <summary>
        ''' Invoked when this page is about to be displayed in a Frame.
        ''' </summary>
        ''' <param name="e">Event data that describes how this page was reached.  The Parameter
        ''' property is typically used to configure the page.</param>
        Protected Overrides Sub OnNavigatedTo(e As Navigation.NavigationEventArgs)
        
        End Sub
    
        Private Sub MainPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
            myMap.Children.Add(_MarkerLayerRadar)
            Dim nwLoc As New Bing.Maps.Location(50.406626367301044, -127.62037552387542)
            Dim swLoc As New Bing.Maps.Location(21.652538062803444, -127.62037552387542)
            Dim neLoc As New Bing.Maps.Location(50.406626367301044, -66.517937876818024)
            Dim seLoc As New Bing.Maps.Location(21.652538062803444, -66.517937876818024)
            _locs.Add(nwLoc)
            _locs.Add(swLoc)
            _locs.Add(neLoc)
            _locs.Add(seLoc)
            _img.Source = New BitmapImage(New System.Uri("http://radar.weather.gov/ridge/Conus/RadarImg/latest_radaronly.gif"))
            _img.Opacity = 1
            _img.Stretch = Windows.UI.Xaml.Media.Stretch.Fill
        End Sub
    
        Private Sub myMap_ViewChanged(sender As Object, e As Bing.Maps.ViewChangedEventArgs) Handles myMap.ViewChanged
            _ptList.Clear()
            Dim success As Boolean = myMap.TryLocationsToPixels(_locs, _ptList)
            If success Then
                _MarkerLayerRadar.Children.Clear()
    
                Dim w As Integer = _ptList(2).X - _ptList(0).X
                Dim h As Integer = _ptList(1).Y - _ptList(0).Y
    
                _img.Width = w
                _img.Height = h
    
                Bing.Maps.MapLayer.SetPosition(_img, _locs(0))
                _MarkerLayerRadar.Children.Add(_img)
            End If
        End Sub
    End Class
    Saturday, March 2, 2013 3:00 PM

Answers

  • use a RenderTransform to scale your object instead of a width and a height, set the

    ' you may need to use a different origin, as
    ' I place my objects on their center and 
    ' scaled around them, if you want to scale out
    ' from the upper left, use 0,0 or just remove this
    ' line all together
    _img.RenderTransformOrigin = new Point(0.5, 0.5);
    _img.RenderTransform = new ScaleTransform

    then adjust the ScaleX and ScaleY instead of adjusting the width and height (I don't do much VB anymore so bear with me)

    Dim scaleTx = _img.RenderTransform as ScaleTransform
    
    scaleTx.ScaleX = newScale * originalWidth
    scaleTx.ScaleY = newScale * originalHeight

    you can figure out the math for yourself, but I use this technique already to avoid the "clipping" you are describing...

    I found the clipping occurs on objects that exceed the dimension of the actual map they are placed inside of... so if your map is 200x300 anything wider than 200 or taller than 300 will be clipped back to the relevant dimension, it doesn't even take offset into consideration...

    I am not sure if this is a bug or if it is the maps team prodding you to use a transform for large overlays and objects.... hope that helps -ck



    • Edited by ckozl Monday, March 25, 2013 3:45 PM
    • Marked as answer by Ricky_Brundritt Monday, March 25, 2013 5:05 PM
    Monday, March 25, 2013 3:40 PM

All replies

  • Bump... anyone have any ideas?
    Thursday, March 21, 2013 12:28 AM
  • use a RenderTransform to scale your object instead of a width and a height, set the

    ' you may need to use a different origin, as
    ' I place my objects on their center and 
    ' scaled around them, if you want to scale out
    ' from the upper left, use 0,0 or just remove this
    ' line all together
    _img.RenderTransformOrigin = new Point(0.5, 0.5);
    _img.RenderTransform = new ScaleTransform

    then adjust the ScaleX and ScaleY instead of adjusting the width and height (I don't do much VB anymore so bear with me)

    Dim scaleTx = _img.RenderTransform as ScaleTransform
    
    scaleTx.ScaleX = newScale * originalWidth
    scaleTx.ScaleY = newScale * originalHeight

    you can figure out the math for yourself, but I use this technique already to avoid the "clipping" you are describing...

    I found the clipping occurs on objects that exceed the dimension of the actual map they are placed inside of... so if your map is 200x300 anything wider than 200 or taller than 300 will be clipped back to the relevant dimension, it doesn't even take offset into consideration...

    I am not sure if this is a bug or if it is the maps team prodding you to use a transform for large overlays and objects.... hope that helps -ck



    • Edited by ckozl Monday, March 25, 2013 3:45 PM
    • Marked as answer by Ricky_Brundritt Monday, March 25, 2013 5:05 PM
    Monday, March 25, 2013 3:40 PM
  • Yep... this works... Thanks!  I'll posts the updated code when I get a chance.  Thanks again!
    Tuesday, March 26, 2013 1:06 AM