Example #1
0
        public void ApplyLayout(LayoutEventArgs e)
        {
            if (e == null)
                return;

            this.Content = e.Content;
            Map = e.Map;

            if (e.AttributeTableContainer != null)
            {
                if (e.AttributeTableContainer.Content == null)
                {
                    AttributeDisplay = new AttributeDisplay()
                    {
                        FeatureDataGrid = new FeatureDataGrid(),
                        AutoScrollToGraphic = AutoScrollRowOnMouseOver,
                        FilterFeaturesByMapExtent = FilterFeaturesOnMapExtentChanged,
                    };
                    e.AttributeTableContainer.Content = AttributeDisplay;
                }
                else
                {
                    FeatureDataGrid featureDataGrid = e.AttributeTableContainer.Content as FeatureDataGrid;
                    if (featureDataGrid != null)
                    {
                        e.AttributeTableContainer.Content = null; // remove from parent
                        AttributeDisplay = new AttributeDisplay()
                        {
                            FeatureDataGrid = featureDataGrid,
                            AutoScrollToGraphic = AutoScrollRowOnMouseOver,
                            FilterFeaturesByMapExtent = FilterFeaturesOnMapExtentChanged,
                        };
                        e.AttributeTableContainer.Content = AttributeDisplay;
                    }
                }
                if (AttributeDisplay != null && AttributeDisplay.FeatureDataGrid != null)
                {
                    try
                    {
                        Binding binding = XamlReader.Load("<Binding xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:extensibility=\"http://schemas.esri.com/arcgis/client/extensibility/2010\" Path=\"GraphicsLayer.(extensibility:LayerProperties.IsEditable)\" />") as Binding;
                        binding.Converter = new ReverseBooleanConverter();
                        binding.Source = AttributeDisplay;
                        BindingOperations.SetBinding(AttributeDisplay.FeatureDataGrid, DataGrid.IsReadOnlyProperty, binding);
                    }
                    catch
                    {
                        //Swallow
                    }

                    // workaround to avoid issue where initial load of attribute table (DataGrid) crashes 
                    // Silverlight when table includes columns with numeric field names.  
                    GraphicsLayer layer = AttributeDisplay.FeatureDataGrid.GraphicsLayer;
                    AttributeDisplay.FeatureDataGrid.GraphicsLayer = null;

                    ToggleTableCommand cmd = new ToggleTableCommand();

                    RoutedEventHandler loaded = null;
                    loaded = (o, args) =>
                    { 
                        cmd.Execute(null);
                        AttributeDisplay.FeatureDataGrid.Loaded -= loaded;
                        AttributeDisplay.FeatureDataGrid.GraphicsLayer = layer;
                    };

                    AttributeDisplay.FeatureDataGrid.Loaded += loaded;
                    cmd.Execute(null);
                }
            }

            if (e.ScaleBarContainer != null && e.ScaleBarContainer.Content == null)
            {
                e.ScaleBarContainer.Content = ScaleBar = new ScaleBar()
                {
                    TargetWidth = 150,
                    MapUnit = MapUnit.Undefined,
                };
            }

            if (e.ProgressIndicatorContainer != null && e.ProgressIndicatorContainer.Content == null)
            {
                e.ProgressIndicatorContainer.Content = ProgressGauge = new ProgressGauge();
            }

            if (e.AttributionDisplayContainer != null && e.AttributionDisplayContainer.Content == null)
            {
                e.AttributionDisplayContainer.Content = AttributionDisplayControl = new AttributionDisplayControl() { 
                    Foreground = e.AttributionDisplayContainer.Foreground,
                };
                AttributionDisplayControl.SetBinding(FrameworkElement.VisibilityProperty, new System.Windows.Data.Binding("Visibility") { Source = e.AttributionDisplayContainer, Mode = System.Windows.Data.BindingMode.TwoWay });
            }

            Editor = MapApplication.Current.FindObjectInLayout(ControlNames.EDITORWIDGET) as EditorWidget;
            if (e.EditorConfigContainer != null && e.EditorConfigContainer.Content == null)
            {
                EditorConfigControl = new GenericConfigControl();
                EditorConfigControl.Name = "EditorConfiguration";
                EditorConfigControl.Title = Controls.Resources.Strings.ConfigureEditorWidget;
                EditorConfigControl.Command = new ConfigureEditorCommand() { Map = Map };
                ElementExtensions.SetIsConfigurable(EditorConfigControl, true);
                object[] attributes = typeof(ToggleEditCommand).GetCustomAttributes(typeof(DisplayNameAttribute), false);
                if (attributes.Length > 0 && !string.IsNullOrEmpty(((DisplayNameAttribute)attributes[0]).Name))
                    ElementExtensions.SetDisplayName(EditorConfigControl, ((DisplayNameAttribute)attributes[0]).Name);
                e.EditorConfigContainer.Content = EditorConfigControl;

                // When done in XAML the binding doesn't work properly until the editorwidget is made visible.
                if (Editor != null)
                {
                    BindingOperations.SetBinding(Editor, EditorWidget.AlwaysDisplayDefaultTemplatesProperty, new Binding("DataContext.AlwaysDisplayDefaultTemplates") { Source = e.EditorConfigContainer });
                    BindingOperations.SetBinding(Editor, EditorWidget.AutoCompleteProperty, new Binding("DataContext.AutoComplete") { Source = e.EditorConfigContainer, Mode = BindingMode.TwoWay });
                    BindingOperations.SetBinding(Editor, EditorWidget.AutoSelectProperty, new Binding("DataContext.AutoSelect") { Source = e.EditorConfigContainer });
                    BindingOperations.SetBinding(Editor, EditorWidget.ContinuousProperty, new Binding("DataContext.Continuous") { Source = e.EditorConfigContainer });
                    BindingOperations.SetBinding(Editor, EditorWidget.EditVerticesEnabledProperty, new Binding("DataContext.EditVerticesEnabled") { Source = e.EditorConfigContainer });
                    BindingOperations.SetBinding(Editor, EditorWidget.FreehandProperty, new Binding("DataContext.Freehand") { Source = e.EditorConfigContainer, Mode = BindingMode.TwoWay });
                    BindingOperations.SetBinding(Editor, EditorWidget.MaintainAspectRatioProperty, new Binding("DataContext.MaintainAspectRatio") { Source = e.EditorConfigContainer });
                    BindingOperations.SetBinding(Editor, EditorWidget.MoveEnabledProperty, new Binding("DataContext.MoveEnabled") { Source = e.EditorConfigContainer });
                    BindingOperations.SetBinding(Editor, EditorWidget.RotateEnabledProperty, new Binding("DataContext.RotateEnabled") { Source = e.EditorConfigContainer });
                    BindingOperations.SetBinding(Editor, EditorWidget.ScaleEnabledProperty, new Binding("DataContext.ScaleEnabled") { Source = e.EditorConfigContainer });
                    BindingOperations.SetBinding(Editor, EditorWidget.LayerIDsProperty, new Binding("DataContext.LayerIds") { Source = e.EditorConfigContainer });
                }
            }

            ContentControl container = MapApplication.Current.FindObjectInLayout(ControlNames.ADDCONTENTCONTROLCONTAINER) as ContentControl;
            if (container != null)
            {
                AddContentDialog addContentDialog = new AddContentDialog()
                {
                    DataSourceProvider = DataSourceProvider,
                    ConnectionsProvider = ConnectionsProvider,
                    BorderThickness = new Thickness(0),
                    Map = Map,
                };
                addContentDialog.LayerAdded += AddContentDialog_LayerAdded;
                addContentDialog.LayerAddFailed += AddContentDialog_LayerAddFailed;
                container.Content = addContentDialog;
            }

            container = MapApplication.Current.FindObjectInLayout(ControlNames.MAPCONTENTS_CONTROL_CONTAINER_NAME) as ContentControl;
            if (container != null)
            {
                MapContents = new EsriMapContents.MapContents();
                MapContents.Name = ControlNames.MAPCONTENTS_CONTROL_NAME;
                ElementExtensions.SetIsConfigurable(MapContents, true);
                object[] attributes = typeof(ToggleMapContentsCommand).GetCustomAttributes(typeof(DisplayNameAttribute), false);
                if (attributes.Length > 0 && !string.IsNullOrEmpty(((DisplayNameAttribute)attributes[0]).Name))
                    ElementExtensions.SetDisplayName(MapContents, ((DisplayNameAttribute)attributes[0]).Name);
                MapContents.Map = Map;
                container.Content = MapContents;

                // Push container foreground and background to Map Contents
                Binding b = new Binding("Foreground") { Source = container };
                MapContents.SetBinding(EsriMapContents.MapContents.ForegroundProperty, b);
                b = new Binding("Background") { Source = container };
                MapContents.SetBinding(EsriMapContents.MapContents.BackgroundProperty, b);
            }

            if (Editor != null)
                Editor.Map = Map;

            WindowManager.FloatingWindowStyle = LayoutStyleHelper.Instance.GetStyle(WindowManager.FloatingWindowStyleKey);

            // Set the logic to be executed when an authentication challenge occurs
            IdentityManager.Current.ChallengeMethod = OnChallenge;
            if (!listeningToCredentials)
            {
                // Listen for changes in the application environment's set of credentials, setting a flag to 
                // ensure that this is only done once.
                listeningToCredentials = true;
                UserManagement.Current.Credentials.CollectionChanged += Credentials_CollectionChanged;
            }

            AttachToControlEvents();
            SubscribeToSymbolConfigProviderEvents();
        }
 private void initCommands()
 {
     toggleTableCommand = new ToggleTableCommand();
 }
        private void RefreshLayer(Layer layer, EventHandler refreshCompletedHander, EventHandler <TaskFailedEventArgs> refreshFailedHandler)
        {
            _isRefreshing = true;
            FeatureLayer featureLayer = layer as FeatureLayer;

            if (featureLayer != null && !string.IsNullOrEmpty(featureLayer.Url))
            {
                // temporarly unhook the AttributeDisplay's layer while we refresh feature layer
                if (View.Instance != null && View.Instance.AttributeDisplay != null && View.Instance.AttributeDisplay.FeatureDataGrid != null)
                {
                    ToggleTableCommand.SetTableVisibility(Visibility.Collapsed);

                    // Set FeatureDataGrid layer to null so that we don't incur the overhead
                    // of all the UpdateItemSource calls as the AttributeTable Graphics layer is
                    // being set to null.
                    View.Instance.AttributeDisplay.FeatureDataGrid.GraphicsLayer = null;
                    // Set the FilterSource to null to prevent potential GraphicsLayer reference exceptions
                    View.Instance.AttributeDisplay.FeatureDataGrid.FilterSource = null;
                    // Now set the AttributeDisplay GraphicsLayer to null so that it
                    // unhooks all the bindings and events
                    View.Instance.AttributeDisplay.GraphicsLayer = null;

                    // Hook up to the UpdateCompleted/UpdateFailed events so that the layer
                    // can be reset to the SelectedLayer
                    featureLayer.UpdateCompleted -= OnFeatureLayerUpdateCompleted;
                    featureLayer.UpdateCompleted += OnFeatureLayerUpdateCompleted;
                    featureLayer.UpdateFailed    -= OnFeatureLayerUpdateFailed;
                    featureLayer.UpdateFailed    += OnFeatureLayerUpdateFailed;
                }

                if (refreshCompletedHander != null)
                {
                    featureLayer.UpdateCompleted -= refreshCompletedHander;
                    featureLayer.UpdateCompleted += refreshCompletedHander;
                }
                if (refreshFailedHandler != null)
                {
                    featureLayer.UpdateFailed -= refreshFailedHandler;
                    featureLayer.UpdateFailed += refreshFailedHandler;
                }
                featureLayer.Update();
                return;
            }

            ArcGISDynamicMapServiceLayer dynamicLayer = layer as ArcGISDynamicMapServiceLayer;

            if (dynamicLayer != null)
            {
                dynamicLayer.Refresh();
                if (refreshCompletedHander != null)
                {
                    refreshCompletedHander.Invoke(layer, EventArgs.Empty);
                }
                return;
            }

            ArcGISTiledMapServiceLayer tiledLayer = layer as ArcGISTiledMapServiceLayer;

            if (tiledLayer != null)
            {
                // Tiled layers do not support refreshing
                if (refreshCompletedHander != null)
                {
                    refreshCompletedHander.Invoke(layer, EventArgs.Empty);
                }
                return;
            }

            ArcGISImageServiceLayer imageServiceLayer = layer as ArcGISImageServiceLayer;

            if (imageServiceLayer != null)
            {
                imageServiceLayer.Refresh();
                if (refreshCompletedHander != null)
                {
                    refreshCompletedHander.Invoke(layer, EventArgs.Empty);
                }
                return;
            }

            ICustomGraphicsLayer customGraphicsLayer = layer as ICustomGraphicsLayer;

            if (customGraphicsLayer != null)
            {
                customGraphicsLayer.ForceRefresh(refreshCompletedHander, refreshFailedHandler);
                return;
            }


            HeatMapLayerBase heatMapLayer = layer as HeatMapLayerBase;

            if (heatMapLayer != null)
            {
                heatMapLayer.Update();
                if (refreshCompletedHander != null)
                {
                    refreshCompletedHander.Invoke(layer, EventArgs.Empty);
                }
                return;
            }

            GeoRssLayer geoRssLayer = Layer as GeoRssLayer;

            if (geoRssLayer != null)
            {
                geoRssLayer.Update();
                return;
            }

            WmsLayer wmsLayer = Layer as WmsLayer;

            if (wmsLayer != null)
            {
                wmsLayer.Refresh();
                return;
            }

            GraphicsLayer graphicsLayer = layer as GraphicsLayer;

            if (graphicsLayer != null)
            {
                graphicsLayer.Refresh();
                if (refreshCompletedHander != null)
                {
                    refreshCompletedHander.Invoke(layer, EventArgs.Empty);
                }
                return;
            }
        }
 private void ToggleAttributeTable_Click(object sender, RoutedEventArgs e)
 {
     toggleTableCommand = toggleTableCommand ?? new ToggleTableCommand();
     toggleTableCommand.Execute(null);
 }