private static async Task BuildThemesForNodeAsync(TmNode tmNode) { IGisLayer layer; try { layer = await GisInterface.ParseItemAtPathAsGisLayerAsync(tmNode.Data.Path); } catch (Exception ex) { Debug.Print("Unable to load GIS data layers at " + tmNode.Data.Path + " " + ex.Message); // The caller set a default type. Do not return too much info, it may generate an unexpected icon. tmNode.Data.Type += "; Unable to load."; return; } tmNode.Data.Type = layer.DataType; if (layer.IsGroup) { await BuildSubThemesForGroupLayerAsync(tmNode, layer); } else { BuildThemeDataForLayer(tmNode.Data, layer); } }
static async Task Main(string[] args) { Console.WriteLine("Getting ESRI License"); await GisInterface.InitializeAsync(); if (!GisInterface.IsInitialized) { Console.WriteLine($"Could not initialize an ArcGIS license. {GisInterface.Status}"); return; } var path = args[0]; Console.WriteLine($"Loading {path}"); var themeList = Load(path); if (themeList == null) { Console.WriteLine("Could not load the Theme List."); return; } themeList.SuspendUpdates(); themeList.Build(); await ReloadAsync(themeList); Console.WriteLine("Saving Updated Theme List"); themeList.SaveAs(path.Replace(".tml", "1.tml")); await SyncAsync(themeList); Console.WriteLine("Saving Updated Theme List"); themeList.SaveAs(path.Replace(".tml", "2.tml")); Console.WriteLine("Done."); }
private void TestEvent(Point worldPos) { //var bmp = GisInterface.GetPrintMap(780000000, 37120000000, /*3860000000*/0, /*205030000000*/0, (decimal) 42.44, (decimal) 43.14); //bmp.Save("c:\\testprint.bmp"); //var pic = GisInterface.GetSymbolImage(3723990000000); //GisInterface.GetSymbolImage(0, "Red"); GisInterface.GetSymbolImage(1, "hfuiwefhweuifhuiwefhui"); //GisInterface.GetSymbolImage(3723990000000, "#A9F5A9"); }
/// <summary> /// Init default map project /// </summary> public void InitMap() { MapSpatRef = CoordinateSystems.SphericalMercatorCS; var defPath = string.IsNullOrEmpty(BaseSettings.DefaultMapProject) ? MapProjectsStorage.DefaultMapPath : BaseSettings.DefaultMapProject; LoadMap(defPath); MapSelector.UpdateValue(GisInterface.GetMapName(defPath)); }
internal string TransformText(string text) { string htmlText; using (StringReader sr = new StringReader(text)) { var metadataXml = new XPathDocument(sr); XsltArgumentList xslArgList; try { xslArgList = EsriLibraryAvailable ? GisInterface.EsriProcessingArguments() : new XsltArgumentList(); } catch (FileNotFoundException) { EsriLibraryAvailable = false; xslArgList = new XsltArgumentList(); } if (EsriStyleSheet && !EsriLibraryAvailable) { throw new FileNotFoundException("Esri Metadata library not found. See installation instructions"); } XslCompiledTransform xlst = GetCachedXslt(); // HTML output TextWriter textWriter = new Utf8StringWriter(); using (XmlWriter xmlWriter = XmlWriter.Create(textWriter)) { xlst.Transform(metadataXml, xslArgList, xmlWriter); } htmlText = textWriter.ToString(); if (EsriStyleSheet) { htmlText = GisInterface.CleanEsriMetadataHtml(htmlText); } } return(htmlText); }
static async Task InspectLayerFileAsync(string layerPath) { var node = await GisInterface.ParseItemAtPathAsGisLayerAsync(layerPath); Print(layerPath, node); }
protected override void OnShown(EventArgs e) { base.OnShown(e); using (new TemporaryWaitCursor()) { //create ok/cancel buttons var okButton = new BarButtonItem(mapControl.barManager, Resources.gis_SetCaseMapForm_Ok);// "OK"); okButton.ItemClick += okButton_Click; okButton.Border = BorderStyles.Default; okButton.Appearance.Font = new Font(okButton.Appearance.Font, FontStyle.Bold); var cancelButton = new BarButtonItem(mapControl.barManager, Resources.gis_SetCaseMapForm_Cancel); cancelButton.ItemClick += cancelButton_Click; cancelButton.Border = BorderStyles.Default; cancelButton.Appearance.Font = new Font(cancelButton.Appearance.Font, FontStyle.Bold); mapControl.barManager.Bars["StatusBar"].AddItem(okButton).BeginGroup = true; mapControl.barManager.Bars["StatusBar"].AddItem(cancelButton); //IT IS UGLY HACK! mapControl.RemoveUglyButton(); //set default tool mapControl.InputTool.IsActive = true; //init map mapControl.MapSpatRef = CoordinateSystems.SphericalMercatorCS; DateTime start = DateTime.Now; //mapControl.LoadMap(MapProjectsStorage.DefaultMapPath); //var defPath = BaseSettings.DefaultMapProject ?? MapProjectsStorage.DefaultMapPath; var defPath = string.IsNullOrEmpty(BaseSettings.DefaultMapProject) ? MapProjectsStorage.DefaultMapPath : BaseSettings.DefaultMapProject; mapControl.LoadMap(defPath); mapControl.MapSelector.UpdateValue(GisInterface.GetMapName(defPath)); Debug.WriteLine("Loaded:" + (DateTime.Now - start).TotalMilliseconds); Debug.WriteLine("Loaded:" + DateTime.Now); //set case point, if exists if (InitWgsPoint != null) { var point = InitWgsPoint.Clone(); if (mapControl.MapSpatRef != CoordinateSystems.WGS84) { point = GeometryTransform.TransformPoint(point, CoordinateSystems.WGS84, mapControl.MapSpatRef); } mapControl.InputTool.Point = point; } //zoom to box if (InitAdminBBox != null) { var adminBox = InitAdminBBox.Clone(); //reproject if need. NotNeed!!!! if (mapControl.MapSpatRef != CoordinateSystems.WGS84) { adminBox = GeometryTransform.TransformBox(adminBox, CoordinateSystems.WGS84, mapControl.MapSpatRef); } mapControl.Map.ZoomToBox(adminBox); } } }
} // Unused but supported as part of the TML file #endregion #region Private Methods /// <summary> /// Tries to load the metadata resource at Path as a text string /// </summary> /// <remarks> /// This method will not throw an exception. /// Side effects: /// It will set ErrorMessage to an error message (if any are encountered) /// It may change the Type and Format if they are wrong. /// </remarks> /// <returns>a text string of the metadata if available or null</returns> private async Task <string> GetContentAsTextAsync() { string contents = null; ErrorMessage = null; if (string.IsNullOrEmpty(Path)) { ErrorMessage = "Metadata has no Path to the content."; return(null); } // using System.Diagnostics.Eventing.Reader; // Trace.TraceInformation("{0}: Start of Metadata.LoadASText({1})", DateTime.Now, Path); Stopwatch time = Stopwatch.StartNew(); // Try to guess an Undefined MetadataType if (Type == MetadataType.Undefined) { if (Path.StartsWith("http", StringComparison.OrdinalIgnoreCase)) { Type = MetadataType.Url; } else if (await MyFile.ExistsAsync(Path)) { Type = MetadataType.FilePath; } else if (Path.Contains(".gdb\\", StringComparison.OrdinalIgnoreCase) || Path.Contains(".sde\\", StringComparison.OrdinalIgnoreCase) || Path.Contains(".mdb\\", StringComparison.OrdinalIgnoreCase)) { Type = MetadataType.EsriDataPath; } else { ErrorMessage = "The Type of the metadata Path is Undefined and not obvious."; return(null); } } // Correct a URL with the file:// scheme if (Type == MetadataType.Url && new Uri(Path).IsFile) { Path = new Uri(Path).LocalPath; Type = MetadataType.FilePath; } // Try and load the content try { if (Type == MetadataType.FilePath) { contents = await MyFile.ReadAllTextAsync(Path); } if (Type == MetadataType.EsriDataPath) { contents = await GisInterface.GetMetadataAsXmlAsync(Path); Format = MetadataFormat.Xml; } if (Type == MetadataType.Url) { // If the format is Undefined, I need to download the contents to check the Format // If the Format is Xml, I will download the contents for getting attributes // For Html and Text Formats, I can't do anything with the contents, so skip this step // The Display method will use the URL to get the contents if (Format == MetadataFormat.Xml || Format == MetadataFormat.Undefined) { var uri = new Uri(Path); ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; HttpClient client = new HttpClient(); var response = await client.GetAsync(uri); if (response.IsSuccessStatusCode) { contents = await response.Content.ReadAsStringAsync(); } else { ErrorMessage = $"Could not get {Path} from server. Status code: {response.StatusCode}({response.ReasonPhrase})"; return(null); } } } } catch (Exception ex) { ErrorMessage = ex.Message; Debug.Print("Exception thrown trying to load Metadata.\n" + ex); return(null); } // If the file, service, or geo-database returned nothing, we are done for. if (string.IsNullOrEmpty(contents) && (Type != MetadataType.Url || Format == MetadataFormat.Xml || Format == MetadataFormat.Undefined)) { ErrorMessage = "The content of the resource at Path is empty."; Format = MetadataFormat.Undefined; return(null); } // Test the format if (Format == MetadataFormat.Undefined) { // ReSharper disable once PossibleNullReferenceException if (contents.StartsWith("<?xml version=", StringComparison.OrdinalIgnoreCase) || contents.StartsWith("<metadata", StringComparison.OrdinalIgnoreCase)) { Format = MetadataFormat.Xml; } if (Regex.IsMatch(contents, "<html>|<html .+>")) { Format = MetadataFormat.Html; } if (!Regex.IsMatch(contents, "<.+>|</.+>")) { Format = MetadataFormat.Text; } } // time.Stop(); Trace.TraceInformation("{0}: End of Metadata.LoadASText() - Elapsed Time: {1}", DateTime.Now, time.Elapsed); return(contents); }