在我的 react 项目中,我使用传单作为地图库。而且我没有使用react-leaflet
包,而是使用原始的传单库。
现在我想添加leaflet-draw
插件,我已经安装了leaflet-draw
npm 包,我的设置如下:
import 'leaflet-draw'
import './leaflet-draw.less'
class GLMap extends Component {
componentDidMount () {
...
this.setUpLeafletDraw()
this.map.on('draw:created', this.leafletDrawHandler)
}
leafletDrawHandler = (e) => {
console.log('11111', e.layer._latlngs)
const type = e.layerType
const layer = e.layer
if (type === 'marker') {
layer.bindPopup('A popup!')
}
this.drawnItemsLayer.addLayer(layer)
}
setUpLeafletDraw = () => {
// this.drawnItems is the layer contains the drawn features
this.drawnItemsLayer = new L.FeatureGroup()
this.map.addLayer(this.drawnItemsLayer)
var drawControl = new L.Control.Draw({
edit: {
featureGroup: this.drawnItemsLayer
}
})
this.map.addControl(drawControl)
}
}
在上面的代码中,this.map
是leaflet Dom 实例。到目前为止,传单绘制的功能可以正常工作。
但问题是工具栏的样式混乱如下:
所以有什么问题?