Skip to content

BuildingLayer

Building layers simulate 3D building effects and require source building data and floor height field information. For large datasets, vector tiling is recommended.

Example

Preview

Building Layer

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

const App = () => {
  const [mapCenter] = useState([116.194322, 39.925238])
  const [zoom, setZoom] = useState(15)

  return (
    <div className="map-wrapper">
      <MbMap center={mapCenter} zoom={zoom} pitch={50}>
        <MbTiandituLayer types={['vec']} />
        <MbBuildingLayer
          heightInfoField="Floor"
          magnification={5}
          color="#acacac"
          geoJsonDataSource="/geoserver/building/ows?service=WFS&maxFeatures=60000&version=1.0.0&request=GetFeature&typeName=cestc:beijing-building-4326&outputFormat=application/json"
        />
      </MbMap>
    </div>
  )
}

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

API

PROPS

名称描述类型默认值
idLayer IDstring-
heightInfoFieldThe corresponding key in the source data for height informationstring-
magnificationHeight magnification factornumber1
baseBase heightnumber0
colorColor value. Supports formats such as "#000000" and "rgb(0,0,0)"string#acacac
dataData for the vector layer. Each object in the array must contain the required coordinates property and the optional properties property. Each object represents a point/line/polygonVectorLayerData-
geoJsonDataSourceGeoJSON data source. Can be set to a GeoJSON data link or a GeoJSON data object. Specification Link. If this property is set, the data property is ignoredstring / GeoJSONSource-
opacityOpacitynumber1
maxzoomMaximum zoom levelnumber22
minzoomMinimum zoom levelnumber0
pickableWhether the layer responds to pick events. If false, the component will not emit mouse-related eventsbooleantrue
showWhether to show the layerbooleantrue
sourceIdID of the layer's source. If this ID is set, both the geoJsonDataSource and data properties are ignoredstring-
sourceLayerNameLayer name in the source data. This property is effective when sourceId is setstring-
sideGradientValue of the Mapbox layer's fill-extrusion-vertical-gradient propertybooleanfalse

EVENTS

NameDescriptionParameters
onCreatedMap initialization completed event-
onClickLayer click eventobject — Contains screen coordinates (pixel), longitude/latitude (coordinate), selected element properties, and originalEvent
onMouseMoveMouse move eventobject — Contains screen coordinates (pixel), longitude/latitude (coordinate), selected element properties, and originalEvent
onMouseLeaveMouse leave element eventMapMouseEvent

METHODS

NameDescriptionDefinition
exportToGeoJsonTranslate the layer's data to GeoJSON formatted text. If the layer's data source comes from a source component or a URL, output null.()=> object | null