0

I need to have an infoWindow that displays the Outfields of a FeatureLayer. The infoWindow is popping up, but it is popping up no matter where you click on the map and it does not contain any of the content. I have looked through the documentation and the only difference is that instead of using a UserControl, I am using a DialogWindowBase. Below is my XAML and C#.

XAML:

<DataTemplate x:Key="MyFeatureLayerInfoWindowTemplate">
                    <StackPanel Margin="7">
                        <TextBlock Text="{Binding [WVAL_ID], StringFormat='ID: \{0\}'}" FontWeight="Bold" Foreground="White"  />
                        <TextBlock Text="{Binding [SIZE], StringFormat='Size: \{0\}'}" FontWeight="Bold" Foreground="White" />
                        <TextBlock Text="{Binding [WVAL_USE], StringFormat='Use: \{0\}'}" FontWeight="Bold" Foreground="White" />
                        <TextBlock Text="{Binding [WVAL_TYPE], StringFormat='Type: \{0\}'}" FontWeight="Bold" Foreground="White"  />
                        <TextBlock Text="{Binding [OPENS], StringFormat='Opens: \{0\}'}" FontWeight="Bold" Foreground="White"  />
                        <TextBlock Text="{Binding [TURNS], StringFormat='Turns: \{0\}'}" FontWeight="Bold" Foreground="White"  />
                        <StackPanel Orientation="Horizontal" >

                        </StackPanel>
                    </StackPanel>
                </DataTemplate>

<esri:Map x:Name="MyMap" Background="#FFE3E3E3" WrapAround="True" MouseClick="MyMap_MouseClick" MouseRightButtonDown="MyMap_MouseRightButtonDown" Extent="-9834972.92753924,4441899.425293319,-9833977.88119163, 4442762.485358352">
               <esri:Map.Layers>

                    <esri:ArcGISTiledMapServiceLayer ID="MyLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
                    <esri:ArcGISDynamicMapServiceLayer ID="Calvert_City" Url="http://localhost:6080/arcgis/rest/services/CalvertCity_Test_2/MapServer"/> 

<esri:FeatureLayer ID="Water_Valves" Url="http://localhost:6080/arcgis/rest/services/CalvertCity_Test_2/MapServer/0" Renderer="{StaticResource MySimpleRenderer}" OutFields="WVAL_ID,SIZE,WVAL_USE,WVAL_TYPE,OPENS,TURNS" MouseLeftButtonDown="FeatureLayer_MouseLeftButtonDown">
    </esri:FeatureLayer>
                    </esri:Map.Layers>
      </esri:Map>

            <esri:InfoWindow x:Name="MyInfoWindow"
                             Padding="2"
                             CornerRadius="20"
                             Background="{StaticResource PanelGradient}"
                             Map="{Binding ElementName=My_Map}"
                             ContentTemplate="{StaticResource MyFeatureLayerInfoWindowTemplate}"
                         MouseLeftButtonUp="MyInfoWindow_MouseLeftButtonUp">

            </esri:InfoWindow>

C#: Here is the C# code that I have that will at least build and allow the infoWindow to appear:

private void MyMap_MouseClick(object sender, Map.MouseEventArgs e)
        {

            FeatureLayer featurelayer = MyMap.Layers["Water_Valves"] as FeatureLayer;
            System.Windows.Point screenPoint = MyMap.MapToScreen(e.MapPoint);

            MyInfoWindow.Anchor = e.MapPoint;
            MyInfoWindow.IsOpen = true;
        }

Here is the way the documentation does it:

 private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            FeatureLayer featureLayer = MyMap.Layers["MyFeatureLayer"] as FeatureLayer;
            System.Windows.Point screenPnt = MyMap.MapToScreen(e.MapPoint);

            // Account for difference between Map and application origin
            GeneralTransform generalTransform = MyMap.TransformToVisual(Application.Current.MainWindow);
            System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt);

            IEnumerable<Graphic> selected =
                featureLayer.FindGraphicsInHostCoordinates(transformScreenPnt);

            foreach (Graphic g in selected)
            {

                MyInfoWindow.Anchor = e.MapPoint;
                MyInfoWindow.IsOpen = true;
                //Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate
                MyInfoWindow.Content = g.Attributes;
                return;
            }
        }

When I try to run it while using the generalTransform is says that is cannot do it because it is not an ancestor.

  • Are you using Arcobjects? All the code posted looks like it is strictly from the WPF API. – Kirk Kuykendall Nov 29 '12 at 21:34
  • Sorry did not mean to put that as a tag. – JLott Nov 29 '12 at 21:36
  • Did you try using from the code from the documentation as-is, but replace "MyFeatureLayer" with "Water_Valves"? – Kirk Kuykendall Nov 29 '12 at 21:37
  • Yes. It still did not work. – JLott Nov 29 '12 at 21:41
1

I have a feeling that the original did not work because the map name does not match the infowindow binding:

<esri:Map x:Name="MyMap">

Map="{Binding ElementName=My_Map}"

0

I found an alternate way to do it that works.

XAML:

<esri:InfoWindow x:Name="MyInfoWindow"
                             Padding="2"
                             CornerRadius="20"
                             Background="{StaticResource PanelGradient}"
                             Map="{Binding ElementName=MyMap}"
                             ContentTemplate="{StaticResource MyFeatureLayerInfoWindowTemplate}">                
            </esri:InfoWindow>

C#:

 MapPoint lastPoint = null;

        private void FeatureLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs e)
        {
            FeatureLayer flayer = sender as FeatureLayer;

            MapPoint clickpoint = MyMap.ScreenToMap(e.GetPosition(MyMap));

            if (clickpoint != lastPoint)
            {
                MyInfoWindow.Anchor = clickpoint;
                MyInfoWindow.Content = e.Graphic.Attributes;
                MyInfoWindow.IsOpen = true;
                lastPoint = clickpoint;
            }
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.