Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda