Пример #1
0
        /// <summary>
        /// Handles changes to the PopupInfo property.
        /// </summary>
        private static void OnPopupInfoChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PopupCommandBase cmd = (PopupCommandBase)d;

            ESRI.ArcGIS.Client.Extensibility.PopupInfo oldPopupInfo = (ESRI.ArcGIS.Client.Extensibility.PopupInfo)e.OldValue;
            ESRI.ArcGIS.Client.Extensibility.PopupInfo newPopupInfo = cmd.PopupInfo;
            if (newPopupInfo != oldPopupInfo)
            {
                cmd.OnPopupInfoChanged(oldPopupInfo, newPopupInfo);
            }
        }
        public void Execute(object parameter)
        {
            ESRI.ArcGIS.Client.Extensibility.PopupInfo param = parameter as ESRI.ArcGIS.Client.Extensibility.PopupInfo;
            if (param == null || param.PopupItem == null)
            {
                return;
            }
            CustomGraphicsLayer cgl = param.PopupItem.Layer as CustomGraphicsLayer;

            if (cgl != null && param.PopupItem.Graphic != null)
            {
                cgl.OnItemClicked(param.PopupItem.Graphic);
            }
        }
        public bool CanExecute(object parameter)
        {
            ESRI.ArcGIS.Client.Extensibility.PopupInfo param = parameter as ESRI.ArcGIS.Client.Extensibility.PopupInfo;
            if (param == null || param.PopupItem == null)
            {
                return(false);
            }
            CustomGraphicsLayer cgl = param.PopupItem.Layer as CustomGraphicsLayer;

            if (cgl != null && param.PopupItem.Graphic != null)
            {
                return(true);
            }
            return(false);
        }
Пример #4
0
 /// <summary>
 /// Normally the popupinfo changes every time a new popup is displayed.  Each time, we bind the
 /// current PopupItem to our dependency property so that if it changes, we can fire a CanExecuteChanged
 /// event on our command
 /// </summary>
 protected virtual void OnPopupInfoChanged(ESRI.ArcGIS.Client.Extensibility.PopupInfo oldPopupInfo, ESRI.ArcGIS.Client.Extensibility.PopupInfo newPopupInfo)
 {
     // remove existing binding
     ClearValue(PopupItemProperty);
     if (newPopupInfo != null)
     {
         // Bind the popupinfo's popupItem to ours so that we can cause
         // the command to check its CanExecute state
         var b = new Binding("PopupItem")
         {
             Source = newPopupInfo
         };
         BindingOperations.SetBinding(this, PopupItemProperty, b);
     }
     RefreshCommand();
 }
        internal static void rebuildMapTipContentsBasedOnFieldVisibility(HoverResults results)
        {
            HoverResults hr = results as HoverResults;

            if (hr == null)
            {
                return;
            }
            GraphicsLayer hrLayer = hr.Layer;

            if (hr.Graphic == null || hr.Graphic.Attributes == null || hrLayer == null)
            {
                hr.Visibility = Visibility.Collapsed;
                return;
            }
            Visibility hrVisibility = Visibility.Visible;

            IEnumerable <FieldInfo> fields = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetFields(hrLayer); // Store the fields on the Map Tips element
            string displayField            = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetDisplayField(hrLayer);

            if (string.IsNullOrEmpty(displayField))
            {
                displayField = FieldInfo.GetDefaultDisplayField(fields);
                ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetDisplayField(hrLayer, displayField);
            }
            Graphic   popupGraphic = hr.Graphic;
            PopupItem popupItem    = new PopupItem()
            {
                DataTemplate    = null,
                Graphic         = popupGraphic,
                Layer           = hrLayer,
                LayerName       = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetLayerName(hrLayer),
                Title           = null,
                TitleExpression = null,
            };

            popupItem.FieldInfos = MapTipsHelper.ToFieldSettings(ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetFields(hrLayer));
            MapTipsHelper.GetTitle(popupItem, null);

            bool hasContent = false;

            popupItem.DataTemplate = MapTipsHelper.BuildMapTipDataTemplate(popupItem, out hasContent);
            if (!hasContent)
            {
                popupItem.DataTemplate = null;
            }

            ESRI.ArcGIS.Client.Extensibility.PopupInfo popupInfo = new ESRI.ArcGIS.Client.Extensibility.PopupInfo()
            {
                AttributeContainer = hr.AttributeContainer,
                Container          = hr,
                PopupItem          = popupItem
            };
            hr.PopupInfo = popupInfo;

            bool hasTitle = !string.IsNullOrEmpty(popupInfo.PopupItem.Title);

            if (hasTitle || hasContent)
            {
                hrVisibility = Visibility.Visible;
                // re-establish delay
                TimeSpan delay = (TimeSpan)hr.Map.GetValue(DelayMapTipHide.HideDelayProperty);
                hrLayer.MapTip.SetValue(GraphicsLayer.MapTipHideDelayProperty, delay);
            }
            else
            {
                hrVisibility = Visibility.Collapsed;
            }
            hr.Visibility = hrVisibility;
        }
 void attributeChangeEventHookups(PopupInfo popupInfo, bool hookup)
 {
     if (PopupInfo != null)
     {
         if (hookup)
             PopupInfo.PopupItem.PropertyChanged += PopupItem_PropertyChanged;
         else
             PopupInfo.PopupItem.PropertyChanged -= PopupItem_PropertyChanged;
     }
 }