Django-Leaflet中的自定义SRID

时间:2019-04-11 21:47:16

标签: django leaflet gis postgis srid

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

关于投影的documentation不太详细,仅简要提及:

  

默认情况下,django-leaflet将尝试从以下位置加载空间参考   您的静态文件位于“ proj4js / {{srid}}。js”。如果失败,它将   最终依赖空间参考网站。

我遵循django-leaflet installation guidelines,并在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

我在leaflet中有INSTALLED_APPS,并且还在页面的头部加载了proj4.jsproj4leaflet.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>

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

0 个答案:

没有答案