[mapguide-users] change layer definition runtime

Liglio liglio at pobox.com
Thu Sep 8 13:03:43 PDT 2016


Put in UtilMap class

        /// <summary>
        /// Get layer object by his name in the Runtime Map
        /// </summary>
        /// Mapguide MapObject
        /// Layer Name
        /// <returns></returns>
        private MgLayerBase GetLayerByName(MgMap map, string layerName)
        {
            try
            {
                MgLayerBase layer = null;
                for (int i = 0; i < map.GetLayers().GetCount(); i++)
                {
                    MgLayerBase nextLayer = map.GetLayers().GetItem(i);
                    if (nextLayer.GetName().ToUpper() ==
layerName.ToUpper())
                    {
                        layer = nextLayer;
                        break;
                    }
                }
                return layer;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

*********************************************************
using System;
using System.IO;
using System.Xml;
using System.Data;

static public class Util
    {
			static public string SetTagTextContent(string strXml, string strNode,
string strContent, bool bolCreateIfInexist = true, string strNodeCreateAfter
= null)
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlNode xmlNode = null;
            XmlNode xmlNewNode;
            XmlNode xmlAfterNode;
            string strRet;
            string strTag;

            xmlDoc.PreserveWhitespace = true;
            xmlDoc.LoadXml(strXml);
            try
            {
                xmlNode = xmlDoc.SelectSingleNode(strNode);
                if (xmlNode == null && bolCreateIfInexist)
                {
                    strTag = strNode.Substring(strNode.LastIndexOf("/") +
1);
                    xmlNewNode = xmlDoc.CreateNode(XmlNodeType.Element,
strTag, null);
                    xmlNewNode.InnerText += " " + strContent;
                    xmlNode = xmlDoc.SelectSingleNode(strNode.Replace("/" +
strTag, ""));
                    xmlAfterNode =
xmlDoc.SelectSingleNode(strNodeCreateAfter);
                    xmlNode.InsertAfter(xmlNewNode, xmlAfterNode);
                }
                else
                {
                    xmlNode.InnerText = strContent;
                }
            }
            catch (System.Xml.XPath.XPathException)
            {
            }

            strRet = xmlDoc.InnerXml;

            return strRet;
        }
        
    }



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/change-layer-definition-runtime-tp5284382p5284826.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list