[mapguide-users] Highlight features in map

Andreas Urech andreas.urech at gmail.com
Fri Dec 16 04:50:37 EST 2011


Hi!

I'm trying to highlight features in the map based on querystring variables.
I.e surfing to http://url.to.server?value=123456&field=FNR should highlight
features with FNR=123456.

Server-side logic as follows (C#, asp.net 2.0, in Default.aspx.cs,
Page_Load-function):

if (!IsPostBack) {

                if (Request.QueryString.Count > 0) {
                    string sessId = Session["MapGuideSessId"] as string;
                    MgSiteConnection siteConn = new MgSiteConnection();
                    siteConn.Open(new MgUserInformation(sessId));
                    string mapName = "MapName";
                    MgMap map = new MgMap(siteConn);

                    /* Need to create a new map?
                    map.Create(new
MgResourceIdentifier("Library://mapname/Mapname.MapDefinition"), mapName);
                    map.Save();

map.Open(siteConn.CreateService(MgServiceType.ResourceService) as
MgResourceService, mapName);
                    */


map.Open(siteConn.CreateService(MgServiceType.ResourceService) as
MgResourceService, mapName);
                    MgLayerBase layer = map.GetLayers().GetItem(0);
                    StringBuilder query = new StringBuilder();
                    MgFeatureQueryOptions queryOptions = new
MgFeatureQueryOptions();

                    /*Constructing up a selection string. Don't mind this.
*/
                    string filterField = GetQueryStringValue("field");
                    string value = GetQueryStringValue("value");
                    string[] filterVal = value.Split('|');

                    int fnrLen = filterVal.Length;

                    for (int i = 0; i < fnrLen; i++) {
                        if (i < fnrLen - 1)
                            query.Append(string.Format("{0} = {1} or",
filterField, filterVal[i]));
                        else
                            query.Append(string.Format("{0} = {1}",
filterField, filterVal[i]));
                    }

                    queryOptions.SetFilter(query.ToString());

                    MgFeatureReader reader =
layer.SelectFeatures(queryOptions);
                    MgSelection selection = new MgSelection(map);
                    selection.AddFeatures(layer, reader, 0);
                    _selectionXml = selection.ToXml();

selection.Save(siteConn.CreateService(MgServiceType.ResourceService) as
MgResourceService, mapName);
                }
                else {
                    // Utils-class sets up and creates session
                    utils = new
Utils(Request.ServerVariables["APPL_PHYSICAL_PATH"]);
                    // Store session globally
                    Session["MapGuideSessId"] = utils.SessionID;

            }

When I run this code nothing gets highlighted in the map at all. I've
debugged the code to make sure that the query works as intended and it
does. I'm guessing that my problem has something to do with the map but I
can't figure out what's wrong.
I'm using pretty much the same code when creating a selection from the
taskpane and that works like a charm.
I've been struggeling with this for several days now and I'd be very glad
if someone could help me, or at least point me in the right direction.
Thank you!

Regards,
Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20111216/488831a1/attachment.html


More information about the mapguide-users mailing list