Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
Openlayers display Points from Geodjango REST API endpoint

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!