zoukankan      html  css  js  c++  java
  • FeatureServiceWithPopups

     1 <UserControl xmlns:esri="http://schemas.esri.com/arcgis/client/2009"  x:Class="FeatureServiceWithPopups.MainPage"
     2     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     3     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     4     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     5     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     6     mc:Ignorable="d"
     7     d:DesignHeight="300" d:DesignWidth="400">
     8 
     9     <Grid x:Name="LayoutRoot" Background="White">
    10         <esri:Map x:Name="MyMap" />
    11 
    12         <esri:InfoWindow x:Name="MyInfoWindow"
    13                          Padding="2"
    14                          CornerRadius="10"                        
    15                          Map="{Binding ElementName=MyMap}" >
    16             <esri:InfoWindow.Background>
    17                 <LinearGradientBrush EndPoint="1.038,1.136" StartPoint="0.015,0.188">
    18                     <GradientStop Color="#FFD1DFF2"/>
    19                     <GradientStop Color="#FF666666" Offset="0.946"/>
    20                 </LinearGradientBrush>
    21             </esri:InfoWindow.Background>
    22         </esri:InfoWindow>
    23 
    24         <Grid HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,15,0" >
    25             <Rectangle Fill="#77919191" Stroke="Gray"  RadiusX="10" RadiusY="10" Margin="0,0,0,5" >
    26                 <Rectangle.Effect>
    27                     <DropShadowEffect/>
    28                 </Rectangle.Effect>
    29             </Rectangle>
    30             <Rectangle Fill="#FFFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,15" />
    31             <StackPanel Orientation="Vertical" Margin="25,20,25,25">
    32                 <TextBlock Text="Display Attributes In:" Foreground="Black" FontWeight="Bold" FontSize="12" Margin="3" />
    33                 <RadioButton GroupName="MyRadioButtons" Checked="MapTipRadioButton_Checked" IsChecked="True" Content="Map Tip" Margin="2" />
    34                 <RadioButton GroupName="MyRadioButtons" Checked="InfoWindowRadioButton_Unchecked" Content="Info Window" Margin="2"/>
    35             </StackPanel>
    36         </Grid>
    37 
    38     </Grid>
    39 </UserControl>
      1 using ESRI.ArcGIS.Client;
      2 using ESRI.ArcGIS.Client.Geometry;
      3 using ESRI.ArcGIS.Client.WebMap;
      4 using System;
      5 using System.Collections.Generic;
      6 using System.Linq;
      7 using System.Net;
      8 using System.Windows;
      9 using System.Windows.Controls;
     10 using System.Windows.Documents;
     11 using System.Windows.Input;
     12 using System.Windows.Media;
     13 using System.Windows.Media.Animation;
     14 using System.Windows.Shapes;
     15 
     16 namespace FeatureServiceWithPopups
     17 {
     18     public partial class MainPage : UserControl
     19     {
     20         Dictionary<string, FrameworkElement> mapTipsElements = new Dictionary<string, FrameworkElement>();
     21         MapPoint lastPoint = null;
     22 
     23 
     24         public MainPage()
     25         {
     26             InitializeComponent();
     27             Document webMap = new Document();
     28             webMap.GetMapCompleted += webMap_GetMapCompleted;
     29 
     30             webMap.GetMapAsync("921e9016d2a5423da8bd08eb306e4e0e");
     31 
     32         }
     33         void webMap_GetMapCompleted(object sender, GetMapCompletedEventArgs e)
     34         {
     35             if (e.Error == null)
     36             {
     37                 MyMap.Extent = e.Map.Extent;
     38                 int i = 0;
     39 
     40                 LayerCollection layerCollection = new LayerCollection();
     41                 foreach (Layer layer in e.Map.Layers)
     42                 {
     43                     layer.ID = i.ToString();
     44                     if (layer is FeatureLayer)
     45                     {
     46                         mapTipsElements.Add(layer.ID, (layer as FeatureLayer).MapTip);
     47                     }
     48                     layerCollection.Add(layer);
     49                     i++;
     50                 }
     51 
     52                 e.Map.Layers.Clear();
     53                 MyMap.Layers = layerCollection;
     54             }
     55         }
     56         private void MapTipRadioButton_Checked(object sender, RoutedEventArgs e)
     57         {
     58             if (MyMap != null)
     59             {
     60                 MyInfoWindow.IsOpen = false;
     61                 foreach (Layer layer in MyMap.Layers)
     62                 {
     63                     if (layer is FeatureLayer)
     64                         (layer as FeatureLayer).MouseLeftButtonUp -= WebMapFeatureServicePopups_MouseLeftButtonUp;
     65                     if (mapTipsElements.ContainsKey(layer.ID))
     66                         (layer as FeatureLayer).MapTip = mapTipsElements[layer.ID];
     67                 }
     68             }
     69         }
     70 
     71         private void InfoWindowRadioButton_Unchecked(object sender, RoutedEventArgs e)
     72         {
     73             foreach (Layer layer in MyMap.Layers)
     74                 if (layer is FeatureLayer)
     75                 {
     76                     (layer as FeatureLayer).MapTip = null;
     77                     (layer as FeatureLayer).MouseLeftButtonUp += WebMapFeatureServicePopups_MouseLeftButtonUp;
     78                 }
     79         }
     80 
     81         void WebMapFeatureServicePopups_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs e)
     82         {
     83             FeatureLayer flayer = sender as FeatureLayer;
     84             MapPoint clickPoint = MyMap.ScreenToMap(e.GetPosition(MyMap));
     85 
     86             if (clickPoint != lastPoint)
     87             {
     88                 if (flayer.GetValue(Document.PopupTemplateProperty) != null)
     89                 {
     90                     DataTemplate dt = flayer.GetValue(Document.PopupTemplateProperty) as DataTemplate;
     91 
     92                     MyInfoWindow.Anchor = clickPoint;
     93                     MyInfoWindow.ContentTemplate = dt;
     94                     MyInfoWindow.Content = e.Graphic.Attributes;
     95                     MyInfoWindow.IsOpen = true;
     96                     lastPoint = clickPoint;
     97                 }
     98             }
     99 
    100         }
    101     }
    102 }
  • 相关阅读:
    2 浮点数
    1 有符号与无符号
    4.变量和不同的赋值方式
    文档格式标准
    常用mysql命令
    一个简单的jsp+servlet实例,实现简单的登录
    容量调度器与公平调度器区别
    CListCtrl用法总结(二)
    CListCtrl 实现排序功能(数字和字母)
    CString 转换成 char *
  • 原文地址:https://www.cnblogs.com/rockman/p/3354782.html
Copyright © 2011-2022 走看看