[mapguide-users] Re: How to use setselection in fusion?
lzzgeo
lzzgeo at yahoo.cn
Thu May 6 02:06:39 EDT 2010
tks a lots.
I will translate it into php, hope it works!
and, I am trying the function--Query of mapwidget, but it donn't support attribite filter.
--- 10年5月6日,周四, miansi [via OSGeo.org] <ml-node+5009766-789116947-393770 at n2.nabble.com> 写道:
发件人: miansi [via OSGeo.org] <ml-node+5009766-789116947-393770 at n2.nabble.com>
主题: Re: How to use setselection in fusion?
收件人: "lzzgeo" <lzzgeo at yahoo.cn>
日期: 2010年5月6日,周四,上午12:21
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 :-)
1. Build Selection XML
Note: searchString is your query (ID==1 || ID==2).
var mgMapName = requestParams["mapName"];
var mgSessionId = requestParams["sessionId"];
// Initialize the web-tier.
var realPath = this.Request.ServerVariables["APPL_PHYSICAL_PATH"];
var configPath = realPath + "..\\webconfig.ini";
MapGuideApi.MgInitializeWebTier(configPath);
// Connect to the site.
var userInfo = new MgUserInformation(mgSessionId);
var conn = new MgSiteConnection();
conn.Open(userInfo);
// get the map
var map = new MgMap(conn);
map.Open(mgMapName);
// Perform any necessary transforms on the layer name or ids
var mapObjects = TransformInputLayer(requestParams["objectTypes"].Split(','), requestParams["objectIds"].Split(','));
// Select the objects on the map
var layers = map.GetLayers();
var selection = new MgSelection(map);
foreach (var layer in layers)
{
var searchString = new StringBuilder();
// Build out the search expression for the map layer
foreach (var mapObject in mapObjects.Where(rec => rec.LayerName == layer.Name))
{
if (searchString.Length > 0)
{
searchString.Append(" OR ");
}
searchString.AppendFormat("Id = '{0}'", mapObject.ObjectId);
}
// Execte the search on the layer
if (searchString.Length > 0)
{
var displayIdQuery = new MgFeatureQueryOptions();
displayIdQuery.SetFilter(searchString.ToString());
var featureReader = layer.SelectFeatures(displayIdQuery);
selection.AddFeatures(layer, featureReader, AppSettings.MgSelectionFilterSize);
featureReader.Close();
featureReader.Dispose();
}
}
var selectionXml = selection.ToXml();
map.Dispose();
2. Now the fun part I am working on right now - pass your selection to Fusion.
I used to have AJAX Viewer and I used following logic:
I have some aspx page (SetMapSelection.aspx)
SetMapSelection.aspx:
<head runat="server">
<title>Set Map Selection Page</title>
<script type="text/javascript" language="javascript" src="http://localhost/mapguide/fusion/layers/MapGuide/MapGuideViewerApi.js"></script>
<script type="text/javascript">
// Emit the following function and assocate it with the onLoad event for
// the page so that it gets executed when this page loads in the browser.
// The function calls the SetSelectionXML method on the Viewer Frame,
// which updates the current selection on the viewer and the server.
function OnPageLoad() {
var selectionXml = document.getElementById("hfSelectionXml").getAttribute("value");
parent.SetSelectionXML(selectionXml);
parent.ExecuteMapAction(10);
parent.ExecuteMapAction(99);
}
</script>
</head>
<body onload="OnPageLoad()">
<form id="formM5Logic" runat="server">
<div>
<asp:TextBox ID="hfSelectionXml" runat="server"></asp:TextBox>
<asp:HiddenField ID="HiddenFieldM5Logic" runat="server"></asp:HiddenField>
</div>
</form>
</body>
SetMapSelection.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
// Disable the client side cache
this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
// Write to session which page is loaded, this is used by the context help to determine the
// approproiate help page to load.
this.Session.Add(SessionStateBase.HELP_PAGE_REFERENCE, this.Request.Path);
// Get the input parameters into the selection
var requestParams = this.Request.HttpMethod == "GET" ? this.Request.QueryString : this.Request.Form;
var mgMapName = requestParams["mapName"];
var mgSessionId = requestParams["sessionId"];
// Initialize the web-tier.
var realPath = this.Request.ServerVariables["APPL_PHYSICAL_PATH"];
var configPath = realPath + "..\\webconfig.ini";
MapGuideApi.MgInitializeWebTier(configPath);
// Connect to the site.
var userInfo = new MgUserInformation(mgSessionId);
var conn = new MgSiteConnection();
conn.Open(userInfo);
// get the map
var map = new MgMap(conn);
map.Open(mgMapName);
// Perform any necessary transforms on the layer name or ids
var mapObjects = TransformInputLayer(requestParams["objectTypes"].Split(','), requestParams["objectIds"].Split(','));
// Select the objects on the map
var layers = map.GetLayers();
var selection = new MgSelection(map);
foreach (var layer in layers)
{
var searchString = new StringBuilder();
// Build out the search expression for the map layer
foreach (var mapObject in mapObjects.Where(rec => rec.LayerName == layer.Name))
{
if (searchString.Length > 0)
{
searchString.Append(" OR ");
}
searchString.AppendFormat("Id = '{0}'", mapObject.ObjectId);
}
// Execte the search on the layer
if (searchString.Length > 0)
{
var displayIdQuery = new MgFeatureQueryOptions();
displayIdQuery.SetFilter(searchString.ToString());
var featureReader = layer.SelectFeatures(displayIdQuery);
selection.AddFeatures(layer, featureReader, AppSettings.MgSelectionFilterSize);
featureReader.Close();
featureReader.Dispose();
}
}
var selectionXml = selection.ToXml();
map.Dispose();
this.hfSelectionXml.Text = selectionXml;
}
So as you can see - Page_Load builds selection XML and OnPageLoad passes it to AJAX Viewer frame for further processing.
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:
function OnPageLoad()
{
var selectionXml = document.getElementById("hfSelectionXml").getAttribute("value");
var vf = top.document.getElementById('frmMap');
vf.document.forms[0].GetFusionMapWidget.setSelection(selectionXml, true);
}
Note:
In my app I have 2 iframes - Map Viewer and Application frame. frmMap is Map Viewer frame:
<iframe name="frmDefault" id="frmDefault" class="frameBoxGeneral" frameborder="0" src="Pages/Loading.aspx">
</iframe>
<iframe name="frmMap" id="frmMap" src="<%= AppSettings.MgServicesUrl %>/fusion/templates/mapguide/standard/index.html"
class="frameBoxMap" frameborder="0"></iframe>
View message @ http://osgeo-org.1803224.n2.nabble.com/How-to-use-setselection-in-fusion-tp5001965p5009766.html
To unsubscribe from How to use setselection in fusion?, click here.
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/How-to-use-setselection-in-fusion-tp5001965p5012703.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20100505/4dc6f4cb/attachment.html
More information about the mapguide-users
mailing list