UNPKG

@uiw/react-baidu-map-label

Version:

Baidu Map label Components for React.

65 lines (64 loc) 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useLabel = useLabel; var _react = require("react"); var _reactBaiduMapUtils = require("@uiw/react-baidu-map-utils"); var _reactBaiduMapMap = require("@uiw/react-baidu-map-map"); function useLabel() { let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; const [label, setLabel] = (0, _react.useState)(); const { offset, style, content = '', position, enableMassClear } = props; const { container, Portal } = (0, _reactBaiduMapUtils.usePortal)(); // const { container } = useRenderDom({ children: props.children }); const { map } = (0, _reactBaiduMapMap.useMapContext)(); (0, _react.useEffect)(() => { if (!BMap || !map) return; if (!label) { const opts = { offset, position, enableMassClear }; const instance = new BMap.Label(props.children ? container.innerHTML : content, opts); instance.setStyle({ ...style }); map.addOverlay(instance); setLabel(instance); } return () => { if (map && label) { map.removeOverlay(label); } }; // eslint-disable-next-line react-hooks/exhaustive-deps }, [map]); (0, _react.useEffect)(() => { if (label) { label.setContent(props.children ? container.innerHTML : content); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [props.children, container, label]); (0, _reactBaiduMapUtils.useVisiable)(label, props); (0, _reactBaiduMapUtils.useEventProperties)(label, props, ['Click', 'DblClick', 'MouseDo', 'MouseUp', 'MouseOout', 'MouseO', 'Remove', 'RightClick']); (0, _reactBaiduMapUtils.useProperties)(label, props, ['Style', 'Position', 'Offset', 'Title', 'ZIndex']); (0, _reactBaiduMapUtils.useEnableProperties)(label, props, ['MassClear']); return { label, setLabel, Portal }; }