in src/lib/components/molecules/canvas-map/lib/layers/VectorLayer.js [15:61]
static Component({
features: featureCollection,
style,
minZoom,
opacity,
hitDetectionEnabled = true,
}) {
const { registerLayer, unregisterLayer } = useContext(MapContext)
// We recreate layer whenever these properties change, which cannot be changed on the fly
// and require recreation
const layer = useMemo(
() => {
const features =
featureCollection instanceof FeatureCollection
? featureCollection.features
: /** @type {import("../Feature").Feature[]} */ (featureCollection)
return VectorLayer.with(features, {
style,
minZoom,
opacity,
hitDetectionEnabled,
})
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[featureCollection, minZoom, opacity, hitDetectionEnabled],
)
useEffect(() => {
registerLayer(layer, this)
return () => {
unregisterLayer(layer)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [layer])
useEffect(() => {
// If the style prop changes, just update the layer, style can be changed without creating a
// new layer
layer.style = style
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [style])
return null
}