Beispiel #1
0
        /// <summary>
        /// Organization feature services, all of them (NB: for all Organization user accounts!)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Connect_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
              string formattedRequest = string.Empty;
              string jsonResponse = string.Empty;

              listBox1.Items.Clear();

              //get the root directory of the service
              string rootURL = txtFeatureServices.Text;

              //check to see if we have an instantiated dictionary to store the attributes
              if (_featureServiceAttributesDataDictionary == null)
              {
            _featureServiceAttributesDataDictionary = new Dictionary<string, FeatureLayerAttributes>();
            _featureServiceRequestAndResponse = new Dictionary<string, string>();
              }
              else
              {
            _featureServiceAttributesDataDictionary.Clear();
            _featureServiceRequestAndResponse.Clear();
              }

              //query for ServiceLayers
              ServiceCatalog serviceCatalogDataContract = RequestAndResponseHandler.GetServiceCatalog(rootURL, _token, out formattedRequest, out jsonResponse);

              //Users on a trial period will be using services1 server, on failure resend to services server in case they have a full account.
              if (serviceCatalogDataContract.services == null)
              {
            rootURL = rootURL.Replace("services1", "services");
            serviceCatalogDataContract = RequestAndResponseHandler.GetServiceCatalog(rootURL, _token, out formattedRequest, out jsonResponse);

            if (serviceCatalogDataContract.services == null)
            {
              this.Cursor = Cursors.Default;
              return;
            }

            txtFeatureServices.Text = rootURL;
              }

              //display the call and response to the user
              ShowRequestResponseStrings(formattedRequest, jsonResponse);

              bool executedOnce = false;
              string serviceURL = string.Empty;
              string serviceRequest = string.Empty;
              string serviceResponse = string.Empty;

              foreach (Service service in serviceCatalogDataContract.services)
              {
            //I am only interested in FeatureServices THAT HAVE BEEN SHARED so only get the attributes for this kind of layer
            if (service.type == "FeatureServer")
            {
              //create the entire url string for the layer so we can make the query for attributes
              serviceURL = string.Format("{0}{1}/{2}/0/", rootURL, service.name,service.type);

              //Feature Layer Attributes
              FeatureLayerAttributes featLayerAttributes = RequestAndResponseHandler.GetFeatureServiceAttributes(serviceURL, _token, out serviceRequest, out serviceResponse);

              //store the request and response so that we can display it to the user when they click each feature service in the list
              _featureServiceRequestAndResponse.Add(service.name, serviceRequest + "$" + serviceResponse);

              //store the attributes
              _featureServiceAttributesDataDictionary.Add(service.name, featLayerAttributes);

              if (executedOnce == false)
              {
            _featureLayerAttributes = featLayerAttributes;

            //display the default symbol
            ShowSymbol(featLayerAttributes);

            if (featLayerAttributes == null)
            {
              this.Cursor = Cursors.Default;
              return;
            }

            //populate the Field Names
            if(featLayerAttributes.fields != null)
              PopulateFieldsList(featLayerAttributes.fields);

            //show feature service extent
            if(featLayerAttributes.extent != null)
              PopulateExtentValues(featLayerAttributes.extent);

            lblSelectedFS.Text = "FS: " + featLayerAttributes.name;
              }

              //lets get the data for the feature service
              //Todo
              string url = string.Format("http://services1.arcgis.com/{0}/arcgis/rest/services/{1}/FeatureServer?f=pjson", _organizationID, service.name);

              _featureServiceInfo = RequestAndResponseHandler.GetDataContractInfo(url, DataContractsEnum.FeatureServiceInfo, out jsonResponse) as FeatureServiceInfo;

              //lets store the name of the featureLayer into the listbox
              ListViewItem item = new ListViewItem();
              item.Text = service.name;
              item.Tag = _featureServiceInfo;
              listBox1.Items.Add(item);

              if (executedOnce == false)
              {
            txtSupportedFunctions.Text = _featureServiceInfo.capabilities;
            executedOnce = true;
              }
            }
              }
              listBox1.SelectedIndexChanged += listBox1_SelectedIndexChanged;
              EnableControls(true);
              this.Cursor = Cursors.Default;
        }
Beispiel #2
0
        /// <summary>
        /// Contains all of your AGOL user layers
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListViewItem item = listBox1.SelectedItem as ListViewItem;
              _featureServiceAttributesDataDictionary.TryGetValue(item.Text, out _featureLayerAttributes);
              _featureServiceInfo = item.Tag as FeatureServiceInfo;

              //supported functionality
              txtSupportedFunctions.Text = _featureLayerAttributes.capabilities;
              EnableEditingButtons(_featureLayerAttributes.capabilities);

              //feature service fields
              if (_featureLayerAttributes.fields != null)
            PopulateFieldsList(_featureLayerAttributes.fields);

              //extent of feature layer.
              if (_featureLayerAttributes.extent != null)
            PopulateExtentValues(_featureLayerAttributes.extent);

              //display the default symbol
              ShowSymbol(_featureLayerAttributes);
              lblSelectedFS.Text = "FS: " + item.Text;

              string value = string.Empty;
              _featureServiceRequestAndResponse.TryGetValue(item.Text, out value);
              if (value.Length > 0)
              {
            string[] split = value.Split('$');
            if(split.Length == 2)
              ShowRequestResponseStrings(split[0], split[1]);
              }
        }