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

206
Visualizações
How to create a clickable grid with leaflet

i'm trying to create a clickable grid in react and leaflet, i want to display a grid over my map, something similar to this: add mouse event to svg <pattern>, detect grid hover. i built the grid in this way:

 var tiles = new L.GridLayer();
var p = new L.featureGroup(tiles);

console.log(p);
setProva(tiles);
tiles.createTile = function() {
  var rows = 5;
  var cols = 5;
  var i = 0;
  tile = L.DomUtil.create('table', 'leaflet-tile');
  tile.className = 'grid';
  
  for (var r=0;r<rows;++r){
    var tr = tile.appendChild(document.createElement('tr'));
    for (var c=0;c<cols;++c){
      var cell = tr.appendChild(document.createElement('td'));
      cell.innerHTML = ++i;

      cell.addEventListener('click',(function(el,r,c,i){
        return function(){ callback(el,r,c,i); }
       })(cell,r,c,i),false);
    
    }

and this is the function that manages the event:

    function callback(el,row,col,i){
  el.className='clicked';
  if (lastClicked) lastClicked.className='';
  lastClicked = el;
}

but when i click, the only event recorded is the click on the map. I think, that i need to manage the click event on the map and propagate over the child component but i cant understand how... Can someone help me? Thanks a lot!

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