[mapguide-users] SelectFeatures doesn't show in map

Vishaal vs2k2000 at rediffmail.com
Fri Jun 20 01:09:11 EDT 2008


Hi Viva_Rose,

if you are doing an attribute query then this code is fine enough though
some modifications are needed. please have a look at the code which i have
inserted . But if you want to do a spatial query then you need to get the
geometry of the district and modify the code accordingly and use spatial
filter. as of now you can try with the following code ( Hope it will solve
your problem):

//*** dnt do the query on page load. if it is a user query after some user
inputs then make a function and cal that function on the button click

//protected void Page_Load(object sender, EventArgs e)

protected void makeQuery(object sender, EventArgs e)
   
    {
        try
        {

            String name = Request.QueryString["id"];
            TxtInvId.Text = name;

            

            String newName = name;
            newName = newName.Substring(0, 2);
            

            // Initialize the web-tier.
            String realPath = Request.ServerVariables["APPL_PHYSICAL_PATH"];
            String configPath = realPath + "..\\webconfig.ini";
            MapGuideApi.MgInitializeWebTier(configPath);

            // Connect to the site
            MgUserInformation userInfo = new MgUserInformation("Anonymous",
"");
            MgSite site = new MgSite();
            site.Open(userInfo);
            String sessionId = site.CreateSession();

            //Associate a session ID with the MgSiteConnection Object
            MgUserInformation userInfo_new = new
MgUserInformation(sessionId);
            MgSiteConnection siteConnection = new MgSiteConnection();
            siteConnection.Open(userInfo_new);

            MgResourceService resourceSrvc =
(MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
// ****  make changes here****//

MgFeatureService featureService =
(MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);

            MgMap map = new MgMap(siteConnection);
            MgResourceIdentifier resId = new
MgResourceIdentifier("Library://CRMIS_GIS/GammerliteMap.MapDefinition");
            String mapName = resId.GetName();
            map.Create(resourceSrvc, resId, mapName);

            MgResourceIdentifier mapStateId = new
MgResourceIdentifier("Session:" + sessionId + "//" + mapName + "." +
MgResourceType.Map);
            map.Save(resourceSrvc, mapStateId);
            //Response.Write("Done. The map name is " + map.GetName());

            // open the map
            map.Open(mapName);

            if (newName == "CU")
            {
            
            MgFeatureQueryOptions districtQuery = new
MgFeatureQueryOptions();
            districtQuery.SetFilter("SPATIALID LIKE '" + TxtInvId.Text +
"%'");

//**** Make changes here as explained ****//

MgResourceIdentifier resId = new
MgResourceIdentifier("Library://---------.FeatureSource");
            MgFeatureReader featureReader =
featureService.SelectFeatures(resId, " your class name", districtQuery );


       //     MgLayer layer = map.GetLayers().GetItem("Gam_Culvert") as
MgLayer;
       //     MgFeatureReader featureReader =
layer.SelectFeatures(districtQuery);
      //    featureReader.ReadNext();

            
        //    featureReader = layer.SelectFeatures(districtQuery);

//*****  Make Changes Here **********//

          //Highlight the query result on the map

            MgSelection selection = new MgSelection(map);
            MgLayer layer = map.GetLayers().GetItem("Gam_Culvert") as
MgLayer;
            featureReader = featureService.SelectFeatures(resId, " your
class name", districtQuery );
           
    while (featureReader.ReadNext())
            {
            selection.AddFeatures(layer, featureReader, 0);
            selection.Save(resourceSrvc , mapName);
            String selectionXml = selection.ToXml();
            litSelectionXml.Text = Server.HtmlEncode(selectionXml);
            hfSelectionXml.Value = selectionXml;
}
}
catch(MgException mge)
{
        Response.Write(mge.GetMessage());
        Response.Write(mge.GetDetails());
}
}

Viva_Rose wrote:
> 
> Hi all,
> 
> I've problem to show the selected features in my map but in the status bar
> it show that the layer are selected. I try to show the selected feature
> based on query input from user. Is it i've done wrong in my coding? here
> is my code : -
> 
> protected void Page_Load(object sender, EventArgs e)
>    
>     {
>         try
>         {
> 
>             String name = Request.QueryString["id"];
>             TxtInvId.Text = name;
> 
>             
> 
>             String newName = name;
>             newName = newName.Substring(0, 2);
>             
> 
>             // Initialize the web-tier.
>             String realPath =
> Request.ServerVariables["APPL_PHYSICAL_PATH"];
>             String configPath = realPath + "..\\webconfig.ini";
>             MapGuideApi.MgInitializeWebTier(configPath);
> 
>             // Connect to the site
>             MgUserInformation userInfo = new
> MgUserInformation("Anonymous", "");
>             MgSite site = new MgSite();
>             site.Open(userInfo);
>             String sessionId = site.CreateSession();
> 
>             //Associate a session ID with the MgSiteConnection Object
>             MgUserInformation userInfo_new = new
> MgUserInformation(sessionId);
>             MgSiteConnection siteConnection = new MgSiteConnection();
>             siteConnection.Open(userInfo_new);
> 
>             MgResourceService resourceSrvc =
> (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
>             MgMap map = new MgMap(siteConnection);
>             MgResourceIdentifier resId = new
> MgResourceIdentifier("Library://CRMIS_GIS/GammerliteMap.MapDefinition");
>             String mapName = resId.GetName();
>             map.Create(resourceSrvc, resId, mapName);
> 
>             MgResourceIdentifier mapStateId = new
> MgResourceIdentifier("Session:" + sessionId + "//" + mapName + "." +
> MgResourceType.Map);
>             map.Save(resourceSrvc, mapStateId);
>             //Response.Write("Done. The map name is " + map.GetName());
> 
>             // open the map
>             map.Open(mapName);
> 
>             if (newName == "CU")
>             {
>             
>             MgFeatureQueryOptions districtQuery = new
> MgFeatureQueryOptions();
>             districtQuery.SetFilter("SPATIALID LIKE '" + TxtInvId.Text +
> "%'");
> 
>             MgLayer layer = map.GetLayers().GetItem("Gam_Culvert") as
> MgLayer;
>             MgFeatureReader featureReader =
> layer.SelectFeatures(districtQuery);
>           featureReader.ReadNext();
> 
>             
>             featureReader = layer.SelectFeatures(districtQuery);
> 
>             
>             MgSelection selection = new MgSelection(map);
>             selection.AddFeatures(layer, featureReader, 0);
>             String selectionXml = selection.ToXml();
> 
>             litSelectionXml.Text = Server.HtmlEncode(selectionXml);
> 
>             hfSelectionXml.Value = selectionXml;
> 
> 

-- 
View this message in context: http://www.nabble.com/SelectFeatures-doesn%27t-show-in-map-tp18022616p18023166.html
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list