|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import { Tooltip } from "antd"; |
|
|
|
|
import { useDispatch } from "react-redux"; |
|
|
|
|
import { editorAction } from "@store"; |
|
|
|
|
import { useDispatch, useSelector } from "react-redux"; |
|
|
|
|
import classnames from "classnames"; |
|
|
|
|
import { editorAction, OverlayNamePrefixs, mapStateSelector } from "@store"; |
|
|
|
|
import { OverlayTypes } from "@types"; |
|
|
|
|
|
|
|
|
|
type IconWithTipProps = { |
|
|
|
@ -8,6 +9,7 @@ type IconWithTipProps = {
|
|
|
|
|
text: string; |
|
|
|
|
onClick?: () => void; |
|
|
|
|
placement?: "top" | "right"; |
|
|
|
|
selected?: boolean; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const IconWithTip = ({ |
|
|
|
@ -15,36 +17,44 @@ const IconWithTip = ({
|
|
|
|
|
text, |
|
|
|
|
onClick = () => {}, |
|
|
|
|
placement = "top", |
|
|
|
|
selected, |
|
|
|
|
}: IconWithTipProps) => { |
|
|
|
|
return ( |
|
|
|
|
<Tooltip title={text} placement={placement}> |
|
|
|
|
<span className={`icon icon-${type}`} onClick={onClick}></span> |
|
|
|
|
<span |
|
|
|
|
className={classnames("icon", `icon-${type}`, { |
|
|
|
|
"icon-selected": selected, |
|
|
|
|
})} |
|
|
|
|
onClick={onClick} |
|
|
|
|
></span> |
|
|
|
|
</Tooltip> |
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const Tools = () => { |
|
|
|
|
type OverlayToolProps = { |
|
|
|
|
type: OverlayTypes; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const OverlayTool = (props: OverlayToolProps) => { |
|
|
|
|
const dispatch = useDispatch(); |
|
|
|
|
const { type } = props; |
|
|
|
|
const text = OverlayNamePrefixs[type]; |
|
|
|
|
|
|
|
|
|
const createOverlay = (type: OverlayTypes) => () => |
|
|
|
|
dispatch(editorAction.createOverlay(type)); |
|
|
|
|
const { overlayType } = useSelector(mapStateSelector); |
|
|
|
|
const selected = type === overlayType; |
|
|
|
|
|
|
|
|
|
const createRectangle = createOverlay(OverlayTypes.Rectangle); |
|
|
|
|
const createPolygon = createOverlay(OverlayTypes.Polygon); |
|
|
|
|
const createPolyline = createOverlay(OverlayTypes.Polyline); |
|
|
|
|
const createCircle = createOverlay(OverlayTypes.Circle); |
|
|
|
|
const onClick = () => dispatch(editorAction.createOverlay(type)); |
|
|
|
|
return <IconWithTip {...{ text, onClick, type, selected }} />; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const Tools = () => { |
|
|
|
|
return ( |
|
|
|
|
<> |
|
|
|
|
<div className="marker-tools"> |
|
|
|
|
<IconWithTip type="rect" text="矩形工具" onClick={createRectangle} /> |
|
|
|
|
<IconWithTip type="polygon" text="多边形工具" onClick={createPolygon} /> |
|
|
|
|
<IconWithTip |
|
|
|
|
type="polyline" |
|
|
|
|
text="多段线工具" |
|
|
|
|
onClick={createPolyline} |
|
|
|
|
/> |
|
|
|
|
<IconWithTip type="circle" text="圆形工具" onClick={createCircle} /> |
|
|
|
|
<OverlayTool type={OverlayTypes.Rectangle} /> |
|
|
|
|
<OverlayTool type={OverlayTypes.Polygon} /> |
|
|
|
|
<OverlayTool type={OverlayTypes.Polyline} /> |
|
|
|
|
<OverlayTool type={OverlayTypes.Circle} /> |
|
|
|
|
</div> |
|
|
|
|
<div className="common-tools"> |
|
|
|
|
<div className="tools-group"> |
|
|
|
|