Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!