WaterLayer
Example
Example Source Code
tsx
import React, { useEffect, useRef, useState } from 'react'
import ReactDOM from 'react-dom'
import { MbMap, MbTiandituLayer } from '@mapbox-react/core'
import { MbWaterLayer } from '@mapbox-react/effect-layers'
const App = () => {
const [mapCenter] = useState([120.12629, 31.20913])
const [zoom, setZoom] = useState(9)
const [pitch, setPitch] = useState(45)
const mapInst = useRef<any>()
return (
<div className="map-wrapper">
<MbMap ref={mapInst} center={mapCenter} zoom={zoom} pitch={pitch}>
<MbTiandituLayer types={['img']} />
<MbWaterLayer
data="https://mapbox-web.github.io/mapbox-react/geojson/taihu.geojson"
waterColor={[0, 89, 128]}
dataTransform={(d) => d.features}
getPolygon={(data) => data.geometry.coordinates[0]}
opacity={0.5}
/>
</MbMap>
</div>
)
}
ReactDOM.render(<App />, document.querySelector('#root'))
API
PROPS
Name | Description | Type | Default |
---|---|---|---|
id | Layer ID | string | - |
waterColor | The color of the water surface. | number[] | [0, 89, 128] |
getPolygon | Function to retrieve polygon outline information. | AnyFunc | - |
data | Source data for the layer. | string / IndexAny / AnyArr / Promise<any> | '' |
show | Whether the layer is visible. | boolean | true |
opacity | The opacity of the layer (0-1). | number | 1 |
pickable | Whether the layer responds to mouse events. If false, the component will not emit mouse-related events. | boolean | false |
autoHighlight | When true and pickable is also true, the hovered object will be highlighted. | boolean | false |
highlightColor | The color to blend with the original color of the highlighted object. | string / number[] | [255, 255, 128, 1] |
highlightedObjectIndex | The index of the highlighted element. | number | -1 |
onDataLoad | Callback function invoked after data loading is complete. | AnyFunc | - |
dataTransform | Function to transform the data before rendering. | AnyFunc | - |
transitions | Transition settings for the layer. | IndexAny | {} |
EVENTS
Name | Description | Parameters |
---|
METHODS
Name | Description | Definition |
---|