import pluginMain, { DEFAULT_TILE_SERVER } from "./lib/plugin_index.js";

export default async function(IMap) {
    const module = await import("./lib/shp-to-geojson.browser.js");

    return class MapImpl extends IMap {
        constructor(response, { map, $page }) {
            super();
            this.content = response;

            L.tileLayer(DEFAULT_TILE_SERVER, { maxZoom: 21 }).addTo(map);
            pluginMain({ map, $page })
        }

        async toGeoJSON() {
            const shp = new module.default({});
            shp._shpBuffer = module.Buffer.from(this.content);
            shp._tableBuffer = module.Buffer.from(new ArrayBuffer(16));
            shp._init();
            await shp.load();
            return shp.getGeoJson();
        }
    }
}
