I am trying to display points on an OSM map using Openlayers and (Geo)Django. The points should be provided by a REST API endpoint which I want to query from within the openlayers javascript.
The JS part looks like this:
<div id="map" class="map shadow m-auto"></div>
<script type="text/javascript">
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Vector({
source: new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: "http://localhost:8000/api/sites"
})
}) ,
new ol.layer.Tile({
source: new ol.source.OSM(),
})
],
view: new ol.View({
center: ol.proj.fromLonLat([8,48]),
zoom: 10
})
});
</script>
The API endpoint is just serializing a django queryset and therefore returns the following:
[
{
"sid":13,
"site_name":"Burgsteig",
"site_notes":"Reuter.2003",
"municipality":1047,
"geom":{
"type":"Point",
"coordinates":[
8.779644092464917,
48.00504767358004
]
}
},
{
"sid":14,
"site_name":"Brederis, \"Weitried\"",
"site_notes":"Hagn2002",
"municipality":16180,
"geom":{
"type":"Point",
"coordinates":[
9.628734475883569,
47.2756455228491
]
}
},
{
"sid":15,
"site_name":"Burgweinting, \"Villa\"/\"Mühlfeld\"",
"site_notes":"Zintl2012, Zintl2013",
"municipality":2767,
"geom":{
"type":"Point",
"coordinates":[
12.11373087937611,
49.01308089544727
]
}
}
]
It is just a basic API endpoint by django-rest-framework and as far as i know returns a pretty standard geoJSON format dataset. However, when running this i get an "Uncaught Error: Unsupported GeoJSON type: undefined". The basemap is displaying, it is just something wrong with that geojson. As far as I understand, the API is not returning GeoJSON as in ol.format.GeoJSON() but something else instead. So how do I process this thing to be displayed on my map?