Skip to content

feat(catalog): add Tianditu, Amap, and Tencent basemaps for mainland China - #33

Merged
giswqs merged 1 commit into
mainfrom
feat/china-basemaps
Aug 13, 2026
Merged

giswqs merged 1 commit into
mainfrom
feat/china-basemaps

Conversation

@giswqs

@giswqs giswqs commented Aug 13, 2026

Copy link
Copy Markdown
Member

Why

Every basemap in the catalog is hosted outside mainland China with no presence inside it, so for users there the whole picker degrades from slow to unreachable: OpenStreetMap, OpenFreeMap, Protomaps, Carto, Google, and Mapbox alike. This adds the three providers that are actually served from inside China.

What

Basemap id Provider Datum Credential
tianditu-vector, tianditu-imagery, tianditu-terrain + their -labels overlays Tianditu (天地图) CGCS2000 tiandituApiKey
amap-street, amap-satellite, amap-labels Amap (高德地图) GCJ-02 none
tencent-street, tencent-dark Tencent Maps (腾讯地图) GCJ-02 none
  • Tianditu is the official National Platform for Common Geospatial Information Services. It needs a free tk, wired through as tiandituApiKey alongside the existing provider credentials: option, setTiandituApiKey(), a field in the API-keys panel, and a "Get a Tianditu API key" help link on the missing-credential error.
  • Tencent is TMS rather than xyz, so rasterBasemap now forwards scheme (the control already honored it).
  • All three are tagged with their Chinese names, so 天地图, 高德, and 腾讯 find them in the panel's search alongside the English ones.

The datum matters more than the speed

Amap and Tencent publish in GCJ-02, the offset datum Chinese law mandates, which silently displaces WGS84 overlays by roughly 100-700 m. Tianditu publishes in CGCS2000 and lines up. Nothing here applies the shift, so Tianditu is the one to reach for when the map also carries your own data — every affected basemap says so in its description, and the README leads with it.

Two limits found by probing rather than reading docs

  • The Tianditu terrain pair (ter_w/cta_w) stops at zoom 14, where its vector and imagery layers reach 18.
  • Amap returns a "no imagery" placeholder tile rather than a 404 past zoom 18, so amap-satellite caps there and lets MapLibre overzoom instead of painting placeholders.

Drive-by

Replaces the nested ternary in _missingRasterKeyError with a lookup map. It had already drifted out of indentation at four providers, and this PR would have made it five.

Verification

7 new tests (109 total, all passing), plus a Chromium run against the live endpoints:

  • Amap tiles load 200 from all four wprd0{1-4} / webst0{1-4} hosts and render correctly placed.
  • Tencent tiles load 200 from all four rt{0-3} hosts and render correctly oriented, which is what proves the TMS flip is applied.
  • Tianditu raises Enter a Tianditu API key before applying this layer. and reveals its key field.
  • The Tianditu field renders in the API keys view between Stadia Maps and TomTom.

I could not fetch a Tianditu tile from this network: their CloudWAF answers foreign requests with a 418 block page regardless of key or UA. The URL shape is the documented DataServer form and the key substitution is covered by tests, but someone inside China should confirm the tiles before release.

Not included: GeoQ (智图, Esri China). Its host resolves but every port is filtered from outside China, so I could not confirm the service is still alive, and shipping an unverifiable endpoint into a public catalog risks a dead entry. Easy to add later if someone can check it from inside China.

Summary by CodeRabbit

  • New Features

    • Added Tianditu, Amap, and Tencent basemap options.
    • Added support for Tianditu API key configuration and updating credentials at runtime.
    • Added provider-specific imagery, terrain, street, satellite, dark, and label layers.
    • Added attribution, zoom limits, tile scheme handling, and China-specific datum guidance.
    • Added filtering for Chinese provider names.
  • Documentation

    • Documented provider availability, setup instructions, API key usage, tile URLs, label overlays, and configuration examples.

…China

Every basemap in the catalog is hosted outside mainland China with no
presence inside it, so for users there the whole picker degrades from slow
to unreachable: OpenStreetMap, OpenFreeMap, Protomaps, Carto, Google, and
Mapbox alike.

Add the three providers that are actually served from inside China:

- Tianditu (天地图), the official National Platform for Common Geospatial
  Information Services: vector, imagery, and terrain, each with its
  separate label overlay. Needs a free `tk`, wired through as
  `tiandituApiKey` alongside the existing provider credentials (option,
  setter, API-keys panel field, and "Get a Tianditu API key" help link).
- Amap (高德地图): street, satellite, and a transparent roads-and-labels
  overlay. Keyless.
- Tencent Maps (腾讯地图): street and dark. Keyless, and TMS rather than
  xyz, so `rasterBasemap` now forwards `scheme` (the control already
  honored it).

Tianditu is the one to reach for when the map also carries your own data:
Amap and Tencent publish in GCJ-02, the offset datum Chinese law mandates,
which silently displaces WGS84 overlays by roughly 100-700 m, while
Tianditu publishes in CGCS2000 and lines up. Nothing here applies the
shift, so every affected basemap says so in its description and the README
leads with it.

All three are tagged with their Chinese names, so 天地图, 高德, and 腾讯
find them in the panel's search alongside the English ones.

Two limits found by probing the endpoints rather than reading docs: the
Tianditu terrain pair stops at zoom 14 where its vector and imagery layers
reach 18, and Amap returns a "no imagery" placeholder rather than a 404
past zoom 18, so its satellite layer caps there and lets MapLibre overzoom.

Also replaces the nested ternary in `_missingRasterKeyError` with a lookup
map, which had already drifted out of indentation at four providers.

Verified in Chromium against the live endpoints: Amap and Tencent tiles
load 200 from all four hosts each and render correctly oriented (which is
what proves the TMS flip), Tianditu raises its missing-credential error
with the right message, and the key field renders in the API keys view.
Copilot AI lite review requested due to automatic review settings August 13, 2026 03:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 156d8560-9e0e-4fda-b626-5fd616471694

📥 Commits

Reviewing files that changed from the base of the PR and between c80a80c and 6491bd6.

📒 Files selected for processing (6)
  • README.md
  • src/lib/core/BasemapControl.ts
  • src/lib/core/catalog.ts
  • src/lib/core/types.ts
  • tests/BasemapControl.test.ts
  • tests/catalog.test.ts

📝 Walkthrough

Walkthrough

The catalog adds Tianditu, Amap, and Tencent basemaps with provider-specific tile URLs, schemes, metadata, and zoom limits. BasemapControl adds Tianditu API-key configuration and updates. Tests and README documentation cover the new providers.

Changes

China basemap providers

Layer / File(s) Summary
Provider catalog and tile sources
src/lib/core/catalog.ts
Registers Tianditu, Amap, and Tencent providers. Adds sharded tile URLs, TMS support, attribution, GCJ-02 metadata, layer categories, and zoom limits.
Tianditu credential integration
src/lib/core/types.ts, src/lib/core/BasemapControl.ts
Adds the tiandituApiKey option and setTiandituApiKey method. Adds credential fields, missing-key labels, provider detection, and API-key substitution.
Provider validation and documentation
tests/BasemapControl.test.ts, tests/catalog.test.ts, README.md
Tests credentials, retries, tile URLs, schemes, filtering, metadata, and provider registration. Documents configuration and China basemap usage.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Mergeability Score: ⚪ Minimal · up to 6491b

The change adds China-hosted basemap providers and related credential handling; no actionable merge-blocking risk remains beyond normal checks and review.

Poem

I’m a rabbit mapping tiles in a row,
Tianditu keys make the blue grids glow.
Amap and Tencent join the run,
With TMS paths and labels in the sun.
I thump for tests that all pass bright!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding Tianditu, Amap, and Tencent basemaps for mainland China.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/china-basemaps

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@giswqs
giswqs merged commit 06a034f into main Aug 13, 2026
2 checks passed
@giswqs
giswqs deleted the feat/china-basemaps branch August 13, 2026 04:02
@giswqs giswqs mentioned this pull request Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants