[mapguide-users] Trying to create an ajax search thingo
Jamo
adam.jamison at portbris.com.au
Mon Apr 27 22:25:36 EDT 2009
I'm trying to populate an Ajax TabContainer with a tab for each search.
I'm getting an error for line 94: "The map definition is invalid. "
foreach (MgLayer cLayer in cadFeatures.GetLayers())
Is it best to store the information needed for each search in a MgSelection
or would it be better to extract information needed to a DataTable? I'm
trying to make it as flexible as possible..... hopefully adding some other
search type other than just DropDownList.
At the moment this runs seperate to mapguide and does not interact with the
map itself (just for testing at the moment).
-------------
Default.aspx
--------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="Searchtool_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit"
TagPrefix="cc1" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<cc1:TabContainer ID="SearchContainer" runat="server" ActiveTabIndex="0"
>
<cc1:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1"
Visible="False">
</cc1:TabPanel>
</cc1:TabContainer>
</div>
</form>
</body>
</html>
-------------------
Default.aspx.cs
-------------------
using System;
using System.Collections.Specialized;
using System.Text;
using System.Globalization;
using OSGeo.MapGuide;
using System.Web;
using System.Data;
using System.Collections;
using System.Web.UI.WebControls;
using System.Web.UI;
public partial class Searchtool_Default : System.Web.UI.Page
{
//define all selections for searches here
internal static MgSelection cadFeatures;
internal static MgSelectionBase geoFeatures;
//get selection ready for searching on
protected MgSelection createSelectionMaster(String[] Layers)
{
MapGuideApi.MgInitializeWebTier(Request.ServerVariables["APPL_PHYSICAL_PATH"]
+ "../webconfig.ini");
MgUserInformation userInfo = new MgUserInformation("Anonymous", "");
MgSite site = new MgSite();
//connect to site
site.Open(userInfo);
String sessionId = site.CreateSession();
MgSiteConnection siteConnection = new MgSiteConnection();
//open site connection
siteConnection.Open(userInfo);
MgResourceService ResourceService =
siteConnection.CreateService(MgServiceType.ResourceService) as
MgResourceService;
MgFeatureService FeatureService =
siteConnection.CreateService(MgServiceType.FeatureService) as
MgFeatureService;
MgResourceIdentifier mgResourceID = new
MgResourceIdentifier("Library://Production/PortBris/Maps/PortBris.MapDefinition");
MgMap map = new MgMap();
map.Create(ResourceService, mgResourceID, "PortBris");
MgSelection thisSel = new MgSelection();
foreach (String layer in Layers)
{
MgLayer cLayer = map.GetLayers().GetItem(layer) as MgLayer;
string layerClassName = cLayer.GetFeatureClassName();
string selectionString = thisSel.GenerateFilter(cLayer,
layerClassName);
string layerFeatureId = cLayer.GetFeatureSourceId();
MgResourceIdentifier layerFeatureResource = new
MgResourceIdentifier(layerFeatureId);
MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
queryOptions.SetFilter(selectionString);
MgFeatureReader cFeatReader =
FeatureService.SelectFeatures(layerFeatureResource, layerClassName,
queryOptions);
thisSel.AddFeatures(cLayer as MgLayerBase, cFeatReader, -1);
}
return thisSel;
}
//return an array
protected String[] StringArray(String CommaSeperatedLayers)
{
return CommaSeperatedLayers.Split(",".ToCharArray());
}
//add a DDL search type to the TabContainer
//ToDo: add list search capabilities and filtering
protected DropDownList addSearchDDL(Control controlToAddTo, String
searchDDLId, String labelText)
{
Label cLabel = new Label();
cLabel.Text = labelText;
controlToAddTo.Controls.Add(cLabel);
DropDownList cDDL = new DropDownList();
cDDL.ID = searchDDLId;
controlToAddTo.Controls.Add(cDDL);
return cDDL;
}
//add a new Tab to the Ajax TabContainer
//each tab is a different search type
protected AjaxControlToolkit.TabPanel
AddTab(AjaxControlToolkit.TabContainer TabCont, String TabID, String Header)
{
AjaxControlToolkit.TabPanel newTab = new AjaxControlToolkit.TabPanel();
newTab.ID = TabID;
newTab.HeaderText = Header;
TabCont.Tabs.Add(newTab);
TabCont.TabIndex = 1;
return newTab;
}
//init all search engines
//ToDo: Add more searches
//ToDo: Add Primary Search properties
//ToDo: Add Advanced Search properties
protected void Page_Load(object sender, EventArgs e)
{
//add tab for search
AjaxControlToolkit.TabPanel cadSearch =
AddTab(SearchContainer,"cadSearch","Cadastre");
//assign all cadastre features to the cadastre selection set.
cadFeatures = createSelectionMaster(StringArray("cadFREE,cadPPLE"));
//find if control with ID already exists on this tabPanel.
foreach (MgLayer cLayer in cadFeatures.GetLayers())
{
//write out each Properties search Drop down List
foreach (MgPropertyDefinition cPropDef in
cLayer.GetClassDefinition().GetProperties())
{
if (cadSearch.Controls.Contains(addSearchDDL(cadSearch,
cPropDef.Name, cPropDef.Description)))
Response.Write("control added already");
}
//MgFeatureReader cFeatReader =
cadSearchResults.GetSelectedFeatures(cLayer as MgLayerBase,
cLayer.GetClassName(),true)
//while(cFeatReader.ReadNext())
//{
// int cPropCount =
cFeatReader.GetClassDefinition().GetProperties().Count;
//}
}
}
}
--
View this message in context: http://n2.nabble.com/Trying-to-create-an-ajax-search-thingo-tp2729762p2729762.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list