コード例 #1
0
        public void btnChangeLayerFilter(object sender, EventArgs e)
        {
            var labelExpression = ((RadioButton)sender).Tag;

            QueuedTask.Run(() =>
            {
                //Get the active map's definition - CIMMap.
                var cimMap = MapView.Active.Map.GetDefinition();
                //Get the labeling engine from the map definition
                var cimGeneralPlacement = cimMap.GeneralPlacementProperties;
                if (cimGeneralPlacement is CIMMaplexGeneralPlacementProperties)
                {
                    Debug.WriteLine("already using maplex");
                }
                else
                {
                    //Create a new Maplex label engine properties
                    var cimMaplexGeneralPlacementProperties = new CIMMaplexGeneralPlacementProperties();
                    //Set the CIMMap's GeneralPlacementProperties to the new label engine
                    cimMap.GeneralPlacementProperties = cimMaplexGeneralPlacementProperties;
                }
                FeatureLayer a = MapView.Active.Map.Layers[1] as FeatureLayer;
                if (labelExpression.ToString() == "None")
                {
                    a.SetLabelVisibility(false);
                }
                else
                {
                    //var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(s => s.ShapeType == esriGeometryType.esriGeometryPolyline);

                    a.SetLabelVisibility(true);
                    a.LabelClasses[0].SetExpression(labelExpression.ToString()); //$feature.RMNUMB +  TextFormatting.NewLine  + $feature.RMAREA
                    CIMTextSymbol s = a.LabelClasses[0].GetTextSymbol();
                    s.SetSize(14);
                    a.LabelClasses[0].SetTextSymbol(s);

                    var lyrDefn = a.GetDefinition() as CIMFeatureLayer;
                    //Get the label classes - we need the first one
                    var listLabelClasses = lyrDefn.LabelClasses.ToList();
                    var theLabelClass    = listLabelClasses.FirstOrDefault();
                    theLabelClass.MaplexLabelPlacementProperties.ThinDuplicateLabels = true;
                    lyrDefn.LabelClasses = listLabelClasses.ToArray(); //Set the labelClasses back
                    a.SetDefinition(lyrDefn);                          //set the layer's definition
                }
            });
        }
コード例 #2
0
        /// <summary>
        /// Change the active map's labeling engine from Standard to Maplex or vice versa
        /// </summary>
        /// <remarks>Switches between the Maplex and Standard labeling engines. The current label engine's properties are stored so they can be restored when swicthed back.</remarks>
        /// <returns></returns>
        private static Task ChangeLabelEngineAsync()
        {
            return(QueuedTask.Run(() =>
            {
                #region Change the active map's labeling engine from Standard to Maplex or vice versa
                //Note: call within QueuedTask.Run()
                //Get the active map's definition - CIMMap.
                var cimMap = MapView.Active.Map.GetDefinition();
                //Get the labeling engine from the map definition
                var cimGeneralPlacement = cimMap.GeneralPlacementProperties;

                if (cimGeneralPlacement is CIMMaplexGeneralPlacementProperties)
                {
                    //Current labeling engine is Maplex labeling engine
                    //store the current label engine props if needed.
                    var maplexLabelEngineProps = cimGeneralPlacement;
                    //Create a new standard label engine properties
                    var cimStandardPlacementProperties = new CIMStandardGeneralPlacementProperties();
                    //Set the CIMMap's GeneralPlacementProperties to the new label engine
                    cimMap.GeneralPlacementProperties = cimStandardPlacementProperties;
                }
                else
                {
                    //Current labeling engine is Standard labeling engine
                    //store the current label engine props if needed.
                    var standardLabelEngine = cimGeneralPlacement;
                    //Create a new Maplex label engine properties
                    var cimMaplexGeneralPlacementProperties = new CIMMaplexGeneralPlacementProperties();
                    //Set the CIMMap's GeneralPlacementProperties to the new label engine
                    cimMap.GeneralPlacementProperties = cimMaplexGeneralPlacementProperties;
                }
                //Set the map's definition
                MapView.Active.Map.SetDefinition(cimMap);
                #endregion
            }));
        }
コード例 #3
0
        public void btnChangeLayerFilter(object sender, EventArgs e)
        {
            var labelExpression = ((RadioButton)sender).Tag;

            QueuedTask.Run(() =>
            {
                //Get the active map's definition - CIMMap.
                var cimMap = MapView.Active.Map.GetDefinition();
                //Get the labeling engine from the map definition
                var cimGeneralPlacement = cimMap.GeneralPlacementProperties;
                if (cimGeneralPlacement is CIMMaplexGeneralPlacementProperties)
                {
                    Debug.WriteLine("already using maplex");
                }
                else
                {
                    //Create a new Maplex label engine properties
                    var cimMaplexGeneralPlacementProperties = new CIMMaplexGeneralPlacementProperties();
                    //Set the CIMMap's GeneralPlacementProperties to the new label engine
                    cimMap.GeneralPlacementProperties = cimMaplexGeneralPlacementProperties;
                }
                FeatureLayer a = MapView.Active.Map.Layers[1] as FeatureLayer;
                if (labelExpression.ToString() == "None")
                {
                    a.SetLabelVisibility(false);
                }
                else
                {
                    a.SetLabelVisibility(true);
                    a.LabelClasses[0].SetExpression(labelExpression.ToString()); //$feature.RMNUMB +  TextFormatting.NewLine  + $feature.RMAREA
                    CIMTextSymbol s = a.LabelClasses[0].GetTextSymbol();
                    s.SetSize(14);
                    a.LabelClasses[0].SetTextSymbol(s);
                }
            });
        }