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); RuntimeMapGroup group = rtMap.Groups[Request.Params["GROUPNAME"]]; if (group != null) { group.Visible = !group.Visible; rtMap.Save(); //Always save changes after modifying Page.ClientScript.RegisterStartupScript( this.GetType(), "load", "<script type=\"text/javascript\"> window.onload = function() { parent.parent.Refresh(); } </script>"); lblMessage.Text = "Group (" + group.Name + ") visible: " + group.Visible; } else { lblMessage.Text = "Group (" + group.Name + ") not found!"; } }
private void trvLegend_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { trvLegend.SelectedNode = e.Node; var meta = e.Node.Tag as LayerNodeMetadata; if (meta != null && meta.DrawSelectabilityIcon) { //Toggle layer's selectability if it's within the bounds of the selectability icon var box = new Rectangle( new Point((e.Node.Bounds.Location.X - 36) + 16, e.Node.Bounds.Location.Y), new Size(16, e.Node.Bounds.Height)); //Uncheckable items need to move 16px to the left if (!meta.Checkable) { box.Offset(-16, 0); } if (box.Contains(e.X, e.Y)) { var layer = meta.Layer; layer.Selectable = !layer.Selectable; _map.Save(); meta.IsSelectable = layer.Selectable; //TODO: This bounds is a guess. We should calculate the bounds as part of node rendering, so we know the exact bounds by which to invalidate trvLegend.Invalidate(new Rectangle(e.Node.Bounds.Location.X - 36, e.Node.Bounds.Location.Y, e.Node.Bounds.Width + 36, e.Node.Bounds.Height)); } } }
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); }
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); }