public static Task ExportMapFrameToJPEGAsync(string LayoutName, string MFName, string Path) { //Reference a layoutitem in a project by name LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(LayoutName)); if (layoutItem == null) { return(Task.FromResult <Layout>(null)); } //Create JPEG format with appropriate settings JPEGFormat JPEG = new JPEGFormat(); JPEG.HasWorldFile = true; JPEG.Resolution = 300; JPEG.OutputFileName = Path; return(QueuedTask.Run(() => { //Export MapFrame Layout lyt = layoutItem.GetLayout(); //Loads and returns the layout associated with a LayoutItem MapFrame mf = lyt.FindElement(MFName) as MapFrame; JPEG.OutputFileName = Path; if (JPEG.ValidateOutputFilePath()) { mf.Export(JPEG); } })); }
async public static void ExportSnippets() { LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout Name")); Layout lyt = await QueuedTask.Run(() => layoutItem.GetLayout()); MapFrame mf = lyt.FindElement("Map1 Map Frame") as MapFrame; #region BMP_Constructor BMPFormat BMP = new BMPFormat(); #endregion BMP_Constructor #region EMF_Constructor EMFFormat EMF = new EMFFormat(); #endregion EMF_Constructor #region EPS_Constructor EPSFormat EPS = new EPSFormat(); #endregion EPS_Constructor #region GIF_Constructor GIFFormat GIF = new GIFFormat(); #endregion GIF_Constructor #region JPEG_Constructor JPEGFormat JPEG = new JPEGFormat(); #endregion JPEG_Constructor #region PNG_Constructor PNGFormat PNG = new PNGFormat(); #endregion PNG_Constructor #region PDF_Constructor PDFFormat PDF = new PDFFormat(); #endregion PDF_Constructor #region SVG_Constructor SVGFormat SVG = new SVGFormat(); #endregion SVG_Constructor #region TGA_Constructor TGAFormat TGA = new TGAFormat(); #endregion TGA_Constructor #region TIFF_Constructor TIFFFormat TIFF = new TIFFFormat(); #endregion TIFF_Constructor PDF.OutputFileName = @"C:\Temp\output.pdf"; #region PDF_lyt_Export lyt.Export(PDF); #endregion PDF_lyt_Export }
public static Task ExportActiveMapToJPEGAsync(string Path) { return(QueuedTask.Run(() => { //Reference the active map view MapView map = MapView.Active; //Create JPEG format with appropriate settings JPEGFormat JPEG = new JPEGFormat(); JPEG.Resolution = 300; JPEG.Height = 500; JPEG.Width = 800; JPEG.HasWorldFile = true; JPEG.OutputFileName = Path; //Export active map view if (JPEG.ValidateOutputFilePath()) { map.Export(JPEG); } })); }
public void snippets_exportLayout() { #region Export a layout // Reference a layoutitem in a project by name LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("MyLayout")); if (layoutItem != null) { QueuedTask.Run(() => { Layout layout = layoutItem.GetLayout(); if (layout == null) { return; } // Create BMP format with appropriate settings BMPFormat BMP = new BMPFormat() { Resolution = 300, OutputFileName = @"C:\temp\Layout.bmp" }; if (BMP.ValidateOutputFilePath()) { layout.Export(BMP); } // Create EMF format with appropriate settings EMFFormat EMF = new EMFFormat() { Resolution = 300, OutputFileName = @"C:\temp\Layout.emf" }; if (EMF.ValidateOutputFilePath()) { layout.Export(EMF); } // create eps format with appropriate settings EPSFormat EPS = new EPSFormat() { Resolution = 300, OutputFileName = @"C:\temp\Layout.eps" }; if (EPS.ValidateOutputFilePath()) { layout.Export(EPS); } // Create GIF format with appropriate settings GIFFormat GIF = new GIFFormat() { Resolution = 300, OutputFileName = @"C:\temp\Layout.gif" }; if (GIF.ValidateOutputFilePath()) { layout.Export(GIF); } // Create JPEG format with appropriate settings JPEGFormat JPEG = new JPEGFormat() { Resolution = 300, OutputFileName = @"C:\temp\Layout.jpg" }; if (JPEG.ValidateOutputFilePath()) { layout.Export(JPEG); } // Create PDF format with appropriate settings PDFFormat PDF = new PDFFormat() { Resolution = 300, OutputFileName = @"C:\temp\Layout.pdf" }; if (PDF.ValidateOutputFilePath()) { layout.Export(PDF); } // Create PNG format with appropriate settings PNGFormat PNG = new PNGFormat() { Resolution = 300, OutputFileName = @"C:\temp\Layout.png" }; if (PNG.ValidateOutputFilePath()) { layout.Export(PNG); } // Create SVG format with appropriate settings SVGFormat SVG = new SVGFormat() { Resolution = 300, OutputFileName = @"C:\temp\Layout.svg" }; if (SVG.ValidateOutputFilePath()) { layout.Export(SVG); } // Create TGA format with appropriate settings TGAFormat TGA = new TGAFormat() { Resolution = 300, OutputFileName = @"C:\temp\Layout.tga" }; if (TGA.ValidateOutputFilePath()) { layout.Export(TGA); } // Create TIFF format with appropriate settings TIFFFormat TIFF = new TIFFFormat() { Resolution = 300, OutputFileName = @"C:\temp\Layout.tif" }; if (TIFF.ValidateOutputFilePath()) { layout.Export(TIFF); } }); } #endregion }
//public async Task UpdateThumbsAsync() //{ // //return Task.Run(() => // //{ // var commandId = DAML.Gallery.esri_mapping_previewBasemapGallery; // var checkboxid = DAML.Checkbox.esri_core_previewShowBasemap; // var iCommand = FrameworkApplication.GetPlugInWrapper(commandId) as ICommand; // var checkboxiCommand = FrameworkApplication.GetPlugInWrapper(checkboxid) as ICommand; // var ttype = iCommand.GetType(); // Task<(MapFrame, Map)> ttest = QueuedTask.Run(() => // { // Guid g = Guid.NewGuid(); // string tempLayout = "TempLayout_"+g; // string tempMap = "TempMap_"+g; // //var newmap = MapFactory.Instance.CreateMap("NewMap", basemap:Basemap.ProjectDefault); // // Create a new CIM page // CIMPage newPage = new CIMPage(); // // Add properties // newPage.Width = 17; // newPage.Height = 11; // newPage.Units = LinearUnit.Inches; // // Add rulers // newPage.ShowRulers = true; // newPage.SmallestRulerDivision = 0.5; // // Apply the CIM page to a new layout and set name // var newLayout = LayoutFactory.Instance.CreateLayout(newPage); // newLayout.SetName(tempLayout); // var newMap = MapFactory.Instance.CreateMap(tempMap, basemap: Basemap.ProjectDefault); // //Map newMap = MapFactory.Instance.CreateMap(tempMap, MapType.Map, MapViewingMode.Map, Basemap.Terrain); // //string url = @"http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"; // // Build a map frame geometry / envelope // Coordinate2D ll = new Coordinate2D(1, 0.5); // Coordinate2D ur = new Coordinate2D(13, 9); // Envelope mapEnv = EnvelopeBuilder.CreateEnvelope(ll, ur); // // Create a map frame and add it to the layout // MapFrame newMapframe = LayoutElementFactory.Instance.CreateMapFrame(newLayout, mapEnv, newMap); // newMapframe.SetName("Map Frame"); // return (newMapframe, newMap); // }); // ttest.Wait(); // MapFrame tempframe = ttest.Result.Item1; // Map tempmap = ttest.Result.Item2; // foreach (var iitem in Project.Current.SelectedItems) // { // Task t = QueuedTask.Run(() => // { // tempmap.RemoveLayers(tempmap.Layers.AsEnumerable()); // Guid gg = Guid.NewGuid(); // Uri uri = new Uri(iitem.Path); // var lyr = LayerFactory.Instance.CreateLayer(uri, tempmap); // string thumbpath = String.Format(_temppath + "{0}_{1}.jpg", lyr.Name, gg); // Uri item_uri = new Uri(iitem.Path); // var lyr_object = LayerFactory.Instance.CreateLayer(item_uri, tempmap); // string tpath = String.Format(_temppath + "{0}_{1}.jpg", lyr.Name, gg); // //MessageBox.Show(thumbpath); // tempframe.SetCamera(lyr_object.QueryExtent()); // //Create JPEG format with appropriate settings // JPEGFormat JPEG = new JPEGFormat(); // JPEG.HasWorldFile = false; // //JPEG.Resolution = 100; // JPEG.OutputFileName = thumbpath; // //Export MapFrame // //Layout lyt = layoutItem.GetLayout(); //Loads and returns the layout associated with a LayoutItem // tempframe.Export(JPEG); // byte[] b = File.ReadAllBytes(thumbpath); // //string utf8string = Encoding.UTF8.GetString(b, 0, b.Length); // //string asciistring = Encoding.ASCII.GetString(b, 0, b.Length); // string b64string = Convert.ToBase64String(b); // string xxml = iitem.GetXml(); // XmlDocument xmldoc = new XmlDocument(); // xmldoc.LoadXml(xxml); // //xmldoc.Save("C:\\Users\\jmaxm\\Desktop\\expxml.xml"); // //todo create new xml if not exist // XmlNode root = xmldoc.DocumentElement; // XmlNode thumb = root.SelectSingleNode("descendant::Binary/Thumbnail/Data"); // if (thumb is null) // { // if (root.SelectSingleNode("descendant::Binary") is null) // { // XmlNode binarynode = xmldoc.CreateNode("element", "Binary", ""); // XmlNode thumbnode = xmldoc.CreateNode("element", "Thumbnail", ""); // XmlNode datanode = xmldoc.CreateNode("element", "Data", ""); // ((XmlElement)datanode).SetAttribute("EsriPropertyType", "PictureX"); // //datanode.Attributes["EsriPropertyType"].Value = "PictureX"; // datanode.InnerText = b64string; // thumbnode.AppendChild(datanode); // binarynode.AppendChild(thumbnode); // root.AppendChild(binarynode); // string newmeta = xmldoc.OuterXml; // iitem.SetXml(newmeta); // } // } // if (thumb != null) // { // root.SelectSingleNode("descendant::Binary/Thumbnail/Data").InnerText = b64string; // //var thumb = xmldoc.GetElementsByTagName("Thumbnail")[0].SelectSingleNode("Data"); // //thumb.SelectSingleNode("Data") // //MessageBox.Show(thumb.InnerXml.ToString()); // string newmeta = xmldoc.OuterXml; // iitem.SetXml(newmeta); // } // //xmldoc.Save("C:\\Users\\jmaxm\\Desktop\\expxml.xml"); // File.Delete(thumbpath); // FrameworkApplication.AddNotification(new Notification() // { // Title = "Updated Metadata Thumbnail", // Message = iitem.Path, // ImageUrl = @"pack://*****:*****@"pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/ErrorException32.png", }); continue; } QueuedTask.Run(() => { Guid g = Guid.NewGuid(); string tempLayout = "TempLayout"; string tempMap = "TempMap"; //var newmap = MapFactory.Instance.CreateMap("NewMap", basemap:Basemap.ProjectDefault); // Create a new CIM page CIMPage newPage = new CIMPage(); // Add properties newPage.Width = 17; newPage.Height = 11; newPage.Units = LinearUnit.Inches; // Add rulers newPage.ShowRulers = true; newPage.SmallestRulerDivision = 0.5; // Apply the CIM page to a new layout and set name var newLayout = LayoutFactory.Instance.CreateLayout(newPage); newLayout.SetName(tempLayout); //string bmap_string = EMEMenu_thumbnailBasemap.thumbnailBasemap.selected; //Basemap bmap = (Basemap)Enum.Parse(typeof(Basemap), bmap_string); Basemap bmap = (Basemap)Enum.Parse(typeof(Basemap), basemap); Map newMap = MapFactory.Instance.CreateMap(tempMap, MapType.Map, MapViewingMode.Map, bmap); Uri uri = new Uri(item.Path); var lyr = LayerFactory.Instance.CreateLayer(uri, newMap); string thumbpath = String.Format(_temppathEme + "{0}.jpg", g); // Build a map frame geometry / envelope Coordinate2D ll = new Coordinate2D(1, 0.5); Coordinate2D ur = new Coordinate2D(13, 9); Envelope mapEnv = EnvelopeBuilder.CreateEnvelope(ll, ur); // Create a map frame and add it to the layout MapFrame newMapframe = LayoutElementFactory.Instance.CreateMapFrame(newLayout, mapEnv, newMap); newMapframe.SetName("Map Frame"); // Create and set the camera //Camera camera = newMapframe.Camera; //camera.X = -118.465; //camera.Y = 33.988; //camera.Scale = 30000; newMapframe.SetCamera(lyr.QueryExtent()); //newMapframe.ZoomTo(lyr.QueryExtent()); //Create JPEG format with appropriate settings JPEGFormat JPEG = new JPEGFormat(); JPEG.HasWorldFile = false; JPEG.Resolution = 100; JPEG.OutputFileName = thumbpath; //Export MapFrame //Layout lyt = layoutItem.GetLayout(); //Loads and returns the layout associated with a LayoutItem newMapframe.Export(JPEG); LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(itm => itm.Name.Equals(tempLayout)); Project.Current.RemoveItem(Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(itm => itm.Name.Equals(tempLayout))); Project.Current.RemoveItem(Project.Current.GetItems<MapProjectItem>().FirstOrDefault(itm => itm.Name.Equals(tempMap))); byte[] b = File.ReadAllBytes(thumbpath); //string utf8string = Encoding.UTF8.GetString(b, 0, b.Length); //string asciistring = Encoding.ASCII.GetString(b, 0, b.Length); string b64string = Convert.ToBase64String(b); string xxml = item.GetXml(); XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(xxml); //xmldoc.Save("C:\\Users\\jmaxm\\Desktop\\expxml.xml"); //todo create new xml if not exist XmlNode root = xmldoc.DocumentElement; XmlNode thumb = root.SelectSingleNode("descendant::Binary/Thumbnail/Data"); if (thumb is null) { if (root.SelectSingleNode("descendant::Binary") is null) { XmlNode binarynode = xmldoc.CreateNode("element", "Binary", ""); XmlNode thumbnode = xmldoc.CreateNode("element", "Thumbnail", ""); XmlNode datanode = xmldoc.CreateNode("element", "Data", ""); ((XmlElement)datanode).SetAttribute("EsriPropertyType", "PictureX"); //datanode.Attributes["EsriPropertyType"].Value = "PictureX"; datanode.InnerText = b64string; thumbnode.AppendChild(datanode); binarynode.AppendChild(thumbnode); root.AppendChild(binarynode); string newmeta = xmldoc.OuterXml; item.SetXml(newmeta); } } if(thumb != null) { root.SelectSingleNode("descendant::Binary/Thumbnail/Data").InnerText = b64string; //var thumb = xmldoc.GetElementsByTagName("Thumbnail")[0].SelectSingleNode("Data"); //thumb.SelectSingleNode("Data") //MessageBox.Show(thumb.InnerXml.ToString()); string newmeta = xmldoc.OuterXml; item.SetXml(newmeta); //MessageBox.Show(item.Type); } //xmldoc.Save("C:\\Users\\jmaxm\\Desktop\\expxml.xml"); File.Delete(thumbpath); }); FrameworkApplication.AddNotification(new Notification() { Title = "Updated Metadata Thumbnail", Message = item.Path, ImageUrl = @"pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericRefresh32.png", }); } }