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); string xml = Request.Params["SELECTION"]; //The map selection contains one or more layer selections //each containing a one or more sets of identity property values //(because a feature may have multiple identity properties) MapSelection selection = new MapSelection(rtMap, HttpUtility.UrlDecode(xml)); if (selection.Count > 0) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < selection.Count; i++) { MapSelection.LayerSelection layerSel = selection[i]; sb.Append("<p>Layer: " + layerSel.Layer.Name + " (" + layerSel.Count + " selected item)"); sb.Append("<table>"); for (int j = 0; j < layerSel.Count; j++) { sb.Append("<tr>"); object[] values = layerSel[j]; for (int k = 0; k < values.Length; k++) { sb.Append("<td>"); sb.Append(values[k].ToString()); sb.Append("</td>"); } sb.AppendFormat("<td><a href='FeatureInfo.aspx?MAPNAME={0}&SESSION={1}&LAYERID={2}&ID={3}'>More Info</a></td>", rtMap.Name, conn.SessionID, layerSel.Layer.ObjectId, HttpUtility.UrlEncode(layerSel.EncodeIDString(values))); sb.Append("</tr>"); } sb.Append("</table>"); lblMessage.Text = "Showing IDs of selected features"; result.InnerHtml = sb.ToString(); } } else { lblMessage.Text = "Nothing selected. Select some features first then run this sample again."; } }
protected void btnSelect_Click(object sender, EventArgs e) { string agent = ConfigurationManager.AppSettings["MapAgentUrl"]; MAPNAME.Value = Request.Params["MAPNAME"]; SESSION.Value = Request.Params["SESSION"]; IServerConnection conn = ConnectionProviderRegistry.CreateConnection( "Maestro.Http", "Url", agent, "SessionId", SESSION.Value); IMappingService mpSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping); string rtMapId = "Session:" + conn.SessionID + "//" + MAPNAME.Value + ".Map"; RuntimeMap rtMap = mpSvc.OpenMap(rtMapId); //Get the selected layer RuntimeMapLayer rtLayer = rtMap.Layers.GetByObjectId(ddlLayers.SelectedValue); //Query using the user filter IFeatureReader reader = conn.FeatureService.QueryFeatureSource( rtLayer.FeatureSourceID, rtLayer.QualifiedClassName, txtFilter.Text); //Get the selection set MapSelection sel = new MapSelection(rtMap); MapSelection.LayerSelection layerSel = null; if (!sel.Contains(rtLayer)) { sel.Add(rtLayer); } layerSel = sel[rtLayer]; //Clear any existing selections layerSel.Clear(); //Populate selection set with query result int added = layerSel.AddFeatures(reader, -1); //Generate selection string string selXml = sel.ToXml(); //Generate a client-side set selection and execute a "Zoom to Selection" afterwards Page.ClientScript.RegisterStartupScript( this.GetType(), "load", "<script type=\"text/javascript\"> window.onload = function() { parent.parent.GetMapFrame().SetSelectionXML('" + selXml + "'); parent.parent.ExecuteMapAction(10); } </script>"); lblMessage.Text = added + " features in " + rtLayer.Name + " selected"; }