コード例 #1
0
        void ApplicationSettingsFileDownloadComplete(object sender, DownloadStringCompletedEventArgs e)
        {
            m_IsDownloadingApplicationSettingsFile = false;

            if (e.Cancelled)
            {
                return;
            }

            if (e.Error != null)
            {
                if (e.Error is System.Security.SecurityException)
                {
                    // Use MessageBoxDialog instead of MessageBox.  There is a bug with
                    // Firefox 3.6 that crashes Silverlight when using MessageBox.Show.
                    MessageBoxDialog.Show("A clientaccesspolicy.xml or crossdomain.xml might be missing at the web root.",
                                          "Error accessing application files", MessageBoxButton.OK);
                }
                Logger.Instance.LogError(e.Error);
                return;
            }

            applicationSettingsFileContents = e.Result;

            initializeDataContext(applicationSettingsFileContents);
        }
コード例 #2
0
        public static void Show(string message, string caption, MessageType messageType, MessageBoxButton messageButtons, MessageBoxClosedEventHandler onClosedHandler = null, bool isModal = true)
        {
            MessageBoxDialog control = new MessageBoxDialog(message, messageType, messageButtons, onClosedHandler);
            Size             maxSize = WindowSizeUtility.GetWindowMaxSize();

            if (maxSize != Size.Empty)
            {
                control.MaxWidth  = maxSize.Width;
                control.MaxHeight = maxSize.Height;
            }

            WindowType windowType = MapApplication.Current != null && MapApplication.Current.IsEditMode ?
                                    WindowType.DesignTimeFloating : WindowType.Floating;

            if (MapApplication.Current != null)
            {
                MapApplication.Current.ShowWindow(caption, control, isModal, null,
                                                  delegate { OnMessageBoxClosed(control); }, windowType);
            }
            else
            {
                WindowManager.ShowWindow(caption, control, isModal, null,
                                         delegate { OnMessageBoxClosed(control); }, windowType);
            }
        }
コード例 #3
0
        public void Execute(object parameter)
        {
            if (View == null)
            {
                return;
            }

            try
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.DefaultExt = ".xml";
                dialog.Filter     = "XML Files|*.xml|Text Files|*.txt|All Files|*.*";

                if (dialog.ShowDialog() == true)
                {
                    using (Stream fs = (Stream)dialog.OpenFile())
                    {
                        string xml       = View.GetMapConfiguration(null);
                        byte[] fileBytes = UTF8Encoding.UTF8.GetBytes(xml.ToString());
                        fs.Write(fileBytes, 0, fileBytes.Length);
                    }
                }
            }
            catch (Exception ex)
            {
                string err = ex.Message;
                MessageBoxDialog.Show("Error saving File"
#if DEBUG
                                      + ": " + err
#endif
                                      );;
            }
        }
        public override void Execute(object parameter)
        {
            ExtensionBehavior extensionBehavior = parameter as ExtensionBehavior;

            if (extensionBehavior == null)
            {
                return;
            }

            ISupportsConfiguration supportConfiguration = extensionBehavior.MapBehavior as ISupportsConfiguration;

            if (supportConfiguration != null)
            {
                try
                {
                    supportConfiguration.Configure();
                }
                catch (Exception ex)
                {
                    if (ViewerApplicationControl.Instance == null)
                    {
                        MessageBoxDialog.Show(LocalizableStrings.GetString("BehaviorConfigurationFailedDescription"), LocalizableStrings.GetString("BehaviorConfigurationFailed"), MessageBoxButton.OK);
                    }
                    else
                    {
                        NotificationPanel.Instance.AddNotification(LocalizableStrings.GetString("BehaviorConfigurationFailed"), LocalizableStrings.GetString("BehaviorConfigurationFailedDescription"), ex.ToString(), MessageType.Warning);
                    }
                }
            }
        }
コード例 #5
0
        void FindButton_Click(object sender, RoutedEventArgs e)
        {
            double distance;

            if (DistanceTextBox == null || OperationalLayersComboBox == null || UnitsCombobox == null)
            {
                return;
            }

            // Parse the Userinput in the locale of the UI Culture. It is also important to specify the number style as float otherwise
            // an entry such as 50.2 gets interpreted/converted to 502
            if (!double.TryParse(DistanceTextBox.Text, System.Globalization.NumberStyles.Any, CultureHelper.GetCurrentCulture(), out distance))
            {
                MessageBoxDialog.Show(ESRI.ArcGIS.Mapping.Controls.Resources.Strings.InvalidDistance, ESRI.ArcGIS.Mapping.Controls.Resources.Strings.InvalidDistanceCaption, MessageBoxButton.OK);
                return;
            }

            StartBusyIndicator();

            OnFindNearbyExecuted(new FindNearbyEventArgs()
            {
                Distance         = distance,
                SelectedLayer    = ((LayerDisplay)OperationalLayersComboBox.SelectedItem).Layer,
                LayerDisplayName = ((LayerDisplay)OperationalLayersComboBox.SelectedItem).DisplayName,
                LinearUnit       = ((DistanceParameter)UnitsCombobox.SelectedItem).Unit,
                EventId          = Guid.NewGuid().ToString("N"),
            });
        }
コード例 #6
0
 void SymbolConfigProvider_GetSymbolCategoriesFailed(object sender, ESRI.ArcGIS.Mapping.Core.ExceptionEventArgs e)
 {
     if (e.Exception != null)
     {
         MessageBoxDialog.Show(e.Exception.Message);
         Logger.Instance.LogError(e.Exception);
     }
 }
コード例 #7
0
 private static void OnMessageBoxClosed(MessageBoxDialog control)
 {
     if (control != null && control.OnClosedHandler != null)
     {
         control.OnClosedHandler.Invoke(control, new MessageBoxClosedArgs()
         {
             Result = control.Result == MessageBoxResult.None ? MessageBoxResult.Cancel : control.Result
         });
     }
 }
コード例 #8
0
        private bool ValidateBehavior()
        {
            if (string.IsNullOrWhiteSpace(ExtensionBehavior.Title))
            {
                MessageBoxDialog.Show(ESRI.ArcGIS.Mapping.Controls.Resources.Strings.PleaseProvideValidTitleForNewBehavior, ESRI.ArcGIS.Mapping.Controls.Resources.Strings.NoBehaviorTitleSpecified, MessageBoxButton.OK, null, true);
                return(false);
            }

            return(true);
        }
コード例 #9
0
        public override void Execute(object parameter)
        {
            if (!CanExecute(parameter))
            {
                return;
            }



            MessageBoxDialog.Show(Resources.Strings.DeleteGraphicConfirmation, Resources.Strings.DeleteGraphicConfirmationTitle, System.Windows.MessageBoxButton.OKCancel,
                                  new MessageBoxClosedEventHandler(delegate(object obj, MessageBoxClosedArgs args1)
            {
                if (args1.Result == System.Windows.MessageBoxResult.OK)
                {
                    var popupInfo = PopupInfo as OnClickPopupInfo;
                    if (popupInfo != null)
                    {
                        // Delete the graphic from the layer
                        FeatureLayer layer = popupInfo.PopupItem.Layer as FeatureLayer;
                        if (layer != null)
                        {
                            layer.Graphics.Remove(popupInfo.PopupItem.Graphic);

                            // Adjust the current PopupItem and SelectedIndex
                            int revisedCount = popupInfo.PopupItems.Count - 1;
                            if (revisedCount <= 0)
                            {
                                // close the popup window
                                if (popupInfo.Container != null && popupInfo.Container is InfoWindow)
                                {
                                    ((InfoWindow)popupInfo.Container).IsOpen = false;
                                }

                                return;
                            }
                            // If the current PopupItem was the end of the list, go to the first PopupItem in the collection
                            int revisedIndex = (popupInfo.SelectedIndex < revisedCount)
                                                       ? popupInfo.SelectedIndex
                                                       : 0;
                            var list = new ObservableCollection <PopupItem>();
                            foreach (PopupItem item in popupInfo.PopupItems)
                            {
                                if (item != popupInfo.PopupItem)
                                {
                                    list.Add(item);
                                }
                            }
                            popupInfo.PopupItems    = list;
                            popupInfo.SelectedIndex = revisedIndex;
                        }
                    }
                }
            }));
        }
コード例 #10
0
        void relationAsync(string agsGeometryServerUrl, IList <Graphic> graphics1, IList <Graphic> graphics2, object userToken)
        {
            GeometryService geomService = new GeometryService
            {
                Url = agsGeometryServerUrl
            };

            geomService.RelationCompleted += geometryService_RelationCompleted;
            geomService.Failed            += (o, e) =>
            {
                MessageBoxDialog.Show(Resources.Strings.MsgErrorExecutingRelationAsyncOperation + Environment.NewLine + e.Error.ToString());
                if (findNearbyToolWindow != null)
                {
                    findNearbyToolWindow.StopBusyIndicator();
                    MapApplication.Current.HideWindow(findNearbyToolWindow);
                }
            };
            geomService.RelationAsync(graphics1, graphics2, GeometryRelation.esriGeometryRelationIntersection, null, userToken);
        }
        public override void Execute(object parameter)
        {
            ExtensionBehavior behavior = parameter as ExtensionBehavior;

            if (behavior == null)
            {
                return;
            }

            MessageBoxDialog.Show(LocalizableStrings.GetString("DeleteBehaviorCaption"), LocalizableStrings.GetString("DeleteBehaviorPrompt"), MessageBoxButton.OKCancel,
                                  new MessageBoxClosedEventHandler(delegate(object obj, MessageBoxClosedArgs args1)
            {
                if (args1.Result == MessageBoxResult.OK)
                {
                    // remove from map
                    removeMapBehavior(behavior);
                }
            }));
        }
コード例 #12
0
 public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     if (value != null && (bool)value)
     {
         if (!ESRI.ArcGIS.Client.Extensibility.LayerProperties.GetIsEditable(Layer))
         {
             return(new FlareClusterer());
         }
         else
         {
             MessageBoxDialog.Show(Strings.ClusteringDisallowedMessage, Strings.ClusteringDisallowedCaption, MessageBoxButton.OK);
             if (CheckBox != null)
             {
                 CheckBox.IsChecked = false;
             }
         }
     }
     return(null);
 }
コード例 #13
0
        public void Execute(object parameter)
        {
            if (View == null)
            {
                return;
            }

            try
            {
                ESRI.ArcGIS.Mapping.Core.MapDocumentUserPersistance.SaveUserDocument(View.GetMapConfiguration(null));
            }
            catch (Exception ex)
            {
                string err = ex.Message;
                MessageBoxDialog.Show("Error saving File"
#if DEBUG
                                      + ": " + err
#endif
                                      );;
            }
        }
コード例 #14
0
        /// <summary>
        /// Executes sign-in failure logic
        /// </summary>
        protected virtual void onSignInFailed(Exception ex, bool showWindow = false)
        {
            var message = StringResourcesManager.Instance.Get("SignInFailed");

            if (viewModel != null)
            {
                viewModel.SignInError = message;
                viewModel.SigningIn   = false;
            }

            if (showWindow)
            {
                MessageBoxDialog.Show(message, StringResourcesManager.Instance.Get("ErrorCaption"), MessageType.Error, MessageBoxButton.OK, (o, e) =>
                {
                    // Raise cancelled event once failed message box has been dismissed
                    OnCancelled();
                });
            }

            Logger.Instance.LogError(ex);
        }
コード例 #15
0
#pragma warning restore 0067

        public void Execute(object parameter)
        {
            Map map = parameter as Map;

            if (map == null)
            {
                map = MapApplication.Current.Map;
            }
            if (map != null)
            {
                MessageBoxDialog.Show(Strings.UnlinkWebMapDialogMessage, Strings.UnlinkWebMapDialogCaption,
                                      MessageType.Warning,
                                      MessageBoxButton.OKCancel, (o, e) =>
                {
                    if (e.Result == MessageBoxResult.OK)
                    {
                        ViewerApplication.WebMapSettings.Linked = false;
                    }
                });
            }
        }
コード例 #16
0
        public override void Execute(object parameter)
        {
            if (Layer == null || Map == null)
            {
                return;
            }

            if (IsRunningInTestHarness) // if running inside the test suite, remove the layer without prompting the user
            {
                removeSeletctedLayerFromMap();
                return;
            }
            string layerName = Layer.GetValue(MapApplication.LayerNameProperty) as string;
            string message   = string.Format(LocalizableStrings.RemoveLayerPrompt, !string.IsNullOrWhiteSpace(layerName) ? layerName : LocalizableStrings.RemoveLayerNameSubstitude);

            MessageBoxDialog.Show(message, LocalizableStrings.RemoveLayerCaption, System.Windows.MessageBoxButton.OKCancel,
                                  new MessageBoxClosedEventHandler(delegate(object obj, MessageBoxClosedArgs args1)
            {
                if (args1.Result == System.Windows.MessageBoxResult.OK)
                {
                    removeSeletctedLayerFromMap();
                }
            }));
        }
コード例 #17
0
        void buffer(string agsGeometryServerUrl, BufferParameters bufferParams, FindNearbyEventArgs findNearbyRequest)
        {
            if (string.IsNullOrEmpty(agsGeometryServerUrl))
            {
                return;
            }

            GeometryService geomService = new GeometryService
            {
                Url = agsGeometryServerUrl
            };

            geomService.BufferCompleted += GeometryService_BufferCompleted;
            geomService.Failed          += (o, e) =>
            {
                if (findNearbyToolWindow != null)
                {
                    findNearbyToolWindow.StopBusyIndicator();
                    MapApplication.Current.HideWindow(findNearbyToolWindow);
                }
                MessageBoxDialog.Show(Resources.Strings.MsgErrorExecutingBufferOperation + Environment.NewLine + e.Error.ToString());
            };
            geomService.BufferAsync(bufferParams, findNearbyRequest);
        }
コード例 #18
0
        public static void Show(string message, string caption, MessageType messageType, MessageBoxButton messageButtons, MessageBoxClosedEventHandler onClosedHandler = null, bool isModal = true)
        {
            MessageBoxDialog control = new MessageBoxDialog(message, messageType, messageButtons, onClosedHandler);
            Size maxSize = WindowSizeUtility.GetWindowMaxSize();
            if (maxSize != Size.Empty)
            {
                control.MaxWidth = maxSize.Width;
                control.MaxHeight = maxSize.Height;
            }

            WindowType windowType = MapApplication.Current != null && MapApplication.Current.IsEditMode ?
                WindowType.DesignTimeFloating : WindowType.Floating;
            if (MapApplication.Current != null)
                MapApplication.Current.ShowWindow(caption, control, isModal, null, 
                    delegate { OnMessageBoxClosed(control); }, windowType);
            else
                WindowManager.ShowWindow(caption, control, isModal, null, 
                    delegate { OnMessageBoxClosed(control); }, windowType);
        }
コード例 #19
0
 private static void OnMessageBoxClosed(MessageBoxDialog control)
 {
     if (control != null && control.OnClosedHandler != null)
         control.OnClosedHandler.Invoke(control, new MessageBoxClosedArgs() { Result = control.Result == MessageBoxResult.None ? MessageBoxResult.Cancel : control.Result });
 }
コード例 #20
0
        public static void UpdateProxyUrl(string proxyUrl)
        {
            Map map = (MapApplication.Current != null) ? MapApplication.Current.Map : null;

            if (map == null)
            {
                return;
            }

            bool mapRequiresRefresh = false;

            #region Check if layers can be updated in-place
            List <Layer> layersForRefresh = new List <Layer>();
            foreach (Layer layer in map.Layers)
            {
                if (ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetUsesProxy(layer))
                {
                    if (ProxyUrlHelper.CanChangeProxyUrl(layer))
                    {
                        layersForRefresh.Add(layer);
                    }
                    else
                    {
                        mapRequiresRefresh = true;
                        break;
                    }
                }
            }
            #endregion
            #region Set proxy url if layers can be updated
            if (!mapRequiresRefresh)
            {
                foreach (Layer layer in layersForRefresh)
                {
                    SecureServicesHelper.SetProxyUrl(layer, proxyUrl);
                }
            }
            #endregion
            #region Else, serialize/deserialize map, remove and re-add layers
            else
            {
                MapXamlWriter writer = new MapXamlWriter(true);
                try
                {
                    string mapXaml = writer.MapToXaml(map);

                    if (!string.IsNullOrEmpty(mapXaml))
                    {
                        Map newMap = System.Windows.Markup.XamlReader.Load(mapXaml) as Map;
                        if (newMap != null && newMap.Layers.Count == map.Layers.Count)
                        {
                            map.Layers.Clear();
                            map.Extent = newMap.Extent;
                            List <Layer> layers = new List <Layer>();
                            foreach (Layer layer in newMap.Layers)
                            {
                                if (ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetUsesProxy(layer))
                                {
                                    SecureServicesHelper.SetProxyUrl(layer, proxyUrl);
                                }
                                layers.Add(layer);
                            }
                            newMap.Layers.Clear();
                            foreach (Layer layer in layers)
                            {
                                map.Layers.Add(layer);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogError(ex);
                    MessageBoxDialog.Show(ESRI.ArcGIS.Mapping.Controls.Resources.Strings.ErrorChangingProxies);
                }
            }
            #endregion
        }
コード例 #21
0
        public void Execute(object parameter)
        {
            if (View == null)
            {
                return;
            }

            try
            {
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Filter      = "XML Files|*.xml|Text Files|*.txt|All Files|*.*";
                dialog.Multiselect = false;

                if (dialog.ShowDialog() == true && dialog.File != null)
                {
                    using (Stream fs = (Stream)dialog.File.OpenRead())
                    {
                        byte[]        buffer = new byte[10000];
                        StringBuilder sb     = new StringBuilder();
                        while (true)
                        {
                            int count = fs.Read(buffer, 0, buffer.Length);
                            if (count <= 0)
                            {
                                break;
                            }
                            string s = UTF8Encoding.UTF8.GetString(buffer, 0, count);
                            sb.Append(s);
                        }

                        string xaml = sb.ToString();

                        object parsedObject = null;
                        try
                        {
                            parsedObject = System.Windows.Markup.XamlReader.Load(xaml);
                            Map map = parsedObject as Map;
                            if (map == null)
                            {
                                throw new Exception(Resources.Strings.NotValidMapDocument);
                            }
                            else
                            {
                                View.SelectedLayer = null;
                                View.Map           = map;
                            }
                        }
                        catch (Exception error)
                        {
                            string err = error.Message;
                            MessageBoxDialog.Show(Resources.Strings.NotValidMapDocument
#if DEBUG
                                                  + Environment.NewLine + err
#endif
                                                  );;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string err = ex.Message;
                MessageBoxDialog.Show(Resources.Strings.MsgErrorOpeningFile
#if DEBUG
                                      + ": " + err
#endif
                                      );;
            }
        }
コード例 #22
0
        public override void Execute(object parameter)
        {
            if (Layer == null)
                return;

            GraphicsLayer graphicsLayer = Layer as GraphicsLayer;
            if (graphicsLayer == null)
                return;

            try
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.DefaultExt = ".csv";
                dialog.Filter = "CSV Files|*.csv|Text Files|*.txt|All Files|*.*";

                if (dialog.ShowDialog() == true)
                {
                    using (Stream fs = (Stream)dialog.OpenFile())
                    {
                        using (var writer = new StreamWriter(fs, Encoding.UTF8))
                        {
                            StringBuilder sb = new StringBuilder();

                            bool wroteHeader = false;
                            Collection<FieldInfo> fields = Core.LayerExtensions.GetFields(graphicsLayer);
                            if (fields == null)
                                return;
                            foreach (Graphic record in graphicsLayer.SelectedGraphics)
                            {
                                if (!wroteHeader)
                                {
                                    // Header Row
                                    foreach (string key in record.Attributes.Keys)
                                    {
                                        FieldInfo field = getField(key, fields);
                                        if (field == null || !field.VisibleInAttributeDisplay)
                                            continue;
                                        if (sb.Length > 0)
                                            sb.Append(",");
                                        sb.Append(field.DisplayName);
                                    }
                                    sb.AppendLine();
                                    wroteHeader = true;
                                }

                                StringBuilder line = new StringBuilder();
                                foreach (KeyValuePair<string, object> display in record.Attributes)
                                {
                                    object o = display.Value;
                                    string key = display.Key;
                                    FieldInfo field = getField(key, fields);
                                    if (field == null || !field.VisibleInAttributeDisplay)
                                        continue;
                                    if (o == null)
                                    {
                                        line.Append(",");
                                        continue;
                                    }
                                    string val = Convert.ToString(o);
                                    if (val == null)
                                        val = string.Empty;

                                    // If the value contains commas, enclose it in quotes
                                    if (val.Contains(","))
                                        val = string.Format("\"{0}\"", val.Trim('"'));
                                    line.AppendFormat("{0},", val);
                                }
                                string s = line.ToString();
                                if (s.Length > 0)
                                    s = s.Substring(0, s.Length - 1); // remove trailing ,
                                if (!string.IsNullOrEmpty(s))
                                    sb.AppendLine(s);
                            }
                            writer.Write(sb.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string err = ex.Message;
                MessageBoxDialog.Show(Resources.Strings.MsgErrorSavingFile
#if DEBUG
 + ": " + err
#endif
); ;
            }
        }
コード例 #23
0
 private void onDeleteBaseMapCommand(object parameter)
 {
     MessageBoxDialog.Show(ESRI.ArcGIS.Mapping.Controls.Resources.Strings.AreYouSureYouWantToDeleteBasemap, ESRI.ArcGIS.Mapping.Controls.Resources.Strings.ConfirmDelete, MessageBoxButton.OKCancel, deleteSelectedBaseMap, true);
 }
コード例 #24
0
        void SymbolConfigProvider_GetSymbolForResourceDictionary(object sender, GetSymbolsForResourceDictionaryCompletedEventArgs e)
        {
            if (e.Symbols == null)
            {
                return;
            }

            if (Symbols != null)
            {
                try
                {
                    Symbols.Items.Clear();
                    foreach (SymbolDescription symbolDescription in e.Symbols)
                    {
                        if (symbolDescription == null || symbolDescription.Symbol == null)
                        {
                            continue;
                        }
                        Symbol symbol = symbolDescription.Symbol;
                        double size   = 50;
                        ESRI.ArcGIS.Mapping.Core.Symbols.MarkerSymbol markerSymbol = symbol as ESRI.ArcGIS.Mapping.Core.Symbols.MarkerSymbol;
                        if (markerSymbol != null)
                        {
                            if (!double.IsNaN(markerSymbol.Size))
                            {
                                size = markerSymbol.Size;
                            }
                        }
                        else if (symbol is FillSymbol || symbol is LineSymbol)
                        {
                            size = 25;
                        }
                        else if (symbol is ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol)
                        {
                            ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol simpleMarkerSymbol =
                                symbol as ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol;
                            if (simpleMarkerSymbol != null && !double.IsNaN(simpleMarkerSymbol.Size))
                            {
                                size = simpleMarkerSymbol.Size;
                            }
                        }
                        else if (symbol is ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleMarkerSymbol)
                        {
                            ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleMarkerSymbol sms =
                                symbol as ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleMarkerSymbol;
                            if (sms != null && !double.IsNaN(sms.Size))
                            {
                                size = sms.Size;
                            }
                        }

                        SymbolDisplay disp = new SymbolDisplay()
                        {
                            Symbol           = symbolDescription.Symbol,
                            Width            = size,
                            Height           = size,
                            IsHitTestVisible = false // Set to false to prevent mouseover and selection effects
                        };

                        // Wrap symbol display in a grid to allow cursor and tooltip
                        Grid symbolGrid = new Grid()
                        {
                            Cursor = Cursors.Hand,
                            // Apply nearly transparent background so grid is hit-test visible
                            Background = new SolidColorBrush(Color.FromArgb(1, 255, 255, 255))
                        };
                        symbolGrid.Children.Add(disp);

                        Symbols.Items.Add(symbolGrid);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogError(ex);
                    MessageBoxDialog.Show(ESRI.ArcGIS.Mapping.Controls.Resources.Strings.ErrorRetrievingSymbols + Environment.NewLine + ex.Message);
                }
            }
        }
コード例 #25
0
        void findNearbyToolWindow_FindNearby(object sender, FindNearbyEventArgs e)
        {
            if (Layer == null)
            {
                return;
            }

            GraphicsLayer graphicsLayer = Layer as GraphicsLayer;

            if (graphicsLayer == null)
            {
                return;
            }

            if (graphicsLayer.SelectionCount < 1)
            {
                findNearbyToolWindow.StopBusyIndicator();
                MessageBoxDialog.Show(Resources.Strings.MsgNoFeaturesSelected, Resources.Strings.ErrorCaption, MessageBoxButton.OK);
                return;
            }

            BufferParameters bufferParams = new BufferParameters();

            switch (e.LinearUnit)
            {
            case LinearUnit.Miles:
                bufferParams.Unit = ESRI.ArcGIS.Client.Tasks.LinearUnit.StatuteMile;
                break;

            case LinearUnit.Meters:
                bufferParams.Unit = ESRI.ArcGIS.Client.Tasks.LinearUnit.Meter;
                break;

            case LinearUnit.Kilometers:
                bufferParams.Unit = ESRI.ArcGIS.Client.Tasks.LinearUnit.Kilometer;
                break;
            }
            bufferParams.UnionResults        = true;
            bufferParams.OutSpatialReference = Map.SpatialReference;
            SpatialReference gcs = new SpatialReference(4326);

            bufferParams.BufferSpatialReference = gcs;
            bufferParams.Geodesic = true;
            bufferParams.Distances.Add(e.Distance);

            // Check the spatial reference of the first graphic
            Graphic firstGraphic = graphicsLayer.SelectedGraphics.ElementAt(0);
            bool    isInGcs      = firstGraphic.Geometry != null &&
                                   firstGraphic.Geometry.SpatialReference != null &&
                                   firstGraphic.Geometry.SpatialReference.Equals(gcs);

            // In order to perform geodesic buffering we need to pass geometries in GCS to the geom service
            if (isInGcs)
            {
                foreach (Graphic selectedGraphic in graphicsLayer.SelectedGraphics)
                {
                    bufferParams.Features.Add(selectedGraphic);
                }

                buffer(GeometryServiceUrl, bufferParams, e);
            }
            else
            {
                GeometryServiceOperationHelper helper = new GeometryServiceOperationHelper(GeometryServiceUrl);
                helper.ProjectGraphicsCompleted += (o, args) => {
                    foreach (Graphic selectedGraphic in args.Graphics)
                    {
                        bufferParams.Features.Add(selectedGraphic);
                    }
                    buffer(GeometryServiceUrl, bufferParams, e);
                };
                helper.ProjectGraphics(graphicsLayer.SelectedGraphics.ToList(), new SpatialReference(4326));
            }
        }