private void AddLayerToMapAsync(IDatabaseLayerItem item) { item.ShowLoadingIndicator(); Task <IDatasource> .Factory.StartNew(() => { var timer = new Stopwatch(); timer.Start(); var ds = GeoSource.OpenFromIdentity(item.Identity) as IVectorLayer; if (ds != null) { var data = ds.Data; } return(ds); }).ContinueWith(t => { if (t.Result != null) { if (_layerService.AddDatasource(t.Result)) { int handle = _layerService.LastLayerHandle; _context.Map.ZoomToLayer(handle); } } item.HideLoadingIndicator(); }, TaskScheduler.FromCurrentSynchronizationContext()); }
public DatasourceInput(string filename) { // TODO: datasource must be closed in case of OGR layers var identity = new LayerIdentity(filename); var ds = GeoSource.OpenFromIdentity(identity); Datasource = ds.GetLayers().FirstOrDefault(); }
/// <summary> /// Reopens datasource which served as input for GisTool. The datasource will be searched /// for among open layers, including in-memory layers and if not present, reoped from the disk. /// </summary> private static IDatasourceInput ReopenDatasource( this DatasourcePointer ds, IAppContext context, IDatasourceInput oldInput) { int layerHandle = ds.LayerHandle; if (layerHandle != -1) { var layer = context.Layers.ItemByHandle(layerHandle); return(ReopenLayerInput(layer, oldInput)); } var identity = ds.LayerIdentity; if (identity != null) { // maybe it opened var layer = context.Layers.FirstOrDefault(l => l.Identity == identity); if (layer != null) { return(ReopenLayerInput(layer, oldInput)); } // if not, let's try to open var source = GeoSource.OpenFromIdentity(identity) as ILayerSource; if (source != null) { return(new DatasourceInput(source)); } } return(null); }