Metadata-Version: 2.4
Name: siontiles
Version: 0.3.1
Summary: Self-hosted vector tile map server — PMTiles + MapLibre GL JS with Chinese fuzzy search
Author: songwupei
License-Expression: MIT
Project-URL: Homepage, https://codeberg.org/songwupei/SinoTiles
Project-URL: Repository, https://codeberg.org/songwupei/SinoTiles
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: Scientific/Engineering :: GIS
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: geo
Requires-Dist: geocode-amap; extra == "geo"
Requires-Dist: polars; extra == "geo"
Provides-Extra: all
Requires-Dist: siontiles[geo]; extra == "all"
Dynamic: license-file

# SinoTiles

自托管矢量瓦片地图服务 — PMTiles + MapLibre GL JS 一键启动，带中文模糊搜索与企业银行分析。

[![PyPI](https://img.shields.io/badge/pypi-v0.3.1-blue)](https://pypi.org/project/siontiles/)
[![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)

## 安装

```bash
pip install siontiles       # 基础安装
pip install siontiles[geo]  # 含 CNAPS 就近银行分析
```
![](https://img.shields.io/badge/license-MIT-green)

## 特性

- **零配置启动** — 一个脚本，浏览器打开即用
- **外部数据目录** — PMTiles 和 POI 数据独立存放，通过 `config.env` 配置
- **PMTiles 矢量瓦片** — 单文件存储，支持 HTTP Range 按需加载
- **中文模糊搜索** — Bigram Jaccard + 字符集预筛选，支持换序匹配，支持联动企业搜索
- **13 层样式** — 道路、水系、建筑、公交站、红绿灯、收费站等
- **联动企业图层** — 810 家企业点位，含银行距离分析，点击查看详情弹窗
- **企业分析弹窗** — 银行机构统计、账户清单、基本户/就近/外省标签、驾车距离
- **一键复制 Markdown** — 弹窗内 📋 按钮将企业分析数据复制为 Markdown 表格
- **暗色模式** — 🌙/☀️ 一键切换，地图、面板、弹窗、zoom 控件全适配
- **全国 z12 图层** — 支持 Protomaps 全国高精度瓦片（z0-12），多数据源切换
- **最近银行分析** — 非就近账户显示最近同银行网点名称和距离
- **跨省判定修复** — 城市→省份映射表，省对省精确比较；境外企业自动识别；银行名提取城市回退
- **国界/省界/十段线** — 省界细虚线 + 陆上国界粗实线 + 十段线粗虚线，8 大边境区域经纬度可配
- **海岸线不画国界** — 14 个沿海省份海岸线自动剔除，`land_border_zones.json` 按经纬度配置
- **自定义 POI** — 独立 GeoJSON 源，GCJ-02 自动转 WGS-84
- **185K+ 地名索引** — 搜索响应毫秒级
- **暗色模式标签适配** — 基本户/就近/外埠标签暗底亮字

## 快速开始

```bash
# 1. 安装
pip install siontiles

# 2. 配置数据路径（环境变量）
export SIONTILES_PMTILES_DIR=~/path/to/pmtiles
export SIONTILES_POI_DIR=~/path/to/poi

# 3. 启动
siontiles serve
# 浏览器打开 http://localhost:8765
```

## 配置

编辑 `config.env` 或通过环境变量覆盖：

| 变量 | 默认值 | 说明 |
|------|--------|------|
| `SIONTILES_PORT` | `8765` | 服务端口 |
| `SIONTILES_PMTILES_DIR` | `~/NutstoreFiles/8-MyData/GeoData/pmtiles` | PMTiles 瓦片目录 |
| `SIONTILES_POI_DIR` | `~/NutstoreFiles/8-MyData/GeoData/poi` | POI 数据目录 |

命令行覆盖：`SIONTILES_PORT=9999 ./start.sh`

## 目录结构

```
├── config.env                  # 配置文件（数据路径、端口）
├── web/
│   ├── index.html              # 前端 (MapLibre + 搜索 + 企业弹窗)
│   ├── style.json              # 地图样式（亮色）
│   ├── style-dark.json         # 地图样式（暗色）
│   ├── server.py               # HTTP 服务器 (Range + gzip + 路由映射)
│   ├── start.sh                # 启动脚本
│   ├── search_index.json.gz    # 预构建搜索索引 (~2.6MB)
│   ├── convert_poi.py          # POI 坐标转换 (GCJ-02→WGS-84)
│   └── dedup_enterprise.py     # 企业数据去重修复工具
│
├── $SIONTILES_PMTILES_DIR/     # ← 外部 PMTiles 目录
│   └── *.pmtiles
│
└── $SIONTILES_POI_DIR/         # ← 外部 POI 目录
    ├── custom-poi_wgs84.geojson      # 自定义 POI (WGS-84)
    ├── geo_enterprise_wgs84.geojson  # 企业分析数据 (WGS-84)
    └── geo_bank_branch_wgs84.geojson # 银行网点原始数据 (WGS-84)
```

Server 内部路由：
- `/pmtiles/*` → `$SIONTILES_PMTILES_DIR`
- `/poi/*` → `$SIONTILES_POI_DIR`
- 其他 → `web/`

## 技术栈

| 组件 | 方案 |
|------|------|
| 瓦片格式 | [PMTiles](https://github.com/protomaps/PMTiles) v4 |
| 地图渲染 | [MapLibre GL JS](https://maplibre.org) v4.7 |
| HTTP 服务 | Python 3 (Range + gzip) |
| 搜索算法 | Bigram Jaccard 相似度 |
| 坐标转换 | GCJ-02 → WGS-84 (内置) |
| 企业分析 | Parquet → GeoJSON (Haversine + 驾车距离) |

## 企业数据更新

```bash
# 1. 重建企业分析（需要 Excel 司库账户数据 + 高德 API Key）
cd ~/NutstoreFiles/8-MyData/GeoData/poi
python3 rebuild_bank_analysis.py

# 2. 复制为 server 读取的文件名
cp geo_enterprise_analysis_wgs84.geojson geo_enterprise_wgs84.geojson
gzip -k -f geo_enterprise_wgs84.geojson

# 3. 去重 + 修复 n_nearest
cd /path/to/SionTiles/web
python3 dedup_enterprise.py

# 4. CNAPS 就近分析（标记 isNearestBranch，自动验证）
cd /path/to/SionTiles
python scripts/update_bank_branches.py

# 5. 部署到现网（脚本运行后会提示具体命令）
cp geo_enterprise_wgs84.geojson geo_enterprise_wgs84.geojson.backup-$(date +%Y%m%d)
cp geo_enterprise_updated_wgs84.geojson geo_enterprise_wgs84.geojson
```

## License

MIT
