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

343
Views
OpenLayers 6.8 : How to get Geojson Vector coordinates?

I have a basic map with openlayers 6.8. I display markers from geojson.

Example of a geojson :

const geoMoscow = new ol.layer.Vector({
    source: new ol.source.Vector({
        url: './assets/moscow.geojson',
        format: new ol.format.GeoJSON()
    }),
    visible: true,
    title: 'geojson',
    style: new ol.style.Style({
        fill: fillStyle,
        stroke: strokeStyle,
        image: new ol.style.Circle({
            fill: new ol.style.Fill({
                color: [245, 49, 5, 1]
            }),
            radius: 10,
        }),
    })
})

I want to get this geojson coordinates for further use. I have been reading many code examples that uses geojson.getSource().getFeatures() that allows to acces the getCoordinates() method from each feature.

Unfortunetly geoMoscow.getSource().getFeatures() gives an empty array.

I am obviously missing something there about openlayers logic. It seems totally doable because my geojson contains a feature object with the coordinates in it but I am unable to access it.

TLDR : How to access informations like coordinates from this geojson Vector.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You must wait until the source is loaded and parsed

geoMoscow.getSource().on('featuresloadend', function(){
  console.log(geoMoscow.getSource().getFeatures());
});

The source will not load until it is added to a map.

about 4 years ago · Juan Pablo Isaza Report
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!