I am porting a webmap built with HTML/CSS/Leaflet to a GeoDjango/Leaflet framework, and want to know the fastest way to display map layers. For the HTML/CSS/Leaflet map, my layers are hosted as flat GeoJSON files and called using L.GeoJSON()
. The layers display very fast.
For the GeoDjango framework, however, the layers display much more slowly. I use almost identical code, but am guessing the geom data has to be serialized to GeoJSON, which is responsible for the slow display. Is there any way to speed up this process? What would be the fastest way to get layers to display using a GeoDjango framework?
GeoDjango code to display layer:
From urls.py
:
from django.conf.urls import include, url
from models import mbls
from djgeojson.views import GeoJSONLayerView
urlpatterns = [
url(r'^mbls/', GeoJSONLayerView.as_view(model=mbls), name='mbls'),
]
From index.html
:
var mblInt = new L.GeoJSON(null, {
style: { color: '#000000',
}
});
$.getJSON('{% url "mbls" %}', function (data) {
mblInt.addData(data);
});
... other code ...
var map = L.map("map", {
zoom: 11,
center: [35.435, -106.54],
minZoom: 6,
maxZoom: 20,
layers: [basemap, mblInt]
});