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

215
Visualizações
QGIS 2 web openlayers - TypeError: Cannot read properties of null

I would like to draw features in the OpenLayers map geerated by QGIS2web plugin. Since eveything seems to be alright and all the features come out now, unlike the recent situation.

My full code is here:

https://jsfiddle.net/go39r4j7/

but I am not convinced enough about the situation, as I keep getting the error:

TypeError: Cannot read properties of null (reading 'get')

enter image description here

which points out the following piece of code:

  map.forEachFeatureAtPixel(pixel, function(feature, layer) {
    if (feature instanceof ol.Feature && (layer.get("interactive") || layer.get("interactive") 
   == undefined)) {
        var doPopup = false;
        for (k in layer.get('fieldImages')) {
            if (layer.get('fieldImages')[k] != "Hidden") {
                doPopup = true;
              }
          }

Theoretically, I know, that I can't access the object, which is null:

https://idiallo.com/javascript/uncaught-typeerror-cannot-read-property-of-null

but any options I tried (removing this piece of code, removing the layer.get property, changing the layer.get("interactive") to my own id ("draw")) weren't successful.

Moroever this piece of code appears to be standard for similar situations like this:

https://gist.github.com/riccardoklinger/e3e2c512a366c8a6a296c10eef9c4162

How can I fix this issue? The tool works, although I am concerned about future modifications.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html#forEachFeatureAtPixel

Feature callback. The callback will be called with two arguments. The first argument is one feature or render feature at the pixel, the second is the layer of the feature and will be null for unmanaged layers.

If you have an unmanaged layer (e.g. the overlay layer used by a Draw interaction) you will need to ensure you have a layer before using .get on it:

if (feature instanceof ol.Feature && layer && (layer.get("interactive") || layer.get("interactive") == undefined)) {
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