This is a migrated thread and some comments may be shown as answers.

ToolTip pushpin

1 Answer 215 Views
Map
This is a migrated thread and some comments may be shown as answers.
Massimiliano
Top achievements
Rank 1
Massimiliano asked on 14 Jul 2011, 08:56 AM
Hi all,
I have two questions:

I have in a WPF form a RadMap control.
1) The only way I know to see the pushpin tooltip is moving the mouse over it.
If in a map I added 10 pushpin is it possible to see simultaneally all the tooltip after the map is loaded?

2) Is it possible to open a new form clicking on the tooltip?



var pin = new Pushpin { Background = new SolidColorBrush(colore) };
var tip = new ToolTip { Content = tool };
ToolTipService.SetToolTip(pin, tip);
var loc = new Location { Latitude = lat, Longitude = lon };
MapLayer.SetLocation(pin, loc);
informationLayer.Items.Add(pin);


Thanks in advance...

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 19 Jul 2011, 11:30 AM
Hello Massimiliano,

Indeed you can show all tooltips automatically using the ToolTip.PlacementTarget, ToolTip.Placement and ToolTip.IsOpen properties. However we suggest that you are not using this approach as if you drag the map then the tooltips will not move together with its pushpin. Also you can't click inside the tooltip for opening another form.

I would recommend that you are using the template of the pushpin as a base for the item template of the information layer. You can add the content presenter element and then bind the "tooltip" to its Content property. You can bind a collection of your items to the information layer.
The sample code is below.
<Window x:Class="WpfTooltip.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <LinearGradientBrush x:Key="MapPushpinStroke" EndPoint="0.5,1" StartPoint="0.5,0" MappingMode="RelativeToBoundingBox">
            <GradientStop Color="White"/>
            <GradientStop Color="Black" Offset="0.853"/>
        </LinearGradientBrush>
    </Window.Resources>
    <Grid>
        <telerik:RadMap
            Name="radMap"
            Center="41, -74"
            ZoomLevel="7">
            <telerik:RadMap.Provider>
                <telerik:OpenStreetMapProvider />
            </telerik:RadMap.Provider>
            <telerik:InformationLayer Name="informationLayer">
                <telerik:InformationLayer.ItemTemplate>
                    <DataTemplate>
                        <Border telerik:MapLayer.Location="{Binding Location}">
                            <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="6"
                              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="15,40,0,0" Content="{Binding Content}" />
                            </Grid>
                        </Border>
                    </DataTemplate>
                </telerik:InformationLayer.ItemTemplate>
            </telerik:InformationLayer>
        </telerik:RadMap>
    </Grid>
</Window>

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Telerik.Windows.Controls.Map;
 
namespace WpfTooltip
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        ObservableCollection<MapItem> items = new ObservableCollection<MapItem>();
 
        public MainWindow()
        {
            InitializeComponent();
 
            this.radMap.InitializeCompleted += new EventHandler(radMap_InitializeCompleted);
        }
 
        private void radMap_InitializeCompleted(object sender, EventArgs e)
        {
            Brush foreground = new SolidColorBrush(Colors.Yellow);
            Brush background = new SolidColorBrush(Colors.Brown);
            TextBlock text = new TextBlock()
            {
                Text = "Content 1",
                Background = background,
                Foreground = foreground
            };
            this.items.Add(new MapItem(41, -73, background, text));
 
            background = new SolidColorBrush(Colors.Blue);
            text = new TextBlock()
            {
                Text = "Content 2",
                Background = background,
                Foreground = foreground
            };
            this.items.Add(new MapItem(41, -74, new SolidColorBrush(Colors.Blue), text));
 
            this.informationLayer.ItemsSource = items;
        }
    }
}

using System.Windows.Media;
using Telerik.Windows.Controls.Map;
 
namespace WpfTooltip
{
    public class MapItem
    {
        public object Content
        {
            get;
            set;
        }
 
        public Location Location
        {
            get;
            set;
        }
 
        public Brush Background
        {
            get;
            set;
        }
 
        public MapItem(double lat, double lon, Brush background, object content)
        {
            this.Location = new Location(lat, lon);
            this.Background = background;
            this.Content = content;
        }
    }
}

Best wishes,
Andrey Murzov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Map
Asked by
Massimiliano
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or