UNPKG

@uiw/react-baidu-map-type-control

Version:

Baidu Map map-type-control Components for React.

48 lines (47 loc) 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useMapTypeControl = useMapTypeControl; var _react = require("react"); var _reactBaiduMapMap = require("@uiw/react-baidu-map-map"); var _reactBaiduMapUtils = require("@uiw/react-baidu-map-utils"); function useMapTypeControl() { let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; const [mapTypeControl, setMapTypeControl] = (0, _react.useState)(); const { anchor, offset, type, mapTypes } = props; const { map } = (0, _reactBaiduMapMap.useMapContext)(); (0, _react.useEffect)(() => { if (map && !mapTypeControl) { const instance = new BMap.MapTypeControl({ anchor: anchor || BMAP_ANCHOR_TOP_LEFT, offset, type, mapTypes }); map.addControl(instance); setMapTypeControl(instance); } return () => { if (map && mapTypeControl) { try { map.removeControl(mapTypeControl); } catch (error) {} } }; // eslint-disable-next-line react-hooks/exhaustive-deps }, [map, mapTypeControl]); (0, _reactBaiduMapUtils.useVisiable)(mapTypeControl, props); (0, _reactBaiduMapUtils.useProperties)(mapTypeControl, props, ['Anchor', 'Offset', 'Unit']); return { mapTypeControl, setMapTypeControl }; }