【发布时间】:2018-08-15 08:53:09
【问题描述】:
我是传单绘制插件和打字稿的新手,所以我正在寻找扩展传单绘制的方法,以创建一个绘制圆圈的自定义控件。看到一个用JS写的例子,但是不知道如何正确创建基于leaflet draw插件的控件。
我正在创建基于 Angular 的网络应用程序。 帮助扩展打字稿中的控制。我正在使用 ars 库。
"leaflet": "^1.3.3",
"leaflet-draw": "^1.0.2",
"@types/leaflet": "^1.2.9",
它的代码sn-p在JS中是如何实现的
}
/*Class for new polygon shape */
L.Draw.CustomCircle = L.Draw.Circle.extend({
options: {
repeatMode: true
},
initialize: function (map, options) {
this.type = 'customCircle';
L.Draw.Feature.prototype.initialize.call(this, map, options);
}
});
/*Changes some of the default text for the toolbar buttons*/
L.drawLocal = {
draw: {
toolbar: {
buttons: {
circle: 'Draw a include circle',
customCircle: 'Draw a exnclude circle',
}
},
handlers: {
circle: {
tooltip: {
start: 'Click and drag to include circle.'
},
radius: 'Radius'
},
customCircle: {
tooltip: {
start: 'Click and drag to exclude circle.'
},
radius: 'Radius'
}
}
},
edit: { }
};
/*Adds new shape types to the options */
L.DrawToolbar.include({
options: {
circle: {},
customCircle: {}
},
initialize: function (options) {
// Ensure that the options are merged correctly since L.extend is only shallow
for (var type in this.options) {
if (this.options.hasOwnProperty(type)) {
if (options[type]) {
options[type] = L.extend({}, this.options[type], options[type]);
}
}
}
this._toolbarClass = 'leaflet-draw-draw';
L.Toolbar.prototype.initialize.call(this, options);
},
getModeHandlers: function (map) {
return [
{
enabled: this.options.customCircle,
handler: new L.Draw.CustomCircle(map, this.options.customCircle),
title: L.drawLocal.draw.toolbar.buttons.customCircle
},
{
enabled: this.options.circle,
handler: new l.draw.circle(map, this.options.circle),
title: l.drawlocal.draw.toolbar.buttons.circle
},
];
},
// Get the actions part of the toolbar
getActions: function (handler) {
return [
{
enabled: handler.completeShape,
title: L.drawLocal.draw.toolbar.finish.title,
text: L.drawLocal.draw.toolbar.finish.text,
callback: handler.completeShape,
context: handler
},
];
},
setOptions: function (options) {
L.setOptions(this, options);
for (var type in this._modes) {
if (this._modes.hasOwnProperty(type) && options.hasOwnProperty(type)) {
this._modes[type].handler.setOptions(options[type]);
}
}
}
});
var drawControl = new L.Control.Draw();
map.addControl(drawControl);
【问题讨论】:
标签: angular typescript leaflet leaflet.draw