Select to view content in your preferred language

How to use MapApplication.ShowPopup ?

3640
5
01-26-2012 11:21 AM
RyanKoehnen
Occasional Contributor
I have a graphics layer that is generated dynamically based on mouse clicks. I would like to show a popup with the attribute info i've set in the graphic to be shown when clicked. The graphic is populated with the geometry from the mouse click and attributes will be based on the result from an ImageServiceIdentifyTask. I can get the popup to appear but it's blank. How do I get this to show the information?

I'm using Draw to generate the graphic, code snippit-
            drawObject = new Draw(MapApplication.Current.Map)
            {
                DrawMode = DrawMode.Point,
                IsEnabled = true,
            };
            drawObject.DrawComplete += DrawObject_DrawComplete;


Then the popup is shown after the draw complete event is fired-

private void DrawObject_DrawComplete(object sender, DrawEventArgs args)
        {
            MapPoint point = args.Geometry as MapPoint;
            point.SpatialReference = MapApplication.Current.Map.SpatialReference;

            Graphic graphic = new Graphic()
            {
                Geometry = point,
            };

            GraphicsLayer graphicsLayer = MapApplication.Current.Map.Layers["IdentifyResultsLayer"] as GraphicsLayer;
            if (graphicsLayer == null)
            {
                graphicsLayer = createResultsLayer();
                MapApplication.Current.Map.Layers.Add(graphicsLayer);
            }
            else
            {
                graphicsLayer.ClearGraphics();
            }

            //test attributes
            graphic.Attributes.Add("ObstacleClearanceSurfaceHeight", 100);
            graphic.Attributes.Add("GroundElevation", 150);
            graphic.Attributes.Add("Difference", 333);

            graphicsLayer.Graphics.Add(graphic);

            MapApplication.Current.ShowPopup(graphic, graphicsLayer);
        }
0 Kudos
5 Replies
RichZwaap
Frequent Contributor
Hi Ryan:

I believe the trick here is to add a graphic containing attributes to the GraphicsLayer before adding the layer to the map.  Since the API does not define a way to specify a GraphicsLayer's schema, the Viewer relies on the first graphic in a layer at the time the layer is added to the map to determine this.
0 Kudos
RyanKoehnen
Occasional Contributor
Hi Ryan:

I believe the trick here is to add a graphic containing attributes to the GraphicsLayer before adding the layer to the map.  Since the API does not define a way to specify a GraphicsLayer's schema, the Viewer relies on the first graphic in a layer at the time the layer is added to the map to determine this.


So, I tried what you suggested. The popup still comes up blank. Am I doing it right? Note: I have a separate method that creates and returns the graphics layer, it just gives it an ID and sets the MapApplication.LayerProperty dependancy object.

private void DrawObject_DrawComplete(object sender, DrawEventArgs args)
        {
            MapPoint point = args.Geometry as MapPoint;
            point.SpatialReference = MapApplication.Current.Map.SpatialReference;

            Graphic graphic = new Graphic()
            {
                Geometry = point,
            };

            //test attributes
            graphic.Attributes.Add("ObstacleClearanceSurfaceHeight", 100);
            graphic.Attributes.Add("GroundElevation", 150);
            graphic.Attributes.Add("Difference", 333);

            GraphicsLayer graphicsLayer = CreateResultsLayer();

            graphicsLayer.Graphics.Add(graphic);

            MapApplication.Current.Map.Layers.Add(graphicsLayer);

            MapApplication.Current.ShowPopup(graphic, graphicsLayer);
        }
0 Kudos
RyanKoehnen
Occasional Contributor
Sorry to be a pest and bump this thread... Esri support's basic response was- yes we see the problem, we'll file it as a defect, thanks. Anybody from Esri knowledgeable with the code base care to share the "proper" usage of this function or a working example? I can't believe you guys would include a function that flat out didn't work (shows a blank popup).
0 Kudos
KatherineDalton
Esri Regular Contributor
Hi Ryan,

When I run the last bit of code you supplied, I get the attributes shown in the pop-up window. I've attached a screenshot. Are you not seeing anything in your pop-up window still?

I have the following in my createResultsMethod (I'm assuming you have the same). My RedMarkerSymbol is actually just coming from my configDialog xaml (which isn't used in this case other than to hold that symbol)

 private GraphicsLayer createResultsLayer()
        {
            GraphicsLayer gl = new GraphicsLayer()
            {
                ID = "GraphicsLayer",
                Renderer = new SimpleRenderer()
                {
                    Symbol = configDialog.Resources["RedMarkerSymbol"] as Symbol
                }
            };
            // Set layer name in Map Contents
            gl.SetValue(MapApplication.LayerNameProperty, "Graphics Results");

            return gl;
}

MyConfigDialog.xaml:
<UserControl x:Class="ViewerApplication7.AddIns.MyConfigDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.Resources>
        <ResourceDictionary>
            <esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="12" Style="Circle" />
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <StackPanel Margin="10" Background="Transparent"></StackPanel>
    </Grid>
</UserControl>
[ATTACH=CONFIG]11824[/ATTACH]
Katy Dalton | Technical Consultant
THE SCIENCE OF WHERE™
0 Kudos
RyanKoehnen
Occasional Contributor
Hi Katy,

The only thing that I can see that is different between your code and mine is you've defined a symbol for the graphics layer. My test code was always showing up with the default yellow pin that appears when you don't define a symbol. I should add, that if I didn't disable the draw object and clicked the map more than once, the attributes would show on a second click. But the popup would always be blank on the first click. Esri support observed the same behavior when I supplied sample code.

The methods and properties around GetPopupInfo, PopupItem, etc. look intriguing, but there isn't enough guidance in the API documentation for me to figure out how to customize that popup (resize, etc).

Since I couldn't find a workaround I switched gears and went with the InfoWindow from the Silverlight API. I add the InfoWindow to the parent Grid of the Map object after the DrawComplete event-

FrameworkElement parent = VisualTreeHelper.GetParent(MapApplication.Current.Map) as FrameworkElement;
((Grid)parent).Children.Add(infoWindow);

If Esri is planning on putting forth more examples for the Viewer API, a good Popup sample showing how to use the above mentioned classes would be great.
0 Kudos