MapLine not working with inline syntax?

4 posts, 1 answers
  1. Johannes
    Johannes avatar
    66 posts
    Member since:
    Dec 2012

    Posted 10 Apr 2013 Link to this post

    I have trouble with some of my map elements, for example MapLine.

    When I use this syntax the MapLine is displayed in red and shows a tooltip when mouse is over.

    <tel:MapLine
      StrokeThickness="5"
      Stroke="Red"
      Point1="{Binding MyViewModel.Point1}"
      Point2="{Binding MyViewModel.Point2}"
      ToolTip="{Binding MyViewModel.ItemName}" />


    When I use this syntax the MapLine is not displayed and there is no tooltip.

    <tel:MapLine
      StrokeThickness="5"
      Point1="{Binding MyViewModel.Point1}"
      Point2="{Binding MyViewModel.Point2}">
      <tel:MapLine.Stroke>
        <SolidColorBrush Color="Red" />
      </tel:MapLine.Stroke>
      <tel:MapLine.ToolTip>
        <TextBlock Text="{Binding MyViewModel.ItemName}" />
      </tel:MapLine.ToolTip>
    </tel:MapLine>
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 10 Apr 2013 Link to this post

    Hi Johannes,

    The map shape is quite specific object. For a case with this kind of tooltip the MapLine will be used as data context for the text block. So, you should specify the binding of text property like following:
    <tel:MapLine
      StrokeThickness="5"
      Point1="{Binding MyViewModel.Point1}"
      Point2="{Binding MyViewModel.Point2}">
      <tel:MapLine.Stroke>
        <SolidColorBrush Color="Red" />
      </tel:MapLine.Stroke>
      <tel:MapLine.ToolTip>
        <TextBlock Text="{Binding DataContext.MyViewModel.ItemName}" />
      </tel:MapLine.ToolTip>
    </tel:MapLine>

    We can't reproduce the problem when the MapLine is not displayed using the syntax above. Could you, please, provide us with a small sample solution which reproduces it?

    Regards,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Johannes
    Johannes avatar
    66 posts
    Member since:
    Dec 2012

    Posted 10 Apr 2013 Link to this post

    Thanks for your quick response. I changed the ToolTip syntax as shown and it worked. I also solved the display/Stroke problem by using a ColorToSolidColorBrush Converter and using the first syntax. So now I can display MapLines on my RadMap.

    Please allow me another question:
    I use two InformationLayers to display MapElements. The 1st displays FrameworkElements designed by DataTemplate (Grid, Elements inside that Grid and a Popup filled with data). I can open/close this Popup when a user clicks on the FrameworkElement. The 2nd Layer displays the MapLines from above. I also want the behavior from my 1st Layer on the 2nd one, but it seems when using MapShapes instead of FrameworkElement there is only one Element allowed inside DataTemplate.

    <tel:InformationLayer ItemsSource="{Binding MyMapItems}">
      <tel:InformationLayer.ItemTemplate>
        <DataTemplate>
          <tel:MapLine Point1="{Binding Point1}" Point2="{Binding Point2}" ... />
          <!-- I need more than just a single MapLine to display my MapItems, for example a Popup Element -->
           <!-- <Popup ... /> -->
        </DataTemplate>
      </tel:InformationLayer.ItemTemplate>
    </tel:InformationLayer>

    When I wrap the MapShape with a Grid to add additional Elements the MapShape is not displayed at all. I hope this is comprehensible.
  5. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 11 Apr 2013 Link to this post

    Hi Johannes,

    Because of the specific of the map shape objects they can be used only as a root element in the data template. You can create control to show additional information over the map shape programmatically. For example:

    private void ShapeMouseEnter(object sender, MouseEventArgs e)
    {
        MapShape shape = sender as MapShape;
        if (shape != null)
        {
            Location location = Location.GetCoordinates(this.radMap, e.GetPosition(this.radMap));
     
            ContentControl content = shape.Tag as ContentControl;
            if (shape.Tag == null)
            {
                content = new ContentControl();
                content.Content = shape.ExtendedData;
                content.ContentTemplate = this.Resources["PopupTemplate"] as DataTemplate;
                shape.Tag = content;
            }
            MapLayer.SetLocation(content, location);
     
            if (content != null)
            {
                this.informationLayer.Items.Add(content);
            }
        }
    }
     
    private void ShapeMouseLeave(object sender, MouseEventArgs e)
    {
        MapShape shape = sender as MapShape;
        if (shape != null)
        {
            ContentControl content = shape.Tag as ContentControl;
            if (content != null)
            {
                this.informationLayer.Items.Remove(content);
            }
        }
    }


    Regards,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top