-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给 new BMap.Marker 对象添加的 click 监听器报错 b.ma(...).Ub is not a function #267
Comments
@xyxc0673 我使用 Example Codeimport ReactDOM from "react-dom";
import { useRef, Fragment, useEffect } from "react";
import { Provider, APILoader, useMap, useMarker } from "@uiw/react-baidu-map";
const Example = () => {
const divElm = useRef(null);
const { setContainer, map } = useMap({
widget: ["GeolocationControl", "NavigationControl"],
zoom: 8
});
const { setType, marker } = useMarker({
map,
position: { lng: 121.444017, lat: 31.237787 }
});
useEffect(() => {
if (divElm.current && !map) {
setContainer(divElm.current);
}
});
useEffect(() => {
if (marker) {
console.log("marker::", marker);
marker.addEventListener("click", () => {
console.log("marker", marker);
});
}
}, [marker]);
return (
<Fragment>
<button onClick={() => setType("red2")}>设置 red2</button>
<button onClick={() => setType("loc_blue")}>设置 loc_blue</button>
<button
onClick={() =>
marker.setPosition(new BMap.Point(121.497197, 31.232847))
}
>
设置坐标点
</button>
<button onClick={() => marker.setAnimation(2)}>设置动画</button>
<button onClick={() => marker.setAnimation(null)}>取消动画</button>
<div ref={divElm} style={{ height: "100%" }} />
</Fragment>
);
};
const Demo = () => (
<div style={{ width: "100%", height: "300px" }}>
<APILoader akay="GTrnXa5hwXGwgQnTBG28SHBubErMKm3f">
<Provider>
<Example />
</Provider>
</APILoader>
</div>
);
ReactDOM.render(<Demo />, document.getElementById("container")); |
@jaywcjlove 如果我查出了原因的话和你说一下,不过我现在的需求是需要遍历添加 marker 以及获得 Map 的 ref 来调用方法,useMarker 的话,好像不太方便遍历,然后使用 Map + Marker 组件的话,通过 ref 的方式获取的 Map 的实例是有的,但是调用方法时没有反应。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
示例代码
在初始化完成,点击 marker 报错,但是移动后再次点击却没有问题。
The text was updated successfully, but these errors were encountered: