1

我无法使用django-leaflet指定自定义 SRID 。

有关预测的文档不是很详细,仅简要提及:

默认情况下,django-leaflet 会尝试从“proj4js/{{ srid }}.js”的静态文件中加载空间参考。如果失败,它最终将依赖于 spatialreference.org。

我遵循了django-leaflet 安装指南,并在 PostGIS 中添加了我的数据中使用的 SRID,如下所示:

LEAFLET_CONFIG = {
    'SRID': 2056,  # See http://spatialreference.org
    'DEFAULT_CENTER': (46.800663464, 8.222665776),
    'DEFAULT_ZOOM': 7,
    'MIN_ZOOM': 1, 
    'MAX_ZOOM': 20, 
}

但这会在 Chrome 中引发以下错误:

uncaught exception: Leaflet and proj4 must be loaded first
The script from “http://127.0.0.1:8000/static/proj4js/2056.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.
Loading failed for the <script> with source “http://127.0.0.1:8000/static/proj4js/2056.js”. 
uncaught exception: No projection definition for code EPSG:2056

我有leafletin INSTALLED_APPS,并且还在我的页面头部加载proj4.jsand proj4leaflet.js

<!DOCTYPE html>
{% load static %} 
{% load leaflet_tags %}

<html lang="en">
    <head>
        {% leaflet_js %}
        {% leaflet_css %}
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-ajax/2.1.0/leaflet.ajax.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/proj4leaflet/1.0.2/proj4leaflet.min.js"></script>

        <meta charset="utf-8">
        <style>
            .leaflet-container { 
                width:  600px;
                height: 400px;
            }       
            #specialbigmap {
                height: 800px;
            }   
            .django-leaflet-raw-textarea {
                width: 100%;
            }
        </style>
    </head>
    <body>          
        <script type="text/javascript">
            function map_init_basic (map, options) {                

                $.getJSON( "http://127.0.0.1:8000/en/api/mydata/?name=my_data1", function( data ) {
                    mygeojson = data.results
                    L.geoJSON(mygeojson).addTo(map);
                    });        
            }
        </script>

        {% leaflet_map "my_django_leaflet_map" callback="window.map_init_basic" %}          
    </body>
</html>

我尝试按照这里collectstatic的建议运行,但错误仍然存​​在(我怀疑是否应该在开发中使用)。有什么建议可以完成这项工作吗?collectstatic

4

0 回答 0