【发布时间】:2019-06-25 09:15:19
【问题描述】:
我需要帮助从 React-Leaflet 创建 GeoJSON 自定义组件
使用 React 和 React-Leaflet 编写(最后一个版本) 该代码在 Map 组件中编写时有效,但我想导入/导出它以拆分代码
import React from 'react';
import { withLeaflet, GeoJSON } from 'react-leaflet'
import L from 'leaflet'
class CustomGesJSON extends GeoJSON {
getStyle(feature) {
// some code
}
pointToLayer(feature, latlng) {
// some code
}
onEachFeature(feature, layer) {
// some code
}
createLeafletElement(opts) {
const CustomGesJSON = L.geoJSON.extend({
onAdd: (map) => {
this.getStyle = this.getStyle.bind(this);
this.pointToLayer = this.pointToLayer.bind(this);
this.onEachFeature = this.onEachFeature.bind(this);
return this ;
}
});
return new CustomGesJSON({ data: this.props.data });
}
}
function testlog(txt) {
// some code
}
export default withLeaflet(CustomGesJSON);
我收到一条错误消息“GeoJSON 不是构造函数”
函数和方法(此处未显示)有效,我只需要帮助来进行正确的继承 欢迎其他解决方案
感谢您的帮助
【问题讨论】:
标签: javascript reactjs leaflet geojson react-leaflet