mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
* Introduce proper error types for a lot of functions, remove main catch-all type * Fix compilation and clippy issues * Map, unmap and drop always * Remove not required parentheses * Fix running on non-vulkan platforms * Add and use thiserror crate
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import * as maplibre from "./wasm/maplibre"
|
|
import {Spector} from "spectorjs"
|
|
import {checkRequirements, checkWasmFeatures} from "./browser";
|
|
import {preventDefaultTouchActions} from "./canvas";
|
|
// @ts-ignore esbuild plugin is handling this
|
|
import MultithreadedPoolWorker from './multithreaded/multithreaded-pool.worker.js';
|
|
// @ts-ignore esbuild plugin is handling this
|
|
import PoolWorker from './singlethreaded/pool.worker.js';
|
|
|
|
export const startMapLibre = async (wasmPath: string | undefined, workerPath: string | undefined) => {
|
|
await checkWasmFeatures()
|
|
|
|
let message = checkRequirements();
|
|
if (message) {
|
|
console.error(message)
|
|
alert(message)
|
|
return
|
|
}
|
|
|
|
if (WEBGL) {
|
|
let spector = new Spector()
|
|
spector.displayUI()
|
|
}
|
|
|
|
preventDefaultTouchActions();
|
|
|
|
if (MULTITHREADED) {
|
|
const MEMORY = 209715200; // 200MB
|
|
const PAGES = 64 * 1024;
|
|
|
|
const memory = new WebAssembly.Memory({initial: 1024, maximum: MEMORY / PAGES, shared: true})
|
|
await maplibre.default(wasmPath, memory)
|
|
|
|
await maplibre.run_maplibre(() => {
|
|
return workerPath ? new Worker(workerPath, {
|
|
type: 'module'
|
|
}) : MultithreadedPoolWorker();
|
|
});
|
|
} else {
|
|
const memory = new WebAssembly.Memory({initial: 1024, shared: false})
|
|
await maplibre.default(wasmPath, memory);
|
|
|
|
await maplibre.run_maplibre((ptr) => {
|
|
let worker: Worker = workerPath ? new Worker(workerPath, {
|
|
type: 'module'
|
|
}) : PoolWorker();
|
|
|
|
worker.onmessage = (message: MessageEvent) => {
|
|
// WARNING: Do not modify data passed from Rust!
|
|
let in_transfer = message.data;
|
|
|
|
const main_entry = maplibre["singlethreaded_main_entry"];
|
|
|
|
if (!main_entry) {
|
|
throw Error("singlethreaded_main_entry is not defined. Maybe the Rust build used the wrong build configuration.")
|
|
}
|
|
|
|
main_entry(ptr, in_transfer)
|
|
}
|
|
|
|
return worker;
|
|
});
|
|
}
|
|
}
|