<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">tks a lots.<br><br>I will translate it into php, hope it works!<br><br>and, I am trying the function--Query of mapwidget, but it donn't support attribite filter.<br><br>--- <b>10年5月6日,周四, miansi [via OSGeo.org] <i><<a href="/user/SendEmail.jtp?type=node&node=5012703&i=0" target="_top" rel="nofollow">[hidden email]</a>></i></b> 写道:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>发件人: miansi [via OSGeo.org] <<a href="/user/SendEmail.jtp?type=node&node=5012703&i=1" target="_top" rel="nofollow">[hidden email]</a>><br>主题: Re: How to use setselection in fusion?<br>收件人: "lzzgeo" <<a href="/user/SendEmail.jtp?type=node&node=5012703&i=2" target="_top" rel="nofollow">[hidden email]</a>><br>日期: 2010年5月6日,周四,上午12:21<br><br><div id="yiv1073787517">
That is what I am trying to do right now. I am working with .NET. So I will share what I am doing and maybe that will help :-)
<br><br>1. Build Selection XML
<br><br>Note: searchString is your query (ID==1 || ID==2).
<br><br><br> var mgMapName = requestParams["mapName"];
<br> var mgSessionId = requestParams["sessionId"];
<br><br> // Initialize the web-tier.
<br> var realPath = this.Request.ServerVariables["APPL_PHYSICAL_PATH"];
<br> var configPath = realPath + "..\\webconfig.ini";
<br> MapGuideApi.MgInitializeWebTier(configPath);
<br><br> // Connect to the site.
<br> var userInfo = new MgUserInformation(mgSessionId);
<br> var conn = new MgSiteConnection();
<br> conn.Open(userInfo);
<br><br> // get the map
<br> var map = new MgMap(conn);
<br> map.Open(mgMapName);
<br><br> // Perform any necessary transforms on the layer name or ids
<br> var mapObjects = TransformInputLayer(requestParams["objectTypes"].Split(','), requestParams["objectIds"].Split(','));
<br><br> // Select the objects on the map
<br> var layers = map.GetLayers();
<br> var selection = new MgSelection(map);
<br><br> foreach (var layer in layers)
<br> {
<br> var searchString = new StringBuilder();
<br><br> // Build out the search expression for the map layer
<br> foreach (var mapObject in mapObjects.Where(rec => rec.LayerName == layer.Name))
<br> {
<br> if (searchString.Length > 0)
<br> {
<br> searchString.Append(" OR ");
<br> }
<br> searchString.AppendFormat("Id = '{0}'", mapObject.ObjectId);
<br> }
<br><br> // Execte the search on the layer
<br> if (searchString.Length > 0)
<br> {
<br> var displayIdQuery = new MgFeatureQueryOptions();
<br> displayIdQuery.SetFilter(searchString.ToString());
<br><br> var featureReader = layer.SelectFeatures(displayIdQuery);
<br> selection.AddFeatures(layer, featureReader, AppSettings.MgSelectionFilterSize);
<br> featureReader.Close();
<br> featureReader.Dispose();
<br> }
<br> }
<br><br> var selectionXml = selection.ToXml();
<br> map.Dispose();
<br><br>2. Now the fun part I am working on right now - pass your selection to Fusion.
<br>I used to have AJAX Viewer and I used following logic:
<br>I have some aspx page (SetMapSelection.aspx)
<br><br><br><b>SetMapSelection.aspx:</b><br><br><head runat="server">
<br> <title>Set Map Selection Page</title>
<br><br> <script type="text/javascript" language="javascript" src="<a rel="nofollow" target="_blank" href="http://localhost/mapguide/fusion/layers/MapGuide/MapGuideViewerApi.js" link="external">http://localhost/mapguide/fusion/layers/MapGuide/MapGuideViewerApi.js</a>"></script>
<br><br> <script type="text/javascript">
<br> // Emit the following function and assocate it with the onLoad event for
<br> // the page so that it gets executed when this page loads in the browser.
<br> // The function calls the SetSelectionXML method on the Viewer Frame,
<br> // which updates the current selection on the viewer and the server.
<br> function OnPageLoad() {
<br> var selectionXml = document.getElementById("hfSelectionXml").getAttribute("value");
<br><br> parent.SetSelectionXML(selectionXml);
<br> parent.ExecuteMapAction(10);
<br> parent.ExecuteMapAction(99);
<br><br> }
<br> </script>
<br><br></head>
<br><body onload="OnPageLoad()">
<br> <form id="formM5Logic" runat="server">
<br> <div>
<br> <asp:TextBox ID="hfSelectionXml" runat="server"></asp:TextBox>
<br> <asp:HiddenField ID="HiddenFieldM5Logic" runat="server"></asp:HiddenField>
<br> </div>
<br> </form>
<br></body>
<br><br><br><b>SetMapSelection.aspx.cs:</b><br><br> protected void Page_Load(object sender, EventArgs e)
<br> {
<br> // Disable the client side cache
<br> this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
<br><br> // Write to session which page is loaded, this is used by the context help to determine the
<br> // approproiate help page to load.
<br> this.Session.Add(SessionStateBase.HELP_PAGE_REFERENCE, this.Request.Path);
<br><br> // Get the input parameters into the selection
<br> var requestParams = this.Request.HttpMethod == "GET" ? this.Request.QueryString : this.Request.Form;
<br> var mgMapName = requestParams["mapName"];
<br> var mgSessionId = requestParams["sessionId"];
<br><br> // Initialize the web-tier.
<br> var realPath = this.Request.ServerVariables["APPL_PHYSICAL_PATH"];
<br> var configPath = realPath + "..\\webconfig.ini";
<br> MapGuideApi.MgInitializeWebTier(configPath);
<br><br> // Connect to the site.
<br> var userInfo = new MgUserInformation(mgSessionId);
<br> var conn = new MgSiteConnection();
<br> conn.Open(userInfo);
<br><br> // get the map
<br> var map = new MgMap(conn);
<br> map.Open(mgMapName);
<br><br> // Perform any necessary transforms on the layer name or ids
<br> var mapObjects = TransformInputLayer(requestParams["objectTypes"].Split(','), requestParams["objectIds"].Split(','));
<br><br> // Select the objects on the map
<br> var layers = map.GetLayers();
<br> var selection = new MgSelection(map);
<br><br> foreach (var layer in layers)
<br> {
<br> var searchString = new StringBuilder();
<br><br> // Build out the search expression for the map layer
<br> foreach (var mapObject in mapObjects.Where(rec => rec.LayerName == layer.Name))
<br> {
<br> if (searchString.Length > 0)
<br> {
<br> searchString.Append(" OR ");
<br> }
<br> searchString.AppendFormat("Id = '{0}'", mapObject.ObjectId);
<br> }
<br><br> // Execte the search on the layer
<br> if (searchString.Length > 0)
<br> {
<br> var displayIdQuery = new MgFeatureQueryOptions();
<br> displayIdQuery.SetFilter(searchString.ToString());
<br><br> var featureReader = layer.SelectFeatures(displayIdQuery);
<br> selection.AddFeatures(layer, featureReader, AppSettings.MgSelectionFilterSize);
<br> featureReader.Close();
<br> featureReader.Dispose();
<br> }
<br> }
<br><br> var selectionXml = selection.ToXml();
<br> map.Dispose();
<br> this.hfSelectionXml.Text = selectionXml;
<br> }
<br><br>So as you can see - Page_Load builds selection XML and OnPageLoad passes it to AJAX Viewer frame for further processing.
<br><br>What I am puzzled with is to how to get a reference to Fusion, so I can pass my selection to Fusion. Something like this:
<br><br> function OnPageLoad()
<br> {
<br> var selectionXml = document.getElementById("hfSelectionXml").getAttribute("value");
<br><br> var vf = top.document.getElementById('frmMap');
<br><br> vf.document.forms[0].GetFusionMapWidget.setSelection(selectionXml, true);
<br> }
<br><br>Note:
<br>In my app I have 2 iframes - Map Viewer and Application frame. frmMap is Map Viewer frame:
<br><br> <iframe name="frmDefault" id="frmDefault" class="frameBoxGeneral" frameborder="0" src="Pages/Loading.aspx">
<br> </iframe>
<br> <iframe name="frmMap" id="frmMap" src="<%= AppSettings.MgServicesUrl %>/fusion/templates/mapguide/standard/index.html"
<br> class="frameBoxMap" frameborder="0"></iframe>
<br>
<br><br>
<hr color="#cccccc" noshade="noshade" size="1">
<div style="color: rgb(102, 102, 102); font: 11px tahoma,geneva,helvetica,arial,sans-serif;">
View message @ <a rel="nofollow" target="_blank" href="http://osgeo-org.1803224.n2.nabble.com/How-to-use-setselection-in-fusion-tp5001965p5009766.html" link="external">http://osgeo-org.1803224.n2.nabble.com/How-to-use-setselection-in-fusion-tp5001965p5009766.html</a>
<br>To unsubscribe from How to use setselection in fusion?, <a rel="nofollow" target="_blank" link="external">click here</a>.
</div>
<br>
</div></blockquote></td></tr></table><br>
<br><hr align="left" width="300">
View this message in context: <a href="http://osgeo-org.1803224.n2.nabble.com/How-to-use-setselection-in-fusion-tp5001965p5012703.html">Re: How to use setselection in fusion?</a><br>
Sent from the <a href="http://osgeo-org.1803224.n2.nabble.com/MapGuide-Users-f1803227.html">MapGuide Users mailing list archive</a> at Nabble.com.<br>