You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
9.8 KiB

2 years ago
{"ast":null,"code":"import { LeafletProvider, createContainerComponent, createControlHook, createElementHook, createElementObject, extendContext, useLeafletContext } from '@react-leaflet/core';\nimport { Control } from 'leaflet';\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nexport const useLayersControlElement = createElementHook(function createLayersControl(_ref, ctx) {\n let {\n children: _c,\n ...options\n } = _ref;\n const control = new Control.Layers(undefined, undefined, options);\n return createElementObject(control, extendContext(ctx, {\n layersControl: control\n }));\n}, function updateLayersControl(control, props, prevProps) {\n if (props.collapsed !== prevProps.collapsed) {\n if (props.collapsed === true) {\n control.collapse();\n } else {\n control.expand();\n }\n }\n});\nexport const useLayersControl = createControlHook(useLayersControlElement); // @ts-ignore\n\nexport const LayersControl = createContainerComponent(useLayersControl);\nexport function createControlledLayer(addLayerToControl) {\n return function ControlledLayer(props) {\n const parentContext = useLeafletContext();\n const propsRef = useRef(props);\n const [layer, setLayer] = useState(null);\n const {\n layersControl,\n map\n } = parentContext;\n const addLayer = useCallback(layerToAdd => {\n if (layersControl != null) {\n if (propsRef.current.checked) {\n map.addLayer(layerToAdd);\n }\n\n addLayerToControl(layersControl, layerToAdd, propsRef.current.name);\n setLayer(layerToAdd);\n }\n }, [layersControl, map]);\n const removeLayer = useCallback(layerToRemove => {\n layersControl?.removeLayer(layerToRemove);\n setLayer(null);\n }, [layersControl]);\n const context = useMemo(() => {\n return extendContext(parentContext, {\n layerContainer: {\n addLayer,\n removeLayer\n }\n });\n }, [parentContext, addLayer, removeLayer]);\n useEffect(() => {\n if (layer !== null && propsRef.current !== props) {\n if (props.checked === true && (propsRef.current.checked == null || propsRef.current.checked === false)) {\n map.addLayer(layer);\n } else if (propsRef.current.checked === true && (props.checked == null || props.checked === false)) {\n map.removeLayer(layer);\n }\n\n propsRef.current = props;\n }\n });\n return props.children ? /*#__PURE__*/React.createElement(LeafletProvider, {\n value: context\n }, props.children) : null;\n };\n}\nLayersControl.BaseLayer = createControlledLayer(function addBaseLayer(layersControl, layer, name) {\n layersControl.addBaseLayer(layer, name);\n});\nLayersControl.Overlay = createControlledLayer(function addOverlay(layersControl, layer, name) {\n layersControl.addOverlay(layer, name);\n});","map":{"version":3,"names":["LeafletProvider","createContainerComponent","createControlHook","createElementHook","createElementObject","extendContext","useLeafletContext","Control","React","useCallback","useEffect","useMemo","useRef","useState","useLayersControlElement","createLayersControl","ctx","children","_c","options","control","Layers","undefined","layersControl","updateLayersControl","props","prevProps","collapsed","collapse","expand","useLayersControl","LayersControl","createControlledLayer","addLayerToControl","ControlledLayer","parentContext","propsRef","layer","setLayer","map","addLayer","layerToAdd","current","checked","name","removeLayer","layerToRemove","context","layerContainer","createElement","value","BaseLayer","addBaseLayer","Overlay","addOverlay"],"sources":["/Users/mahdi/Documents/work/programming/barnameNegar/arbaeenWebApp/node_modules/react-leaflet/lib/LayersControl.js"],"sourcesContent":["import { LeafletProvider, createContainerComponent, createControlHook, createElementHook, createElementObject, extendContext, useLeafletContext } from '@react-leaflet/core';\nimport { Control } from 'leaflet';\nimport React, { useCallback, use