Disable extra pop-ups and Pop-Up Images

2309
3
Jump to solution
07-20-2012 01:14 AM
JohnWall
Occasional Contributor
I am attempting to modify the InfoWindowSimple Sample to not provide pop-ups when someone clicks outside of the feature layer (i.e. not display random Lat/Long values) and to provide a picture (served locally; i.e. not via a Flickr feed) in the pop-up.

My code is currently using ArcGIS as stand in for the data that I will serve out via ArcServer. My XAML code currently looks like this:

<UserControl x:Class="jwall_test.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009">
    <Grid x:Name="LayoutRoot">

        <Grid.Resources>
            <esri:SimpleRenderer x:Key="MySimpleRenderer">
                <esri:SimpleRenderer.Symbol>
                    <esri:SimpleMarkerSymbol Style="Circle" Size="10" Color="Orange" />
                </esri:SimpleRenderer.Symbol>
            </esri:SimpleRenderer>

            <DataTemplate x:Key="LocationInfoWindowTemplate">
                <StackPanel Margin="2">
                    <TextBlock Text="Location:" />
                    <TextBlock Text="{Binding X, StringFormat=X\=\{0:0.000\}}" />
                    <TextBlock Text="{Binding Y, StringFormat=Y\=\{0:0.000\}}" />
                </StackPanel>
            </DataTemplate>
            <DataTemplate x:Key="MyFeatureLayerInfoWindowTemplate">
                <StackPanel Margin="2">
                    <TextBlock Text="{Binding [objectid]}" Foreground="Black" FontSize="12" FontWeight="Bold" />
                    <TextBlock Text="{Binding [datetime]}" Foreground="Black" FontSize="10" />
                    <TextBlock Text="{Binding [depth]}" Foreground="Black" FontSize="10" />
                    <TextBlock Text="{Binding [magnitude]}" Foreground="Black" FontSize="10" />
                    <TextBlock Text="{Binding [region]}" Foreground="Black" FontSize="10" />
                </StackPanel>
            </DataTemplate>
        </Grid.Resources>

        <esri:Map x:Name="MyMap" WrapAround="True" MouseClick="MyMap_MouseClick">
            <esri:ArcGISTiledMapServiceLayer ID="MyStreetMapLayer"
                    Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
            <esri:ArcGISDynamicMapServiceLayer ID="California" Opacity="0.4" VisibleLayers="8,10"
                    Url="http://maverick.arcgis.com/ArcGIS/rest/services/California/MapServer" />
            <esri:FeatureLayer ID="MyFeatureLayer"
                               Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/EarthquakesFromLastSevenDays/..."
                               OutFields="objectid,datetime,depth,magnitude,region"
                               Renderer="{StaticResource MySimpleRenderer}"
                               />
        </esri:Map>

        <esri:InfoWindow x:Name="MyInfoWindow"
                         Padding="2"
                         CornerRadius="20"
                         Background="LightSalmon"
                         Map="{Binding ElementName=MyMap}"
                         ContentTemplate="{StaticResource MyFeatureLayerInfoWindowTemplate}"
                         MouseLeftButtonUp="MyInfoWindow_MouseLeftButtonUp" />
       
        <Border Background="#77919191" BorderThickness="1" CornerRadius="5"
            HorizontalAlignment="Right"  VerticalAlignment="Top"
            Margin="20" Padding="5" BorderBrush="Black" >
            <ListBox x:Name="MyList" ItemsSource="{Binding ElementName=MyMap, Path=Layers}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <!--Layer visibility checkbox-->
                            <CheckBox IsChecked="{Binding Visible, Mode=TwoWay}" />
                            <!--Opacity slider-->
                            <Slider Margin="-5,0,0,0" Minimum="0" Maximum="1" Width="30"
                                Value="{Binding Opacity, Mode=TwoWay}" Height="18" />
                            <!--Layer name-->
                            <TextBlock Text="{Binding ID, Mode=OneWay}" Margin="5,0,0,0" >
                            <!-- Tooltip on hover-->
                                <ToolTipService.ToolTip>
                                    <StackPanel MaxWidth="400">
                                        <TextBlock FontWeight="Bold" Text="{Binding CopyrightText}" TextWrapping="Wrap" />
                                        <TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
                                    </StackPanel>
                                </ToolTipService.ToolTip>
                            </TextBlock>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Border>
       
        <esri:ScaleLine Map="{Binding ElementName=MyMap}" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Bottom" />
        <Line></Line>
        <esri:Attribution Layers="{Binding ElementName=MyMap, Path=Layers}" Margin="10" VerticalAlignment="Bottom" />
    </Grid>
</UserControl>
0 Kudos
1 Solution

Accepted Solutions
JonathanHouck
New Contributor III
I can't help you with the images, but in the sample for the InfoWindow the C# code behind handles that coordinate window like this:


InfoWindow window = new InfoWindow()             {                 Anchor = e.MapPoint,                 Map = MyMap,                 IsOpen = true,                 ContentTemplate = LayoutRoot.Resources["LocationInfoWindowTemplate"] as System.Windows.DataTemplate,                 //Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate                 Content = e.MapPoint              };


The code for the original InfoWindow (for the feature layer) has a return when it's invoked, so this code only fires when you click outside the feature layer.  It would probably be as simple as just removing this code as far as I can tell, or you could hook up an if (selection != null) to the original InfoWindow and leave the else unhandled.

View solution in original post

0 Kudos
3 Replies
JonathanHouck
New Contributor III
I can't help you with the images, but in the sample for the InfoWindow the C# code behind handles that coordinate window like this:


InfoWindow window = new InfoWindow()             {                 Anchor = e.MapPoint,                 Map = MyMap,                 IsOpen = true,                 ContentTemplate = LayoutRoot.Resources["LocationInfoWindowTemplate"] as System.Windows.DataTemplate,                 //Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate                 Content = e.MapPoint              };


The code for the original InfoWindow (for the feature layer) has a return when it's invoked, so this code only fires when you click outside the feature layer.  It would probably be as simple as just removing this code as far as I can tell, or you could hook up an if (selection != null) to the original InfoWindow and leave the else unhandled.
0 Kudos
JohnWall
Occasional Contributor
I can't help you with the images, but in the sample for the InfoWindow the C# code behind handles that coordinate window like this:


InfoWindow window = new InfoWindow()
            {
                Anchor = e.MapPoint,
                Map = MyMap,
                IsOpen = true,
                ContentTemplate = LayoutRoot.Resources["LocationInfoWindowTemplate"] as System.Windows.DataTemplate,
                //Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate
                Content = e.MapPoint 
            };


The code for the original InfoWindow (for the feature layer) has a return when it's invoked, so this code only fires when you click outside the feature layer.  It would probably be as simple as just removing this code as far as I can tell, or you could hook up an if (selection != null) to the original InfoWindow and leave the else unhandled.


Jonathan,
Thanks! It really was that simple.

Now to just figure out how to add images.
Thanks,
John
0 Kudos
JoeHershman
MVP Regular Contributor
Jonathan,
Thanks! It really was that simple.

Now to just figure out how to add images.
Thanks,
John


Put an <Image Source="MyLocalImageURI" /> into the appropriate InfoWIndowTemplate where you want and it will show an image.
Thanks,
-Joe
0 Kudos