Estoy trabajando con módulos de javascript para cargar capas espaciales en un mapa de folleto. Cada vez que trato de agregar o diseñar mi capa GEOJSON llamada como una promesa a través de la función "getLayer" que creé en mi módulo, aparece el error "layer.addTo" no es una función. Javascript básicamente no reconoce mi capa GEOJSON como tal. Qué me estoy perdiendo ? Gracias.
El módulo que exporta la capa:
// 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 } ); }El módulo de la aplicación donde llamo a la capa e intento agregarla:
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()