Javascript 将传单标记与bage循环反应
我正在使用Javascript 将传单标记与bage循环反应,javascript,reactjs,leaflet,react-leaflet,Javascript,Reactjs,Leaflet,React Leaflet,我正在使用react传单,我需要多个带有徽章的标记,但每当我在地图上使用onMoveEnd和setState时,就会导致循环和错误。 同样,当我使用onDragEnd而不是onMoveEnd时,循环问题消失了,但我不能再将拖动到我想要的地方 const onMapMoveEnd = (e) => { setCenter(e.target.getCenter()) } <Map ref={mapRef} onMoveend={(e) => onMapMoveEnd(e
react传单
,我需要多个带有徽章的标记,但每当我在地图上使用onMoveEnd
和setState
时,就会导致循环和错误。
同样,当我使用onDragEnd
而不是onMoveEnd
时,循环问题消失了,但我不能再将拖动到我想要的地方
const onMapMoveEnd = (e) => {
setCenter(e.target.getCenter())
}
<Map ref={mapRef} onMoveend={(e) => onMapMoveEnd(e)}>
markers.map( (mark, index) => <MarkerWithBadge markerIcon={myIcon} position={position}>
{index}
</MarkerWithBadge>
)
const onMapMoveEnd=(e)=>{
setCenter(e.target.getCenter())
}
onMapMoveEnd(e)}>
markers.map((标记,索引)=>
{index}
)
const MarkerWithBadge=props=>{
常量initMarker=ref=>{
如果(参考){
const popup=L.popup().setContent(props.children);
参考元素
.addTo(ref.contextValue.map)
.bindPopup(弹出{
类名:“徽章”,
//closeOnClick:false,
自动关闭:错误
})
.openPopup()
//防止徽章在单击时消失
.关闭(“点击”);
}
};
返回;
};
导出默认标记WithBadge;
尝试将L.popup()
的autoPan
选项设置为false
。它防止地图平移以适应打开的弹出窗口。至少对我来说,这就是解决问题的方法
文档参考:.尝试将L.popup()
的autoPan
选项设置为false
。它防止地图平移以适应打开的弹出窗口。至少对我来说,这就是解决问题的方法
文件参考:
const MarkerWithBadge = props => {
const initMarker = ref => {
if (ref) {
const popup = L.popup().setContent(props.children);
ref.leafletElement
.addTo(ref.contextValue.map)
.bindPopup(popup, {
className: "badge",
// closeOnClick: false,
autoClose: false
})
.openPopup()
// prevent badge from dissapearing onClick
.off("click");
}
};
return <Marker ref={initMarker} {...props} />;
};
export default MarkerWithBadge;