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

183
Visualizações
how to apply a class on mapbox-gl-js popUp based on the value from external json file

I want to apply different class for pop-up according to temperature (tempData variable) received from json file. Basically selecting class according to temperature in this line .

<div class=" bg-a bg-b bg-c bg-d bg-e py-3 rounded mx-4" id= "popBox" >

Below is my code example where I fetch the data and create a object to pass my json data to map. I tried to do some if else condition before my obj variable , but that did not work.

fetch('mapdata.json')
.then(function(response){
 return response.json();
})
.then(function (data) {
 appendMapData(data);
})
function appendMapData(data){
data.map(function(element){

  var pmData = element.pm25
  var locName = element.name
  var tempData = parseInt(element.temperature)
 

  var longitude = element.longitude
  var latitude = element.latitude
  var final = [longitude,latitude]

  
  var obj = {
'type': 'Feature',
'properties': {
   'temperature' : tempData,
   
   'description': //------------------custom popup
   `<div class="card bg-dark-blue d-block pt-4 text-white">
<span class="d-block text-center"> ${locName} </span>
<span class="d-block small text-center mb-3">23:00, Mar 16 (local time)</span>

<div class=" bg-a bg-b bg-c bg-d bg-e py-3 rounded mx-4" id= "popBox" >
<h5 class="d-block text-center h3" id="exampleModalLabel">${tempData}</h5>
<span class="d-block text-center">Moderate</span>
</div>

<div class="modal-body">
<div class="row mt-3">
    <span class="col-md-6 small">PM25</span>
    <span class="col-md-6 text-right small"> ${pmData} µg/m³</span>
  </div>
<div class="progress mt-2">
    <div class="progress-bar bg-state-moderate border-0" role="progressbar" style="width: 60%" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="text-center">
<a href="https://airqualitydev.wpengine.com/aq_sensors/${locName}?lon=${longitude}&lat=${latitude}" class="my-3 btn btn-outline-light">See in-depth <i class="fa-solid fa-circle-arrow-right"></i></a>
</div>
</div>
</div>`
 },
    
'geometry': {
   'type': 'Point',
   'coordinates': final
}
  
}


  return featuresArray.push(obj) 
})

}

how can I do this?

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