Center Map on Collection

2 posts, 0 answers
  1. Joe Bohen
    Joe Bohen avatar
    62 posts
    Member since:
    May 2009

    Posted 02 Nov 2012 Link to this post

    Hi,

     

    I am using the radmap and placing  items onto the information layer using an example you provide. The items are an observable collection of the mapitem class:

     

    Private items As New ObservableCollection(Of MapItem)()

     

    This works well, but how would I get the best view for items created using this method where the items contain only the latitude and lonitude.

     

    Regards,

    Joe

     

     

    <telerik:RadMap x:Name="radMap" DistanceUnit="Mile" ZoomLevel="6" DataContext="{Binding}" >

                                <telerik:InformationLayer Name="informationLayer">

                                    <telerik:InformationLayer.ItemTemplate>

                                        <DataTemplate>

                                            <Border telerik:MapLayer.Location="{Binding Location}" x:Name="Border" ToolTip="{Binding DateofFix}"  DataContext="{Binding}">

                                                <telerik:MapLayer.HotSpot>

                                                    <telerik:HotSpot X="0.5" Y="40" XUnits="Fraction" YUnits="InsetPixels" ElementName="path" />

                                                </telerik:MapLayer.HotSpot>

                                                <Grid>

                                                    <Path x:Name="path" Stretch="None"

                                  Stroke="{StaticResource MapPushpinStroke}"

                                  StrokeThickness="4"

                                  Data="M12,26.083 L16,26.083 13.916667,32.083 z M14,3 C20.075132,3 25,7.9248676 25,14 25,20.075132 20.075132,25 14,25 7.9248677,25 3,20.075132 3,14 3,7.9248676 7.9248677,3 14,3 z"

                                  Fill="{Binding Background}">

                                                        <Path.Effect>

                                                            <telerik:IsFullTrust>

                                                                <![CDATA[

                                        <DropShadowEffect xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

                                            BlurRadius="7" ShadowDepth="1" />

                                        ]]>

                                                            </telerik:IsFullTrust>

                                                        </Path.Effect>

                                                    </Path>

                                                    <ContentPresenter Margin="0,40,0,0" Content="{Binding Content}" />

                                                </Grid>

                                            </Border>

                                        </DataTemplate>

                                    </telerik:InformationLayer.ItemTemplate>

                                </telerik:InformationLayer>

                            </telerik:RadMap>

     

  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 06 Nov 2012 Link to this post

    Hi Joe,

    You can use the code below for calculating the best view for items of this type.
    If Me.items.Count > 0 Then
        Dim rect As LocationRect = Me.CalculateBestView(Me.items, New Size(2, 2))
        Me.radMap.SetView(rect)
    End If
     
        Private Function CalculateBestView(itemsList As IEnumerable(Of MapItem), defaultSize As Size) As LocationRect
            Dim minLat As Double? = Nothing
            Dim maxLat As Double? = Nothing
            Dim minLong As Double? = Nothing
            Dim maxLong As Double? = Nothing
            Dim bestView As LocationRect
            For Each item As MapItem In itemsList
                Dim location = item.Location
                If minLat Is Nothing Then
                    minLat = location.Latitude
                End If
                If maxLat Is Nothing Then
                    maxLat = location.Latitude
                End If
                If minLong Is Nothing Then
                    minLong = location.Longitude
                End If
                If maxLong Is Nothing Then
                    maxLong = location.Longitude
                End If
                minLat = Math.Min(location.Latitude, minLat.Value)
                minLong = Math.Min(location.Longitude, minLong.Value)
                maxLat = Math.Max(location.Latitude, maxLat.Value)
                maxLong = Math.Max(location.Longitude, maxLong.Value)
            Next
            If minLat IsNot Nothing AndAlso minLong IsNot Nothing AndAlso maxLat IsNot Nothing AndAlso maxLong IsNot Nothing Then
                bestView = New LocationRect(New Location(minLat, minLong), New Location(maxLat, maxLong))
                If bestView.IsEmpty Then
                    bestView = New LocationRect(New Location(bestView.North + defaultSize.Height / 2.0, bestView.West - defaultSize.Width / 2.0),
                           New Location(bestView.North - defaultSize.Height / 2.0, bestView.West + defaultSize.Width / 2.0))
                End If
                Return bestView
            Else
                Return New LocationRect
            End If
        End Function

    Greetings,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top