public class IdedFeatures { public string LayerName { get; set; } public IDictionary<string, Object> AttrData { get; set; } public string DisplayString { get; set; } public Graphic idedGraphic { get; set; } }
if (e.IdentifyResults != null && e.IdentifyResults.Count > 0) { //List that will hold the all identified features as an instance our custom class "IdedFeatures" m_ListIdedFeatures = new List<IdedFeatures>(); //loop thru each identified feature,create instance of the class "IdedFeatures", set its properties //using IdentifiedFeature and add this instance to its list. foreach (IdentifyResult idResult in e.IdentifyResults) { IdedFeatures idedFeat = new IdedFeatures(); idedFeat.LayerName = idResult.LayerName; idedFeat.AttrData = idResult.Feature.Attributes; idedFeat.idedGraphic = idResult.Feature; idedFeat.DisplayString = idResult.LayerName + " : " + idResult.Value; m_ListIdedFeatures.Add(idedFeat); } //set datasource of combo box cmbIdentifyResult.ItemsSource = null; cmbIdentifyResult.ItemsSource = m_ListIdedFeatures; }
//cast selected combo box item to the type of IdedFeatures so that we can have reference to the Graphic of the selected item. IdedFeatures selectedFeature = cmbIdentifyResult.SelectedItem as IdedFeatures; //zoom to the extent of the extent of the selected item in the listbox MapControl.Extent = selectedFeature.idedGraphic.Geometry.Extent;
If I understand correctly,you are populating ComboBox with the values which you got as a result of query.And, you want to zoom to selected item in the ListBox.If this is right, I have done something similar to this as below.1. Created class that exposes two properties, first is name and other is geometry. Created private List<ThisClass> to hold instances of my class.2. In the first query completed event, I had created instance of this class ,set its property name by "(graphic.Attributes["Name"].ToString());". And the geometry property by graphic.Geometry.Added this instance to the List.3. Populated the ComboBox by this name property.4. In the Combobox selection changed event, I would iterate thru this list, check name property and if name matches, I would use Geometry property of that instance to set the extent of the map.So ,no need to execute another query.hope, this helps.
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.