我试图在一个由react-leaflet-draw创建的层中呈现一些反应组件。
这是我的尝试:
_onCreate(e) {
var layer = e.layer
layer.bindPopup(
<Content>
<Label>Flower Name</Label>
<Input type="text" placeholder="Flower Name"/>
<Label>Flower Index</Label>
<Input type="number" placeholder="Flower Index"/>
<Label>Flower Radius</Label>
<Input type="number" placeholder="Flower Radius"/>
<Button color="isSuccess" >Add Flower</Button>
</Content>
)
}组件由反应球提供。
但是我尝试这种方法,我得到了以下错误:Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'。
如果我把内容变成一个简单的字符串,我会得到一个简单的HTML字段和一个按钮,但是不能访问外部函数,也不能访问实际的Bulma组件。
实际上,我希望能够在数据库中保存新的形状。
从一个简短的在线搜索来看,这似乎是react-leaflet的一个限制,但我想先在这里检查一下。
另外,这是为新创建的形状设置弹出窗口的最佳方法吗?我很难将常规的leaflet-draw方法转换为react-leaflet-draw。
发布于 2017-03-20 22:40:25
有可能有反应组件内的反应-传单弹出。在您的示例中,您使用的是传单的API,而应该使用的是react传单的组件。请参阅单击地图后显示弹出窗口的以下示例:
const React = window.React;
const { Map, TileLayer, Marker, Popup } = window.ReactLeaflet;
let numMapClicks = 0
class SimpleExample extends React.Component {
state = {}
addPopup = (e) => {
this.setState({
popup: {
key: numMapClicks++,
position: e.latlng
}
})
}
handleClick = (e) => {
alert('clicked')
}
render() {
const {popup} = this.state
return (
<Map
center={[51.505, -0.09]}
onClick={this.addPopup}
zoom={13}
>
<TileLayer
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
/>
{popup &&
<Popup
key={`popup-${popup.key}`}
position={popup.position}
>
<div>
<p>A pretty CSS3 popup. <br/> Easily customizable.</p>
<button onClick={this.handleClick}>Click Me!</button>
</div>
</Popup>
}
</Map>
);
}
}
window.ReactDOM.render(<SimpleExample />, document.getElementById('container'));下面是一个要演示的小提琴。
https://stackoverflow.com/questions/42894803
复制相似问题