reactjs - 用箭头问题反应传单折线
问题描述
我正在使用反应传单。我尝试用带箭头的折线来实现它。
它显示以下错误。
1.TypeError:无法读取 tncomponentDidMount 处未定义的属性“addLayer”(MapLayer.js:40) 2.TypeError:无法读取 a.value 处未定义的属性“leafletElement”(Polyline.js:8) 3.TypeError:无法读取tncomponentWillUnmount (MapLayer.js:61) 处未定义的属性“removeLayer”
在这里我也添加了我的 Maplayer.js 和 Polyline.js
MapLayer.js
import type { Layer } from 'leaflet'
import React, { Fragment } from 'react'
import { LeafletProvider } from './context'
import MapComponent from './MapComponent'
import type { LeafletContext, MapLayerProps } from './types'
export default class MapLayer<LeafletElement: Layer,Props: MapLayerProps,>
extends MapComponent<LeafletElement, Props> {
contextValue: ?LeafletContext
leafletElement: LeafletElement
constructor(props: Props) {
super(props)
this.leafletElement = this.createLeafletElement(props)
}
get layerContainer(): Layer {
return this.props.leaflet.layerContainer || this.props.leaflet.map
}
createLeafletElement(_props: Props): LeafletElement {
throw new Error('createLeafletElement() must be implemented')
}
updateLeafletElement(_fromProps: Props, _toProps: Props) {}
componentDidMount() {
super.componentDidMount()
this.layerContainer.addLayer(this.leafletElement)
}
componentDidUpdate(prevProps: Props) {
super.componentDidUpdate(prevProps)
if (this.props.attribution !== prevProps.attribution) {
const { map } = this.props.leaflet
if (map != null && map.attributionControl != null) {
map.attributionControl.removeAttribution(prevProps.attribution)
map.attributionControl.addAttribution(this.props.attribution)
}
}
this.updateLeafletElement(prevProps, this.props)
}
componentWillUnmount() {
super.componentWillUnmount()
this.layerContainer.removeLayer(this.leafletElement)
}
render() {
const { children } = this.props
if (children == null) {
return null
}
return this.contextValue == null ? (
<Fragment>{children}</Fragment>
) : (
<LeafletProvider value={this.contextValue}>{children}</LeafletProvider>
)
}
}
折线.js
import React from 'react'
import { Polyline } from 'react-leaflet'
import 'leaflet-arrowheads'
class ArrowheadsPolyline extends React. Component{
componentDidMount(){
const polyline = this.polylineRef.leafletElement
if (this.props.arrowheads){
polyline.arrowheads(this.props.arrowheads)
polyline._update()
}
}
componentWillUnmount(){
if (this.props.arrowheads){
const polyline = this.polylineRef.leafletElement
polyline.deleteArrowheads()
}
}
render(){
return(
<Polyline {...this.props} ref={polylineRef => this.polylineRef = polylineRef} />
)
}
}
export default ArrowheadsPolyline
我的地图组件就像
<Map <Polyline positions={ [coordinates] } arrowheads /> />
如果你们有任何想法,请告诉我
解决方案
推荐阅读
- django - 如何解决 Django 实时服务器中的延迟问题?
- javascript - 如何在 react/redux 中记录容器和子容器中的操作
- windows - 如何在 Windows 10 中安装 NASM?
- javascript - TouchableNativeFeedback onPress 不起作用
- reactjs - 字段数组中的 Formik 验证
- nrwl - Angular 控制台:无法创建库
- sql-server - 从 VBA 调用存储过程
- python - 获取卷积算法失败
- python - 独立 R 脚本加载依赖项的性能
- drupal - Drupal 8 来宾用户访问节点