Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

341
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda