displaying large shapefile in leaflet-geojson-vt

41 Views Asked by At

I am trying to display a shapefile with 50000 polygons in geodjango using leaflet. My data takes a really long time to display so I have been trying different things.Recently I came across the leaflet-geojson-vt plugin which generates vector tiles for geojson data and apparently it should reduce the processing time. If I try to display my data using GeoJSON, my data is being displayed but it takes a really long time to do it, now I am trying to use this plugin but I don't manage to display my data at all.

this my html :

{% load static %}


{% load leaflet_tags %}


DISPLAY
{% leaflet_js s%}
{% leaflet_css %} 


 function displaydata(map, options){
            
            var ourdata = L.geoJson.vt('{% url "data" %}',{
                style: function colors(feature){
                   switch(feature.properties.clas.toString()){
                     case '1':
                       return {
                       color: 'orange',
                       fillOpacity: 0.5
                       };
                     break;
                     case '2':
                       return {
                       color: 'purple',
                       fillOpacity: 0.5
                       };
                     break;
                     
                   }
                },
                onEachFeature: function(feature,layer){
                  layer.bindPopup(feature.properties.clas.toString())}
        
            });
            ourdata.addTo(map); 
            ourdata.on('data:loaded', function() {
                 map.fitBounds(ourdata.getBounds());
            }  
         } 

{% leaflet_map "my_map" callback="window.displaydata"  %}

my url file:

from .models import Polygons
from djgeojson.views import TiledGeoJSONLayerView

urlpatterns = [

path('data/', TiledGeoJSONLayerView.as_view(model=Polygons, properties=('clas')),   name='data'),]

my models file:

class Polygons(models.Model):

clas = models.BigIntegerField()
poly = models.MultiPolygonField()

def __str__(self):

return str(self.clas)

I have saved all my polygons into a model called Polygons. I am not sure I need to do this but I think it displays faster when I get the polygons from a model rather than from the shapefile directly.

I just want to display all my polygons in a fast way. Any help would be highly appreciated

0

There are 0 best solutions below