private FeatureLayer AddLayer([NotNull] Uri dataSource, string worklistName, [NotNull] string layerName) { PluginDatasourceConnectionPath connector = new PluginDatasourceConnectionPath(PluginIdentifier, dataSource); using (var datastore = new PluginDatastore(connector)) { using (Table table = datastore.OpenTable(worklistName)) { FeatureLayer worklistLayer = LayerFactory.Instance.CreateFeatureLayer((FeatureClass)table, MapView.Active.Map, LayerPosition.AddToTop, layerName); LayerUtils.SetLayerSelectability(worklistLayer, false); if (!_uriByWorklistName.ContainsKey(worklistName)) { _uriByWorklistName.Add(worklistName, LayerUtils.GetUri(worklistLayer)); } return(worklistLayer); } } }
// todo daro Use MapViewInitialized or DrawComplete? //private void OnMapViewInitialized(MapViewEventArgs e) //{ // // https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-wait-for-mapview-to-load/td-p/831290 // // https://community.esri.com/t5/arcgis-pro-sdk-questions/initialize-module-when-map-loaded/m-p/816108#M2596 // // fires every time a view is initialized // // todo daro obj.MapView or MapView.Active? // foreach (var pair in _uriByWorklistName) // { // // ReSharper disable once UnusedVariable // string worklistName = pair.Key; // // ReSharper disable once UnusedVariable // string uri = pair.Value; // } //} private void OnMapMemberPropertiesChanged(MapMemberPropertiesChangedEventArgs e) { ViewUtils.Try(() => { List <MapMember> mapMembers = e.MapMembers.ToList(); List <MapMemberEventHint> eventHints = e.EventHints.ToList(); if (mapMembers.Count == 0) { return; } Assert.AreEqual(mapMembers.Count, eventHints.Count, $"Unequal count of {nameof(MapMember)} and {nameof(MapMemberEventHint)}"); for (var index = 0; index < mapMembers.Count; index++) { if (eventHints[index] != MapMemberEventHint.Name) { continue; } MapMember mapMember = mapMembers[index]; string uri = LayerUtils.GetUri(mapMember); string name = WorkListUtils.ParseName(uri); if (!_viewsByWorklistName.TryGetValue(name, out IWorkListObserver view)) { continue; } if (view.View == null) { continue; } ViewUtils.RunOnUIThread(() => { view.View.Title = mapMember.Name; }); } }, _msg); }