${REST_GetFeaturesByGeometryParameters_Title}
${REST_GetFeaturesByGeometryParameters_Description}
async void DrawCompleted(object sender, DrawEventArgs e) { if (e.Geometry == null) { return; } GetFeaturesByGeometryParameters param = new GetFeaturesByGeometryParameters { DatasetNames = new List<string> { "World:Countries" }, SpatialQueryMode = SpatialQueryMode.INTERSECT, Geometry = e.Geometry }; //与服务端交互 try { GetFeaturesByGeometryService service = new GetFeaturesByGeometryService(url); var result = await service.ProcessAsync(param); featureslayer.ClearFeatures(); if (result != null) { featureslayer.AddFeatureSet(result.Features); } else { await MessageBox.Show("查询结果为空!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private Dictionary<string, string> GetParameters(GetFeaturesByGeometryParameters parameters) { Dictionary<string, string> dictionary = new Dictionary<string, string>(); if (string.IsNullOrEmpty(parameters.AttributeFilter)) { dictionary.Add("getFeatureMode", "\"SPATIAL\""); } else { dictionary.Add("getFeatureMode", "\"SPATIAL_ATTRIBUTEFILTER\""); dictionary.Add("attributeFilter", parameters.AttributeFilter); } if (parameters.DatasetNames != null && parameters.DatasetNames.Count > 0) { string jsonDatasetNames = "["; List<string> list = new List<string>(); for (int i = 0; i < parameters.DatasetNames.Count; i++) { list.Add(string.Format("\"{0}\"", parameters.DatasetNames[i])); } jsonDatasetNames += string.Join(",", list.ToArray()); jsonDatasetNames += "]"; dictionary.Add("datasetNames", jsonDatasetNames); } else { throw new ArgumentNullException(ExceptionStrings.ArgumentIsNull); } dictionary.Add("spatialQueryMode", parameters.SpatialQueryMode.ToString().ToUpper()); if (parameters.Geometry != null) { dictionary.Add("geometry", ServerGeometry.ToJson(Bridge.ToServerGeometry(parameters.Geometry))); } else { throw new ArgumentNullException(ExceptionStrings.ArgumentIsNull); } if (parameters.Fields != null && parameters.Fields.Count > 0) { FilterParameter fp = new FilterParameter(); fp.Fields = parameters.Fields; dictionary.Add("queryParameter", FilterParameter.ToJson(fp)); } return dictionary; }
/// <summary>${REST_GetFeaturesByGeometryService_method_ProcessAsync_D}</summary> /// <param name="parameters">${REST_GetFeaturesByGeometryService_method_ProcessAsync_param_Parameters}</param> /// <param name="state">${REST_GetFeaturesByGeometryService_method_ProcessAsync_param_state}</param> public async Task<GetFeaturesResult> ProcessAsync(GetFeaturesByGeometryParameters parameters) { if (parameters == null) { throw new ArgumentNullException(ExceptionStrings.ArgumentIsNull); } if (string.IsNullOrEmpty(this.Url)) { throw new InvalidOperationException(ExceptionStrings.InvalidUrl); } //base.Url += ".json?returnContent=true"; base.Url += string.Format(".json?returnContent=true&debug=true&fromIndex={0}&toIndex={1}", parameters.FromIndex, parameters.ToIndex); var result = await base.SubmitRequest(base.Url, GetParameters(parameters), true); JsonObject jsonObject = JsonObject.Parse(result); return GetFeaturesResult.FromJson(jsonObject); }