@uiw/react-amap-map-type-control
Version:
用于在地图上弹出一个详细信息展示窗体,地图上只允许同时展示 `1` 个信息窗体。
43 lines • 1.22 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["visiable", "visible", "defaultType"];
import { useEffect, useState } from 'react';
import { useVisiable } from '@uiw/react-amap-utils';
import { useMapContext } from '@uiw/react-amap-map';
export function useMapTypeControl(props) {
if (props === void 0) {
props = {};
}
var [mapTypeControl, setMapTypeControl] = useState();
var {
visiable,
visible,
defaultType = 0
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
var {
map
} = useMapContext();
useEffect(() => {
if (map && !mapTypeControl) {
var instance;
map.plugin(['AMap.MapType'], () => {
instance = new AMap.MapType(_extends({
defaultType
}, other));
map.addControl(instance);
setMapTypeControl(instance);
});
return () => {
if (instance) {
map.removeControl(instance);
}
};
}
}, [map]);
useVisiable(mapTypeControl, visible != null ? visible : visiable);
return {
mapTypeControl,
setMapTypeControl
};
}