我想使用Leaflet.VectorGrid插件,我有一个问题。有没有在react-leaflet中创建自定义组件的例子?
发布于 2020-06-02 15:38:08
React-Leaflet旨在提供Leaflet提供的所有控件和层,但它不支持任何Leaflet插件。
创建自定义组件需要执行以下步骤:
1.)扩展React-Leaflet提供的抽象类
2.)实现createLeafletElement (props: Object): Object方法创建Leaflet-element。例如,
createLeafletElement(opts) {
const MapInfo = L.Control.extend({
onAdd: (map) => {
this.panelDiv = L.DomUtil.create('div', 'info');
return this.panelDiv;
}
});
return new MapInfo({ position: 'bottomleft' });
}3.)使用withLeaflet -包装您的组件。例如,
export default withLeaflet(MapInfo);此示例将帮助您- https://codesandbox.io/s/p5zzmnlk8j
另外,请参阅此文档https://react-leaflet.js.org/docs/en/custom-components.html
https://stackoverflow.com/questions/62146880
复制相似问题