---
title: "MaplibreWmtsLayer"
description: "Add an OGC WMTS (KVP GetTile) service as a raster layer, with subdomain expansion and custom auth parameters."
canonical_url: "https://maplibre.mhaibaraai.cn/en/docs/extensions/wmts"
---
# MaplibreWmtsLayer

> Add an OGC WMTS (KVP GetTile) service as a raster layer, with subdomain expansion and custom auth parameters.

## Introduction

`MaplibreWmtsLayer` integrates a standard WMTS (KVP GetTile) service as a raster layer: `url` and `layer` are required; `tileMatrixSet` / `style` / `format` are forwarded as-is; when `url` contains `{s}`, `subdomains` is used to expand multi-host URLs; `params` appends auth parameters (e.g. `tk`). [MaplibreTiandituLayer](https://maplibre.mhaibaraai.cn/docs/extensions/tianditu) is built on top of this component.

## Usage

Demonstrating WMTS integration using Tianditu imagery (`tk` is read from runtime config):

```vue [WmtsLayerExample.vue]
<script setup lang="ts">
// 以天地图影像为例演示通用 WMTS（KVP）接入；tk 取自运行时配置，不硬编码
const tk = (useRuntimeConfig().public.maplibre as { tk?: string }).tk
const subdomains = ['0', '1', '2', '3', '4', '5', '6', '7']
</script>

<template>
  <div class="h-115 w-full overflow-hidden rounded-(--ui-radius) border border-default">
    <MaplibreMap :options="{ style: 'https://tiles.openfreemap.org/styles/positron', center: [116.397, 39.908], zoom: 10 }">
      <MaplibreWmtsLayer
        url="https://t{s}.tianditu.gov.cn/img_w/wmts"
        layer="img"
        :subdomains="subdomains"
        :params="{ tk }"
        attribution="© 天地图"
      />
    </MaplibreMap>
  </div>
</template>
```

## API

### Props

```ts
/**
 * Props for the MaplibreWmtsLayer component
 */
interface MaplibreWmtsLayerProps {
  /**
   * WMTS 服务基础地址；含 {s} 时配合 subdomains 展开
   */
  url: string;
  /**
   * 图层标识 LAYER
   */
  layer: string;
  /**
   * source/layer id
   * @default `wmts-${layer}`
   */
  layerId?: string | undefined;
  /**
   * 瓦片矩阵集
   * @default 'w'
   */
  tileMatrixSet?: string | undefined;
  /**
   * 瓦片格式
   * @default 'tiles'
   */
  format?: string | undefined;
  /**
   * 子域名列表，替换 url 中的 {s}
   */
  subdomains?: string[] | undefined;
  /**
   * 瓦片尺寸
   * @default 256
   */
  tileSize?: number | undefined;
  /**
   * 版权信息
   */
  attribution?: string | undefined;
  /**
   * 透传查询参数（如 { tk }）
   */
  params?: Record<string, string | undefined> | undefined;
  /**
   * 插入到该图层之前
   */
  beforeId?: string | undefined;
}
```

## Changelog

See commit history for [src/runtime/components/extensions/WmtsLayer.vue](https://github.com/mhaibaraai/movk-maplibre/commits/main/src/runtime/components/extensions/WmtsLayer.vue).


## Sitemap

See the full [sitemap](https://maplibre.mhaibaraai.cn/sitemap.md) for all pages.
