1

I have done my leaflet program using django-leaflet but the map is not displaying anything in output

Here is the code

models.py

from django.db import models
from django.contrib.gis.db import models as gismodels
class MushroomSpot(gismodels.Model):
    title = models.CharField(max_length=256)
    id1=models.IntegerField(primary_key=True)
    geom = gismodels.PointField()
    objects = gismodels.GeoManager()
    def __unicode__(self):
        return self.title

urls.py

from django.conf import settings
from django.conf.urls import url
from django.conf.urls.static import static
from django.contrib import admin
from django.views.generic import TemplateView
from djgeojson.views import GeoJSONLayerView
from .models import MushroomSpot

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', TemplateView.as_view(template_name='index.html'), name='home'),
    url(r'^data.geojson$', GeoJSONLayerView.as_view(model=MushroomSpot), name='data'),    
]

index.html

{% load leaflet_tags %}
<html>
  <head>
    {% leaflet_js %}
    {% leaflet_css %}
  </head>
  <body>
    <h1>Weather Stations</h1>
    {% leaflet_map "main" callback="main_map_init" %}

    <script type="text/javascript">
        function main_map_init (map, options) {
            var dataurl = '{% url "data" %}';
    // Download GeoJSON via Ajax
    $.getJSON(dataurl, function (data) {
        // Add GeoJSON layer
        L.geoJson(data).addTo(map);
    });
        }
    </script>
  </body>
</html>

contents related to leaflet in settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.spatialite',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

SPATIALITE_LIBRARY_PATH = 'mod_spatialite'
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR

LEAFLET_CONFIG = {
'DEFAULT_ZOOM': 6,
'MIN_ZOOM': 1,
'MAX_ZOOM': 20,
}

And I run the setup.py file which has

import csv
from django.contrib.gis.geos import Point

from mushrooms.models import MushroomSpot


csv_file = 'mycsv.csv'

def dms2dec(value):
    """
    Degres Minutes Seconds to Decimal degres
    """
    degres, minutes, seconds = value.split()
    #seconds, direction = seconds[:-1], seconds[-1]
    dec = float(degres) + float(minutes)/60 + float(seconds)/3600
    #if direction in ('S', 'W'):
    #    return -dec
    return dec

reader = csv.DictReader(open(csv_file), delimiter=",")
for line in reader:
    lng = dms2dec(line.pop('mlong'))
    lat = dms2dec(line.pop('mlat'))
    wmoid = int(line.pop('id'))
    name = line.pop('place').title()
    print(lng,lat)
    MushroomSpot(id1=wmoid, title=name, geom=Point(lng, lat)).save()

Please help me in getting the output map in screen I dont know what is the error in it The csv file contains the data of about 8 cities in india And I want the desired India map as an interactive webmap Please let me to my desired output

0 Answers0