我的views.py
里有这个
import json
import requests
def geojsonFun(request):
r = requests.get('http://localhost:8000/villeLis/')
data = r.json()
geojson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [d["coordonate_x"], d["coordonate_y"]],
},
"properties": d,
} for d in data]
}
# print(geojson)
return HttpResponse(geojson)
我使用序列化程序从我的mysql数据库中获取json文件,并且链接工作正常,问题是我无法在dashboard.html
上看到地图上的点,这是其中的一部分:
<script>
var geojson = geojson;
mapboxgl.accessToken = 'pk.eyJ1IjoieW9zcmFqYWJyaSIsImEiOiJjazh4M3duc3AwMnJhM2VzMmxjOThxa2F6In0.OAugyooi_oKgzRTznR4eyw';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
center: [9.5, 36.5],
zoom: 7
});
map.addSource(currentKey, {
"type": "geojson",
"data": geojson,
cluster: true
});
map.addLayer({
id: 'points',
source: 'pointsSource',
type: 'circle',});
</script>
我想在python中检索函数的结果,并将其用作js中的geojson。
转载请注明出处:http://www.sjzxcyzs.com/article/20230401/1299926.html