[英]React-Leaflet: Uncaught TypeError: pointToLayer is not a function
我正在尝试在GeoJSON组件中使用pointToLayer参数。 我在组件(不同文件)之外定义了函数pointToLayer,并且遇到了该错误。
Map.js:
import {pointToLayer} from '../helpers/helper-country-point';
<GeoJSON>
key={_.uniqueId()}
data={this.props.activeCountry.geojson}
pointToLayer={pointToLayer(this)}
></GeoJSON>
文件../helpers/helper-country-point是:
import L from 'leaflet';
export function pointToLayer(feature, latlng) {
return L.circleMarker(latlng, {
color: 'white',
fillColor: 'white',
fillOpacity: .8,
radius: 3,
stroke: false
}).bindPopup("MESSAGE") // Change marker to circle
}
当我在Map.js中定义pointToLayer并使用时:
<GeoJSON
key={_.uniqueId()}
data= {this.props.countrySelected.geojson}
pointToLayer={this.pointToLayer.bind(this)}
></GeoJSON>
有用。 知道为什么我会不断收到此错误吗?
在第一个中,您要调用该函数并将this
用作参数。
在第二个中,您不调用该功能。 您只是将函数作为道具传递。 您可以尝试在第一个示例中删除(this)
部分,以便仅传递函数而不调用它。
然后,由于错误是pointToLayer
而不是一个函数,并且在map.js
声明该函数时已解决,因此我怀疑您可能将错误的路径写入了helper.js
文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.