Friday 22 March 2013

MapGuide tidbits: The MgMap constructor

Question. How do you create your MgMap objects. Like this?

MgMap map = new MgMap();

If you do, please stop. Not only is this way of creating a MgMap object long been deprecated (thanks to RFC129, you'll now get nice C#/java compiler warnings about it), but you lose access to a whole bunch of convenience APIs that have been introduced with RFC9 (ie. MapGuide Open Source 1.2)
  • MgLayerBase.GetClassDefinition()
  • MgLayerBase.SelectFeatures()
  • MgLayerBase.SelectAggregate()
  • MgLayerBase.UpdateFeatures()
  • MgSelectionBase.GetSelectedFeatures()
These APIs are only available if your MgMap was created like so:

MgSiteConnection siteConn = new MgSiteConnection();
...
MgMap map = new MgMap(siteConn);

This constructor is deprecated along with a whole bunch of other related MgMap methods. See the RFC for more information. You should be using the alternatives as described in that RFC.

No comments: