示例#1
0
        private async void Initialize()
        {
            // Create the US states feature table.
            _usStatesTable = new ServiceFeatureTable(_usStatesServiceUri);

            try
            {
                // Load the table.
                await _usStatesTable.LoadAsync();

                // Fill the fields combo and "group by" list with field names from the table.
                _fieldNames = _usStatesTable.Fields.Select(field => field.Name).ToList();

                // Create a model that will provide statistic definition choices for the picker.
                _statsPickerModel = new StatDefinitionModel(_fieldNames.ToArray());

                // Create a list of fields the user can select for grouping.
                // Value is initially false, since no fields are selected by default.
                _groupByFields = _fieldNames.ToDictionary(name => name, name => false);
            }
            catch (Exception e)
            {
                new UIAlertView("Error", e.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show();
            }
        }
示例#2
0
        // Constructor that takes a picker for defining new statistics.
        public ChooseStatisticOverlay(CGRect frame, nfloat transparency, UIColor color, UIPickerView statPicker) : base(frame)
        {
            // Store the statistics picker.
            UIPickerView statisticPicker = statPicker;

            // Create a semi-transparent overlay with the specified background color.
            BackgroundColor = color;
            Alpha           = transparency;

            // Set the total height and width of the control set.
            nfloat totalHeight = 400;
            nfloat totalWidth  = 320;

            // Find the bottom x and y of the view.
            nfloat centerX = Frame.Width / 2;
            nfloat centerY = Frame.Bottom - 40;

            // Find the start x and y for the control layout (aligned to the bottom of the view).
            nfloat controlX = centerX - totalWidth / 2;
            nfloat controlY = centerY - totalHeight;

            // Toolbar with "Add" and "Done" buttons.
            UIToolbar toolbar = new UIToolbar
            {
                BarStyle    = UIBarStyle.Black,
                Translucent = false
            };

            toolbar.SizeToFit();

            // Add Button (add the new stat and don't dismiss the UI).
            UIBarButtonItem addButton = new UIBarButtonItem("Add", UIBarButtonItemStyle.Done, (s, e) =>
            {
                // Get the selected StatisticDefinition.
                StatDefinitionModel statPickerModel   = (StatDefinitionModel)statisticPicker.Model;
                StatisticDefinition newStatDefinition = statPickerModel.SelectedStatDefinition;
                if (newStatDefinition != null)
                {
                    // Fire the OnMapInfoEntered event and provide the statistic definition.
                    OnStatisticDefined?.Invoke(this, newStatDefinition);
                }
            });

            // Done Button (dismiss the UI, don't use the selected statistic).
            UIBarButtonItem doneButton = new UIBarButtonItem("Done", UIBarButtonItemStyle.Plain,
                                                             (s, e) => { OnCanceled?.Invoke(this, null); });

            // Add the buttons to the toolbar.
            toolbar.SetItems(new[] { addButton, doneButton }, true);

            // Define the location of the statistic picker.
            controlY = controlY + 200;
            statisticPicker.Frame = new CGRect(controlX, controlY, totalWidth, 200);

            // Set the location for the toolbar.
            controlY      = controlY + 220;
            toolbar.Frame = new CGRect(controlX, controlY, totalWidth, 30);

            // Add the controls.
            AddSubviews(toolbar, statisticPicker);
        }