Wednesday, 13 March 2013

MapGuide tidbits: The golden rule of selection

I probably have mentioned about this in passing in a previous post, but it's probably worth repeating in a separate dedicated post because it's very important. The golden rule of selection:

For a layer to be selectable, it's feature class must have identity properties

If you can't select objects on from a layer on a map, always refer to the above rule. It will be true 99% of the time.

Now where this would commonly be the case (no identity properties) is if you are creating a layer off of a database view, where FDO is generally not clever enough to infer the identity properties from that view. In such cases, schema overrides come to the rescue allowing to you override how the FDO provider is supposed to interpret your physical data store.

Now surprisingly, this rule does not just apply to you users and developers building MapGuide applications. It equally applies to us developers hacking on the MapGuide core.

Case in point, a show-stopping bug relating to the RFC123 optimizations. After scratching my head for days wondering why a SQL Server RFC123-optimized layer was not selectable, I remembered about this rule and it lit a light bulb, giving me greater clues about the source of the problems. Turns out the MgFeatureReader wrapping our FDO join query result used for rendering/stylization presented a class definition that (you guessed it) did not have any identity properties. So when MapGuide needed to extract the class definition from the MgFeatureReader to build a selection set, there was nothing there to build a selection out of!

After some hacking around of the class definition that's returned by the reader in such cases, we now have selections working again!

So it helps to memorize this rule. It won't let you down because it sure didn't let me down.

No comments: