Skip to content

Commit

Permalink
完成了SharpMap打开shapefile功能
Browse files Browse the repository at this point in the history
  • Loading branch information
birderyu committed Jan 11, 2019
1 parent 34a275f commit 42500dd
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 6 deletions.
49 changes: 43 additions & 6 deletions Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
using System.IO;
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
{
Expand All @@ -11,6 +18,7 @@ public class Plugin : IViewer

public void Init()
{
// do nothing
}

public bool CanHandle(string path)
Expand All @@ -20,21 +28,50 @@ public bool CanHandle(string path)

public void Prepare(string path, ContextObject context)
{
context.PreferredSize = new Size {Width = 600, Height = 400};
context.SetPreferredSizeFit(new Size { Width = 1920, Height = 1440 }, 0.9);
}

public void View(string path, ContextObject context)
{
var viewer = new Label {Content = "I am a Label. I do nothing at all."};

context.ViewerContent = viewer;
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.IsBusy = false;
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
}
}
}
57 changes: 57 additions & 0 deletions QuickLook.Plugin.ShapefileViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,70 @@
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="BruTile, Version=0.7.4.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\BruTile.0.7.4.4\lib\net40\BruTile.dll</HintPath>
</Reference>
<Reference Include="BruTile.Desktop, Version=0.7.4.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\BruTile.0.7.4.4\lib\net40\BruTile.Desktop.dll</HintPath>
</Reference>
<Reference Include="BruTile.MbTiles, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\BruTile.0.7.4.4\lib\net40\BruTile.MbTiles.dll</HintPath>
</Reference>
<Reference Include="BruTile.Serialization, Version=0.7.4.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\BruTile.0.7.4.4\lib\net40\BruTile.Serialization.dll</HintPath>
</Reference>
<Reference Include="Common.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<HintPath>packages\Common.Logging.2.0.0\lib\2.0\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="GeoAPI, Version=1.7.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\GeoAPI.1.7.2\lib\net403-client\GeoAPI.dll</HintPath>
</Reference>
<Reference Include="NetTopologySuite, Version=1.13.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\NetTopologySuite.1.13.2\lib\net403-client\NetTopologySuite.dll</HintPath>
</Reference>
<Reference Include="NetTopologySuite.IO.GeoTools, Version=1.13.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\NetTopologySuite.IO.1.13.2\lib\net403-client\NetTopologySuite.IO.GeoTools.dll</HintPath>
</Reference>
<Reference Include="NetTopologySuite.IO.MsSqlSpatial, Version=1.13.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\NetTopologySuite.IO.1.13.2\lib\net403-client\NetTopologySuite.IO.MsSqlSpatial.dll</HintPath>
</Reference>
<Reference Include="NetTopologySuite.IO.PostGis, Version=1.13.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\NetTopologySuite.IO.1.13.2\lib\net403-client\NetTopologySuite.IO.PostGis.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PowerCollections, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\NetTopologySuite.1.13.2\lib\net403-client\PowerCollections.dll</HintPath>
</Reference>
<Reference Include="ProjNet, Version=1.3.0.3, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\ProjNET4GeoAPI.1.3.0.3\lib\net403-client\ProjNet.dll</HintPath>
</Reference>
<Reference Include="SharpMap, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\SharpMap.1.1.0\lib\net40-client\SharpMap.dll</HintPath>
</Reference>
<Reference Include="SharpMap.UI, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\SharpMap.UI.1.1.0\lib\net40-client\SharpMap.UI.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Data.SQLite, Version=1.0.86.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>packages\System.Data.SQLite.MSIL.1.0.86.0\lib\net45\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.Data.SQLite.Linq, Version=1.0.86.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>packages\System.Data.SQLite.MSIL.1.0.86.0\lib\net45\System.Data.SQLite.Linq.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="WindowsFormsIntegration" />
</ItemGroup>
<ItemGroup>
<Compile Include="GitVersion.cs" />
Expand All @@ -78,6 +134,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="QuickLook.Plugin.Metadata.Base.config" />
<None Include="QuickLook.Plugin.Metadata.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
13 changes: 13 additions & 0 deletions packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BruTile" version="0.7.4.4" targetFramework="net462" />
<package id="Common.Logging" version="2.0.0" targetFramework="net462" />
<package id="GeoAPI" version="1.7.2" targetFramework="net462" />
<package id="NetTopologySuite" version="1.13.2" targetFramework="net462" />
<package id="NetTopologySuite.IO" version="1.13.2" targetFramework="net462" />
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net462" />
<package id="ProjNET4GeoAPI" version="1.3.0.3" targetFramework="net462" />
<package id="SharpMap" version="1.1.0" targetFramework="net462" />
<package id="SharpMap.UI" version="1.1.0" targetFramework="net462" />
<package id="System.Data.SQLite.MSIL" version="1.0.86.0" targetFramework="net462" />
</packages>

0 comments on commit 42500dd

Please sign in to comment.