Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string agent = ConfigurationManager.AppSettings["MapAgentUrl"];

            IServerConnection conn = ConnectionProviderRegistry.CreateConnection(
                "Maestro.Http",
                "Url", agent,
                "SessionId", Request.Params["SESSION"]);

            IMappingService mpSvc   = (IMappingService)conn.GetService((int)ServiceType.Mapping);
            string          rtMapId = "Session:" + conn.SessionID + "//" + Request.Params["MAPNAME"] + ".Map";

            RuntimeMap rtMap = mpSvc.OpenMap(rtMapId);

            RuntimeMapLayer tracks = rtMap.Layers["Tracks"];

            if (tracks != null)
            {
                lblMessage.Text = "Tracks layer already added";
            }
            else
            {
                string          groupName = "Transportation";
                RuntimeMapGroup group     = rtMap.Groups[groupName];
                if (group == null)
                {
                    group = mpSvc.CreateMapGroup(rtMap, groupName);
                    rtMap.Groups.Add(group);
                }

                //For some reason, the Sheboygan sample data does not have a Rail
                //Layer Definition, so what better time to show how to create a
                //layer dynamically :)

                //Our Feature Source
                string fsId = "Library://Samples/Sheboygan/Data/Rail.FeatureSource";

                //The place we'll store the layer definition
                string layerId = "Session:" + conn.SessionID + "//Rail.LayerDefinition";

                CreateTracksLayer(conn, fsId, layerId);

                ILayerDefinition layerDef = (ILayerDefinition)conn.ResourceService.GetResource(layerId);
                RuntimeMapLayer  layer    = mpSvc.CreateMapLayer(rtMap, layerDef);

                layer.Group          = groupName;
                layer.Name           = "Tracks";
                layer.LegendLabel    = "Tracks";
                layer.ShowInLegend   = true;
                layer.ExpandInLegend = true;
                layer.Selectable     = true;
                layer.Visible        = true;

                //Set it to be drawn above districts.
                //In terms of draw order, it goes [0...n] -> [TopMost ... Bottom]
                //So for a layer to be drawn above something else, its draw order must be
                //less than that particular layer.

                int index = rtMap.Layers.IndexOf("Districts");
                rtMap.Layers.Insert(index, layer);

                rtMap.Save();

                Page.ClientScript.RegisterStartupScript(
                    this.GetType(),
                    "load",
                    "<script type=\"text/javascript\"> window.onload = function() { parent.parent.Refresh(); } </script>");

                lblMessage.Text = "Tracks layer added again";
            }

            rtMap = mpSvc.OpenMap(rtMapId);
            DumpMap(rtMap);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string agent = ConfigurationManager.AppSettings["MapAgentUrl"];

            IServerConnection conn = ConnectionProviderRegistry.CreateConnection(
                "Maestro.Http",
                "Url", agent,
                "SessionId", Request.Params["SESSION"]);

            IMappingService mpSvc   = (IMappingService)conn.GetService((int)ServiceType.Mapping);
            string          rtMapId = "Session:" + conn.SessionID + "//" + Request.Params["MAPNAME"] + ".Map";

            RuntimeMap rtMap = mpSvc.OpenMap(rtMapId);

            RuntimeMapLayer parcels = rtMap.Layers["Parcels"];

            if (parcels != null)
            {
                rtMap.Layers.Remove(parcels);

                rtMap.Save();

                Page.ClientScript.RegisterStartupScript(
                    this.GetType(),
                    "load",
                    "<script type=\"text/javascript\"> window.onload = function() { parent.parent.Refresh(); } </script>");

                lblMessage.Text = "Parcels layer removed";
            }
            else
            {
                string          groupName = "Municipal";
                RuntimeMapGroup group     = rtMap.Groups[groupName];
                if (group == null)
                {
                    group = mpSvc.CreateMapGroup(rtMap, groupName);
                    rtMap.Groups.Add(group);
                    throw new Exception("Layer group not found");
                }

                ILayerDefinition layerDef = (ILayerDefinition)conn.ResourceService.GetResource("Library://Samples/Sheboygan/Layers/Parcels.LayerDefinition");
                RuntimeMapLayer  layer    = mpSvc.CreateMapLayer(rtMap, layerDef);

                layer.Group          = group.Name;
                layer.LegendLabel    = "Parcels";
                layer.ShowInLegend   = true;
                layer.ExpandInLegend = true;
                layer.Selectable     = true;
                layer.Visible        = true;

                //Set it to be drawn above islands.
                //In terms of draw order, it goes [0...n] -> [TopMost ... Bottom]
                //So for a layer to be drawn above something else, its draw order must be
                //less than that particular layer.

                int index = rtMap.Layers.IndexOf("Islands");
                rtMap.Layers.Insert(index, layer);

                rtMap.Save();

                Page.ClientScript.RegisterStartupScript(
                    this.GetType(),
                    "load",
                    "<script type=\"text/javascript\"> window.onload = function() { parent.parent.Refresh(); } </script>");

                lblMessage.Text = "Parcels layer added again";
            }

            rtMap = mpSvc.OpenMap(rtMapId);
            DumpMap(rtMap);
        }