「Dotspatial」を利用して、複数のマップを並べて表示するプラグインの改訂

前回作成した複数のマップを並べて表示するプラグインの改訂を行いました。
・サブマップのレイヤの非表示を設定できるよう、サブマップ用のレイヤツリーを作成
・マップ及びサブマップのタブの×ボタンを削除

1.複数のマップを並べて表示するプラグイン(SubMapView)の改訂

SubMapViewプラグインに、サブマップ用のレイヤツリー変更用のボタンを追加します。
このボタンをクリックすると、サブマップ用のレイヤツリーが作成されます。このレイヤツリーは、メインマップと独立しているため、レイヤの情報を変更した場合でも影響しません。

namespace DotSpatial.Plugins.SubMapView
{
    public class SubMapViewPlugin : Extension
    {
        private void AddButtons()
        {
            var groupCaption = "地図の表示";
            var menuContainerKey = "並べて表示";
            this.App.HeaderControl.Add(new SeparatorItem(ViewMenuKey, groupCaption) { SortOrder = 11 });

            var mc = new MenuContainerItem()
            {
                Key = menuContainerKey,
                Caption = menuContainerKey,
                LargeImage = Resources.SplitMap_32x32,
                GroupCaption = groupCaption,
                RootKey = ViewMenuKey,
            };
            base.App.HeaderControl.Add(mc);

            this.btnSubMapView = new SimpleActionItem("並べて表示", this.OnSubMapViewClick)
            {
                MenuContainerKey = menuContainerKey,
                GroupCaption = groupCaption,
                SmallImage = Resources.SplitMap_32x32,
                ToolTipText = "2つの地図を並べて表示します",
                RootKey = ViewMenuKey,
                ToggleGroupKey = menuContainerKey
            };
            this.App.HeaderControl.Add(this.btnSubMapView);
            this.btnSubMapLegend = new SimpleActionItem("表示レイヤの選択", this.OnSubMapLegendClick)
            {
                MenuContainerKey = menuContainerKey,
                GroupCaption = groupCaption,
                SmallImage = Resources.AutoExpand_32x32,
                ToolTipText = "並べた地図の表示レイヤを選択します",
                RootKey = ViewMenuKey,
            };
            this.App.HeaderControl.Add(this.btnSubMapLegend);
        }

        private void OnSubMapViewClick(object sender, EventArgs e)
        {
            if (this.SubMap == null)
            {
                this.CreateSubMap();
                this.btnSubMapLegend.Enabled = true;
            }
            else
            {
                this.App.DockManager.Remove("kMap2");
                this.SubMap = null;
                this.btnSubMapLegend.Enabled = false;
            }
        }

        private void OnSubMapLegendClick(object sender, EventArgs e)
        {
            var subMapLegendDialog = new SubMapLegendDialog();
            var cname = "DotSpatial.Plugins.CustomLegend.CustomLegend";
            var legend = (Control)ClassUtil.CreateInstance(cname);
            legend.Dock = DockStyle.Fill;
            subMapLegendDialog.Controls.Add(legend);
            this.SubMap.Legend = (ILegend)legend;
            subMapLegendDialog.Show();
        }
    }
}

2.マップ及びサブマップのタブの×ボタンを削除

マップ及びサブマップのタブの×ボタンを押すと、マップ及びサブマップの画面が閉じられるのですが、一度閉じてしまうと復帰できなくなったので、×ボタンを表示しないように改訂しました。

namespace DotSpatial.Plugins.DockManager
{
    public class DockingManager : IDockManager, IPartImportsSatisfiedNotification
    {
        private void OnImportsSatisfied()
        {
            // 省略…
        
            // ×ボタンを削除
            this.tabbedView.DocumentProperties.AllowClose = false;
            this.tabbedView.DocumentGroupProperties.ClosePageButtonShowMode =
                DevExpress.XtraTab.ClosePageButtonShowMode.InTabControlHeader;
            this.tabbedView.DocumentGroupProperties.HeaderButtonsShowMode = TabButtonShowMode.Never;

            // 省略…
        }
    }
}

以下レイヤ選択画面です。任意のレイヤの表示/非表示設定が可能になりました。
以下では、背景画像を航空写真に変更してます。

何処までできるかわかりませんが、レイヤの色は変更できました。
以下ではラインの色を赤から青に変更しています。

今回の改訂では、想定より少ないソース変更で、サブマップのレイヤツリーを作成できました。
メインマップとは別の、独立したレイヤツリーが作成でいることが分かったので、統合型GISなどでよくある、レイヤの全体管理など、他の機能に応用できそうです。

シェアする

  • このエントリーをはてなブックマークに追加

フォローする