public static async void GenerateReport(FeatureLayer featureLayer)
        {
            #region Create report
            //Note: Call within QueuedTask.Run()
            //The fields in the datasource used for the report
            //This uses a US Cities dataset
            var listFields = new List <CIMReportField> {
                //Grouping should be the first field
                new CIMReportField {
                    Name = "STATE_NAME", FieldOrder = 0, Group = true, SortInfo = FieldSortInfo.Desc
                },                                                                                                    //Group cities using STATES
                new CIMReportField {
                    Name = "CITY_NAME", FieldOrder = 1
                },
                new CIMReportField {
                    Name = "POP1990", FieldOrder = 2,
                },
            };
            //Definition query to use for the data source
            var defQuery = "STATE_NAME LIKE 'C%'";
            //Define the Datasource
            //pass true to use the selection set
            var reportDataSource = new ReportDataSource(featureLayer, defQuery, false, listFields);
            //The CIMPage defintion - page size, units, etc
            var cimReportPage = new CIMPage
            {
                Height          = 11,
                StretchElements = false,
                Width           = 6.5,
                ShowRulers      = true,
                ShowGuides      = true,
                Margin          = new CIMMargin {
                    Bottom = 1, Left = 1, Right = 1, Top = 1
                },
                Units = LinearUnit.Inches
            };

            //Report template
            var reportTemplates = await ReportTemplateManager.GetTemplatesAsync();

            var reportTemplate = reportTemplates.Where(r => r.Name == "Attribute List with Grouping").First();

            //Report Styling
            var reportStyles = await ReportStylingManager.GetStylingsAsync();

            var reportStyle = reportStyles.Where(s => s == "Cool Tones").First();

            //Field Statistics
            var fieldStatisticsList = new List <ReportFieldStatistic> {
                new ReportFieldStatistic {
                    Field = "POP1990", Statistic = FieldStatisticsFlag.Sum
                }
                //Note: NoStatistics option for FieldStatisticsFlag is not supported.
            };
            var report = ReportFactory.Instance.CreateReport("USAReport", reportDataSource, cimReportPage, fieldStatisticsList, reportTemplate, reportStyle);
            #endregion
        }
Esempio n. 2
0
        async public static void LayoutClassSnippets()
        {
            #region LayoutProjectItem_GetLayout
            LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout Name"));
            Layout            layout     = await QueuedTask.Run(() => layoutItem.GetLayout());

            #endregion LayoutProjectItem_GetLayout

            TextElement elm = layout.FindElement("Text") as TextElement;

            await QueuedTask.Run(() =>
            {
                #region Layout_DeleteElement
                //Note: call within QueuedTask.Run()
                layout.DeleteElement(elm);
                #endregion Layout_DeleteElement

                #region Layout_DeleteElements
                //Note: call within QueuedTask.Run()
                layout.DeleteElements(item => item.Name.Contains("Clone"));
                #endregion Layout_DeleteElements
            });

            #region Layout_FindElement
            TextElement txtElm = layout.FindElement("Text") as TextElement;
            #endregion Layout_FindElement

            await QueuedTask.Run(() =>
            {
                #region Layout_GetDefinition
                //Note: call within QueuedTask.Run()
                CIMLayout cimLayout = layout.GetDefinition();
                #endregion Layout_GetPage

                #region Layout_SetDefinition
                //Note: call within QueuedTask.Run()
                layout.SetDefinition(cimLayout);
                #endregion Layout_GetPage

                #region Layout_GetPage
                //Note: call within QueuedTask.Run()
                CIMPage page = layout.GetPage();
                #endregion Layout_GetPage

                #region Layout_SetPage
                //Note: call within QueuedTask.Run()
                layout.SetPage(page);
                #endregion Layout_SetPage

                #region Layout_SetName
                //Note: call within QueuedTask.Run()
                layout.SetName("New Name");
                #endregion Layout_SetName
            });
        }
Esempio n. 3
0
        async public static Task <Layout> CreateCIMLayout(double width, double height, LinearUnit units, string LayoutName)
        {
            Layout CIMlayout = null;
            await QueuedTask.Run(() =>
            {
                //Set up a page
                CIMPage newPage = new CIMPage();

                //required
                newPage.Width  = width;
                newPage.Height = height;
                newPage.Units  = units;

                //optional rulers
                newPage.ShowRulers            = true;
                newPage.SmallestRulerDivision = 5;

                //optional guides
                newPage.ShowGuides = true;
                CIMGuide guide1    = new CIMGuide();
                guide1.Position    = 25;
                guide1.Orientation = Orientation.Vertical;
                CIMGuide guide2    = new CIMGuide();
                guide2.Position    = 185;
                guide2.Orientation = Orientation.Vertical;
                CIMGuide guide3    = new CIMGuide();
                guide3.Position    = 25;
                guide3.Orientation = Orientation.Horizontal;
                CIMGuide guide4    = new CIMGuide();
                guide4.Position    = 272;
                guide4.Orientation = Orientation.Horizontal;

                List <CIMGuide> guideList = new List <CIMGuide>();
                guideList.Add(guide1);
                guideList.Add(guide2);
                guideList.Add(guide3);
                guideList.Add(guide4);
                newPage.Guides = guideList.ToArray();

                Layout layout = LayoutFactory.Instance.CreateLayout(newPage);

                layout.SetName(LayoutName);
            });

            //Open the layout in a pane
            await ProApp.Panes.CreateLayoutPaneAsync(CIMlayout);

            return(CIMlayout);
        }
Esempio n. 4
0
 public static Task LoopLayoutsAsync()
 {
     return(QueuedTask.Run(() =>
     {
         //Loop through each item in the list and reference and load each Layout
         foreach (var layoutItem in Project.Current.GetItems <LayoutProjectItem>())
         {
             Layout lyt = layoutItem.GetLayout();
             CIMPage page = lyt.GetPage();
             page.Width = 8.5;
             page.Height = 11;
             lyt.SetPage(page);
         }
     }));
 }
        public static void ModifyReport(string reportName, FeatureLayer featureLayer)
        {
            var report = GetReport(reportName);

            #region Rename Report
            //Note: Call within QueuedTask.Run()
            ReportProjectItem reportProjItem = Project.Current.GetItems <ReportProjectItem>().FirstOrDefault(item => item.Name.Equals(reportName));
            reportProjItem.GetReport().SetName("RenamedReport");
            #endregion

            #region Modify the Report datasource
            //Note: Call within QueuedTask.Run()
            //Remove Groups
            // The fields in the datasource used for the report
            var listFields = new List <string> {
                "STATE_NAME"
            };
            report.RemoveGroups(listFields);

            //Add Group
            report.AddGroup("STATE_NAME", true, true, "");

            //Modify the Definition Query
            var defQuery = "STATE_NAME LIKE 'C%'";
            report.SetDefinitionQuery(defQuery);
            #endregion


            #region Modify the report Page
            //Note: Call within QueuedTask.Run()
            var cimReportPage = new CIMPage
            {
                Height          = 12,
                StretchElements = false,
                Width           = 6.5,
                ShowRulers      = true,
                ShowGuides      = true,
                Margin          = new CIMMargin {
                    Bottom = 1, Left = 1, Right = 1, Top = 1
                },
                Units = LinearUnit.Inches
            };
            report.SetPage(cimReportPage);
            //Change only the report's page height
            report.SetPageHeight(12);
            #endregion
        }
Esempio n. 6
0
        public void snippets_CIMChanges()
        {
            #region Change layout page size

            //Get the project item
            LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("MyLayout"));
            if (layoutItem != null)
            {
                QueuedTask.Run(() =>
                {
                    //Get the layout
                    Layout layout = layoutItem.GetLayout();
                    if (layout != null)
                    {
                        //Change properties
                        CIMPage page = layout.GetPage();
                        page.Width   = 8.5;
                        page.Height  = 11;
                        layout.SetPage(page);
                    }
                });
            }
            #endregion
        }
Esempio n. 7
0
        async public void snippets_ProjectItems()
        {
            #region Reference layout project items

            //A layout project item is an item that appears in the Layouts folder in the Catalog pane

            //Reference all the layout project items
            IEnumerable <LayoutProjectItem> layouts = Project.Current.GetItems <LayoutProjectItem>();

            //Or reference a specific layout project item by name
            LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("MyLayout"));
            #endregion

            #region Open a layout project item in a new view
            //A layout project item may be in a project but it may not be open in a view and/or active
            //First get the layout associated with the layout project item
            Layout layout = layoutItem.GetLayout();
            //Open a new pane
            ILayoutPane iNewLayoutPane = await ProApp.Panes.CreateLayoutPaneAsync(layout);

            #endregion

            #region Activate an already open layout view
            //A layout view may exist but it may not be active

            //Iterate through each pane in the application and check to see if the layout is already open and if so, activate it
            foreach (var pane in ProApp.Panes)
            {
                var layoutPane = pane as ILayoutPane;
                if (layoutPane == null) //if not a layout view, continue to the next pane
                {
                    continue;
                }
                if (layoutPane.LayoutView.Layout == layout) //if there is a match, activate the view
                {
                    (layoutPane as Pane).Activate();
                    return;
                }
            }
            #endregion



            #region Reference the active layout view
            //First check to see if the current, active view is a layout view.  If it is, use it
            LayoutView activeLayoutView = LayoutView.Active;
            if (activeLayoutView != null)
            {
                // use activeLayoutView
            }
            #endregion



            #region Create a new, basic layout and open it
            //Create a new layout project item layout in the project
            Layout newLayout = await QueuedTask.Run <Layout>(() =>
            {
                newLayout = LayoutFactory.Instance.CreateLayout(8.5, 11, LinearUnit.Inches);
                newLayout.SetName("New 8.5x11 Layout");
                return(newLayout);
            });

            //Open new layout on the GUI thread
            await ProApp.Panes.CreateLayoutPaneAsync(newLayout);

            #endregion



            #region Create a new layout using a modified CIM and open it
            //Create a new layout project item layout in the project
            Layout newCIMLayout = await QueuedTask.Run <Layout>(() =>
            {
                //Set up a CIM page
                CIMPage newPage = new CIMPage
                {
                    //required parameters
                    Width  = 8.5,
                    Height = 11,
                    Units  = LinearUnit.Inches,

                    //optional rulers
                    ShowRulers            = true,
                    SmallestRulerDivision = 0.5,

                    //optional guides
                    ShowGuides = true
                };
                CIMGuide guide1 = new CIMGuide
                {
                    Position    = 1,
                    Orientation = Orientation.Vertical
                };
                CIMGuide guide2 = new CIMGuide
                {
                    Position    = 6.5,
                    Orientation = Orientation.Vertical
                };
                CIMGuide guide3 = new CIMGuide
                {
                    Position    = 1,
                    Orientation = Orientation.Horizontal
                };
                CIMGuide guide4 = new CIMGuide
                {
                    Position    = 10,
                    Orientation = Orientation.Horizontal
                };

                List <CIMGuide> guideList = new List <CIMGuide>
                {
                    guide1,
                    guide2,
                    guide3,
                    guide4
                };
                newPage.Guides = guideList.ToArray();

                //Create a new page
                newCIMLayout = LayoutFactory.Instance.CreateLayout(newPage);
                newCIMLayout.SetName("New 8.5x11 Layout");
                return(newCIMLayout);
            });

            //Open new layout on the GUI thread
            await ProApp.Panes.CreateLayoutPaneAsync(newCIMLayout);

            #endregion



            #region Import a pagx into a project
            //Create a layout project item from importing a pagx file
            IProjectItem pagx = ItemFactory.Instance.Create(@"C:\Temp\Layout.pagx") as IProjectItem;
            Project.Current.AddItem(pagx);
            #endregion


            #region Remove a layout project item
            //Remove a layout from the project completely
            Project.Current.RemoveItem(layoutItem);
            #endregion
        }
        async protected override void OnClick()
        {
            //Check to see if the Game Board layout already exists
            LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Game Board"));

            if (layoutItem != null)
            {
                Layout lyt = await QueuedTask.Run(() => layoutItem.GetLayout());

                //Next check to see if a layout view is already open that referencs the Game Board layout
                foreach (var pane in ProApp.Panes)
                {
                    var lytPane = pane as ILayoutPane;
                    if (lytPane == null) //if not a layout view, continue to the next pane
                    {
                        continue;
                    }
                    if (lytPane.LayoutView.Layout == lyt) //if there is a match, activate the view
                    {
                        (lytPane as Pane).Activate();
                        System.Windows.MessageBox.Show("Activating existing pane");
                        return;
                    }
                }

                //If panes don't exist, then open a new pane
                await ProApp.Panes.CreateLayoutPaneAsync(lyt);

                System.Windows.MessageBox.Show("Opening already existing layout");
                return;
            }

            //The layout does not exist so create a new one
            Layout layout = await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run <Layout>(() =>
            {
                //*** CREATE A NEW LAYOUT ***

                //Set up a page
                CIMPage newPage = new CIMPage();
                //required properties
                newPage.Width  = 17;
                newPage.Height = 11;
                newPage.Units  = LinearUnit.Inches;

                //optional rulers
                newPage.ShowRulers            = true;
                newPage.SmallestRulerDivision = 0.5;

                layout = LayoutFactory.Instance.CreateLayout(newPage);
                layout.SetName("Game Board");

                //*** INSERT MAP FRAME ***

                // create a new map with an ArcGIS Online basemap
                Map map = MapFactory.Instance.CreateMap("World Map", MapType.Map, MapViewingMode.Map, Basemap.NationalGeographic);

                //Build map frame geometry
                Coordinate2D ll = new Coordinate2D(4, 0.5);
                Coordinate2D ur = new Coordinate2D(13, 6.5);
                Envelope env    = EnvelopeBuilder.CreateEnvelope(ll, ur);

                //Create map frame and add to layout
                MapFrame mfElm = LayoutElementFactory.Instance.CreateMapFrame(layout, env, map);
                mfElm.SetName("Main MF");

                //Set the camera
                Camera camera = mfElm.Camera;
                camera.X      = 3365;
                camera.Y      = 5314468;
                camera.Scale  = 175000000;
                mfElm.SetCamera(camera);

                //*** INSERT TEXT ELEMENTS ***

                //Title text
                Coordinate2D titleTxt_ll   = new Coordinate2D(6.5, 10);
                CIMTextSymbol arial36bold  = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlueRGB, 36, "Arial", "Bold");
                GraphicElement titleTxtElm = LayoutElementFactory.Instance.CreatePointTextGraphicElement(layout, titleTxt_ll, "Feeling Puzzled?", arial36bold);
                titleTxtElm.SetName("Title");

                //Instuctions text
                Coordinate2D recTxt_ll = new Coordinate2D(4.25, 6.5);
                Coordinate2D recTxt_ur = new Coordinate2D(13, 9.75);
                Envelope recEnv        = EnvelopeBuilder.CreateEnvelope(recTxt_ll, recTxt_ur);
                CIMTextSymbol arial18  = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreyRGB, 20, "Arial", "Regular");
                string text            = "<bol>Instructions:</bol> " +
                                         "\n\n  - Activate the map frame below and pan / zoom to desired extent" +
                                         "\n\n  - Close map frame activation" +
                                         "\n\n  - Click the 'Scramble Pieces' command" as String;
                GraphicElement recTxtElm = LayoutElementFactory.Instance.CreateRectangleParagraphGraphicElement(layout, recEnv, text, arial18);
                recTxtElm.SetName("Instructions");

                //Service layer credits
                Coordinate2D slcTxt_ll   = new Coordinate2D(0.5, 0.2);
                Coordinate2D slcTxt_ur   = new Coordinate2D(16.5, 0.4);
                Envelope slcEnv          = EnvelopeBuilder.CreateEnvelope(slcTxt_ll, slcTxt_ur);
                CIMTextSymbol arial8reg  = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8, "Arial", "Regular");
                String slcText           = "<dyn type='layout' name='Game Board' property='serviceLayerCredits'/>";
                GraphicElement slcTxtElm = LayoutElementFactory.Instance.CreateRectangleParagraphGraphicElement(layout, slcEnv, slcText, arial8reg);
                slcTxtElm.SetName("SLC");

                //Status and results text (blank to start)
                Coordinate2D statusTxt_ll   = new Coordinate2D(4.5, 7);
                CIMTextSymbol arial24bold   = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 24, "Arial", "Bold");
                GraphicElement statusTxtElm = LayoutElementFactory.Instance.CreatePointTextGraphicElement(layout, statusTxt_ll, "", arial24bold);
                statusTxtElm.SetName("Status");
                return(layout);
            });

            //*** OPEN LAYOUT VIEW (must be in the GUI thread) ***
            var layoutPane = await ProApp.Panes.CreateLayoutPaneAsync(layout);

            var sel = layoutPane.LayoutView.GetSelectedElements();

            if (sel.Count > 0)
            {
                layoutPane.LayoutView.ClearElementSelection();
            }
        }
Esempio n. 9
0
        async public static void MethodSnippets()
        {
            #region LayoutProjectItem_GetLayout
            //Reference the layout associated with a layout project item.

            LayoutProjectItem layoutItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout Name"));
            Layout            layout     = await QueuedTask.Run(() => layoutItem.GetLayout()); //Perform on the worker thread

            #endregion LayoutProjectItem_GetLayout


            TextElement elm = layout.FindElement("Text") as TextElement;
            #region Layout_DeleteElement
            //Delete a single layout element.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                layout.DeleteElement(elm);
            });

            #endregion Layout_DeleteElement


            #region Layout_DeleteElements
            //Delete multiple layout elements.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                layout.DeleteElements(item => item.Name.Contains("Clone"));
            });

            #endregion Layout_DeleteElements


            #region Layout_FindElement
            //Find a layout element.  The example below is referencing an existing text element.

            TextElement txtElm = layout.FindElement("Text") as TextElement;
            #endregion Layout_FindElement


            #region Layout_GetSetDefinition
            //Modify a layout's CIM definition

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                CIMLayout cimLayout = layout.GetDefinition();

                //Do something

                layout.SetDefinition(cimLayout);
            });

            #endregion Layout_GetSetDefinition


            #region Layout_GetSetPage
            //Modify a layouts page settings.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                CIMPage page = layout.GetPage();

                //Do something

                layout.SetPage(page);
            });

            #endregion Layout_GetSetPage


            String filePath = null;
            #region Layout_ExportPDF
            //See ProSnippets "Export layout to PDF"
            #endregion Layout_ExportPDF


            #region Layout_ExportMS_PDF
            //Export multiple map series pages to PDF

            //Create a PDF export format
            PDFFormat msPDF = new PDFFormat()
            {
                Resolution               = 300,
                OutputFileName           = filePath,
                DoCompressVectorGraphics = true
            };

            //Set up the export options for the map series
            MapSeriesExportOptions MSExport_custom = new MapSeriesExportOptions()
            {
                ExportPages           = ExportPages.Custom,
                CustomPages           = "1-3, 5",
                ExportFileOptions     = ExportFileOptions.ExportAsSinglePDF,
                ShowSelectedSymbology = false
            };

            //Check to see if the path is valid and export
            if (msPDF.ValidateOutputFilePath())
            {
                layout.Export(msPDF, MSExport_custom); //Export the PDF to a single, multiple page PDF.
            }
            #endregion Layout_ExportMS_PDF


            #region Layout_ExportMS_TIFF
            //Export multiple map series pages to TIFF

            //Create a TIFF export format
            TIFFFormat msTIFF = new TIFFFormat()
            {
                Resolution     = 300,
                OutputFileName = filePath,
                ColorMode      = ColorMode.TwentyFourBitTrueColor,
                HasGeoTiffTags = true,
                HasWorldFile   = true
            };

            //Set up the export options for the map series
            MapSeriesExportOptions MSExport_All = new MapSeriesExportOptions()
            {
                ExportPages           = ExportPages.All,
                ExportFileOptions     = ExportFileOptions.ExportMultipleNames,
                ShowSelectedSymbology = false
            };

            //Check to see if the path is valid and export
            if (msPDF.ValidateOutputFilePath())
            {
                layout.Export(msPDF, MSExport_All); //Export each page to a TIFF and apppend the page name suffix to each output file
            }
            #endregion Layout_ExportMS_TIFF


            #region Layout_RefreshMapSeries
            //Refresh the map series associated with the layout.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                layout.RefreshMapSeries();
            });

            #endregion Layout_RefreshMapSeries


            #region Layout_SaveAsFile
            //Save a layout to a pagx file.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                layout.SaveAsFile(filePath);
            });

            #endregion Layout_SaveAsFile


            #region Layout_SetName
            //Change the name of a layout.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                layout.SetName("New Name");
            });

            #endregion Layout_SetName


            SpatialMapSeries SMS = null;
            #region Layout_SetMapSeries
            //Change the properities of a spacial map series.

            //Perform on the worker thread
            await QueuedTask.Run(() =>
            {
                layout.SetMapSeries(SMS);
            });

            #endregion Layout_SetMapSeries


            #region Layout_ShowProperties
            //Open the layout properties dialog.

            //Get the layout associated with a layout project item
            LayoutProjectItem lytItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout Name"));
            Layout            lyt     = await QueuedTask.Run(() => lytItem.GetLayout()); //Worker thread

            //Open the properties dialog
            lyt.ShowProperties(); //GUI thread
            #endregion Layout_ShowProperties
        }
        //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",

                });
            }
        }