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

176
Visualizações
add and style layer in leaflet from promise

I'm working with javascript modules to load spatial layers on a leaflet map. Everytime I try to add or style my GEOJSON layer called as a promise throught the function "getLayer" I created in my module, I get the error "layer.addTo" is not a function. Javascript basically doesn't recognize my GEOJSON layer as such. What am I missing ? Thanks.

The module that exports the layer :

// A mapping of paths to layers. Not exported, so only visible within this module
const layers = {};

 // exported. this is the only part of the module visible from the outside.
export async function getLayer(path) {
    if (!layers[path]) {
        // if we don't already have it do the fetch and add it to the mapping
        layers[path] = await fetchLayer(path);
    }
    // return the layer for the given path from the mapping
    return layers[path];
}

// "private" functions for fetching and processing data

async function fetchLayer(path) {
    return fetch('commerces_final', { credentials: 'include' })
        .then(response => response.json())
        .then(data => process1(data))
}

function process1(donnees){
  return L.geoJson(donnees, 
    {
      weight:12,
      opacity: 0.1,
      color: "#a19e83",
      dashArray: '1',
      fillOpacity: 1
  }
  );
}

The app module where I call the layer and try to add it :

import { getLayer } from '/js/toulouse.js';

async function app () {

var map = L.map('map', { drawControl: true });
const buildings = getLayer('commerces_final');
buildings.addTo(map)
}

app()
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