/// <summary> /// Constructor initializing the base class with the layer and object id associated with the pop-up content /// </summary> //public DynamicPopupContent(MapMember mapMember, long id, List<HierarchyRow> hierarchyRows) : base(mapMember, id) public DynamicPopupContent(MapMember mapMember, long id, string featureClassName, RelateInfo relateInfo) : base(mapMember, id) { //Set property indicating the html content will be generated on demand when the content is viewed. IsDynamicContent = true; _featureClassName = featureClassName; _id = id; _relateInfo = relateInfo; }
/// <summary> /// Called when a sketch is completed. /// </summary> protected override async Task <bool> OnSketchCompleteAsync(Geometry geometry) { var popupContent = await QueuedTask.Run(async() => { var mapView = MapView.Active; if (mapView == null) { return(null); } //Get the features that intersect the sketch geometry. var features = mapView.GetFeatures(geometry); if (features.Count == 0) { return(null); } var firstLyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(); //get the first layer in the map if (firstLyr == null) { return(null); } var gdb = await GetGDBFromLyrAsync(firstLyr); LayersInMapFeatureClassMap = Module1.GetMapLayersFeatureClassMap(gdb); var oidList = features[firstLyr]; //gets the OIds of all the features selected. var oid = firstLyr.GetTable().GetDefinition().GetObjectIDField(); //gets the OId field var qf = new QueryFilter() //create the query filter { WhereClause = string.Format("({0} in ({1}))", oid, string.Join(",", oidList)) }; //Create the new selection Selection selection = firstLyr.Select(qf); var relateInfo = new RelateInfo(firstLyr, selection); return(await relateInfo.GetPopupContent(features)); //passes the selection to gather the relationShip class information. }); MapView.Active.ShowCustomPopup(popupContent); return(true); }
/// <summary> /// Called when a sketch is completed. /// </summary> protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry) { var popupContent = await QueuedTask.Run(async () => { var mapView = MapView.Active; if (mapView == null) return null; //Get the features that intersect the sketch geometry. var features = mapView.GetFeatures(geometry); if (features.Count == 0) return null; var firstLyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(); //get the first layer in the map if (firstLyr == null) return null; var gdb = await GetGDBFromLyrAsync(firstLyr); LayersInMapFeatureClassMap = Module1.GetMapLayersFeatureClassMap(gdb); var oidList = features[firstLyr]; //gets the OIds of all the features selected. var oid = firstLyr.GetTable().GetDefinition().GetObjectIDField(); //gets the OId field var qf = new QueryFilter() //create the query filter { WhereClause = string.Format("({0} in ({1}))", oid, string.Join(",", oidList)) }; //Create the new selection Selection selection = firstLyr.Select(qf); var relateInfo = new RelateInfo(firstLyr, selection); return await relateInfo.GetPopupContent(features); //passes the selection to gather the relationShip class information. }); MapView.Active.ShowCustomPopup(popupContent); return true; }
/// <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>"; var layer = MapMember as BasicFeatureLayer; if (layer == null) { 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); //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; })); }