public ArcGISLocatorPlaceSearchProvider(Map map) : base() { if (map == null) throw new ArgumentException(); _map = map; _spatialRefWKID = _map.SpatialReference.WKID; // Determine map units _map.GetMapUnitsAsync(OnGetMapUnitsCompleted, OnGetMapUnitsFailed); // Hook to property changed to detect a change in map units _map.PropertyChanged += Map_PropertyChanged; // Initialize commands updateLocatorInfo = new DelegateCommand(doUpdateLocatorInfo, canUpdateLocatorInfo); // Initialize views ResultsView = new ArcGISLocatorResultsView(); InputView = new SingleLineSearchInputView(); _widthUnits = Utils.GetEnumDescriptions<LengthUnits>(); if (_widthUnits.ContainsKey(LengthUnits.UnitsDecimalDegrees)) _widthUnits.Remove(LengthUnits.UnitsDecimalDegrees); Results = _results; PagedResults = new PagedCollectionView(Results) { PageSize = _pageSize }; ExtentFields = new ExtentFields(); // Initialize geometry service and proxy URL with values from application environment if available if (MapApplication.Current != null) { // Bind the geometry service's URL to the environment's by default Binding b = new Binding("GeometryServiceUrl") { Source = MapApplication.Current.Urls }; BindingOperations.SetBinding(this, GeometryServiceUrlProperty, b); } // Initialize display name Properties.SetDisplayName(this, this.GetDisplayNameFromAttribute()); // Listen for changes to the proxy URL Properties.NotifyOnDependencyPropertyChanged("ProxyUrl", this, OnProxyUrlChanged); }
/// <summary> /// Initializes the search provider based on a configuration string /// </summary> public void LoadConfiguration(string configData) { // Store configuration string in case configuration needs to be reverted _lastConfiguration = configData; // Deserialize configuration Dictionary<string, object> configSettings = configData.DataContractDeserialize<Dictionary<string, object>>(knownSerializationTypes); LocatorInfo = (LocatorService)configSettings["LocatorInfo"]; UseExtentFields = (bool)configSettings["UseExtentFields"]; if (UseExtentFields) { ExtentFields fields = (ExtentFields)configSettings["ExtentFields"]; // The extent fields must be the same field instances contained in the locator info's candidate // fields collection. The deserialization creates new fields instances, so a lookup is required // to initialize ExtentFields with the field instances from LocatorInfo.CandidateFields ExtentFields = new ExtentFields(); ExtentFields.XMinField = findCandidateField(fields.XMinField); ExtentFields.XMaxField = findCandidateField(fields.XMaxField); ExtentFields.YMinField = findCandidateField(fields.YMinField); ExtentFields.YMaxField = findCandidateField(fields.YMaxField); } else { ExtentWidth = (double)configSettings["ExtentWidth"]; } WidthUnit = (LengthUnits)configSettings["WidthUnit"]; // Initialize locator task if (_locator == null) { _locator = new Locator(); _locator.AddressToLocationsCompleted += AddressToLocationsCompleted; _locator.Failed += Locator_Failed; } _locator.Url = LocatorServiceUrl = LocatorInfo.Url; // Initialize proxy UseProxy = (bool)configSettings["UseProxy"]; _locator.ProxyURL = UseProxy ? ProxyUrl : null; }