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

282
Visualizações
How to Add a dropdown and a free text popup to a layer in Leaflet for adding two attribute values

I would like to add two attributes to the layer. This layer drawn by using leaflet draw control( new L.Control.Draw). First attribute from drop down and another one as free text. I can do it separately with the pop-up option, but it does not work together. Please go through my code and help me to resolve this issue.

/ Leaflet Draw
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);

var drawControl = new L.Control.Draw({
  edit: {
    featureGroup: drawnItems,
    poly: {
      allowIntersection: false
    }
  },
  draw: {
    circle: false,
    circlemarker: false,
    polygon: {
      allowIntersection: false,
      showArea: true,
      
    }
  }
});

map.addControl(drawControl);


const dropdown =
    `Opt from dropdown:
    <select id="ddlViewBy">
    <option value="building">building</option>
    <option value="road">road</option>
    <option value = "poi">poi</option>
    </select>: <button onclick="buttonFunction()">submit</button>`;



// Object created - bind popup to layer, add to feature group
map.on(L.Draw.Event.CREATED, function (event) {
  var layer = event.layer;
  var content = getPopupContent(layer);
  if (content !== null) {
    layer.bindPopup(content);
    
  }

  // Add info to feature properties
  feature = layer.feature = layer.feature || {};
  feature.type = feature.type || "Feature";
  var props = feature.properties = feature.properties || {}; // Intialize feature.properties
  props.info = content;
  //props.domain=domain;
  drawnItems.addLayer(layer);
  
  addPopup(layer)

  console.log(JSON.stringify(drawnItems.toGeoJSON())); 
});


function addPopup(layer) {
  var content = document.createElement("textarea");
  
    content.addEventListener("keyup", function () {
    //layer.getPopup().on('remove', function() {
      console.log('ffff')
      layer.feature.properties.desc = content.value;
    });
    layer.on("popupopen", function () {
      console.log('cccc')
      content.value = layer.feature.properties.desc;
      content.focus();
    });
    //layer.bindPopup(content,{closeOnClick: false, autoClose: true}).openPopup();
    layer.bindPopup().setPopupContent(dropdown)
    buttonFunction = () => {
      const dropdonwValue = document.getElementById("ddlViewBy").value;
      layer.feature.properties.domain = dropdonwValue;
      layer.bindPopup(dropdonwValue,{closeOnClick: false, autoClose: true})
    }
    var dupLayer= L.geoJSON(drawnItems);
    dupLayer.bindPopup(content,{closeOnClick: false, autoClose: true}).openPopup().addTo(map)
    
    
}
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