Setting up a SRID to a Leaflet - Geodjango

2019-07-23 12:40发布

问题:

I have data in my Postgres DB which are in 31277 projection. Anyway, I am using Leaflet map to show them with Geodjango. Right now, my data are moved somewhere down in the map, so I need to change the projection of the Leaflet map.

In documentation (http://django-leaflet.readthedocs.io/en/latest/advanced.html) is written just to add SRID attribute to LEAFLET_CONFIG variable, which I did. Like here:

LEAFLET_CONFIG = {
    'DEFAULT_ZOOM': 13,
    'MIN_ZOOM': 2,
    'MAX_ZOOM': 18,
    'SRID':31277
}

But after I added SRID attribute I got an error when I tried to access to that page with a map:

"GET /static/proj4js/31277.js HTTP/1.1" 404 1770

Also, I get same error for the WGS84 - 4326

回答1:

Judging by the path of the error you are getting, that starts with static and the documentation of django-leaflet on the CONFIG subject:

By default, django-leaflet will try to load the spatial reference from your static files at “proj4js/{{ srid }}.js”.

I would suggest configuring your static file settings and run

python manage.py collectstatic