Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
712
Highlight groups of countries
posted

Hi,

When world spatial data is loaded into MapLayer, each country will be highlighted when mouse hovers.

I want to change that behavior. Instead of highlighting each country,  I want to highlight a group of countries when mouse hovers.

How could i achieve it?

 

Thanks,

Regards,

NNT

  • 3255
    Verified Answer
    posted

    Hi nyinyithann,

    you can attach to XamMap's ElementHover and ElementUnhover and control manually group of contries that should be highlighted. Try the following code snippet:

    xamMap.ElementHoverAction = ElementHoverAction.None;
    xamMap.ElementHover += xamMap_ElementHover;
    xamMap.ElementUnhover += xamMap_ElementUnhover;

    private List<MapElement> _highlightedElements = new List<MapElement>(3);

    void xamMap_ElementUnhover(object sender, MapElementHoverEventArgs e)
    {
     foreach (var element in _highlightedElements)
     {
      element.Fill = null;
     }

     _highlightedElements.Clear();
    }

    private void xamMap_ElementHover(object sender, MapElementHoverEventArgs e)
    {                       
     if (e.Element.Caption == "United States")
     {
      _highlightedElements.Add(e.Element);
      _highlightedElements.Add(xamMap.Layers[0].Elements["Mexico"].Single());
      _highlightedElements.Add(xamMap.Layers[0].Elements["Canada"].Single());

      foreach (var element in _highlightedElements)
      {
       element.Fill = new SolidColorBrush(Colors.Orange);
      }
     }           
    }

    Please let me know if this works for you.

    Regards,

    Ivan Kotev