Mapsui 标志

Mapsui

社区
znlgis
mapsui

Use when embedding interactive 2D maps in .NET desktop (WPF/WinUI/WinForms) or mobile (MAUI/Avalonia/Blazor) apps with Mapsui 5.1.0 (net8.0/net9.0) — Mapsui.Wpf/Mapsui.Maui packages, Map and Layers, OpenStreetMap.CreateTileLayer, Shapefile/GeoJSON via Mapsui.Nts, SphericalMercator.FromLonLat, or fixing a blank MapControl.

概览

发布者znlgis
代码仓库opengis-skills
技能名称mapsui
星标数
76
复刻数
12
附带文件
仅含指令
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 指令自成一体

    模型所需的一切都包含在指令中,无需同步额外文件。

  • 开源

    由 znlgis 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Mapsui AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/znlgis/opengis-skills/tree/main/gis/mapsui
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/znlgis/opengis-skills.git /tmp/opengis-skills
mkdir -p .claude/skills
cp -r /tmp/opengis-skills/gis/mapsui .claude/skills/mapsui
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Mapsui,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Mapsui。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Mapsui 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

项目地址: https://github.com/Mapsui/Mapsui

官方文档: https://mapsui.com/v5/documentation/index.html

最新版本: 5.1.0(截至 2026-10,NuGet 稳定版;5.2.0-beta.1 为预发布)

许可证: MIT

概述

  • 跨 UI 框架:WPF / WinUI / MAUI / Avalonia / Uno / Blazor / WinForms
  • SkiaSharp 渲染,性能优于 GDI+
  • 数据源:OSM / WMS / WMTS / TMS / XYZ / Shapefile / GeoJSON / MBTiles / PostGIS
  • 几何基于 NetTopologySuite
  • 投影:ProjNet / Mapsui.Projections
  • 内置交互:拖动、缩放、旋转、捏合、命中

安装

bash
# 按 UI 框架选一个
dotnet add package Mapsui.Wpf --version 5.1.0      # WPF(net8.0-windows / net9.0-windows)
dotnet add package Mapsui.Maui --version 5.1.0     # MAUI,或 Mapsui.Avalonia / Mapsui.WinUI / Mapsui.Blazor
# 按数据源按需追加
dotnet add package Mapsui.Tiling --version 5.1.0   # 瓦片底图
dotnet add package Mapsui.Nts --version 5.1.0      # NTS 几何 / Shapefile

验证

bash
dotnet --list-sdks                        # 需 .NET 8/9 SDK
dotnet restore                            # 能解析 Mapsui 5.1.0 即包可用
dotnet build                              # 编译通过后才进入渲染验证

所有 Mapsui.* 子包版本必须一致(同样写 5.1.0),混版会在运行时抛类型加载异常。


WPF 入门

xml
<Window xmlns:mapsui="clr-namespace:Mapsui.UI.Wpf;assembly=Mapsui.UI.Wpf">
    <mapsui:MapControl x:Name="MapControl"/>
</Window>
csharp
using Mapsui;
using Mapsui.Tiling;
using Mapsui.Projections;

var map = new Map();
map.Layers.Add(OpenStreetMap.CreateTileLayer());

var pt = SphericalMercator.FromLonLat(116.397, 39.908).ToMPoint();
map.Navigator.CenterOnAndZoomTo(pt, map.Navigator.Resolutions[10]);

MapControl.Map = map;

核心概念

类型说明
Map地图
Layer / MemoryLayer / ImageLayer / TileLayer图层
IProvider数据提供者
IFeature / GeometryFeature要素(NTS 几何)
IStyle / VectorStyle / LabelStyle / SymbolStyle样式
Navigator视图操作

矢量图层

csharp
using Mapsui.Nts;
using Mapsui.Styles;
using NetTopologySuite.NtsGeometryServices;

// 视图坐标系为 EPSG:3857,经纬度数据必须先投影
var factory = NtsGeometryServices.Instance.CreateGeometryFactory(3857);

var features = new List<IFeature>
{
    new GeometryFeature(factory.CreatePoint(SphericalMercator.FromLonLat(116.397, 39.908).ToCoordinate()))
    {
        Styles = { new VectorStyle {
            Fill = new Brush(Color.Red),
            Outline = new Pen(Color.Black, 1)
        }}
    }
};

map.Layers.Add(new MemoryLayer("Roads") { Features = features, Style = null });

线/面要素用 factory.CreateLineString(coords) / factory.CreatePolygon(shell, holes),坐标同样要先 SphericalMercator.FromLonLat 投影。


Shapefile

csharp
using Mapsui.Nts.Providers.Shapefile;
var prov = new ShapeFile("china.shp", true);
map.Layers.Add(new Layer("China") { DataSource = prov });

瓦片图层

csharp
map.Layers.Add(OpenStreetMap.CreateTileLayer());

var src = new HttpTileSource(
    new GlobalSphericalMercator(0, 18),
    "https://webst02.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}",
    name: "AMap");
map.Layers.Add(new TileLayer(src) { Name = "AMap" });

// MBTiles
var mb = new MbTilesTileSource(new SQLiteConnectionString("city.mbtiles", false));
map.Layers.Add(new TileLayer(mb));

WMS

csharp
using Mapsui.Providers.Wms;
var wms = new WmsProvider("https://demo.mapserver.org/cgi-bin/wms?",
    new[] { "continents" });
map.Layers.Add(new ImageLayer("WMS") { DataSource = wms });

样式

csharp
new SymbolStyle { SymbolScale = 0.7, Fill = new Brush(Color.Red) };

new LabelStyle {
    Text = "{name}",
    Font = new Font { Size = 14 },
    BackColor = new Brush(Color.WhiteSmoke),
    Halo = new Pen(Color.White, 2)
};

主题样式

csharp
public class PopulationStyle : IThemeStyle {
    public IStyle? GetStyle(IFeature f) {
        var pop = (int)f["population"];
        return new VectorStyle { Fill = new Brush(pop > 1_000_000 ? Color.Red : Color.Blue) };
    }
}
layer.Style = new PopulationStyle();

交互

csharp
MapControl.Info += (s, e) => {
    if (e.MapInfo?.Feature is GeometryFeature gf)
        Debug.WriteLine($"clicked {gf["name"]}");
};

典型工作流

工作流 1:加载底图 + GeoJSON 矢量数据

输入 POI 记录(含 Lon / Lat / Name),输出 WPF 窗口里可拖拽缩放的底图 + 红色点图层。

csharp
using Mapsui;
using Mapsui.Tiling;
using Mapsui.Nts;
using Mapsui.Styles;
using Mapsui.Projections;

var map = new Map();

// 1. OSM 底图(来自 Mapsui.Tiling)
map.Layers.Add(OpenStreetMap.CreateTileLayer());

// 2. 构造点图层。Mapsui 的视图坐标系默认是 Web Mercator(EPSG:3857),
//    GeoJSON/业务数据里的经纬度必须先投影,否则会画到南太平洋附近。
var features = new List<IFeature>();
var factory = NetTopologySuite.NtsGeometryServices.Instance.CreateGeometryFactory(3857);

foreach (var item in poiList)              // item:含 Lon / Lat / Name 的 POI 记录
{
    var p = SphericalMercator.FromLonLat(item.Lon, item.Lat).ToCoordinate();
    var feature = new GeometryFeature(factory.CreatePoint(p)) { ["name"] = item.Name };
    feature.Styles.Add(new SymbolStyle
    {
        SymbolScale = 0.8,
        Fill = new Brush(Color.Red),
        Outline = new Pen(Color.White, 1)
    });
    features.Add(feature);
}
var dataLayer = new MemoryLayer("Data") { Features = features, Style = null };
map.Layers.Add(dataLayer);

// 3. 定位到北京
var center = SphericalMercator.FromLonLat(116.4, 39.9).ToMPoint();
map.Navigator.CenterOnAndZoomTo(center, map.Navigator.Resolutions[10]);

MapControl.Map = map;   // 忘记这一步窗口就是空白

工作流 2:Shapefile + WMS 叠加

输入 data/china.shp 与返回 rivers 图层的 WMS,输出底图 + 行政界 + 河流栅格图层。

csharp
using Mapsui.Nts.Providers.Shapefile;
using Mapsui.Providers.Wms;

// 1. Shapefile 矢量层(需 Mapsui.Nts)
var shpProvider = new ShapeFile("data/china.shp", true);
map.Layers.Add(new Layer("China") { DataSource = shpProvider });

// 2. WMS 栅格层:构造参数依次为服务地址,图层名数组
var wmsProvider = new WmsProvider("https://geo.example.com/wms?", new[] { "rivers" });
map.Layers.Add(new ImageLayer("Rivers") { DataSource = wmsProvider });

map.ZoomToExtents();

验证产物:dotnet build 通过不等于出图。无头环境用 Mapsui.Rendering.Skia.MapRenderer 把 map 渲染成 PNG 再打开 PNG 检查;有窗口时请用户运行后提供截图。

性能优化

  1. 海量点 → RasterizingTileLayer 包一层(按瓦片预渲染)
  2. 优先 MemoryLayer + 缓存 Feature
  3. 异步加载 + await Layer.WaitForFinishedRefresh()
  4. 共享 Brush/Pen/Style 实例
  5. SkiaSharp 关闭抗锯齿对极小符号有性能提升

常见问题

问题解决
WPF 无图NuGet 缺 Mapsui.Wpf 或没设置 MapControl.Map
找不到 Mapsui.UI.Wpf 包NuGet 包名为 Mapsui.Wpf(v3 起启用该名称;程序集仍为 Mapsui.UI.Wpf.dll)
投影错误SphericalMercator.FromLonLat 转换
MAUI 空白MauiProgram 中 UseSkiaSharp() + UseMapsui()
Shapefile 中文乱码Mapsui 的 DBF 默认按 UTF-7 解析,中文会乱码:.dbf 缺 .cpg 声明时按实际编码赋值 new ShapeFile(path, true) { Encoding = Encoding.GetEncoding("GBK") }(属性赋值,不是构造参数)
GeometryFeature / 瓦片类型找不到矢量要素需安装 Mapsui.Nts,瓦片图层需安装 Mapsui.Tiling

AI 使用建议

  • 执行环境:先 dotnet --list-sdks;Mapsui 5.1.0 的目标框架是 net8.0/net9.0(Mapsui.Wpf 为 net8.0-windows/net9.0-windows),低于 .NET 8 的工程不能直接引用。命令在终端中执行,例如 dotnet add package Mapsui.Wpf --version 5.1.0。
  • 验证产物:dotnet build 只证明编译通过;无头渲染用 Mapsui.Rendering.Skia.MapRenderer.RenderToBitmapStream(map, ...) 输出 PNG 的 MemoryStream(参数以 IntelliSense 为准),落盘后打开 PNG 检查;WinForms/WPF 窗口 AI 助手 看不到,需用户运行后提供截图。
  • 投影:定位坐标必须 SphericalMercator.FromLonLat(lon, lat) 转换,直接用经纬度会定位到南太平洋。
  • 数据:Shapefile 中文要设 ShapeFile.Encoding(UTF8 或 GBK);矢量要素装 Mapsui.Nts,瓦片装 Mapsui.Tiling,UI 包装 Mapsui.Wpf/Mapsui.Maui。
  • 常见症状:MapControl 空白先查是否赋值 MapControl.Map;MAUI 空白查 UseSkiaSharp() 与 UseMapsui() 是否注册。
  • 安全与权限:新建工程、装包、运行桌面程序前先征得用户同意;PostGIS/瓦片服务的密码不要写进代码或回答。

相关技能

参考资源

常见问题

Mapsui AI 技能有什么作用?

Use when embedding interactive 2D maps in .NET desktop (WPF/WinUI/WinForms) or mobile (MAUI/Avalonia/Blazor) apps with Mapsui 5.1.0 (net8.0/net9.0) — Mapsui.Wpf/Mapsui.Maui packages, Map and Layers, OpenStreetMap.CreateTileLayer, Shapefile/GeoJSON via Mapsui.Nts, SphericalMercator.FromLonLat, or fixing a blank MapControl.

为什么在 TypingMind 中使用 Mapsui?

因为您只需安装一次,就能搭配任何模型使用。Mapsui 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Mapsui?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/znlgis/opengis-skills/tree/main/gis/mapsui。TypingMind 会读取其中的 SKILL.md,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Mapsui?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Mapsui 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Mapsui 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Mapsui AI 技能免费吗?

是的。znlgis 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇