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; //feature service fields if (_featureLayerAttributes.fields != null) PopulateFieldsList(_featureLayerAttributes.fields); //display the default symbol ShowSymbol(_featureLayerAttributes); }
private void connectToFeatureServices() { this.Cursor = Cursors.WaitCursor; string formattedRequest = string.Empty; string jsonResponse = string.Empty; listBox1.Items.Clear(); //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(_baseApplyEditsURL, _token, out formattedRequest, out 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/", _baseApplyEditsURL, 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); //populate the Field Names if (featLayerAttributes.fields != null) PopulateFieldsList(featLayerAttributes.fields); } string url = string.Format("http://services.arcgis.com/{0}/arcgis/rest/services/{1}/FeatureServer?f=pjson", _organizationID, service.name); url += "&token=" + _token; _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; this.Cursor = Cursors.Default; }