---
title: "MaplibreRasterLayer"
description: "Raster tile layer that overlays an external XYZ/TMS tile service onto the map."
canonical_url: "https://maplibre.mhaibaraai.cn/en/docs/layers/raster"
---
# MaplibreRasterLayer

> Raster tile layer that overlays an external XYZ/TMS tile service onto the map.

## Introduction

`MaplibreRasterLayer` overlays an external raster tile service using a `{z}/{x}/{y}` template URL. Supports `tileSize`, `scheme`, `minzoom`, `maxzoom`, `attribution`, and `opacity`. For Chinese basemap services like Tianditu, see [Extensions](https://maplibre.mhaibaraai.cn/docs/extensions/tianditu).

> [!TIP]
> 
> url
> 
>  can replace 
> 
> tiles
> 
>  with a TileJSON address or a protocol address, such as a 
> 
> cog://
> 
>  address after registering the 
> 
> COG
> 
>  protocol.

## Usage

Overlay OpenStreetMap tiles on an empty style basemap:

```vue [RasterLayerExample.vue]
<script setup lang="ts">
const tiles = ['https://tile.openstreetmap.org/{z}/{x}/{y}.png']
</script>

<template>
  <div class="h-115 w-full overflow-hidden rounded-(--ui-radius) border border-default">
    <!-- 省略 style 即空白样式，仅叠加外部栅格瓦片 -->
    <MaplibreMap :options="{ center: [116.4, 39.9], zoom: 9 }">
      <MaplibreRasterLayer
        :tiles="tiles"
        :tile-size="256"
        attribution="© OpenStreetMap contributors"
      />
    </MaplibreMap>
  </div>
</template>
```

## API

### Props

```ts
/**
 * Props for the MaplibreRasterLayer component
 */
interface MaplibreRasterLayerProps {
  /**
   * 图层 id；省略时自动生成，变更需配合 `:key` 重建
   */
  layerId?: string | undefined;
  /**
   * URL 模板瓦片地址（{z}/{x}/{y} 占位）；与 `url` 至少提供一个
   */
  tiles?: string[] | undefined;
  /**
   * TileJSON 地址或协议地址（如 `cog://https://.../image.tif`）；与 `tiles` 至少提供一个
   */
  url?: string | undefined;
  /**
   * 瓦片尺寸
   * @default 256
   */
  tileSize?: number | undefined;
  /**
   * 瓦片坐标方案
   * @default 'xyz'
   */
  scheme?: "xyz" | "tms" | undefined;
  /**
   * 数据源最小缩放级别
   */
  minzoom?: number | undefined;
  /**
   * 数据源最大缩放级别
   */
  maxzoom?: number | undefined;
  /**
   * 版权信息
   */
  attribution?: string | undefined;
  /**
   * 不透明度
   * @default 1
   */
  opacity?: number | undefined;
  /**
   * 插入到该图层之前
   */
  beforeId?: string | undefined;
}
```

## Changelog

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


## Sitemap

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