How to Add Support for Loading DotSpatial.Plugins.Ribbon

Introduction

DotSpatial is an open-source project that contains controls which can be used to manipulate and display geographic information. DotSpatial can be extended with a number of extensions. Some of these extensions require the application developer provide additional support before they will load. We look at adding support for those that require a Shell export, which includes the extensions providing ribbon and docking features.

Getting Started

You will need to implement basic extensions loading support as described: How to Support Loading Extensions in DotSpatial. For practical purposes, we assume you are coming to this article after having completed the previous one.

Extensions may depend on other extensions being available. They may also “light up” synergistically when other extensions are available. This behavior is made possible through the Managed Extension Framework (MEF) via a set of Import and Export attributes. Since MEF is available on MSDN, instead of explaining how it works, I’ll cover how the DockManager, Ribbon, and ToolManager plugins use it.

Windows Forms

In order for an extension like the Ribbon to register itself properly with the main form of your application, it must be told what form that is. Your application could include a number of forms, so one of them must be specified as the Shell.

This functionality relies on MEF, and not on DotSpatial, because it is not directly related to mapping. So, instead of creating an interface in DotSpatial, we provide a convention to be followed.

Specifying a Shell

The application should Export a field or property with the contact name of “Shell” and type of ContainerControl. In MapWindow 6, this is added as a field to the MainForm class (as shown).

[Export("Shell", typeof(ContainerControl))]
private static ContainerControl Shell;

At any point before LoadExtensions() is called, this field should be set to the form that is considered the Shell. We do this in the MainForm constructor in MapWindow 6.

Shell = this;
appManager.LoadExtensions();

The Ribbon extension imports Shell when it is being loaded and adds a ribbon control to the associated form’s control collection. You can similarly export other types from one extension to another, and create a more loosely coupled set of classes.

Points of Interest

You will want to obtain a copy of the Ribbon or DockManager so that you can test your implementation. These can be pulled as packages from the DotSpatial feed (gallery).

Advertisements

9 thoughts on “How to Add Support for Loading DotSpatial.Plugins.Ribbon

  1. Pingback: Anwendungsoberfläche erstellen « KnowHow-Developer-Blog

  2. Hello! I love your work here but I can’t get this step to work for me. Pressing the feed link just downloads me a XML-file. Further explanations on how to get the ribbon to work would be lovely! Thanks!

    • The feed displays the package information in xml. If you wanted to download the package directly, you could find the correct entry and look for the tag with content type=”application/zip”. The current version is here. Each package is a zip file which you will want to unpack. In future (1.3+) versions of the Extension Manager, you will be able to search for the Ribbon from the Online tab. Then, you can install the package you are interested in and click Show extensions folder to grab a copy.

      In general, we have recommended that your application be setup to download the latest version when it is first used. An example of how to do this is in the Extension Manager.

      • Thank you, however I still don’t get it to work.

        This is my entire code:
        Imports DotSpatial.Controls
        Imports System.ComponentModel.Composition

        Public Class Form1
        Private Shared Shell As ContainerControl

        Public Sub New()
        ‘ This call is required by the designer.
        InitializeComponent()

        ‘ Add any initialization after the InitializeComponent() call.
        Shell = Me
        Me.AppManager1.LoadExtensions()
        End Sub

        Private Sub uxOpenFile_Click(sender As Object, e As EventArgs) Handles uxOpenFile.Click
        Me.uxMap.AddLayer()
        End Sub

        Private Sub uxZoomIn_Click(sender As Object, e As EventArgs) Handles uxZoomIn.Click
        Me.uxMap.ZoomIn()
        End Sub

        Private Sub uxZoomWide_Click(sender As Object, e As EventArgs) Handles uxZoomWide.Click
        Me.uxMap.ZoomToMaxExtent()
        End Sub

        Private Sub uxPan_Click(sender As Object, e As EventArgs) Handles uxPan.Click
        Me.uxMap.FunctionMode = FunctionMode.Pan
        End Sub
        End Class

        And I have added all the DLL files from the net40-client folder in the ribbon zip file into the Plugins folder.
        The buttons all work nice, but not the ribbon.

      • I’m not sure what you mean by

        The buttons all work nice, but not the ribbon

        If you are looking for the default menu items shipped in MapWindow, they are in the MenuBar extension. MenuBar creates the menu items, Ribbon hosts them in a ribbon control.

      • One line disappeared from my last comment, under “Public Class Form1” so is it:
        Private Shared Shell As ContainerControl

        (spaces added for the signs to hopefully be able to post the line here.)

      • Okay, that didn’t work….
        Here’s my line again.
        “Smaller then sign”Export(“Shell”, GetType(ContainerControl))”Greater then sign” Private Shared Shell As ContainerControl

      • (This is a reply to the post made by MUDNUG on JUNE 8, 2012, 7:35 PM)

        Thank you, I didn’t know that I also needed the menubar and dockingmanager extensions to get the ribbon to work.
        Everything works ok now, thank you.

  3. @MARKUS PERSSON. Can u please let me know how you accomplished that. I understand dotspatial well but still in confusion with adding support to extensions. I referred all the articles by mudnug including how to add support to loading extensions, composing an application by…, how to support loading extensions… still couldn’t get.
    Asking you help, considering mudnug and others will be busy.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s