首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GeoDjango将传单插件添加到管理站点

GeoDjango将传单插件添加到管理站点
EN

Stack Overflow用户
提问于 2020-05-04 02:19:12
回答 1查看 613关注 0票数 0

我遵循这个文件https://github.com/makinacorpus/django-leaflet/blob/master/docs/widget.rst,我正在尝试添加叶控件地理编码器到管理网站上的叶控件。谢谢你阅读我的问题,很抱歉我的英语不好。

我的代码:

admin/change_form.html

代码语言:javascript
复制
{% extends "admin/change_form.html" %}
{% load i18n admin_urls static leaflet_tags %}

{% block stylesheets %}
{{ block.super }}
{% leaflet_css plugins="ALL" %}
<style>
/* Force leaflet controls underneath header (z-index 1000) and
   above leaflet tiles (z-index 400)*/
/*.leaflet-top{z-index:999;}*/
</style>

{% endblock %}

{% block javascripts %}
{{ block.super }}
{% leaflet_js plugins="ALL" %}

<script type="text/javascript">
    window.addEventListener("map:init", function (event) {
        var map = event.detail.map; // Get reference to map

        L.Control.geocoder(
            {
                collapsed: true,
                geocoder: L.Control.Geocoder.nominatim({
                    geocodingQueryParams: {countrycodes: 'VN'}
                })
            }
        ).addTo(map);
    });
</script>

{% endblock %}

setting.py

代码语言:javascript
复制
# leaflet Module
LEAFLET_CONFIG = {
    'DEFAULT_CENTER': (10.762622, 106.660172), #default center of your map
    'DEFAULT_ZOOM': 14, #default zoom level
    'MIN_ZOOM': 3,
    'MAX_ZOOM': 22,
    'SCALE': 'both',
    'ATTRIBUTION_PRIFIX': 'tekson', #attribution of your map
    'PLUGINS': {
        'forms': {
                'js': ['/static/leaflet_geocoder/geocoder.js'],
                'css': ['/static/leaflet_geocoder/geocoder.css'],
                'auto-include': True,
        },
    },
}

结果:什么都没有改变

EN

回答 1

Stack Overflow用户

发布于 2020-05-13 00:45:45

我已经通过关注this post解决了我的问题

我的代码:

setting.py

代码语言:javascript
复制
# leaflet Module
LEAFLET_CONFIG = {
    'DEFAULT_CENTER': (10.762622, 106.660172), #default center of your map
    'DEFAULT_ZOOM': 14, #default zoom level
    'MIN_ZOOM': 3,
    'MAX_ZOOM': 22,
    'SCALE': 'both',
    'ATTRIBUTION_PRIFIX': 'tekson', #attribution of your map
    'PLUGINS': {
        'forms': {
                'js': ['/static/leaflet_geocoder/geocoder.js', '/static/Leaflet_Coordinates/Leaflet.Coordinates-0.1.5.min.js', '/static/js_admin/leaflet_widget.js'],
                'css': ['/static/leaflet_geocoder/geocoder.css', '/static/Leaflet_Coordinates/Leaflet.Coordinates-0.1.5.css'],
        },
    },
}

leaflet_widget.js

代码语言:javascript
复制
window.addEventListener("map:init", function (event) {
    var map = event.detail.map; // Get reference to map

    L.Control.geocoder(
        {
            collapsed: true,
            geocoder: L.Control.Geocoder.nominatim({
                geocodingQueryParams: {countrycodes: 'VN'}
            })
        }
    ).addTo(map);

    L.control.coordinates({
        position:"bottomleft", //optional default "bootomright"
        decimals:6, //optional default 4
        decimalSeperator:".", //optional default "."
        labelTemplateLat:"Latitude: {y}", //optional default "Lat: {y}"
        labelTemplateLng:"Longitude: {x}", //optional default "Lng: {x}"
        enableUserInput:true, //optional default true
        useDMS:false, //optional default false
        useLatLngOrder: true, //ordering of labels, default false-> lng-lat
        markerType: L.marker, //optional default L.marker
        markerProps: {}, //optional default {},
    }).addTo(map);
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61579498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档