使用leaflet.draw,我将drawControl I实例化为:
scope.drawOptions = {
position: 'topright',
draw: {
polyline: false,
polygon: {
icon: new L.DivIcon({
iconSize: new L.Point(16, 16),
className: 'leaflet-div-icon leaflet-editing-icon my-own-class'
}),
allowIntersection: false,
drawError: {
color: '#5878B8',
message: '<strong>Oh snap!<strong> you can\'t draw that!'
},
shapeOptions: shapeOptions
},
circle: false, // Turns off this drawing tool
rectangle: false,
marker: false
},
edit: {
featureGroup: self.featureGroup
}
};
scope.drawControl = new L.Control.Draw(scope.drawOptions);
map.addControl(scope.drawControl);
但进入编辑模式后,样式会恢复为“默认”状态。我尝试用以下方法解决这个问题:
map.on('draw:editstart', function(e) {
scope.drawControl.setDrawingOptions({
polygon: {
icon: new L.DivIcon({
iconSize: new L.Point(16, 16),
className: 'leaflet-div-icon leaflet-editing-icon my-own-class'
})
},
})
});
但这没有帮助。有什么建议吗?
这方面有一个封闭的github问题,但我无法弄明白:https://github.com/Leaflet/Leaflet.draw/issues/48#issuecomment-141546589
如果有人想玩,我创造了这个小问题:http://jsfiddle.net/markdickersonvt/mwz7pg2n/
答案 0 :(得分:6)
赞this?
基本上,我只是扩展L.Edit.Poly
类
L.Edit.Poly = L.Edit.Poly.extend({
options : {
icon: new L.DivIcon({
iconSize: new L.Point(20, 20),
className: 'leaflet-div-icon leaflet-editing-icon my-own-icon'
})
}
});
我以前使用Draw
插件,滥用扩展默认方法来摆脱工具提示。我认为这是最好的事情,这就是leaflet
以这种方式设计的原因。