Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

342
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda