I'm very new to GIS and for learning I started with building a simple web app with GeoDjango. I am using django-leaflet. Since I have a very limited knowledge I am facing many challenges. I'm trying to put a specifc marker on my map as a test
models.py
from django.db import models
from django.contrib.gis.geos import point
from django.contrib.gis.db import models as gismodels
class Points(gismodels.Model):
data_lat = 44.915223
data_long = -93.209741
@property
def geom(self):
return point(self.data_lat, self.data_long, srid=4326)
def __unicode__(self):
return self.title
about.html
<body>
<h1> Map </h1>
{% leaflet_map "main" callback="main_map_init" %}
<script type="text/javascript">
function main_map_init (map, options){
var dataurl = '{% url "data" %}';
$.getJSON('dataurl', function(data) {
L.geoJson(data).addTo(map);
})
}
</script>
</body>
I'm having issue with data not being passed on to map. It would be nice if someone could point me to the right direction.
In about.html, the correct code would be (supposing data would be a link to the geojson created on the fly
var dataurl = '{% url "data" %}';
$.getJSON(dataurl, function(data) {
L.geoJson(data).addTo(map);
})
I suggest you to see for reference http://leafletjs.com/examples/geojson.html and try to create a map manually in an html page to see how it works, then you can add content dynamically with Python.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.