在我的反应项目中,我使用传单作为地图库。我没有使用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是传单Dom实例。到目前为止,传单绘图的功能可以很好地发挥作用。
但问题是工具栏的样式混乱如下:

那有什么问题吗?
发布于 2019-01-23 14:51:07
很可能缺少包含leaflet-draw声明的.leaflet-draw-toolbar CSS文件。
它可以从这样的leaflet-draw包中导入:
import "leaflet-draw/dist/leaflet.draw-src.css";或者通过public/index.html引用CDN,如下所示:
<link rel="stylesheet" href="https://unpkg.com/leaflet-draw@latest/dist/leaflet.draw-src.css" />这是演示
https://stackoverflow.com/questions/54324758
复制相似问题