/// <summary>
        /// Called the first time the pop-up content is viewed. This is good practice when you may show a pop-up for multiple items at a time.
        /// This allows you to delay generating the html content until the item is actually viewed.
        /// </summary>
        protected override Task <string> OnCreateHtmlContent()
        {
            return(QueuedTask.Run(async() =>
            {
                var invalidPopup = "<p>Pop-up content could not be generated for this feature.</p>";
                var layer = MapMember as BasicFeatureLayer;
                if (layer == null)
                {
                    return invalidPopup;
                }

                List <HierarchyRow> completeHierarchyRows = new List <HierarchyRow>();
                var newRow = await _relateInfo.GetRelationshipChildren(_featureClassName, _id);
                completeHierarchyRows.Add(newRow);

                //Construct a new html string that we will use to update our html template.
                var sb = new StringBuilder();
                sb.Append(new JavaScriptSerializer().Serialize(completeHierarchyRows));
                string rootType = completeHierarchyRows[0].type;
                sb.Replace(@"""children"":[],", string.Empty);

                //Get the html from the template file on disk that we have packaged with our add-in.
                var htmlPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "template.html");
                var html = File.ReadAllText(htmlPath);

                //Update the template with our custom html and return it to be displayed in the pop-up window.
                html = html.Replace("insert root layer here", layer.Name);
                html = html.Replace("'insert data here'", sb.ToString());
                html = html.Replace("insert root type field here", rootType);
                return html;
            }));
        }
예제 #2
0
        /// <summary>
        /// Called the first time the pop-up content is viewed. This is good practice when you may show a pop-up for multiple items at a time.
        /// This allows you to delay generating the html content until the item is actually viewed.
        /// </summary>
        protected override Task <string> OnCreateHtmlContent()
        {
            return(QueuedTask.Run(() =>
            {
                var invalidPopup = "<p>Pop-up content could not be generated for this feature.</p>";
                if (!(MapMember is BasicFeatureLayer layer))
                {
                    return invalidPopup;
                }

                List <HierarchyRow> completeHierarchyRows = new List <HierarchyRow>();
                var gdb = layer.GetTable().GetDatastore() as Geodatabase;
                var fcName = layer.GetTable().GetName();
                if (_relateInfo == null)
                {
                    _relateInfo = new RelateInfo();
                }
                var newRow = _relateInfo.GetRelationshipChildren(layer, gdb, fcName, _id);
                completeHierarchyRows.Add(newRow);

                //Using our html template we construct a new html string that we return through OnCreateHtmlContent
                var sb = new StringBuilder();
                sb.Append(JsonConvert.SerializeObject(completeHierarchyRows));
                string rootType = completeHierarchyRows[0].type;
                sb.Replace(@"""children"":[],", string.Empty);

                //Get the html from the template file on disk that we have packaged with our add-in.
                var htmlPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "template.html");
                var html = File.ReadAllText(htmlPath);

                //Update the template with our custom html and return it to be displayed in the pop-up window.
                html = html.Replace("insert root layer here", layer.Name);
                html = html.Replace("'insert data here'", sb.ToString());
                html = html.Replace("insert root type field here", rootType);
                return html;
            }));
        }