GraphicsLayer Maptip that Hyperlinks?

2413
9
10-28-2010 09:00 PM
MikeDavis
New Contributor
I'm wondering if its possible to hyperlink a graphicslayer point AND the associated Maptip?

I have added the link into the graphics.Attributes.add property:

graphic.Attributes.Add("Link", item.Links(0).Uri)

I'd like to have the point clickable so that it will immediately spawn a browser to the link specified in the graphics attributes.

I have the MapTip working okay and displaying a few entries in the graphics' attributes.  But I'd like to make the hyperlink clickable (at this point, I move off of the immediate graphic and attempt to click on a hyperlink _inside_ of the maptip and I can't because it disappears so quickly).

any ideas on how I can best accomplish either or both??
0 Kudos
9 Replies
DanielWalton
Occasional Contributor
Handle the GraphicsLayer.MouseLeftButtonDown event with the following code:

private void graphicsLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs args)
{
        System.Windows.Browser.HtmlPage.Window.Navigate(new System.Uri((string)args.Graphic.Attributes["link"], System.UriKind.Absolute), "_blank");
}
Setting the target to "_blank" ensures that you don't leave the app by clicking.

If you want to make the maptip more hyperlink friendly, you'll probably want to use the maptip included in the toolkit instead of the default ESRI.ArcGis.Client.Maptip control.
0 Kudos
KevinSesock
New Contributor


If you want to make the maptip more hyperlink friendly, you'll probably want to use the maptip included in the toolkit instead of the default ESRI.ArcGis.Client.Maptip control.


Any thoughts on how?
0 Kudos
DanielWalton
Occasional Contributor
You can download and modify the toolkit maptip source. On the template, You need to replace the datagrid with something like:

<HyperlinkButton NavigateUri="{TemplateBinding Url}" TargetName="_blank" />

And then create a Dependency Property named Url and assign it in code behind in graphicsLayer_MouseEnter().
0 Kudos
dotMorten_esri
Esri Notable Contributor
Set a hide delay on the maptip, so the user gets a change to move the mouse to the maptip before it closes. This example assumes the graphic you are hovering on has a "Link" attribute.
<esri:GraphicsLayer>
   <esri:GraphicsLayer.MapTip>
      <Border Background="White" esri:GraphicsLayer.MapTipHideDelay="0:0:0.5">
         <StackPanel Margin="10">
            <TextBlock Text="More info:" />
            <HyperlinkButton NavigateUri="{Binding [Link]}" TargetName="_blank" />
         </StackPanel>
      </Border>
   </esri:GraphicsLayer.MapTip>
</esri:GraphicsLayer>
0 Kudos
KevinSesock
New Contributor
The problem I have with either of the below, is that I have multiple layers, several of which have URL fields. As it stands, we've been using something similar to the window in the Identify Tool example:

http://resources.esri.com/help/9.3/arcgisserver/apis/silverlight/samples/start.htm#Identify

Since we have layers that may be stacked, we need to provide a way to view the different layers. Seeing as one of our layers has a URL field, but we don't care about showing any of the other feature attributes in it, this is the method we've been using. We'd like to move to a method where we use the MapTip, as it's cleaner and can position around the map more easily. Unfortunately, we have one layer that will always be present (it's a grid of 7.5 minute quads that shows old scanned topo maps), and would like to use the URL field from this layer, always present in the MapTip. In addition, our other layers will have URLs as well, but not all of them.

This just keeps getting more complicated, but I'm not sure where to begin.

In an ideal world, we could use the Toolkit (widget) MapTip with the drop-down box from the Identify tool, and then easily pick and choose attribute fields from other layers.

I know I can get this granular, I'm just afraid the way we're doing it is rather... kludgey.

Any advice?

Also, please accept my apologies for hijacking the thread.
0 Kudos
DanielWalton
Occasional Contributor
I hear you on the kludgey bit. It's not difficult to get that way when you're using new tech and aren't sure what patterns and practices to use. We had a similar issue where we wanted to use the same UI to interact with different types of map objects. Some of our symbols were KML with HTML in one of the Attribute fields, and others were Shapefile or ESRI Features that just had a table of attributes. It may not be the best approach, but we went with the toolkit maptip, and modded it to allow display of an HTML panel (see Morten Nielsen's blog) in the case where the Url or HTML attributes were present, and a feature grid in the case where they weren't. The Maptip controltemplate has both controls present, with their visibility databound to a (added) dependency property in the maptip control, whose value is set when you click a graphic.
0 Kudos
MikeDavis
New Contributor
Handle the GraphicsLayer.MouseLeftButtonDown event with the following code:

private void graphicsLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs args)
{
        System.Windows.Browser.HtmlPage.Window.Navigate(new System.Uri((string)args.Graphic.Attributes["link"], System.UriKind.Absolute), "_blank");
}
Setting the target to "_blank" ensures that you don't leave the app by clicking.

If you want to make the maptip more hyperlink friendly, you'll probably want to use the maptip included in the toolkit instead of the default ESRI.ArcGis.Client.Maptip control.


Thanks Danwallie,

I'm getting the following problem with the code provided: Unable to cast object of type 'System.Uri' to type 'System.String'

Also, SharpGIS with regards to the MapTipHideDelay -- is there any way to set this with a GraphicsLayer that is being created programmatically (ie. not in XAML?)

Thanks guys for any help you can provide
0 Kudos
DanielWalton
Occasional Contributor
Looks like the "Link" attribute of your graphic is of type System.Uri. In that case just use:

private void graphicsLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs args)
{
        System.Windows.Browser.HtmlPage.Window.Navigate((System.Uri)args.Graphic.Attributes["link"], "_blank");
}
0 Kudos
MikeDavis
New Contributor
Thanks danwallie, that's terrific, worked well!  Sorry, bit of a newbie here!
0 Kudos