forked from QL-Win/QuickLook.Plugin.HelloWorld
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPlugin.cs
77 lines (70 loc) · 2.07 KB
/
Plugin.cs
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
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using QuickLook.Common.Plugin;
using SharpMap.Data.Providers;
using SharpMap.Forms;
using SharpMap.Layers;
using static SharpMap.Forms.MapBox;
namespace QuickLook.Plugin.HelloWorld
{
public class Plugin : IViewer
{
public int Priority => 0;
public void Init()
{
// do nothing
}
public bool CanHandle(string path)
{
return !Directory.Exists(path) && path.ToLower().EndsWith(".shp");
}
public void Prepare(string path, ContextObject context)
{
context.SetPreferredSizeFit(new Size { Width = 1920, Height = 1440 }, 0.9);
}
public void View(string path, ContextObject context)
{
context.Title = $"{Path.GetFileName(path)}";
try
{
MapBox mapBox = new MapBox()
{
Dock = DockStyle.Fill,
ActiveTool = Tools.Pan,
PreviewMode = PreviewModes.Fast
};
WindowsFormsHost host = new WindowsFormsHost()
{
Child = mapBox,
};
VectorLayer layer = new VectorLayer(Path.GetFileName(path))
{
DataSource = new ShapeFile(path, false, true)
};
mapBox.Map.Layers.Add(layer);
mapBox.Map.ZoomToExtents();
mapBox.Refresh();
context.ViewerContent = host;
}
catch (Exception ex)
{
context.ViewerContent = new System.Windows.Controls.Label
{
Content = $"Can not open shapefile because of: {ex.Message}"
};
}
finally
{
context.IsBusy = false;
}
}
public void Cleanup()
{
// do nothing
}
}
}