I am trying to do a simple buffer around a geojson I created with a model. The buffer does not show up. Here is my code.

    lyrStores2 = L.geoJSON.ajax("{% url 'stores' %}", {

    storeBuffer = turf.buffer(lyrStores2.toGeoJSON(), 10, {units: 'miles'});
    lyrStoreBuffer = L.geoJSON(storeBuffer, {style:{

The layer itself appears just fine. I'm not sure if the geoJSON isn't appearing because I havn't created a url or a view for it like I had to for the shapefiles I created models for...

I have tried linking the for the minified js and even tried this cdn


Update: So I saved the file as a geoJson using qgis. I put the file into my static folder and everything worked fine. This is what the code looks like for that:

    Storesjson = L.geoJSON.ajax("{% static 'mymap/data/storesgeojson.geojson' %}");

    Storesjson.on('data:loaded', function(){
            jsonStores = turf.buffer(Storesjson.toGeoJSON(), 10, {units: 'miles'});
            storesBuffer = L.geoJSON(jsonStores, {
                    style: {
                        color: 'red',

The original file is loaded in like this

lyrStores = new L.GeoJSON.AJAX("{% url 'stores' %}", {


My url for that looks like

path('Store_data/', Stores_datasets, name='stores'),

This is my view where I have it serialized:

def Stores_datasets(request):
stores = serialize('geojson', Stores.objects.all())
return HttpResponse(stores, content_type='json')
  • Have you checked the javascript console in your browser for errors? – Spacedman Jun 4 '18 at 7:09
  • Yes, there is no error. It has to do something with the way i'm loading it in. I put a geoJson (the same file just saved as a geoJson while before it had to be serialized through django into a geoJson) in the static folder and turf worked just fine. – Petey Jun 4 '18 at 16:53
  • I am having the exact same problem, have you figured this out? – ziggy Oct 3 '18 at 12:42
  • question answered -- stackoverflow.com/questions/52627582/… – ziggy Oct 12 '18 at 15:18
  • @ziggy oh man thanks for the update. I actually ended up using an API and Angular on the front end. – Petey Nov 7 '18 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.