DotSpatialは、索引図がなかったので、索引図プラグインを作成した。
1.索引図のコントロールを作成
UserControlクラスを継承した、索引図のOverviewMapControlを作成し、DotSpatial.Controls.Mapクラスを張りつけておく。※作成したクラスは、下段パネルに住所検索機能をつけている。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
namespace DotSpatial.Plugins.OverviewMap { public partial class OverviewMapControl : UserControl { public OverviewMapControl() { InitializeComponent(); } public Map OverviewMap { get { return this.map1; } } } } |
2.索引図用のファンクションを作成
ファンクションは、地図上で実行できる機能を定義したのもで、索引図の場合は主題図よりも、機能を限定させる必要があるため、新たに作成する。ファンクションクラスは、本家Mapクラスで利用しているファンクションなどを参考にした。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
namespace DotSpatial.Plugins.OverviewMap { public class MoveMapAreaFunction : MapFunction { public MoveMapAreaFunction(IMap map) : base(map) { Configure(); this.BusySet = false; } public IFeatureLayer ActiveLayer { get; set; } public bool IsDragging { get; set; } public Coordinate DragCoord { get; set; } public IGeometry DragGeometry { get; set; } public IMap MainMap { get; set; } public Rectangle DragView { get; set; } public Rectangle MoveView { get; set; } public Extent MoveExtent { get; set; } private Timer ZoomTimer { get; set; } public bool BusySet { get; set; } #region Constructors |
3.プラグインクラスを作成
DotSpatial.Controls.Extensionクラスを継承した、OverviewMapPluginを作成する。
主な処理は以下の通り。
・主題図の表示変更時のイベントの実装
・索引図用のファンクション登録
・DockManagerで、索引図のコントロールを登録
・主題図の範囲を表す矩形レイヤーを作成
・索引図サイズ変更時のイベントの実装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
namespace DotSpatial.Plugins.OverviewMap { public class OverviewMapPlugin : Extension { public OverviewMapPlugin() { DeactivationAllowed = false; } private OverviewMapControl OverviewMapControl { get; set; } private TreeList TreeList { get; set; } private IMapFeatureLayer MapAreaLayer { get; set; } private IMapFeatureLayer OverviewMapLayer { get; set; } private MoveMapAreaFunction MoveMapAreaFunction { get; set; } private IMap OverviewMap { get { return (IMap)((Map)this.App.Map).Tag; } set { ((Map)this.App.Map).Tag = value; } } public override void Activate() { this.App.Map.MapFrame.ViewExtentsChanged += OnMapViewExtentsChanged; this.OverviewMapControl = new OverviewMapControl(); this.TreeList = this.OverviewMapControl.TreeList; this.OverviewMap = this.OverviewMapControl.OverviewMap; this.OverviewMap.MapFunctions.Clear(); this.OverviewMap.FunctionMode = FunctionMode.None; this.OverviewMap.Projection = this.App.Map.Projection; this.OverviewMap.MapFrame.ProjectionModeDefine = ActionMode.Always; this.MoveMapAreaFunction = new MoveMapAreaFunction(this.OverviewMap); this.MoveMapAreaFunction.MainMap = this.App.Map; this.OverviewMap.MapFunctions.Add(this.MoveMapAreaFunction); this.App.DockManager.Add( new DockablePanel("kOvMap", "索引図", this.OverviewMapControl, DockStyle.Right) { SmallImage = Resources.map_16x16 }); this.AddOverViewMap(); base.Activate(); } private void AddOverViewMap() { var fileName = ConfigurationManager.AppSettings["overview_map.file"]; var provider = new ShapefileDataProvider(); var featureSet = provider.Open(fileName); featureSet.Projection = this.App.Map.Projection; this.OverviewMapLayer = (IMapFeatureLayer)this.OverviewMap.Layers.Add(featureSet); ((PolygonSymbolizer)this.OverviewMapLayer.Symbolizer).SetFillColor( ColorTranslator.FromHtml(ConfigurationManager.AppSettings["overview_map.fill_color"])); ((PolygonSymbolizer)this.OverviewMapLayer.Symbolizer).SetOutline( ColorTranslator.FromHtml(ConfigurationManager.AppSettings["overview_map.out_line_color"]), double.Parse(ConfigurationManager.AppSettings["overview_map.out_line_width"])); this.MapAreaLayer = this.OverviewMap.Layers.Add(new FeatureSet(FeatureType.Line)); ((LineSymbolizer)this.MapAreaLayer.Symbolizer).SetFillColor(Color.Red); ((LineSymbolizer)this.MapAreaLayer.Symbolizer).SetWidth(2); var linearRing = featureSet.Extent.ToEnvelope().ToLinearRing(); this.MapAreaLayer.DataSet.AddFeature(linearRing); this.MoveMapAreaFunction.ActiveLayer = this.MapAreaLayer; this.MoveMapAreaFunction.Activate(); this.OverviewMap.ZoomToMaxExtent(); this.OverviewMap.Resized += OnResized; } } } |