UNPKG

@mapbox-react/env-layers

Version:

Mapbox React Component Library Env Layers

2 lines (1 loc) 1.2 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("react/jsx-runtime"),l=require("react"),p=require("ahooks"),q=require("uuid"),L=require("@deck.gl/mapbox"),v=require("@mapbox-react/core"),C=require("@mapbox-web/deck-gl-extension"),x=require("./props.js");function M(t){const y=l.useContext(v.MapContext),r=l.useRef(null),d=l.useRef(t.id||q.v4());return p.useMount(()=>{const{image:e,min:n,max:o,range:a,origin:s,resolution:u,rampColors:i,opacity:c,visible:m}={...x.tempLayerDefaultProps(),...t},b=y.mapboxInstance,f={id:d.current,image:e,min:n,max:o,range:a,origin:s,resolution:u,rampColors:i,opacity:c,visible:m};r.current=new L.MapboxLayer(Object.assign({type:C.ScalarFieldLayer},f)),b.addLayer(r.current)}),p.useUnmount(()=>{const e=y.mapboxInstance;e&&r.current&&e.removeLayer(d.current)}),p.useDeepCompareEffect(()=>{const{image:e,min:n,max:o,range:a,origin:s,resolution:u,rampColors:i,opacity:c,visible:m}={...x.tempLayerDefaultProps(),...t};r.current&&r.current.setProps({image:e,min:n,max:o,range:a,origin:s,resolution:u,rampColors:i,opacity:c,visible:m})},[t]),g.jsx("i",{className:"mb-temp-layer"})}exports.default=M;