Skip to content

TiandituLayer

Tianditu Layer, supporting all Tianditu tile services (unbiased).

Example

Example Source Code
tsx
import React, { useEffect, useRef, useState } from 'react'
import ReactDOM from 'react-dom'
import { MbMap, MbTiandituLayer } from '@mapbox-react/core'

const App = () => {
  const [mapCenter] = useState([116.35, 39.91])
  const [zoom, setZoom] = useState(5)

  const layerOptions = [
    {
      label: '矢量底图',
      layerTypes: ['vec'],
    },
    {
      label: '矢量底图+注记',
      layerTypes: ['vec', 'cva'],
    },
    {
      label: '影像底图',
      layerTypes: ['img'],
    },
    {
      label: '影像底图+注记',
      layerTypes: ['img', 'cia'],
    },
    {
      label: '地形晕渲',
      layerTypes: ['ter'],
    },
    {
      label: '地形晕渲+注记',
      layerTypes: ['ter', 'cta'],
    },
  ]

  const [layerIndex, setLayerIndex] = useState(0)

  return (
    <div className="map-wrapper">
      <div className="action-bar">
        <select
          value={layerIndex}
          onChange={(e) => setLayerIndex(+e.target.value)}
        >
          {layerOptions.map((lo, index) => (
            <option key={lo.label} value={index}>
              {lo.label}
            </option>
          ))}
        </select>
      </div>
      <MbMap center={mapCenter} zoom={zoom}>
        {layerOptions.map((item, index) => (
          <MbTiandituLayer
            key={item.layerTypes[0] + index}
            types={item.layerTypes}
            show={layerIndex === index}
          />
        ))}
      </MbMap>
    </div>
  )
}

ReactDOM.render(<App />, document.querySelector('#root'))

API

PROPS

NameDescriptionTypeDefault
tokenTianditu service token (API key). This is required to access Tianditu services. You can obtain a token from the Tianditu official website.string-
idLayer ID. A unique identifier for the layer.string-
maxzoomMaximum zoom level. The highest zoom level at which tiles are available. This corresponds to the highest resolution.number22
minzoomMinimum zoom level. The lowest zoom level at which tiles are available. This corresponds to the lowest resolution.number0
showVisibility of the layer. If true, the layer is displayed; if false, the layer is hidden.booleantrue
typesTypes of TianDiTu layers to include. Possible values are: 'vec' (Vector Base Map), 'cva' (Vector Annotations), 'img' (Imagery Base Map), 'cia' (Imagery Annotations), 'ter' (Terrain Shading), and 'cta' (Terrain Annotations). This property accepts an array of strings, allowing for multiple layer types to be combined.string[]["vec", "cva"]

EVENTS

NameDescriptionParameters
onCreatedInitialization complete event-

METHODS

NameDescriptionDefinition