Skip to content

Tile3dLayer

Example

Preview

3D Layer

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

const App = () => {
  const [mapCenter] = useState([118.86685053716911, 33.31780722522485])
  const [zoom, setZoom] = useState(8)
  const [pitch, setPitch] = useState(20)
  const mapInst = useRef<any>()

  const tileLoadedHandler = (tileset: any) => {
    console.log('tileset', tileset)
  }

  return (
    <div className="map-wrapper">
      <MbMap ref={mapInst} center={mapCenter} zoom={zoom} pitch={pitch}>
        <MbTiandituLayer types={['vec']} />
        <MbTile3dLayer data="/json/tileset.json" onLoaded={tileLoadedHandler} />
      </MbMap>
    </div>
  )
}

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

API

PROPS

NameDescriptionTypeDefault
idLayer IDstring-
autoHighlightWhen this property is true and pickable is also true, the hovered object will be highlighted.booleanfalse
dataSource data for the layer.string / IndexAny / AnyArr / Promise<any>''
highlightColorThe color to blend with the original color of the highlighted object.string / number[][255, 255, 128, 1]
highlightedObjectIndexThe index of the currently highlighted element.number-1
opacityThe opacity of the layer (0-1).number1
pickableWhether the layer responds to mouse events. If false, the component will not emit mouse-related events.booleanfalse
pointSizeSize of the points.number1
showWhether the layer is visible.booleantrue

EVENTS

NameDescriptionParameters
onCreatedInitialization complete event-
onMouseMove-{ object: any; coordinates: mapboxgl.LngLat; pixel: [number, number] }
onMouseLeave--
clonClickick-{ object: any; coordinates: mapboxgl.LngLat; pixel: [number, number] }
onLoaded-tileset

METHODS

NameDescriptionDefinition