Select to view content in your preferred language

Adding MapTip in code-behind

862
3
Jump to solution
09-19-2012 12:44 AM
JohanCarlsson
Regular Contributor
Hi!

I'm new to programming with this API and I'm trying to add MapTip's dynamically where the user clicks.
I want to do everything in the code-behind since I'm working with the viewer and can't initialize any new maps in the XAML.

Here's what I got so far, code is executed in the order below:

Creating the layer:
GraphicsLayer mapTipLayer = new GraphicsLayer();                 mapTipLayer.ID = "mapTipLayer"; MapApplication.Current.Map.Layers.Add(mapTipLayer); MapApplication.SetLayerName(mapTipLayer, "MapTip Layer");


Setting a DefaultSymbol where the user clicks:
ESRI.ArcGIS.Client.Graphic g = new ESRI.ArcGIS.Client.Graphic() {      Geometry = mapPoint,      Symbol = LayoutRoot.Resources["DefaultMapTipSymbol"] as Symbol, }; mapTipLayer.Graphics.Add(g);


Everything works fine so far, the problems start when I try to use the MapTip-class. The graphic I addshows up but there's no hover function that displays anything.
ESRI.ArcGIS.Client.Toolkit.MapTip mapTip = new ESRI.ArcGIS.Client.Toolkit.MapTip(); mapTip.GraphicsLayer = mapTipLayer; mapTip.Title = "Some content"; mapTipLayer.MapTip = mapTip;


Am I doing it in the wrong order? Am I missing something? If I understood the API reference correctly this should be enough to display a MapTip. Should I add all MapTips before I add the layer to the current map? Should I use a FeatureLayer instead?

I've also tried this instead for the first code block:
mapTipLayer = new GraphicsLayer();                 mapTipLayer.ID = "mapTipLayer"; mapTipLayer.MapTip = new ESRI.ArcGIS.Client.Toolkit.MapTip() { Title = "test" }; MapApplication.Current.Map.Layers.Add(mapTipLayer); MapApplication.SetLayerName(mapTipLayer, "MapTip Layer");


Any suggestions, tips or references to similiar problems would be greatly appreciated.

Regards
Johan Carlsson
0 Kudos
1 Solution

Accepted Solutions
DominiqueBroux
Esri Frequent Contributor
ESRI.ArcGIS.Client.Toolkit.MapTip mapTip = new ESRI.ArcGIS.Client.Toolkit.MapTip();
mapTip.GraphicsLayer = mapTipLayer;
mapTip.Title = "Some content";
mapTipLayer.MapTip = mapTip;


To get maptips, you can either use the maptip control or set the maptip property of the layer. But don't do both.

Removing the latest line of your code shoudl work:
ESRI.ArcGIS.Client.Toolkit.MapTip mapTip = new ESRI.ArcGIS.Client.Toolkit.MapTip();

mapTip.GraphicsLayer = mapTipLayer;
mapTip.Title = "Some content";
///mapTipLayer.MapTip = mapTip;[/CODE]

View solution in original post

0 Kudos
3 Replies
JohanCarlsson
Regular Contributor
I scrapped this approach, it was too troublesome. In a fraction of the time I implemented a simple MouseEnter and MouseLeave to create something similar to a MapTip.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
ESRI.ArcGIS.Client.Toolkit.MapTip mapTip = new ESRI.ArcGIS.Client.Toolkit.MapTip();
mapTip.GraphicsLayer = mapTipLayer;
mapTip.Title = "Some content";
mapTipLayer.MapTip = mapTip;


To get maptips, you can either use the maptip control or set the maptip property of the layer. But don't do both.

Removing the latest line of your code shoudl work:
ESRI.ArcGIS.Client.Toolkit.MapTip mapTip = new ESRI.ArcGIS.Client.Toolkit.MapTip();

mapTip.GraphicsLayer = mapTipLayer;
mapTip.Title = "Some content";
///mapTipLayer.MapTip = mapTip;[/CODE]
0 Kudos
JohanCarlsson
Regular Contributor
Thank you Dominique, that solved the problem. Alot less code to maintain now.
I forgot another cruicial thing though, assigning the MapTip to the symbol (g.MapTip = mapTip).

Is there any way to loop through all of my MapTips and keep them visible indefinitely? The reason I want to implement this is because when we want to print the maps, we won't have any visible notes.

Edit:
To make things clearer, I'd like to click on the symbol I placed and that will launch a function that sets the HideDelay of the MapTip to infinity, through code-behind.

Regards
Johan Carlsson
0 Kudos