UNPKG

@mapbox-react/env-layers

Version:

Mapbox React Component Library Env Layers

68 lines (67 loc) 1.62 kB
import { jsx as d } from "react/jsx-runtime"; import { useContext as g, useRef as f } from "react"; import { useMount as L, useUnmount as C, useDeepCompareEffect as v } from "ahooks"; import { v4 as M } from "uuid"; import { MapboxLayer as D } from "@deck.gl/mapbox"; import { MapContext as $ } from "@mapbox-react/core"; import j from "@mapbox-web/deck-gl-extension"; import { tempLayerDefaultProps as x } from "./props.mjs"; function N(t) { const u = g($), r = f(null), l = f(t.id || M()); return L(() => { const { image: e, min: o, max: n, range: a, origin: m, resolution: i, rampColors: s, opacity: c, visible: p } = { ...x(), ...t }, y = u.mapboxInstance, b = { id: l.current, image: e, min: o, max: n, range: a, origin: m, resolution: i, rampColors: s, opacity: c, visible: p }; r.current = new D( Object.assign({ type: j.ScalarFieldLayer }, b) ), y.addLayer(r.current); }), C(() => { const e = u.mapboxInstance; e && r.current && e.removeLayer(l.current); }), v(() => { const { image: e, min: o, max: n, range: a, origin: m, resolution: i, rampColors: s, opacity: c, visible: p } = { ...x(), ...t }; r.current && r.current.setProps({ image: e, min: o, max: n, range: a, origin: m, resolution: i, rampColors: s, opacity: c, visible: p }); }, [t]), /* @__PURE__ */ d("i", { className: "mb-temp-layer" }); } export { N as default };