コード例 #1
0
        /// <summary>
        /// Generate label categories for the given set of shapefile categories
        /// </summary>
        /// <param name="mapWin">The reference to MapWindow</param>
        /// <param name="layerHandle">The handle of the layer</param>
        internal static void GenerateCategories(LegendControl.Legend legend, int layerHandle)
        {
            Layer     lyr = legend.GetLayer(layerHandle);
            Shapefile sf  = lyr.GetObject() as MapWinGIS.Shapefile;
            Labels    lb  = sf.Labels;

            sf.Labels.ClearCategories();
            for (int i = 0; i < sf.Categories.Count; i++)
            {
                ShapefileCategory cat      = sf.Categories.get_Item(i);
                LabelCategory     labelCat = lb.AddCategory(cat.Name);
                labelCat.Expression = cat.Expression;
            }

            SymbologySettings settings = Globals.get_LayerSettings(layerHandle);
            ColorBlend        blend    = (ColorBlend)settings.LabelsScheme;

            if (blend != null)
            {
                ColorScheme scheme = ColorSchemes.ColorBlend2ColorScheme(blend);
                if (settings.LabelsRandomColors)
                {
                    lb.ApplyColorScheme(tkColorSchemeType.ctSchemeRandom, scheme);
                }
                else
                {
                    lb.ApplyColorScheme(tkColorSchemeType.ctSchemeGraduated, scheme);
                }
            }

            if (settings.LabelsVariableSize)
            {
                for (int i = 0; i < lb.NumCategories; i++)
                {
                    lb.get_Category(i).FontSize = (int)((double)sf.Labels.FontSize +
                                                        (double)settings.LabelsSizeRange / ((double)lb.NumCategories - 1) * (double)i);
                }
            }

            // Expressions aren't supported by labels yet, therefore we need to copy indices from the symbology
            for (int i = 0; i < lb.Count; i++)
            {
                MapWinGIS.Label label = lb.get_Label(i, 0);
                label.Category = sf.get_ShapeCategory(i);
            }
        }
コード例 #2
0
        /// <summary>
        /// Generates labels with specified positions
        /// </summary>
        private void btnOk_Click(object sender, EventArgs e)
        {
            // callback and wait cursor
            ICallback cBackOld = m_shapefile.GlobalCallback;
            Callback  cback    = new Callback();

            m_shapefile.GlobalCallback = cback;
            this.Enabled = false;
            this.Cursor  = Cursors.WaitCursor;

            MapWinGIS.Labels   lb          = m_shapefile.Labels;
            tkLabelPositioning positioning = get_LabelPositioning();

            lb.LineOrientation = (tkLineLabelOrientation)cboLineOrientation.SelectedIndex;

            try
            {
                // generation
                m_shapefile.GenerateLabels(-1, positioning, !chkLabelEveryPart.Checked);
                m_shapefile.Labels.SavingMode = tkSavingMode.modeXMLOverwrite;  // .lbl file should be updated

                ShpfileType type = Globals.ShapefileType2D(m_shapefile.ShapefileType);
                if (type == ShpfileType.SHP_POINT || type == ShpfileType.SHP_MULTIPOINT)
                {
                    if (optAlignBottomCenter.Checked)
                    {
                        m_alignment = tkLabelAlignment.laBottomCenter;
                    }
                    if (optAlignBottomLeft.Checked)
                    {
                        m_alignment = tkLabelAlignment.laBottomLeft;
                    }
                    if (optAlignBottomRight.Checked)
                    {
                        m_alignment = tkLabelAlignment.laBottomRight;
                    }
                    if (optAlignCenter.Checked)
                    {
                        m_alignment = tkLabelAlignment.laCenter;
                    }
                    if (optAlignCenterLeft.Checked)
                    {
                        m_alignment = tkLabelAlignment.laCenterLeft;
                    }
                    if (optAlignCenterRight.Checked)
                    {
                        m_alignment = tkLabelAlignment.laCenterRight;
                    }
                    if (optAlignTopCenter.Checked)
                    {
                        m_alignment = tkLabelAlignment.laTopCenter;
                    }
                    if (optAlignTopLeft.Checked)
                    {
                        m_alignment = tkLabelAlignment.laTopLeft;
                    }
                    if (optAlignTopRight.Checked)
                    {
                        m_alignment = tkLabelAlignment.laTopRight;
                    }
                }

                // updating references to categories
                if (lb.NumCategories > 0)
                {
                    for (int i = 0; i < lb.Count; i++)
                    {
                        MapWinGIS.Label label = lb.get_Label(i, 0);
                        label.Category = m_shapefile.get_ShapeCategory(i);
                    }
                }
            }
            finally
            {
                this.Enabled = true;
                this.Cursor  = Cursors.Default;
                cback.Clear();
                m_shapefile.GlobalCallback = cBackOld;
            }
        }