How to access Map control from plugins in the DemoMap DotSpatial program

145 Views Asked by At

I am using the DotSpatial DemoMap as the main frontend in my application, and I created a number of plugins to be loaded into DemoMap at launch and they are working. However, I am not very clear how to allow my custom plugins to access the main map control.

I see in the main form of DemoMap, there is App.Map property as the handle to the main map control (am I right?), if this is true, then I suppose I need to pass it into each plugin when it is initiated?

Bottom line, what is the most efficient/best way to allow the main map control to be accessible throughout the entire application from all custom plugins? (I am using DotSpatial 2.0 libraries on .Net 4.5.2)

1

There are 1 best solutions below

1
On BEST ANSWER

Derive from Extension and access the AppManger-supplied map via the App.Map property.

An extension (plugin) can access the map via the App.Map property. The is accessible to any class which derives from Extension so it doesn't need to be passed into the plugin. The AppManager which lets you access that property is injected via MEF automatically.

Here's a sample extension

public class SimpleMapPlugin : Extension
{
    public SimpleMapPlugin()
    {
        // Access App.Map as needed.
    }
}