コード例 #1
0
        private void AddPointLabel(Forms.Point p, string labelName, XmlElement parent, bool newVersion)
        {
            try
            {
                XmlElement   Label    = m_doc.CreateElement("Label");
                XmlAttribute X        = m_doc.CreateAttribute("X");
                XmlAttribute Y        = m_doc.CreateAttribute("Y");
                XmlAttribute Rotation = m_doc.CreateAttribute("Rotation");
                XmlAttribute Name     = m_doc.CreateAttribute("Name");

                X.InnerText        = p.x.ToString();
                Y.InnerText        = p.y.ToString();
                Rotation.InnerText = p.rotation.ToString();
                Name.InnerText     = labelName;

                Label.Attributes.Append(X);
                Label.Attributes.Append(Y);
                if (newVersion == true)
                {
                    Label.Attributes.Append(Rotation);
                }
                Label.Attributes.Append(Name);

                parent.AppendChild(Label);
            }
            catch (System.Exception ex)
            {
                m_MapWin.ShowErrorDialog(ex);
            }
        }
コード例 #2
0
        public bool LoadLabelInfo(MapWindow.Interfaces.IMapWin m_MapWin, MapWindow.Interfaces.Layer layer, ref Forms.Label label, System.Windows.Forms.Form owner)
        {
            if (layer == null)
            {
                return(false);
            }

            //make sure the file exists
            string filename = "";

            if (m_MapWin.View.LabelsUseProjectLevel)
            {
                if (m_MapWin.Project.FileName != null && m_MapWin.Project.FileName.Trim() != "")
                {
                    filename = System.IO.Path.GetFileNameWithoutExtension(m_MapWin.Project.FileName) + @"\" + System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(layer.FileName), ".lbl");
                }
            }
            if (filename == "" || !System.IO.File.Exists(filename))
            {
                filename = System.IO.Path.ChangeExtension(layer.FileName, ".lbl");
            }
            if (!System.IO.File.Exists(filename))
            {
                return(false);
            }

            try
            {
                //load the xml file
                m_doc.Load(filename);

                //get the root of the file
                System.Xml.XmlElement root = m_doc.DocumentElement;

                label.points     = new System.Collections.ArrayList();
                label.labelShape = new System.Collections.ArrayList();

                XmlNodeList nodeList = root.GetElementsByTagName("Labels");

                //get the font
                int field  = int.Parse(nodeList[0].Attributes.GetNamedItem("Field").InnerText);
                int field2 = 0;
                if (nodeList[0].Attributes.GetNamedItem("Field2") != null)
                {
                    field2 = int.Parse(nodeList[0].Attributes.GetNamedItem("Field2").InnerText);
                }
                string fontName                  = nodeList[0].Attributes.GetNamedItem("Font").InnerText;
                float  size                      = float.Parse(nodeList[0].Attributes.GetNamedItem("Size").InnerText);
                System.Drawing.Color color       = System.Drawing.Color.FromArgb(int.Parse(nodeList[0].Attributes.GetNamedItem("Color").InnerText));
                int  justification               = int.Parse(nodeList[0].Attributes.GetNamedItem("Justification").InnerText);
                bool UseMinZoom                  = bool.Parse(nodeList[0].Attributes.GetNamedItem("UseMinZoomLevel").InnerText);
                bool Scaled                      = false;
                bool UseShadows                  = false;
                System.Drawing.Color ShadowColor = System.Drawing.Color.White;
                int    Offset                    = 0;
                double StandardViewWidth         = 0.0;
                bool   UseLabelCollision         = false;
                bool   RemoveDuplicateLabels     = false;
                string RotationField             = "";

                try
                {
                    if (nodeList[0].Attributes.GetNamedItem("Scaled") != null)
                    {
                        Scaled = bool.Parse(nodeList[0].Attributes.GetNamedItem("Scaled").InnerText);
                    }
                    if (nodeList[0].Attributes.GetNamedItem("UseShadows") != null)
                    {
                        UseShadows = bool.Parse(nodeList[0].Attributes.GetNamedItem("UseShadows").InnerText);
                    }
                    if (nodeList[0].Attributes.GetNamedItem("ShadowColor") != null)
                    {
                        ShadowColor = System.Drawing.Color.FromArgb(int.Parse(nodeList[0].Attributes.GetNamedItem("ShadowColor").InnerText));
                    }
                    if (nodeList[0].Attributes.GetNamedItem("Offset") != null)
                    {
                        Offset = int.Parse(nodeList[0].Attributes.GetNamedItem("Offset").InnerText);
                    }
                    if (nodeList[0].Attributes.GetNamedItem("StandardViewWidth") != null)
                    {
                        StandardViewWidth = double.Parse(nodeList[0].Attributes.GetNamedItem("StandardViewWidth").InnerText);
                    }
                }
                catch
                {
                    Scaled            = false;
                    UseShadows        = false;
                    ShadowColor       = System.Drawing.Color.White;
                    Offset            = 0;
                    StandardViewWidth = 0.0;
                }

                if (nodeList[0].Attributes.GetNamedItem("UseLabelCollision") != null)
                {
                    UseLabelCollision = bool.Parse(nodeList[0].Attributes.GetNamedItem("UseLabelCollision").InnerText);
                }
                if (nodeList[0].Attributes.GetNamedItem("RemoveDuplicateLabels") != null)
                {
                    RemoveDuplicateLabels = bool.Parse(nodeList[0].Attributes.GetNamedItem("RemoveDuplicateLabels").InnerText);
                }
                if (nodeList[0].Attributes.GetNamedItem("RotationField") != null)
                {
                    RotationField = nodeList[0].Attributes.GetNamedItem("RotationField").InnerText;
                }

                double xMin = double.Parse(nodeList[0].Attributes.GetNamedItem("xMin").InnerText);
                double yMin = double.Parse(nodeList[0].Attributes.GetNamedItem("yMin").InnerText);
                double xMax = double.Parse(nodeList[0].Attributes.GetNamedItem("xMax").InnerText);
                double yMax = double.Parse(nodeList[0].Attributes.GetNamedItem("yMax").InnerText);

                //set all the properties of the label
                label.font          = new System.Drawing.Font(fontName, size);
                label.color         = color;
                label.field         = field;
                label.field2        = field2;
                label.handle        = layer.Handle;
                label.alignment     = (MapWinGIS.tkHJustification)justification;
                label.UseMinExtents = UseMinZoom;

                label.Scaled            = Scaled;
                label.UseShadows        = UseShadows;
                label.shadowColor       = ShadowColor;
                label.Offset            = Offset;
                label.StandardViewWidth = StandardViewWidth;
                label.RotationField     = RotationField;

                if (nodeList[0].Attributes.GetNamedItem("UseLabelCollision") != null)
                {
                    label.UseLabelCollision = UseLabelCollision;
                }
                if (nodeList[0].Attributes.GetNamedItem("RemoveDuplicateLabels") != null)
                {
                    label.RemoveDuplicates = RemoveDuplicateLabels;
                }

                if (nodeList[0].Attributes.GetNamedItem("AppendLine1") != null)
                {
                    label.AppendLine1 = nodeList[0].Attributes.GetNamedItem("AppendLine1").InnerText;
                }
                if (nodeList[0].Attributes.GetNamedItem("AppendLine2") != null)
                {
                    label.AppendLine2 = nodeList[0].Attributes.GetNamedItem("AppendLine2").InnerText;
                }
                if (nodeList[0].Attributes.GetNamedItem("PrependLine1") != null)
                {
                    label.PrependLine1 = nodeList[0].Attributes.GetNamedItem("PrependLine1").InnerText;
                }
                if (nodeList[0].Attributes.GetNamedItem("PrependLine2") != null)
                {
                    label.PrependLine2 = nodeList[0].Attributes.GetNamedItem("PrependLine2").InnerText;
                }

                label.extents = new MapWinGIS.ExtentsClass();
                label.extents.SetBounds(xMin, yMin, 0, xMax, yMax, 0);
                label.Modified            = false;
                label.LabelExtentsChanged = false;
                label.updateHeaderOnly    = true;

                //add all the points to this label
                Forms.Point p;
                XmlNode     node;
                double      x, y, rotation = 0;
                System.Collections.IEnumerator enumerator = nodeList[0].ChildNodes.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    node = (XmlNode)enumerator.Current;
                    x    = double.Parse(node.Attributes.GetNamedItem("X").InnerText);
                    y    = double.Parse(node.Attributes.GetNamedItem("Y").InnerText);

                    if (nodeList[0].Attributes.GetNamedItem("Rotation") != null)
                    {
                        rotation = double.Parse(node.Attributes.GetNamedItem("Rotation").InnerText);
                    }


                    p          = new Forms.Point();
                    p.x        = x;
                    p.y        = y;
                    p.rotation = rotation;

                    label.points.Add(p);
                }
                label.xml_LblFile = m_doc.InnerXml;
            }
            catch
            {
                return(false);
            }

            return(true);
        }