【问题标题】:django leaflet - adding/removing controls on HTML page button clickdjango 传单 - 在 HTML 页面按钮单击上添加/删除控件
【发布时间】: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


    【解决方案1】:

    你试过没有 django 吗?

    只需添加:

    <Div id = 'map'> </ div>
    
    Var map = L.map ( 'map')
    

    在涉及 Leaflet 时,我从未在 Django 中设置模板变量。我尽量保持常用的“传单 javascript”方式!

    尤其是在向 Leaflet 添加一些插件/插件/扩展时。

    如果您更喜欢 Django,最好能发布您的整个模板 (html)!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-17
      • 1970-01-01
      • 1970-01-01
      • 2013-10-25
      • 2015-05-30
      • 1970-01-01
      相关资源
      最近更新 更多