Esempio n. 1
0
        protected override async void OnClick()
        {
            MapView mapvView = MapView.Active;

            if (mapvView == null)
            {
                return;
            }

            // get the layers
            FeatureLayer precinctLayer = mapvView.Map.GetLayersAsFlattenedList().
                                         OfType <FeatureLayer>().FirstOrDefault(l => l.Name == "Portland Precincts");
            FeatureLayer fireLayer = mapvView.Map.GetLayersAsFlattenedList().
                                     OfType <FeatureLayer>().FirstOrDefault(l => l.Name == "Fire Stations");
            FeatureLayer policeLayer = mapvView.Map.GetLayersAsFlattenedList().
                                       OfType <FeatureLayer>().FirstOrDefault(l => l.Name == "Police Stations");

            if ((precinctLayer == null) || (fireLayer == null) || (policeLayer == null))
            {
                return;
            }

            await QueuedTask.Run(() =>
            {
                // group templates are stored on the primary layer
                var layerDef = precinctLayer.GetDefinition() as CIMFeatureLayer;

                // create group template from primary layer
                var myGroupTemplateDef = precinctLayer.CreateGroupTemplateDefinition("My Group Template", "North Precinct", "some desc", new[] { "Group", "Polygon" });

                // set the default construction tool
                myGroupTemplateDef.SetDefaultToolID("esri_editing_SketchPolygonTool");

                // remove construction tools from being available with this template
                List <string> filter = new List <string>();
                // guid = esri_editing_SketchFreehandPolygonTool
                filter.Add("0A7C16B9-1CFD-467f-8ECE-6BA376192431");
                // esri_editing_SketchAutoCompleteFreehandPolygonTool
                filter.Add("ACD53634-CBC7-44d5-BDE9-692FA8D45850");
                // esri_editing_SketchTracePolygonTool
                filter.Add("E22F7D98-007D-427C-8282-13704F7C84C3");
                myGroupTemplateDef.ExcludedToolGUIDs = filter.ToArray();

                // add component parts
                myGroupTemplateDef = myGroupTemplateDef.AddComponentTemplate(fireLayer, "Fire Stations", GroupTemplateBuilderMethods.builderPointAtPolygonCentroid);
                myGroupTemplateDef = myGroupTemplateDef.AddComponentTemplate(policeLayer, "Police Stations", GroupTemplateBuilderMethods.builderPointAtPolygonStart);

                // add group template to layer
                var template = precinctLayer.CreateTemplate(myGroupTemplateDef);
            });
        }