private void repoView_RequestAddToMap(object sender, EventArgs e)
        {
            var item = repoView.SelectedItem;

            if (item != null && item.ResourceType == ResourceTypes.LayerDefinition.ToString())
            {
                var layer = _mapSvc.CreateMapLayer(_rtMap, ((ILayerDefinition)this.EditorService.CurrentConnection.ResourceService.GetResource(item.ResourceId)));
                layer.Name         = LiveMapEditorLegend.GenerateUniqueName(ResourceIdentifier.GetName(item.ResourceId), _rtMap.Layers);
                layer.LegendLabel  = ResourceIdentifier.GetName(item.ResourceId);
                layer.Visible      = true;
                layer.ShowInLegend = true;
                _rtMap.Layers.Insert(0, layer);
                viewer.RefreshMap();
            }
        }
Beispiel #2
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["ThemedDistricts"];

            if (tracks != null)
            {
                lblMessage.Text = "Themed districts layer already added";
            }
            else
            {
                //Add our themed districts layer

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

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

                CreateDistrictsLayer(conn, fsId, layerId);

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

                layer.Name           = "ThemedDistricts";
                layer.Group          = "";
                layer.LegendLabel    = "Themed Districts";
                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 = "Themed districts layer added";
            }

            rtMap = mpSvc.OpenMap(rtMapId);
            DumpMap(rtMap);
        }
Beispiel #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string agent   = ConfigurationManager.AppSettings["MapAgentUrl"];
                string mapName = Request.Params["MAPNAME"];
                string session = Request.Params["SESSION"];

                IServerConnection conn = ConnectionProviderRegistry.CreateConnection(
                    "Maestro.Http",
                    "Url", agent,
                    "SessionId", session);

                IMappingService mpSvc   = (IMappingService)conn.GetService((int)ServiceType.Mapping);
                string          rtMapId = "Session:" + conn.SessionID + "//" + mapName + ".Map";

                RuntimeMap      rtMap      = mpSvc.OpenMap(rtMapId);
                int             layerIndex = rtMap.Layers.IndexOf("Parcels");
                RuntimeMapLayer layer      = rtMap.Layers[layerIndex];

                //Here is now the layer replacement technique works:
                //
                //We take the Layer Definition content referenced by the old layer
                //Modify the filter in this content and save it to a new resource id
                //We then create a replacement layer that points to this new resource id
                //and set the public properties to be identical of the old layer.
                //
                //Finally we then remove the old layer and put the replacement layer in its
                //place, before saving the runtime map.

                ILayerDefinition       ldf = (ILayerDefinition)conn.ResourceService.GetResource(layer.LayerDefinitionID);
                IVectorLayerDefinition vl  = (IVectorLayerDefinition)ldf.SubLayer;

                //Sets the layer filter
                vl.Filter = "RNAME LIKE 'SCHMITT%'";
                if (Request.Params["RESET"] == "1")
                {
                    vl.Filter = "";
                }

                //Save this modified layer under a different resource id
                string ldfId = "Session:" + conn.SessionID + "//ParcelsFiltered.LayerDefinition";
                conn.ResourceService.SaveResourceAs(ldf, ldfId);
                //Note that SaveResourceAs does not modify the ResourceID of the resource we want to save
                //so we need to update it here
                ldf.ResourceID = ldfId;

                //Create our replacement layer and apply the same properties from the old one
                RuntimeMapLayer replace = mpSvc.CreateMapLayer(rtMap, ldf);
                replace.ExpandInLegend = layer.ExpandInLegend;
                replace.Group          = layer.Group;
                replace.LegendLabel    = layer.LegendLabel;
                replace.Name           = layer.Name;
                replace.Selectable     = layer.Selectable;
                replace.ShowInLegend   = layer.ShowInLegend;
                replace.Visible        = layer.Visible;

                //Remove the old layer and put the new layer at the same position (thus having the
                //same draw order)
                rtMap.Layers.RemoveAt(layerIndex);
                rtMap.Layers.Insert(layerIndex, replace);
                replace.ForceRefresh();

                rtMap.Save();

                if (Request.Params["RESET"] == "1")
                {
                    lblMessage.Text   = "Layer filter has been reset";
                    resetLink.Visible = false;
                }
                else
                {
                    lblMessage.Text = "Layer filter has been set (to RNAME LIKE 'SCHMITT%')";
                    resetLink.Attributes["href"] = "ModifyParcelsFilter.aspx?MAPNAME=" + mapName + "&SESSION=" + session + "&RESET=1";
                }

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