• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk MapGuide Enterprise Developer

    Reply
    Member
    Posts: 4
    Registered: ‎02-19-2013

    Set Active Selection From MapFrame

    286 Views, 1 Replies
    02-25-2013 11:00 PM

    hi everyone;
    I added some code to mapFrame file to set active selection. Bu It doesnt work

      map.Create(resourceSrvc, resId, mapName);
    
                //create an empty selection object and store it in the session repository
    
                    MgSelection sel;
                    string layerId = "";
                    string classId = "";
                    StringBuilder selectionXml = new StringBuilder();
                    MgLayerCollection layers = map.GetLayers();
                    foreach (MgLayerBase layer in layers)
                    {                
                        if (layer.GetName() == "Parcels")
                        {                        
                            layerId = layer.GetObjectId();                                                
                            classId = layer.FeatureClassName;
                            selectionXml.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><FeatureSet><Layer id=\"");
                            selectionXml.Append(layerId);
                            selectionXml.Append("\"><Class id=\"");
                            selectionXml.Append(classId);
                            selectionXml.Append("\"><ID>");
                            selectionXml.Append("LDMAAA==");
                            selectionXml.Append("</ID>");
                            selectionXml.Append("</Class>");
                            selectionXml.Append("</Layer>");
                            selectionXml.Append("</FeatureSet>");                           
                            break;
                        }
                    }
    
                    sel = new MgSelection(map,selectionXml.ToString());
                    sel.Save(resourceSrvc, mapName);

    I got an Xml String  with GetSelectionXml  which I select with mouse, And I write the same xml file into mapFrame,
    But I cant select the same parcel why it didnt work ?

    good works

    Please use plain text.
    Mentor
    Posts: 238
    Registered: ‎10-06-2008

    Re: Set Active Selection From MapFrame

    03-03-2013 04:48 PM in reply to: AliKara1

    For dumping a MgSelection out to XML, just call:

     

    MgSelection sel = ...
    String selectionXml = sel.ToXml();

    For initializing a MgSelection, if you use this constructor:

     

    MgSelection(MgMap map, String xmlSelectionString)

    Your MgSelection will be initialized with the selection based on the XML string you feed into it, eliminating the need to construct this XML fragment yourself.

     

    You should never have to manually construct this selection XML yourself.

     

    - Jackie

    Please use plain text.