import { useView } from '@/hooks/view'; import MapView from '@arcgis/core/views/MapView'; import React, { ReactNode, useEffect, useRef } from 'react'; import Feature from '@arcgis/core/widgets/Feature'; import IdentifyResult from '@arcgis/core/rest/support/IdentifyResult'; import './index.less'; import { getDomOffset } from '@/utils'; interface Props { view?: MapView; position: IdentifyResult; children: ReactNode; } export default function MarkerWrap(props: Props) { const { view, position, children } = props; const viwes = useView(view); const markRef = useRef<HTMLDivElement | null>(null); const watchHandle = useRef<IHandle>(); const render = () => { const { geometry } = position.feature; const { type, centroid, extent } = geometry as any; const top = getDomOffset.top(viwes?.container); const left = getDomOffset.left(viwes?.container); if (!markRef.current) return; const { clientWidth, clientHeight } = markRef.current; let p = null; if (type === 'point') { p = geometry; } else if (type === 'polygon') { p = centroid; } else if (type === 'polyline') { p = extent.center; } if (p) { const screenPoint = viwes?.toScreen(p); if (screenPoint && markRef.current) { markRef.current.style.top = screenPoint.y + left - clientWidth / 2 + 'px'; markRef.current.style.left = screenPoint.x + top - clientHeight + 'px'; } } }; useEffect(() => { if (viwes && position) { render(); watchHandle.current = viwes.watch('extent', render); } }, [position, viwes]); useEffect(() => { return () => { if (watchHandle.current) watchHandle.current.remove(); }; }, []); return ( <div className="MarkerWrap" ref={markRef}> {children} </div> ); }
正文
arcgis api封装弹窗组件
文章版权声明:除非注明,否则均为
譬如朝露博客原创文章,转载或复制请以超链接形式并注明出处。
发表评论
侧栏公告
寄语
譬如朝露博客是一个分享前端知识的网站,联系方式11523518。
热评文章
标签列表
热门文章
友情链接