【发布时间】:2016-11-13 10:37:56
【问题描述】:
我目前正在使用 django-leaflet 和 Leaflet-draw 控件。我想让绘制控件在某个事件(例如切换按钮)上可用(添加到地图)。
我目前有一个简单的 jQuery 骨架:
$("#mode").on("click", function() {
if(document.getElementById('mode').checked) {
$("#save").removeClass("hidden");
alert("Edit Mode");
//event where I want to add controls to map
//map.addControl(drawControl);
} else {
$("#save").addClass("hidden");
alert("View Mode");
//event where I want to remove controls from map
//map.removeControl(drawControl);
}
});
我的 map.js 位于 html 文件的外部,我在模板中仅使用这一行调用它(按照 django-leaflet 中的说明):
{% leaflet_map "mapdiv" callback="leafletinit" %}
注意:我还尝试在同一页面上包含 drawControl 变量,但我认为我做的不正确...我的 map.js 加载正确,因为它确实加载了地图和直接无事件视图上的控件
【问题讨论】:
标签: javascript jquery html django leaflet