---
title: "MaplibreWmsLayer"
description: "接入标准 WMS 服务为栅格图层，透传版本、格式、CRS 等参数。"
canonical_url: "https://maplibre.mhaibaraai.cn/docs/extensions/wms"
---
# MaplibreWmsLayer

> 接入标准 WMS 服务为栅格图层，透传版本、格式、CRS 等参数。

## 简介

`MaplibreWmsLayer` 把标准 WMS（GetMap）服务接入为栅格图层：`url` 与 `layers` 必填，`version` / `format` / `crs` / `transparent` 等透传，`params` 追加自定义查询参数。瓦片按 `{bbox-epsg-3857}` 逐块请求。

## 用法

接入 terrestris 公开 OSM-WMS：

```vue [WmsLayerExample.vue]
<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: [10.45, 51.16], zoom: 5 }">
      <!-- terrestris 公开 OSM-WMS（EPSG:3857） -->
      <MaplibreWmsLayer
        url="https://ows.terrestris.de/osm/service"
        layers="OSM-WMS"
        attribution="© terrestris / OpenStreetMap"
      />
    </MaplibreMap>
  </div>
</template>
```

## API

### Props

```ts
/**
 * Props for the MaplibreWmsLayer component
 */
interface MaplibreWmsLayerProps {
  /**
   * WMS 服务基础地址
   */
  url: string;
  /**
   * 图层 LAYERS（逗号分隔多层）
   */
  layers: string;
  /**
   * source/layer id
   * @default `wms-${layers}`
   */
  layerId?: string | undefined;
  /**
   * WMS 版本
   * @default '1.1.1'
   */
  version?: string | undefined;
  /**
   * 图片格式
   * @default 'image/png'
   */
  format?: string | undefined;
  /**
   * 是否透明
   * @default true
   */
  transparent?: boolean | undefined;
  /**
   * 样式
   * @default ''
   */
  styles?: string | undefined;
  /**
   * 坐标参考系
   * @default 'EPSG:3857'
   */
  crs?: string | undefined;
  /**
   * 瓦片尺寸
   * @default 256
   */
  tileSize?: number | undefined;
  /**
   * 版权信息
   */
  attribution?: string | undefined;
  /**
   * 透传查询参数
   */
  params?: Record<string, string | undefined> | undefined;
  /**
   * 插入到该图层之前
   */
  beforeId?: string | undefined;
}
```

## Changelog

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


## Sitemap

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