mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-05 13:38:31 +02:00
Merge branch 'wasm-job-leaflet' into 'main'
wasm-job / leaflet example See merge request freepascal.org/fpc/source!839
This commit is contained in:
commit
b4bd0c3c62
864
packages/wasm-job/examples/leaflet/browser.dom.js
Normal file
864
packages/wasm-job/examples/leaflet/browser.dom.js
Normal file
@ -0,0 +1,864 @@
|
||||
"use strict";
|
||||
var ZenFS_DOM = (() => {
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/index.ts
|
||||
var src_exports = {};
|
||||
__export(src_exports, {
|
||||
IndexedDB: () => IndexedDB,
|
||||
IndexedDBStore: () => IndexedDBStore,
|
||||
IndexedDBTransaction: () => IndexedDBTransaction,
|
||||
WebAccess: () => WebAccess,
|
||||
WebAccessFS: () => WebAccessFS,
|
||||
WebStorage: () => WebStorage,
|
||||
WebStorageStore: () => WebStorageStore
|
||||
});
|
||||
|
||||
// global-externals:@zenfs/core
|
||||
var core_default = ZenFS;
|
||||
var { ActionType, Async, AsyncIndexFS, AsyncTransaction, BigIntStats, BigIntStatsFs, Dir, Dirent, Errno, ErrnoError, Fetch, FetchFS, File, FileIndex, FileSystem, FileType, InMemory, InMemoryStore, IndexDirInode, IndexFS, IndexFileInode, IndexInode, Inode, LockedFS, Mutex, NoSyncFile, Overlay, OverlayFS, Port, PortFS, PortFile, PreloadFile, ReadStream, Readonly, SimpleAsyncStore, SimpleTransaction, Stats, StatsCommon, StatsFs, StoreFS, Sync, SyncIndexFS, SyncTransaction, Transaction, UnlockedOverlayFS, WriteStream, _toUnixTimestamp, access, accessSync, appendFile, appendFileSync, attachFS, checkOptions, chmod, chmodSync, chown, chownSync, close, closeSync, configure, constants, copyFile, copyFileSync, cp, cpSync, createReadStream, createWriteStream, decode, decodeDirListing, detachFS, encode, encodeDirListing, errorMessages, exists, existsSync, fchmod, fchmodSync, fchown, fchownSync, fdatasync, fdatasyncSync, flagToMode, flagToNumber, flagToString, fs, fstat, fstatSync, fsync, fsyncSync, ftruncate, ftruncateSync, futimes, futimesSync, isAppendable, isBackend, isBackendConfig, isExclusive, isReadable, isSynchronous, isTruncating, isWriteable, lchmod, lchmodSync, lchown, lchownSync, levenshtein, link, linkSync, lopenSync, lstat, lstatSync, lutimes, lutimesSync, mkdir, mkdirSync, mkdirpSync, mkdtemp, mkdtempSync, mount, mountObject, mounts, nop, normalizeMode, normalizeOptions, normalizePath, normalizeTime, open, openAsBlob, openSync, opendir, opendirSync, parseFlag, pathExistsAction, pathNotExistsAction, promises, randomIno, read, readFile, readFileSync, readSync, readdir, readdirSync, readlink, readlinkSync, readv, readvSync, realpath, realpathSync, rename, renameSync, resolveMountConfig, rm, rmSync, rmdir, rmdirSync, rootCred, rootIno, setImmediate, size_max, stat, statSync, statfs, statfsSync, symlink, symlinkSync, truncate, truncateSync, umount, unlink, unlinkSync, unwatchFile, utimes, utimesSync, watch, watchFile, write, writeFile, writeFileSync, writeSync, writev, writevSync } = ZenFS;
|
||||
|
||||
// node_modules/@zenfs/core/dist/emulation/path.js
|
||||
function normalizeString(path, allowAboveRoot) {
|
||||
let res = "";
|
||||
let lastSegmentLength = 0;
|
||||
let lastSlash = -1;
|
||||
let dots = 0;
|
||||
let char = "\0";
|
||||
for (let i = 0; i <= path.length; ++i) {
|
||||
if (i < path.length) {
|
||||
char = path[i];
|
||||
} else if (char == "/") {
|
||||
break;
|
||||
} else {
|
||||
char = "/";
|
||||
}
|
||||
if (char == "/") {
|
||||
if (lastSlash === i - 1 || dots === 1) {
|
||||
} else if (dots === 2) {
|
||||
if (res.length < 2 || lastSegmentLength !== 2 || res.at(-1) !== "." || res.at(-2) !== ".") {
|
||||
if (res.length > 2) {
|
||||
const lastSlashIndex = res.lastIndexOf("/");
|
||||
if (lastSlashIndex === -1) {
|
||||
res = "";
|
||||
lastSegmentLength = 0;
|
||||
} else {
|
||||
res = res.slice(0, lastSlashIndex);
|
||||
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
||||
}
|
||||
lastSlash = i;
|
||||
dots = 0;
|
||||
continue;
|
||||
} else if (res.length !== 0) {
|
||||
res = "";
|
||||
lastSegmentLength = 0;
|
||||
lastSlash = i;
|
||||
dots = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (allowAboveRoot) {
|
||||
res += res.length > 0 ? "/.." : "..";
|
||||
lastSegmentLength = 2;
|
||||
}
|
||||
} else {
|
||||
if (res.length > 0)
|
||||
res += "/" + path.slice(lastSlash + 1, i);
|
||||
else
|
||||
res = path.slice(lastSlash + 1, i);
|
||||
lastSegmentLength = i - lastSlash - 1;
|
||||
}
|
||||
lastSlash = i;
|
||||
dots = 0;
|
||||
} else if (char === "." && dots !== -1) {
|
||||
++dots;
|
||||
} else {
|
||||
dots = -1;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
__name(normalizeString, "normalizeString");
|
||||
function normalize(path) {
|
||||
if (!path.length)
|
||||
return ".";
|
||||
const isAbsolute = path.startsWith("/");
|
||||
const trailingSeparator = path.endsWith("/");
|
||||
path = normalizeString(path, !isAbsolute);
|
||||
if (!path.length) {
|
||||
if (isAbsolute)
|
||||
return "/";
|
||||
return trailingSeparator ? "./" : ".";
|
||||
}
|
||||
if (trailingSeparator)
|
||||
path += "/";
|
||||
return isAbsolute ? `/${path}` : path;
|
||||
}
|
||||
__name(normalize, "normalize");
|
||||
function join(...parts) {
|
||||
if (!parts.length)
|
||||
return ".";
|
||||
const joined = parts.join("/");
|
||||
if (!joined?.length)
|
||||
return ".";
|
||||
return normalize(joined);
|
||||
}
|
||||
__name(join, "join");
|
||||
function dirname(path) {
|
||||
if (path.length === 0)
|
||||
return ".";
|
||||
const hasRoot = path[0] === "/";
|
||||
let end = -1;
|
||||
let matchedSlash = true;
|
||||
for (let i = path.length - 1; i >= 1; --i) {
|
||||
if (path[i] === "/") {
|
||||
if (!matchedSlash) {
|
||||
end = i;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
matchedSlash = false;
|
||||
}
|
||||
}
|
||||
if (end === -1)
|
||||
return hasRoot ? "/" : ".";
|
||||
if (hasRoot && end === 1)
|
||||
return "//";
|
||||
return path.slice(0, end);
|
||||
}
|
||||
__name(dirname, "dirname");
|
||||
function basename(path, suffix) {
|
||||
let start = 0;
|
||||
let end = -1;
|
||||
let matchedSlash = true;
|
||||
if (suffix !== void 0 && suffix.length > 0 && suffix.length <= path.length) {
|
||||
if (suffix === path)
|
||||
return "";
|
||||
let extIdx = suffix.length - 1;
|
||||
let firstNonSlashEnd = -1;
|
||||
for (let i = path.length - 1; i >= 0; --i) {
|
||||
if (path[i] === "/") {
|
||||
if (!matchedSlash) {
|
||||
start = i + 1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (firstNonSlashEnd === -1) {
|
||||
matchedSlash = false;
|
||||
firstNonSlashEnd = i + 1;
|
||||
}
|
||||
if (extIdx >= 0) {
|
||||
if (path[i] === suffix[extIdx]) {
|
||||
if (--extIdx === -1) {
|
||||
end = i;
|
||||
}
|
||||
} else {
|
||||
extIdx = -1;
|
||||
end = firstNonSlashEnd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (start === end)
|
||||
end = firstNonSlashEnd;
|
||||
else if (end === -1)
|
||||
end = path.length;
|
||||
return path.slice(start, end);
|
||||
}
|
||||
for (let i = path.length - 1; i >= 0; --i) {
|
||||
if (path[i] === "/") {
|
||||
if (!matchedSlash) {
|
||||
start = i + 1;
|
||||
break;
|
||||
}
|
||||
} else if (end === -1) {
|
||||
matchedSlash = false;
|
||||
end = i + 1;
|
||||
}
|
||||
}
|
||||
if (end === -1)
|
||||
return "";
|
||||
return path.slice(start, end);
|
||||
}
|
||||
__name(basename, "basename");
|
||||
|
||||
// src/utils.ts
|
||||
function errnoForDOMException(ex) {
|
||||
switch (ex.name) {
|
||||
case "IndexSizeError":
|
||||
case "HierarchyRequestError":
|
||||
case "InvalidCharacterError":
|
||||
case "InvalidStateError":
|
||||
case "SyntaxError":
|
||||
case "NamespaceError":
|
||||
case "TypeMismatchError":
|
||||
case "ConstraintError":
|
||||
case "VersionError":
|
||||
case "URLMismatchError":
|
||||
case "InvalidNodeTypeError":
|
||||
return "EINVAL";
|
||||
case "WrongDocumentError":
|
||||
return "EXDEV";
|
||||
case "NoModificationAllowedError":
|
||||
case "InvalidModificationError":
|
||||
case "InvalidAccessError":
|
||||
case "SecurityError":
|
||||
case "NotAllowedError":
|
||||
return "EACCES";
|
||||
case "NotFoundError":
|
||||
return "ENOENT";
|
||||
case "NotSupportedError":
|
||||
return "ENOTSUP";
|
||||
case "InUseAttributeError":
|
||||
return "EBUSY";
|
||||
case "NetworkError":
|
||||
return "ENETDOWN";
|
||||
case "AbortError":
|
||||
return "EINTR";
|
||||
case "QuotaExceededError":
|
||||
return "ENOSPC";
|
||||
case "TimeoutError":
|
||||
return "ETIMEDOUT";
|
||||
case "ReadOnlyError":
|
||||
return "EROFS";
|
||||
case "DataCloneError":
|
||||
case "EncodingError":
|
||||
case "NotReadableError":
|
||||
case "DataError":
|
||||
case "TransactionInactiveError":
|
||||
case "OperationError":
|
||||
case "UnknownError":
|
||||
default:
|
||||
return "EIO";
|
||||
}
|
||||
}
|
||||
__name(errnoForDOMException, "errnoForDOMException");
|
||||
function convertException(ex, path, syscall) {
|
||||
if (ex instanceof ErrnoError) {
|
||||
return ex;
|
||||
}
|
||||
const code = ex instanceof DOMException ? Errno[errnoForDOMException(ex)] : Errno.EIO;
|
||||
const error = new ErrnoError(code, ex.message, path, syscall);
|
||||
error.stack = ex.stack;
|
||||
error.cause = ex.cause;
|
||||
return error;
|
||||
}
|
||||
__name(convertException, "convertException");
|
||||
|
||||
// src/access.ts
|
||||
var WebAccessFS = class extends Async(FileSystem) {
|
||||
_handles = /* @__PURE__ */ new Map();
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
_sync;
|
||||
constructor({ handle }) {
|
||||
super();
|
||||
this._handles.set("/", handle);
|
||||
this._sync = InMemory.create({ name: "accessfs-cache" });
|
||||
}
|
||||
metadata() {
|
||||
return {
|
||||
...super.metadata(),
|
||||
name: "WebAccess"
|
||||
};
|
||||
}
|
||||
async sync(path, data, stats) {
|
||||
const currentStats = await this.stat(path);
|
||||
if (stats.mtime !== currentStats.mtime) {
|
||||
await this.writeFile(path, data);
|
||||
}
|
||||
}
|
||||
async rename(oldPath, newPath) {
|
||||
try {
|
||||
const handle = await this.getHandle(oldPath);
|
||||
if (handle instanceof FileSystemDirectoryHandle) {
|
||||
const files = await this.readdir(oldPath);
|
||||
await this.mkdir(newPath);
|
||||
if (files.length == 0) {
|
||||
await this.unlink(oldPath);
|
||||
} else {
|
||||
for (const file of files) {
|
||||
await this.rename(join(oldPath, file), join(newPath, file));
|
||||
await this.unlink(oldPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(handle instanceof FileSystemFileHandle)) {
|
||||
return;
|
||||
}
|
||||
const oldFile = await handle.getFile(), destFolder = await this.getHandle(dirname(newPath));
|
||||
if (!(destFolder instanceof FileSystemDirectoryHandle)) {
|
||||
return;
|
||||
}
|
||||
const newFile = await destFolder.getFileHandle(basename(newPath), { create: true });
|
||||
const writable = await newFile.createWritable();
|
||||
await writable.write(await oldFile.arrayBuffer());
|
||||
writable.close();
|
||||
await this.unlink(oldPath);
|
||||
} catch (ex) {
|
||||
throw convertException(ex, oldPath, "rename");
|
||||
}
|
||||
}
|
||||
async writeFile(fname, data) {
|
||||
const handle = await this.getHandle(dirname(fname));
|
||||
if (!(handle instanceof FileSystemDirectoryHandle)) {
|
||||
return;
|
||||
}
|
||||
const file = await handle.getFileHandle(basename(fname), { create: true });
|
||||
const writable = await file.createWritable();
|
||||
await writable.write(data);
|
||||
await writable.close();
|
||||
}
|
||||
async createFile(path, flag) {
|
||||
await this.writeFile(path, new Uint8Array());
|
||||
return this.openFile(path, flag);
|
||||
}
|
||||
async stat(path) {
|
||||
const handle = await this.getHandle(path);
|
||||
if (!handle) {
|
||||
throw ErrnoError.With("ENOENT", path, "stat");
|
||||
}
|
||||
if (handle instanceof FileSystemDirectoryHandle) {
|
||||
return new Stats({ mode: 511 | FileType.DIRECTORY, size: 4096 });
|
||||
}
|
||||
if (handle instanceof FileSystemFileHandle) {
|
||||
const { lastModified, size } = await handle.getFile();
|
||||
return new Stats({ mode: 511 | FileType.FILE, size, mtimeMs: lastModified });
|
||||
}
|
||||
throw new ErrnoError(Errno.EBADE, "Handle is not a directory or file", path, "stat");
|
||||
}
|
||||
async openFile(path, flag) {
|
||||
const handle = await this.getHandle(path);
|
||||
if (!(handle instanceof FileSystemFileHandle)) {
|
||||
throw ErrnoError.With("EISDIR", path, "openFile");
|
||||
}
|
||||
try {
|
||||
const file = await handle.getFile();
|
||||
const data = new Uint8Array(await file.arrayBuffer());
|
||||
const stats = new Stats({ mode: 511 | FileType.FILE, size: file.size, mtimeMs: file.lastModified });
|
||||
return new PreloadFile(this, path, flag, stats, data);
|
||||
} catch (ex) {
|
||||
throw convertException(ex, path, "openFile");
|
||||
}
|
||||
}
|
||||
async unlink(path) {
|
||||
const handle = await this.getHandle(dirname(path));
|
||||
if (handle instanceof FileSystemDirectoryHandle) {
|
||||
try {
|
||||
await handle.removeEntry(basename(path), { recursive: true });
|
||||
} catch (ex) {
|
||||
throw convertException(ex, path, "unlink");
|
||||
}
|
||||
}
|
||||
}
|
||||
async link(srcpath) {
|
||||
throw ErrnoError.With("ENOSYS", srcpath, "WebAccessFS.link");
|
||||
}
|
||||
async rmdir(path) {
|
||||
return this.unlink(path);
|
||||
}
|
||||
async mkdir(path) {
|
||||
const existingHandle = await this.getHandle(path);
|
||||
if (existingHandle) {
|
||||
throw ErrnoError.With("EEXIST", path, "mkdir");
|
||||
}
|
||||
const handle = await this.getHandle(dirname(path));
|
||||
if (!(handle instanceof FileSystemDirectoryHandle)) {
|
||||
throw ErrnoError.With("ENOTDIR", path, "mkdir");
|
||||
}
|
||||
await handle.getDirectoryHandle(basename(path), { create: true });
|
||||
}
|
||||
async readdir(path) {
|
||||
const handle = await this.getHandle(path);
|
||||
if (!(handle instanceof FileSystemDirectoryHandle)) {
|
||||
throw ErrnoError.With("ENOTDIR", path, "readdir");
|
||||
}
|
||||
const _keys = [];
|
||||
for await (const key of handle.keys()) {
|
||||
_keys.push(join(path, key));
|
||||
}
|
||||
return _keys;
|
||||
}
|
||||
async getHandle(path) {
|
||||
if (this._handles.has(path)) {
|
||||
return this._handles.get(path);
|
||||
}
|
||||
let walked = "/";
|
||||
for (const part of path.split("/").slice(1)) {
|
||||
const handle = this._handles.get(walked);
|
||||
if (!(handle instanceof FileSystemDirectoryHandle)) {
|
||||
throw ErrnoError.With("ENOTDIR", walked, "getHandle");
|
||||
}
|
||||
walked = join(walked, part);
|
||||
try {
|
||||
const dirHandle = await handle.getDirectoryHandle(part);
|
||||
this._handles.set(walked, dirHandle);
|
||||
} catch (_ex) {
|
||||
const ex = _ex;
|
||||
if (ex.name == "TypeMismatchError") {
|
||||
try {
|
||||
const fileHandle = await handle.getFileHandle(part);
|
||||
this._handles.set(walked, fileHandle);
|
||||
} catch (ex2) {
|
||||
convertException(ex2, walked, "getHandle");
|
||||
}
|
||||
}
|
||||
if (ex.name === "TypeError") {
|
||||
throw new ErrnoError(Errno.ENOENT, ex.message, walked, "getHandle");
|
||||
}
|
||||
convertException(ex, walked, "getHandle");
|
||||
}
|
||||
}
|
||||
return this._handles.get(path);
|
||||
}
|
||||
};
|
||||
__name(WebAccessFS, "WebAccessFS");
|
||||
var WebAccess = {
|
||||
name: "WebAccess",
|
||||
options: {
|
||||
handle: {
|
||||
type: "object",
|
||||
required: true,
|
||||
description: "The directory handle to use for the root"
|
||||
}
|
||||
},
|
||||
isAvailable() {
|
||||
return typeof FileSystemHandle == "function";
|
||||
},
|
||||
create(options) {
|
||||
return new WebAccessFS(options);
|
||||
}
|
||||
};
|
||||
|
||||
// node_modules/@zenfs/core/dist/error.js
|
||||
var Errno2;
|
||||
(function(Errno3) {
|
||||
Errno3[Errno3["EPERM"] = 1] = "EPERM";
|
||||
Errno3[Errno3["ENOENT"] = 2] = "ENOENT";
|
||||
Errno3[Errno3["EINTR"] = 4] = "EINTR";
|
||||
Errno3[Errno3["EIO"] = 5] = "EIO";
|
||||
Errno3[Errno3["ENXIO"] = 6] = "ENXIO";
|
||||
Errno3[Errno3["EBADF"] = 9] = "EBADF";
|
||||
Errno3[Errno3["EAGAIN"] = 11] = "EAGAIN";
|
||||
Errno3[Errno3["ENOMEM"] = 12] = "ENOMEM";
|
||||
Errno3[Errno3["EACCES"] = 13] = "EACCES";
|
||||
Errno3[Errno3["EFAULT"] = 14] = "EFAULT";
|
||||
Errno3[Errno3["ENOTBLK"] = 15] = "ENOTBLK";
|
||||
Errno3[Errno3["EBUSY"] = 16] = "EBUSY";
|
||||
Errno3[Errno3["EEXIST"] = 17] = "EEXIST";
|
||||
Errno3[Errno3["EXDEV"] = 18] = "EXDEV";
|
||||
Errno3[Errno3["ENODEV"] = 19] = "ENODEV";
|
||||
Errno3[Errno3["ENOTDIR"] = 20] = "ENOTDIR";
|
||||
Errno3[Errno3["EISDIR"] = 21] = "EISDIR";
|
||||
Errno3[Errno3["EINVAL"] = 22] = "EINVAL";
|
||||
Errno3[Errno3["ENFILE"] = 23] = "ENFILE";
|
||||
Errno3[Errno3["EMFILE"] = 24] = "EMFILE";
|
||||
Errno3[Errno3["ETXTBSY"] = 26] = "ETXTBSY";
|
||||
Errno3[Errno3["EFBIG"] = 27] = "EFBIG";
|
||||
Errno3[Errno3["ENOSPC"] = 28] = "ENOSPC";
|
||||
Errno3[Errno3["ESPIPE"] = 29] = "ESPIPE";
|
||||
Errno3[Errno3["EROFS"] = 30] = "EROFS";
|
||||
Errno3[Errno3["EMLINK"] = 31] = "EMLINK";
|
||||
Errno3[Errno3["EPIPE"] = 32] = "EPIPE";
|
||||
Errno3[Errno3["EDOM"] = 33] = "EDOM";
|
||||
Errno3[Errno3["ERANGE"] = 34] = "ERANGE";
|
||||
Errno3[Errno3["EDEADLK"] = 35] = "EDEADLK";
|
||||
Errno3[Errno3["ENAMETOOLONG"] = 36] = "ENAMETOOLONG";
|
||||
Errno3[Errno3["ENOLCK"] = 37] = "ENOLCK";
|
||||
Errno3[Errno3["ENOSYS"] = 38] = "ENOSYS";
|
||||
Errno3[Errno3["ENOTEMPTY"] = 39] = "ENOTEMPTY";
|
||||
Errno3[Errno3["ELOOP"] = 40] = "ELOOP";
|
||||
Errno3[Errno3["ENOMSG"] = 42] = "ENOMSG";
|
||||
Errno3[Errno3["EBADE"] = 52] = "EBADE";
|
||||
Errno3[Errno3["EBADR"] = 53] = "EBADR";
|
||||
Errno3[Errno3["EXFULL"] = 54] = "EXFULL";
|
||||
Errno3[Errno3["ENOANO"] = 55] = "ENOANO";
|
||||
Errno3[Errno3["EBADRQC"] = 56] = "EBADRQC";
|
||||
Errno3[Errno3["ENOSTR"] = 60] = "ENOSTR";
|
||||
Errno3[Errno3["ENODATA"] = 61] = "ENODATA";
|
||||
Errno3[Errno3["ETIME"] = 62] = "ETIME";
|
||||
Errno3[Errno3["ENOSR"] = 63] = "ENOSR";
|
||||
Errno3[Errno3["ENONET"] = 64] = "ENONET";
|
||||
Errno3[Errno3["EREMOTE"] = 66] = "EREMOTE";
|
||||
Errno3[Errno3["ENOLINK"] = 67] = "ENOLINK";
|
||||
Errno3[Errno3["ECOMM"] = 70] = "ECOMM";
|
||||
Errno3[Errno3["EPROTO"] = 71] = "EPROTO";
|
||||
Errno3[Errno3["EBADMSG"] = 74] = "EBADMSG";
|
||||
Errno3[Errno3["EOVERFLOW"] = 75] = "EOVERFLOW";
|
||||
Errno3[Errno3["EBADFD"] = 77] = "EBADFD";
|
||||
Errno3[Errno3["ESTRPIPE"] = 86] = "ESTRPIPE";
|
||||
Errno3[Errno3["ENOTSOCK"] = 88] = "ENOTSOCK";
|
||||
Errno3[Errno3["EDESTADDRREQ"] = 89] = "EDESTADDRREQ";
|
||||
Errno3[Errno3["EMSGSIZE"] = 90] = "EMSGSIZE";
|
||||
Errno3[Errno3["EPROTOTYPE"] = 91] = "EPROTOTYPE";
|
||||
Errno3[Errno3["ENOPROTOOPT"] = 92] = "ENOPROTOOPT";
|
||||
Errno3[Errno3["EPROTONOSUPPORT"] = 93] = "EPROTONOSUPPORT";
|
||||
Errno3[Errno3["ESOCKTNOSUPPORT"] = 94] = "ESOCKTNOSUPPORT";
|
||||
Errno3[Errno3["ENOTSUP"] = 95] = "ENOTSUP";
|
||||
Errno3[Errno3["ENETDOWN"] = 100] = "ENETDOWN";
|
||||
Errno3[Errno3["ENETUNREACH"] = 101] = "ENETUNREACH";
|
||||
Errno3[Errno3["ENETRESET"] = 102] = "ENETRESET";
|
||||
Errno3[Errno3["ETIMEDOUT"] = 110] = "ETIMEDOUT";
|
||||
Errno3[Errno3["ECONNREFUSED"] = 111] = "ECONNREFUSED";
|
||||
Errno3[Errno3["EHOSTDOWN"] = 112] = "EHOSTDOWN";
|
||||
Errno3[Errno3["EHOSTUNREACH"] = 113] = "EHOSTUNREACH";
|
||||
Errno3[Errno3["EALREADY"] = 114] = "EALREADY";
|
||||
Errno3[Errno3["EINPROGRESS"] = 115] = "EINPROGRESS";
|
||||
Errno3[Errno3["ESTALE"] = 116] = "ESTALE";
|
||||
Errno3[Errno3["EREMOTEIO"] = 121] = "EREMOTEIO";
|
||||
Errno3[Errno3["EDQUOT"] = 122] = "EDQUOT";
|
||||
})(Errno2 || (Errno2 = {}));
|
||||
var errorMessages2 = {
|
||||
[Errno2.EPERM]: "Operation not permitted",
|
||||
[Errno2.ENOENT]: "No such file or directory",
|
||||
[Errno2.EINTR]: "Interrupted system call",
|
||||
[Errno2.EIO]: "Input/output error",
|
||||
[Errno2.ENXIO]: "No such device or address",
|
||||
[Errno2.EBADF]: "Bad file descriptor",
|
||||
[Errno2.EAGAIN]: "Resource temporarily unavailable",
|
||||
[Errno2.ENOMEM]: "Cannot allocate memory",
|
||||
[Errno2.EACCES]: "Permission denied",
|
||||
[Errno2.EFAULT]: "Bad address",
|
||||
[Errno2.ENOTBLK]: "Block device required",
|
||||
[Errno2.EBUSY]: "Resource busy or locked",
|
||||
[Errno2.EEXIST]: "File exists",
|
||||
[Errno2.EXDEV]: "Invalid cross-device link",
|
||||
[Errno2.ENODEV]: "No such device",
|
||||
[Errno2.ENOTDIR]: "File is not a directory",
|
||||
[Errno2.EISDIR]: "File is a directory",
|
||||
[Errno2.EINVAL]: "Invalid argument",
|
||||
[Errno2.ENFILE]: "Too many open files in system",
|
||||
[Errno2.EMFILE]: "Too many open files",
|
||||
[Errno2.ETXTBSY]: "Text file busy",
|
||||
[Errno2.EFBIG]: "File is too big",
|
||||
[Errno2.ENOSPC]: "No space left on disk",
|
||||
[Errno2.ESPIPE]: "Illegal seek",
|
||||
[Errno2.EROFS]: "Cannot modify a read-only file system",
|
||||
[Errno2.EMLINK]: "Too many links",
|
||||
[Errno2.EPIPE]: "Broken pipe",
|
||||
[Errno2.EDOM]: "Numerical argument out of domain",
|
||||
[Errno2.ERANGE]: "Numerical result out of range",
|
||||
[Errno2.EDEADLK]: "Resource deadlock would occur",
|
||||
[Errno2.ENAMETOOLONG]: "File name too long",
|
||||
[Errno2.ENOLCK]: "No locks available",
|
||||
[Errno2.ENOSYS]: "Function not implemented",
|
||||
[Errno2.ENOTEMPTY]: "Directory is not empty",
|
||||
[Errno2.ELOOP]: "Too many levels of symbolic links",
|
||||
[Errno2.ENOMSG]: "No message of desired type",
|
||||
[Errno2.EBADE]: "Invalid exchange",
|
||||
[Errno2.EBADR]: "Invalid request descriptor",
|
||||
[Errno2.EXFULL]: "Exchange full",
|
||||
[Errno2.ENOANO]: "No anode",
|
||||
[Errno2.EBADRQC]: "Invalid request code",
|
||||
[Errno2.ENOSTR]: "Device not a stream",
|
||||
[Errno2.ENODATA]: "No data available",
|
||||
[Errno2.ETIME]: "Timer expired",
|
||||
[Errno2.ENOSR]: "Out of streams resources",
|
||||
[Errno2.ENONET]: "Machine is not on the network",
|
||||
[Errno2.EREMOTE]: "Object is remote",
|
||||
[Errno2.ENOLINK]: "Link has been severed",
|
||||
[Errno2.ECOMM]: "Communication error on send",
|
||||
[Errno2.EPROTO]: "Protocol error",
|
||||
[Errno2.EBADMSG]: "Bad message",
|
||||
[Errno2.EOVERFLOW]: "Value too large for defined data type",
|
||||
[Errno2.EBADFD]: "File descriptor in bad state",
|
||||
[Errno2.ESTRPIPE]: "Streams pipe error",
|
||||
[Errno2.ENOTSOCK]: "Socket operation on non-socket",
|
||||
[Errno2.EDESTADDRREQ]: "Destination address required",
|
||||
[Errno2.EMSGSIZE]: "Message too long",
|
||||
[Errno2.EPROTOTYPE]: "Protocol wrong type for socket",
|
||||
[Errno2.ENOPROTOOPT]: "Protocol not available",
|
||||
[Errno2.EPROTONOSUPPORT]: "Protocol not supported",
|
||||
[Errno2.ESOCKTNOSUPPORT]: "Socket type not supported",
|
||||
[Errno2.ENOTSUP]: "Operation is not supported",
|
||||
[Errno2.ENETDOWN]: "Network is down",
|
||||
[Errno2.ENETUNREACH]: "Network is unreachable",
|
||||
[Errno2.ENETRESET]: "Network dropped connection on reset",
|
||||
[Errno2.ETIMEDOUT]: "Connection timed out",
|
||||
[Errno2.ECONNREFUSED]: "Connection refused",
|
||||
[Errno2.EHOSTDOWN]: "Host is down",
|
||||
[Errno2.EHOSTUNREACH]: "No route to host",
|
||||
[Errno2.EALREADY]: "Operation already in progress",
|
||||
[Errno2.EINPROGRESS]: "Operation now in progress",
|
||||
[Errno2.ESTALE]: "Stale file handle",
|
||||
[Errno2.EREMOTEIO]: "Remote I/O error",
|
||||
[Errno2.EDQUOT]: "Disk quota exceeded"
|
||||
};
|
||||
var ErrnoError2 = class extends Error {
|
||||
static fromJSON(json) {
|
||||
const err = new ErrnoError2(json.errno, json.message, json.path, json.syscall);
|
||||
err.code = json.code;
|
||||
err.stack = json.stack;
|
||||
return err;
|
||||
}
|
||||
static With(code, path, syscall) {
|
||||
return new ErrnoError2(Errno2[code], errorMessages2[Errno2[code]], path, syscall);
|
||||
}
|
||||
/**
|
||||
* Represents a ZenFS error. Passed back to applications after a failed
|
||||
* call to the ZenFS API.
|
||||
*
|
||||
* Error codes mirror those returned by regular Unix file operations, which is
|
||||
* what Node returns.
|
||||
* @param type The type of the error.
|
||||
* @param message A descriptive error message.
|
||||
*/
|
||||
constructor(errno, message = errorMessages2[errno], path, syscall = "") {
|
||||
super(message);
|
||||
this.errno = errno;
|
||||
this.path = path;
|
||||
this.syscall = syscall;
|
||||
this.code = Errno2[errno];
|
||||
this.message = `${this.code}: ${message}${this.path ? `, '${this.path}'` : ""}`;
|
||||
}
|
||||
/**
|
||||
* @return A friendly error message.
|
||||
*/
|
||||
toString() {
|
||||
return this.message;
|
||||
}
|
||||
toJSON() {
|
||||
return {
|
||||
errno: this.errno,
|
||||
code: this.code,
|
||||
path: this.path,
|
||||
stack: this.stack,
|
||||
message: this.message,
|
||||
syscall: this.syscall
|
||||
};
|
||||
}
|
||||
/**
|
||||
* The size of the API error in buffer-form in bytes.
|
||||
*/
|
||||
bufferSize() {
|
||||
return 4 + JSON.stringify(this.toJSON()).length;
|
||||
}
|
||||
};
|
||||
__name(ErrnoError2, "ErrnoError");
|
||||
|
||||
// node_modules/@zenfs/core/dist/backends/store/store.js
|
||||
var Transaction2 = class {
|
||||
constructor() {
|
||||
this.aborted = false;
|
||||
}
|
||||
async [Symbol.asyncDispose]() {
|
||||
if (this.aborted) {
|
||||
return;
|
||||
}
|
||||
await this.commit();
|
||||
}
|
||||
[Symbol.dispose]() {
|
||||
if (this.aborted) {
|
||||
return;
|
||||
}
|
||||
this.commitSync();
|
||||
}
|
||||
};
|
||||
__name(Transaction2, "Transaction");
|
||||
var AsyncTransaction2 = class extends Transaction2 {
|
||||
getSync(ino) {
|
||||
throw ErrnoError2.With("ENOSYS", void 0, "AsyncTransaction.getSync");
|
||||
}
|
||||
setSync(ino, data) {
|
||||
throw ErrnoError2.With("ENOSYS", void 0, "AsyncTransaction.setSync");
|
||||
}
|
||||
removeSync(ino) {
|
||||
throw ErrnoError2.With("ENOSYS", void 0, "AsyncTransaction.removeSync");
|
||||
}
|
||||
commitSync() {
|
||||
throw ErrnoError2.With("ENOSYS", void 0, "AsyncTransaction.commitSync");
|
||||
}
|
||||
abortSync() {
|
||||
throw ErrnoError2.With("ENOSYS", void 0, "AsyncTransaction.abortSync");
|
||||
}
|
||||
};
|
||||
__name(AsyncTransaction2, "AsyncTransaction");
|
||||
|
||||
// src/IndexedDB.ts
|
||||
function wrap(request) {
|
||||
return new Promise((resolve, reject) => {
|
||||
request.onsuccess = () => resolve(request.result);
|
||||
request.onerror = (e) => {
|
||||
e.preventDefault();
|
||||
reject(convertException(request.error));
|
||||
};
|
||||
});
|
||||
}
|
||||
__name(wrap, "wrap");
|
||||
var IndexedDBTransaction = class extends AsyncTransaction2 {
|
||||
constructor(tx, store) {
|
||||
super();
|
||||
this.tx = tx;
|
||||
this.store = store;
|
||||
}
|
||||
get(key) {
|
||||
return wrap(this.store.get(key.toString()));
|
||||
}
|
||||
async set(key, data) {
|
||||
await wrap(this.store.put(data, key.toString()));
|
||||
}
|
||||
remove(key) {
|
||||
return wrap(this.store.delete(key.toString()));
|
||||
}
|
||||
async commit() {
|
||||
this.tx.commit();
|
||||
}
|
||||
async abort() {
|
||||
try {
|
||||
this.tx.abort();
|
||||
} catch (e) {
|
||||
throw convertException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
__name(IndexedDBTransaction, "IndexedDBTransaction");
|
||||
async function createDB(name, indexedDB = globalThis.indexedDB) {
|
||||
const req = indexedDB.open(name);
|
||||
req.onupgradeneeded = () => {
|
||||
const db = req.result;
|
||||
if (db.objectStoreNames.contains(name)) {
|
||||
db.deleteObjectStore(name);
|
||||
}
|
||||
db.createObjectStore(name);
|
||||
};
|
||||
const result = await wrap(req);
|
||||
return result;
|
||||
}
|
||||
__name(createDB, "createDB");
|
||||
var IndexedDBStore = class {
|
||||
constructor(db) {
|
||||
this.db = db;
|
||||
}
|
||||
sync() {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
get name() {
|
||||
return IndexedDB.name + ":" + this.db.name;
|
||||
}
|
||||
clear() {
|
||||
return wrap(this.db.transaction(this.db.name, "readwrite").objectStore(this.db.name).clear());
|
||||
}
|
||||
clearSync() {
|
||||
throw ErrnoError.With("ENOSYS", void 0, "IndexedDBStore.clearSync");
|
||||
}
|
||||
transaction() {
|
||||
const tx = this.db.transaction(this.db.name, "readwrite");
|
||||
return new IndexedDBTransaction(tx, tx.objectStore(this.db.name));
|
||||
}
|
||||
};
|
||||
__name(IndexedDBStore, "IndexedDBStore");
|
||||
var IndexedDB = {
|
||||
name: "IndexedDB",
|
||||
options: {
|
||||
storeName: {
|
||||
type: "string",
|
||||
required: false,
|
||||
description: "The name of this file system. You can have multiple IndexedDB file systems operating at once, but each must have a different name."
|
||||
},
|
||||
idbFactory: {
|
||||
type: "object",
|
||||
required: false,
|
||||
description: "The IDBFactory to use. Defaults to globalThis.indexedDB."
|
||||
}
|
||||
},
|
||||
async isAvailable(idbFactory = globalThis.indexedDB) {
|
||||
try {
|
||||
if (!(idbFactory instanceof IDBFactory)) {
|
||||
return false;
|
||||
}
|
||||
const req = idbFactory.open("__zenfs_test");
|
||||
await wrap(req);
|
||||
idbFactory.deleteDatabase("__zenfs_test");
|
||||
return true;
|
||||
} catch (e) {
|
||||
idbFactory.deleteDatabase("__zenfs_test");
|
||||
return false;
|
||||
}
|
||||
},
|
||||
async create(options) {
|
||||
const db = await createDB(options.storeName || "zenfs", options.idbFactory);
|
||||
const store = new IndexedDBStore(db);
|
||||
const fs2 = new StoreFS(store);
|
||||
return fs2;
|
||||
}
|
||||
};
|
||||
|
||||
// src/Storage.ts
|
||||
var WebStorageStore = class {
|
||||
constructor(_storage) {
|
||||
this._storage = _storage;
|
||||
}
|
||||
get name() {
|
||||
return WebStorage.name;
|
||||
}
|
||||
clear() {
|
||||
this._storage.clear();
|
||||
}
|
||||
clearSync() {
|
||||
this._storage.clear();
|
||||
}
|
||||
async sync() {
|
||||
}
|
||||
transaction() {
|
||||
return new SimpleTransaction(this);
|
||||
}
|
||||
get(key) {
|
||||
const data = this._storage.getItem(key.toString());
|
||||
if (typeof data != "string") {
|
||||
return;
|
||||
}
|
||||
return encode(data);
|
||||
}
|
||||
set(key, data) {
|
||||
try {
|
||||
this._storage.setItem(key.toString(), decode(data));
|
||||
} catch (e) {
|
||||
throw new ErrnoError(Errno.ENOSPC, "Storage is full.");
|
||||
}
|
||||
}
|
||||
delete(key) {
|
||||
try {
|
||||
this._storage.removeItem(key.toString());
|
||||
} catch (e) {
|
||||
throw new ErrnoError(Errno.EIO, "Unable to delete key " + key + ": " + e);
|
||||
}
|
||||
}
|
||||
};
|
||||
__name(WebStorageStore, "WebStorageStore");
|
||||
var WebStorage = {
|
||||
name: "WebStorage",
|
||||
options: {
|
||||
storage: {
|
||||
type: "object",
|
||||
required: false,
|
||||
description: "The Storage to use. Defaults to globalThis.localStorage."
|
||||
}
|
||||
},
|
||||
isAvailable(storage = globalThis.localStorage) {
|
||||
return storage instanceof globalThis.Storage;
|
||||
},
|
||||
create({ storage = globalThis.localStorage }) {
|
||||
return new StoreFS(new WebStorageStore(storage));
|
||||
}
|
||||
};
|
||||
return __toCommonJS(src_exports);
|
||||
})();
|
||||
//# sourceMappingURL=browser.js.map
|
14734
packages/wasm-job/examples/leaflet/browser.min.js
vendored
Normal file
14734
packages/wasm-job/examples/leaflet/browser.min.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
packages/wasm-job/examples/leaflet/bulma.min.css
vendored
Normal file
1
packages/wasm-job/examples/leaflet/bulma.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
108
packages/wasm-job/examples/leaflet/index.htm
Normal file
108
packages/wasm-job/examples/leaflet/index.htm
Normal file
@ -0,0 +1,108 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr"><head>
|
||||
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Free Pascal wasm-job Leaflet example</title>
|
||||
<!-- taken in demojitsimeet de Michael Van Canneyt for Bootstrap test -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.js" type="text/javascript"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
|
||||
<!-- end add for bootstrap -->
|
||||
|
||||
<!-- Bulma / ZenFS -->
|
||||
<link href="bulma.min.css" rel="stylesheet">
|
||||
<script src="browser.min.js"></script>
|
||||
<script src="browser.dom.js"></script>
|
||||
<!-- end Bulma / ZenFS -->
|
||||
<!-- Openstreetmap / Leaflet -->
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
|
||||
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
|
||||
crossorigin=""/>
|
||||
<!-- Make sure you put this AFTER Leaflet's CSS -->
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
|
||||
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
|
||||
crossorigin=""></script>
|
||||
<!-- end Openstreetmap / Leaflet -->
|
||||
|
||||
<script src="js_leaflet.js"></script>
|
||||
<style>
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="card">
|
||||
<!--
|
||||
<div class="card-header" id="chParameters">
|
||||
<h5 class="mb-0">
|
||||
<button class="btn btn-link" data-bs-toggle="collapse" data-bs-target="#Parameters" aria-expanded="true" aria-controls="Parameters">
|
||||
Parameters ...
|
||||
</button>
|
||||
</h5>
|
||||
</div>
|
||||
-->
|
||||
<div id="Parameters" class="collapse.show" aria-labelledby="chParameters">
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<div class="form-floating">
|
||||
<input id="iParameters_Latitude" type="text" class="form-control" aria-describedby="lParameters_Latitude" value="0"/>
|
||||
<label for="iParameters_Latitude">Latitude</label>
|
||||
<small id="lParameters_Latitude" class="form-text text-muted">
|
||||
Latitude of the location for calculation.
|
||||
</small>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input id="iParameters_Longitude" type="text" class="form-control" aria-describedby="lParameters_Longitude" value="0"/>
|
||||
<label for="iParameters_Longitude">Longitude</label>
|
||||
<small id="lParameters_Longitude" class="form-text text-muted">
|
||||
Longitude of the location for calculation, negative towards the West.
|
||||
</small>
|
||||
</div>
|
||||
<button id='bCalculation' class="button is-primary" style="visibility: hidden;"> Re-Calculation</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="dMap" style="height: 600px;"></div>
|
||||
<div class="card">
|
||||
<div class="card-header" id="chCalculation">
|
||||
<h5 class="mb-0">
|
||||
<button class="btn btn-link" data-bs-toggle="collapse" data-bs-target="#Calculation" aria-expanded="true" aria-controls="Calculation">
|
||||
More calculations ...
|
||||
</button>
|
||||
</h5>
|
||||
</div>
|
||||
<div id="Calculation" class="collapse" aria-labelledby="chCalculation">
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<div id='dCalculation_Result'>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header" id="chConsole">
|
||||
<h5 class="mb-0">
|
||||
<button class="btn btn-link" data-bs-toggle="collapse" data-bs-target="#Console" aria-expanded="true" aria-controls="Console">
|
||||
Console
|
||||
</button>
|
||||
</h5>
|
||||
</div>
|
||||
<div id="Console" class="collapse" aria-labelledby="chConsole">
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<div class="box" id="pasjsconsole"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<script>
|
||||
rtl.showUncaughtExceptions=true;
|
||||
rtl.run();
|
||||
</script>
|
||||
|
||||
|
||||
</body></html>
|
153357
packages/wasm-job/examples/leaflet/job_web.pas
Normal file
153357
packages/wasm-job/examples/leaflet/job_web.pas
Normal file
File diff suppressed because it is too large
Load Diff
6649
packages/wasm-job/examples/leaflet/js_leaflet.js
Normal file
6649
packages/wasm-job/examples/leaflet/js_leaflet.js
Normal file
File diff suppressed because it is too large
Load Diff
2
packages/wasm-job/examples/leaflet/js_leaflet.js.map
Normal file
2
packages/wasm-job/examples/leaflet/js_leaflet.js.map
Normal file
File diff suppressed because one or more lines are too long
85
packages/wasm-job/examples/leaflet/js_leaflet.lpi
Normal file
85
packages/wasm-job/examples/leaflet/js_leaflet.lpi
Normal file
@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="12"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasTitleStatement Value="False"/>
|
||||
<MainUnitHasScaledStatement Value="False"/>
|
||||
<Runnable Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<Title Value="js_leaflet"/>
|
||||
<UseAppBundle Value="False"/>
|
||||
<ResourceType Value="res"/>
|
||||
</General>
|
||||
<CustomData Count="3">
|
||||
<Item0 Name="Pas2JSProject" Value="1"/>
|
||||
<Item1 Name="PasJSPort" Value="1024"/>
|
||||
<Item2 Name="PasJSWebBrowserProject" Value="1"/>
|
||||
</CustomData>
|
||||
<BuildModes>
|
||||
<Item Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<UseFileFilters Value="True"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
</RunParams>
|
||||
<Units>
|
||||
<Unit>
|
||||
<Filename Value="js_leaflet.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="js_leaflet"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="js"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<CStyleOperator Value="False"/>
|
||||
<AllowLabel Value="False"/>
|
||||
<UseAnsiStrings Value="False"/>
|
||||
<CPPInline Value="False"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
<CodeGeneration>
|
||||
<TargetOS Value="browser"/>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<GenerateDebugInfo Value="False"/>
|
||||
<UseLineInfoUnit Value="False"/>
|
||||
</Debugging>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CustomOptions Value="-Jeutf-8 -Jirtl.js -Jc -Jminclude"/>
|
||||
<CompilerPath Value="$(pas2js)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions>
|
||||
<Item>
|
||||
<Name Value="EAbort"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
80
packages/wasm-job/examples/leaflet/js_leaflet.lpr
Normal file
80
packages/wasm-job/examples/leaflet/js_leaflet.lpr
Normal file
@ -0,0 +1,80 @@
|
||||
program js_leaflet;
|
||||
|
||||
{$mode objfpc}
|
||||
|
||||
uses
|
||||
BrowserConsole, BrowserApp, WASIHostApp, JOB_Browser,JS,
|
||||
Classes, SysUtils, Web, wasitypes, wasizenfs, libzenfs, libzenfsdom,wasienv;
|
||||
|
||||
type
|
||||
|
||||
{ Tjs_leaflet }
|
||||
|
||||
Tjs_leaflet
|
||||
=
|
||||
class(TWASIHostApplication)
|
||||
protected
|
||||
FS :TWASIZenFS;
|
||||
procedure RunWasm ; async;
|
||||
procedure DoRun; override;
|
||||
private
|
||||
ob: TJSObjectBridge;
|
||||
sd: TWebAssemblyStartDescriptor;
|
||||
function wasmBeforeStart(_Sender: TObject; _Descriptor: TWebAssemblyStartDescriptor): Boolean;
|
||||
procedure wasmWrite(Sender: TObject; const aOutput: String);
|
||||
public
|
||||
constructor Create(aOwner : TComponent); override;
|
||||
end;
|
||||
|
||||
var
|
||||
Application : Tjs_leaflet;
|
||||
|
||||
constructor Tjs_leaflet.Create(aOwner: TComponent);
|
||||
begin
|
||||
inherited Create(aOwner);
|
||||
ob:= TJSObjectBridge.Create( WasiEnvironment);
|
||||
RunEntryFunction:='_initialize';
|
||||
|
||||
WasiEnvironment.OnStdErrorWrite :=@wasmWrite;
|
||||
WasiEnvironment.OnStdOutputWrite:=@wasmWrite;
|
||||
//WasiEnvironment.LogAPI:=True;
|
||||
//Writeln('Enabling logging');
|
||||
end;
|
||||
|
||||
function Tjs_leaflet.wasmBeforeStart( _Sender: TObject; _Descriptor: TWebAssemblyStartDescriptor): Boolean;
|
||||
begin
|
||||
//WriteLn(ClassName+'.wasmBeforeStart');
|
||||
|
||||
sd:= _Descriptor;
|
||||
|
||||
ob.InstanceExports:=_Descriptor.Exported;
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
procedure Tjs_leaflet.DoRun;
|
||||
begin
|
||||
RunWasm;
|
||||
end;
|
||||
|
||||
procedure Tjs_leaflet.wasmWrite(Sender: TObject; const aOutput: String);
|
||||
begin
|
||||
Writeln( aOutput);
|
||||
end;
|
||||
|
||||
procedure Tjs_leaflet.RunWasm;
|
||||
begin
|
||||
// Writeln('Enabling logging');
|
||||
// WasiEnvironment.LogAPI:=True;
|
||||
FS:=TWASIZenFS.Create;
|
||||
WasiEnvironment.FS:=FS;
|
||||
StartWebAssembly('wasm_leaflet.wasm',true,@wasmBeforeStart);
|
||||
end;
|
||||
|
||||
begin
|
||||
//ConsoleStyle:=DefaultConsoleStyle;
|
||||
ConsoleStyle:=DefaultCRTConsoleStyle;
|
||||
HookConsole;
|
||||
Application:=Tjs_leaflet.Create(nil);
|
||||
Application.Initialize;
|
||||
Application.Run;
|
||||
end.
|
466
packages/wasm-job/examples/leaflet/uCoordinate.pas
Normal file
466
packages/wasm-job/examples/leaflet/uCoordinate.pas
Normal file
@ -0,0 +1,466 @@
|
||||
unit uCoordinate;
|
||||
|
||||
{$mode Delphi}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Math;
|
||||
|
||||
type
|
||||
TLongitude_from_LatitudeOverflow_Proc= procedure of object;
|
||||
|
||||
{ T_Coordinate }
|
||||
|
||||
T_Coordinate
|
||||
=
|
||||
class
|
||||
private
|
||||
//FLatLon_ True: type Latitude -90..+90; False: Longitude -180..+180
|
||||
FLatLon_: Boolean;
|
||||
FStr: String;
|
||||
FSign, FDeg, FMin, FSec: Integer;
|
||||
FDegrees, FRadians: Extended;
|
||||
procedure Set_Degrees ( Value: Extended);
|
||||
procedure Set_Radians( Value: Extended);
|
||||
|
||||
function String_to_Sexagesimal: Byte;
|
||||
procedure Sexagesimal_to_String;
|
||||
procedure Sexagesimal_to_Degrees;
|
||||
procedure Degrees_to_Sexagesimal;
|
||||
procedure Degrees_to_Radians;
|
||||
procedure Radians_to_Degrees;
|
||||
|
||||
function Check_Radians: Boolean;
|
||||
function Check_Degrees: Boolean;
|
||||
function Check_Sexagesimal: Byte;
|
||||
|
||||
procedure doModify;
|
||||
public
|
||||
sinus, cosinus: Extended;
|
||||
|
||||
//procedure called by latitude if 90° is exceeded in absolute value
|
||||
// in this case we make a half turn in longitude and recalculate the latitude
|
||||
Longitude_from_LatitudeOverflow: TLongitude_from_LatitudeOverflow_Proc; //for the latitude coordinate
|
||||
procedure Longitude_Turnaround; // for the longitude coordinate, the link is made in Twasm_leaflet
|
||||
|
||||
constructor Create( _LatLon_: Boolean);
|
||||
destructor Destroy; override;
|
||||
procedure Copy_From( _Coordinate: T_Coordinate);
|
||||
function Set_To(aSign, aDeg, aMin, aSec: Integer): Byte;
|
||||
function Set_Str(Value: String): Byte;
|
||||
property LatLon_: Boolean read FLatLon_;
|
||||
property Str : String read FStr;
|
||||
property Sign : integer read FSign;
|
||||
property Deg : integer read FDeg;
|
||||
property Min : Integer read FMin;
|
||||
property Sec : Integer read FSec;
|
||||
property Degrees : Extended read FDegrees write Set_Degrees ;
|
||||
property Radians: Extended read FRadians write Set_Radians;
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
//from uuStrings.pas
|
||||
function StrToK( Key: String; var S: String): String;
|
||||
var
|
||||
I: Integer;
|
||||
begin
|
||||
I:= Pos( Key, S);
|
||||
if I = 0
|
||||
then
|
||||
begin
|
||||
Result:= S;
|
||||
S:= '';
|
||||
end
|
||||
else
|
||||
begin
|
||||
Result:= Copy( S, 1, I-1);
|
||||
Delete( S, 1, (I-1)+Length( Key));
|
||||
end;
|
||||
end;
|
||||
|
||||
//from uuStrings.pas
|
||||
//Like StrToK but takes the first NbCaracteres characters
|
||||
function StrReadString( var S: String; NbCaracteres: Integer): String;
|
||||
begin
|
||||
Result:= Copy( S, 1, NbCaracteres);
|
||||
Delete( S, 1, NbCaracteres);
|
||||
end;
|
||||
|
||||
//from uuStrings.pas
|
||||
function IsDigit( S: String): Boolean;
|
||||
var
|
||||
I: Integer;
|
||||
begin
|
||||
Result:= S <> '';
|
||||
if not Result then exit;
|
||||
|
||||
for I:= 1 to Length( S)
|
||||
do
|
||||
begin
|
||||
Result:= S[I] in ['0'..'9'];
|
||||
if not Result then break;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
//from uuStrings.pas
|
||||
function IsInt( S: String): Boolean;
|
||||
var
|
||||
I, LS: Integer;
|
||||
begin
|
||||
Result:= False;
|
||||
|
||||
// String length
|
||||
LS:= Length( S);
|
||||
if LS = 0 then exit; // empty string
|
||||
|
||||
// Evacuation of spaces before the number
|
||||
I:= 1;
|
||||
while I <= LS
|
||||
do
|
||||
if S[I] = ' '
|
||||
then
|
||||
Inc( I)
|
||||
else
|
||||
break;
|
||||
if I > LS then exit; // only spaces
|
||||
|
||||
// Process eventual sign
|
||||
if S[I] = '+'
|
||||
then
|
||||
Inc( I)
|
||||
else if S[I] = '-'
|
||||
then
|
||||
Inc( I);
|
||||
if I > LS then exit; // no digits
|
||||
|
||||
// Checking that we only have digits
|
||||
Result:= True;
|
||||
while I <= LS
|
||||
do
|
||||
if IsDigit(S[I])
|
||||
then
|
||||
Inc( I)
|
||||
else
|
||||
begin
|
||||
Result:= False;
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ T_Coordinate }
|
||||
|
||||
constructor T_Coordinate.Create( _LatLon_: Boolean);
|
||||
begin
|
||||
FLatLon_:= _LatLon_;
|
||||
Longitude_from_LatitudeOverflow:= nil;
|
||||
end;
|
||||
|
||||
destructor T_Coordinate.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
|
||||
const
|
||||
DegSize: array[False..True] of Byte = (4,3); // LatLon_
|
||||
MinSize= 3;
|
||||
SecSize= 3;
|
||||
// 4: incorrect sign, 3: incorrect deg , 2: incorrect Min, 1: incorrect Sec
|
||||
// 0: OK
|
||||
function T_Coordinate.String_to_Sexagesimal: Byte;
|
||||
var
|
||||
sSign, sDeg, sMin, sSec: String;
|
||||
S: String;
|
||||
cSign: Char;
|
||||
begin
|
||||
S:= FStr;
|
||||
sSign:= StrReadString( S, 1);
|
||||
cSign:= sSign[1];
|
||||
|
||||
sDeg:= StrTok( '°', S);
|
||||
sMin:= StrTok( '''', S);
|
||||
sSec:= StrTok( '"', S);
|
||||
|
||||
if sSec = ''
|
||||
then
|
||||
sSec:= '0';
|
||||
//if not FLatLon_
|
||||
//then
|
||||
// begin
|
||||
// WriteLn(ClassName+'.String_to_Sexagesimal: cSign:'+cSign+' sDeg:'+sDeg+' sMin:'+sMin+' sSec:'+sSec);
|
||||
// end;
|
||||
|
||||
Result:= 4; if (cSign <> '-') and (cSign <> '+') then exit;
|
||||
|
||||
Result:= 3; if not IsInt( sDeg) then exit;
|
||||
|
||||
Result:= 2; if not IsInt( sMin) then exit;
|
||||
|
||||
Result:= 1; if not IsInt( sSec) then exit;
|
||||
|
||||
Result:= 0;
|
||||
|
||||
case sSign[1]
|
||||
of
|
||||
'-': FSign:= -1;
|
||||
'+': FSign:= +1;
|
||||
end;
|
||||
FDeg:= StrToInt( sDeg);
|
||||
FMin:= StrToInt( sMin);
|
||||
FSec:= StrToInt( sSec);
|
||||
end;
|
||||
|
||||
procedure T_Coordinate.Sexagesimal_to_String;
|
||||
var
|
||||
sSign, sDeg, sMin, sSec: String;
|
||||
begin
|
||||
if FSign < 0
|
||||
then
|
||||
sSign:= '-'
|
||||
else
|
||||
sSign:= '+';
|
||||
|
||||
sDeg:= IntToStr(FDeg)+'°';
|
||||
while Length(sDeg) < DegSize[LatLon_] do sDeg:= ' '+sDeg;
|
||||
|
||||
sMin:= IntToStr(FMin)+ '''';
|
||||
while Length(sMin) < 3 do sMin:= ' '+sMin;
|
||||
|
||||
sSec:= IntToStr(FSec)+'"';
|
||||
while Length(sSec) < 3 do sSec:= ' '+sSec;
|
||||
|
||||
FStr:= sSign+sDeg+sMin+sSec;
|
||||
end;
|
||||
|
||||
procedure T_Coordinate.Sexagesimal_to_Degrees;
|
||||
begin
|
||||
FDegrees:= FSign*(FDeg+(FMin+FSec/60.0)/60.0);
|
||||
end;
|
||||
|
||||
procedure T_Coordinate.Degrees_to_Sexagesimal;
|
||||
var
|
||||
d: Extended;
|
||||
begin
|
||||
if FDegrees < 0
|
||||
then
|
||||
begin
|
||||
FSign:= -1;
|
||||
d:= -FDegrees;
|
||||
end
|
||||
else
|
||||
begin
|
||||
FSign:= +1;
|
||||
d:= FDegrees;
|
||||
end;
|
||||
FDeg:= Trunc(d);
|
||||
d:= (d - FDeg) * 60;
|
||||
FMin:= Trunc(d);
|
||||
d:= (d - FMin) * 60;
|
||||
FSec:= Trunc( d);
|
||||
end;
|
||||
|
||||
procedure T_Coordinate.Degrees_to_Radians;
|
||||
begin
|
||||
FRadians:= FDegrees * PI /180;
|
||||
end;
|
||||
|
||||
procedure T_Coordinate.Radians_to_Degrees;
|
||||
begin
|
||||
FDegrees:= FRadians * 180 / PI;
|
||||
end;
|
||||
|
||||
procedure T_Coordinate.Set_Degrees(Value: Extended);
|
||||
begin
|
||||
if FDegrees = Value then exit;
|
||||
FDegrees:= Value;
|
||||
Check_Degrees;
|
||||
Degrees_to_Radians;
|
||||
Degrees_to_Sexagesimal;Sexagesimal_to_String;
|
||||
doModify;
|
||||
end;
|
||||
|
||||
procedure T_Coordinate.Set_Radians(Value: Extended);
|
||||
begin
|
||||
if FRadians = Value then exit;
|
||||
FRadians:= Value;
|
||||
Check_Radians;
|
||||
Radians_to_Degrees; Degrees_to_Sexagesimal; Sexagesimal_to_String;
|
||||
doModify;
|
||||
end;
|
||||
|
||||
function T_Coordinate.Set_To(aSign, aDeg, aMin, aSec: Integer): Byte;
|
||||
begin
|
||||
Result:= 0;
|
||||
if (Sign = aSign) and (Deg = aDeg) and (Min = aMin) and (Sec = aSec) then exit;
|
||||
|
||||
FSign:= aSign;
|
||||
FDeg:= aDeg;
|
||||
FMin:= aMin;
|
||||
FSec:= aSec;
|
||||
|
||||
Sexagesimal_to_Degrees;
|
||||
if Check_Degrees
|
||||
then
|
||||
begin
|
||||
Result:= Check_Sexagesimal;
|
||||
Radians_to_Degrees;
|
||||
Degrees_to_Sexagesimal;
|
||||
exit;
|
||||
end;
|
||||
|
||||
Degrees_to_Radians;
|
||||
Sexagesimal_to_String;
|
||||
doModify;
|
||||
end;
|
||||
|
||||
function T_Coordinate.Set_Str(Value: String): Byte;
|
||||
begin
|
||||
Result:= 0;
|
||||
if FStr = Value then exit;
|
||||
FStr:= Value;
|
||||
|
||||
Result:= String_to_Sexagesimal;
|
||||
if Result > 0
|
||||
then
|
||||
begin
|
||||
Sexagesimal_to_String;
|
||||
exit;
|
||||
end;
|
||||
|
||||
Sexagesimal_to_Degrees;
|
||||
if Check_Degrees
|
||||
then
|
||||
begin
|
||||
Result:= Check_Sexagesimal;
|
||||
Radians_to_Degrees;
|
||||
|
||||
Degrees_to_Sexagesimal;
|
||||
Sexagesimal_to_String;
|
||||
exit;
|
||||
end;
|
||||
|
||||
Degrees_to_Radians;
|
||||
Sexagesimal_to_String;
|
||||
doModify;
|
||||
end;
|
||||
|
||||
function T_Coordinate.Check_Sexagesimal: Byte;
|
||||
begin
|
||||
Result:= 4; if abs(FSign) <> 1 then exit;
|
||||
if LatLon_
|
||||
then
|
||||
begin
|
||||
Result:= 3; if (FDeg < 0)or( 89 < FDeg ) then exit;
|
||||
end
|
||||
else
|
||||
begin
|
||||
Result:= 3; if (FDeg < 0)or(179 < FDeg ) then exit;
|
||||
end;
|
||||
|
||||
Result:= 2; if (FMin < 0)or(59 < FMin) then exit;
|
||||
Result:= 1; if (FSec < 0)or(59 < FMin) then exit;
|
||||
Result:= 0;
|
||||
end;
|
||||
|
||||
function T_Coordinate.Check_Degrees: Boolean;
|
||||
begin
|
||||
Result:= True;
|
||||
if LatLon_
|
||||
then
|
||||
if 90 < FDegrees
|
||||
then
|
||||
FDegrees:= 180 - FDegrees
|
||||
else
|
||||
if FDegrees < -90
|
||||
then
|
||||
FDegrees:= 180 + FDegrees
|
||||
else
|
||||
Result:= False
|
||||
else
|
||||
if 180 < FDegrees
|
||||
then
|
||||
FDegrees:= 360 - FDegrees
|
||||
else
|
||||
if FDegrees < -180
|
||||
then
|
||||
FDegrees:= 360 + FDegrees
|
||||
else
|
||||
Result:= False;
|
||||
end;
|
||||
|
||||
function T_Coordinate.Check_Radians: Boolean;
|
||||
begin
|
||||
Result:= True;
|
||||
if LatLon_
|
||||
then
|
||||
if PI/2 < FRadians
|
||||
then
|
||||
begin
|
||||
if Assigned( Longitude_from_LatitudeOverflow)
|
||||
then
|
||||
Longitude_from_LatitudeOverflow;
|
||||
FRadians:= PI - FRadians
|
||||
end
|
||||
else
|
||||
if FRadians < -PI/2
|
||||
then
|
||||
begin
|
||||
if Assigned( Longitude_from_LatitudeOverflow)
|
||||
then
|
||||
Longitude_from_LatitudeOverflow;
|
||||
FRadians:= -PI - FRadians
|
||||
end
|
||||
else
|
||||
Result:= False
|
||||
else
|
||||
if PI < FRadians
|
||||
then
|
||||
FRadians:= FRadians - 2*PI
|
||||
else if FRadians < -PI
|
||||
then
|
||||
FRadians:= 2*PI + FRadians
|
||||
else
|
||||
Result:= False;
|
||||
end;
|
||||
|
||||
procedure T_Coordinate.Longitude_Turnaround;
|
||||
begin
|
||||
if LatLon_ then exit; // this only applies to a longitude coordinate.
|
||||
|
||||
FRadians:= FRadians + PI;
|
||||
Check_Radians;
|
||||
|
||||
Radians_To_Degrees;
|
||||
Degrees_to_Sexagesimal;
|
||||
Sexagesimal_to_String;
|
||||
doModify;
|
||||
end;
|
||||
|
||||
procedure T_Coordinate.Copy_From( _Coordinate: T_Coordinate);
|
||||
begin
|
||||
if _Coordinate = nil then exit;
|
||||
|
||||
FLatLon_:= _Coordinate.FLatLon_;
|
||||
FStr := _Coordinate.FStr ;
|
||||
FSign := _Coordinate.FSign ;
|
||||
FDeg := _Coordinate.FDeg ;
|
||||
FMin := _Coordinate.FMin ;
|
||||
FSec := _Coordinate.FSec ;
|
||||
FDegrees := _Coordinate.FDegrees ;
|
||||
FRadians:= _Coordinate.FRadians;
|
||||
|
||||
sinus := _Coordinate.sinus ;
|
||||
cosinus := _Coordinate.cosinus ;
|
||||
end;
|
||||
|
||||
procedure T_Coordinate.doModify;
|
||||
begin
|
||||
SinCos( FRadians, sinus, cosinus);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
168
packages/wasm-job/examples/leaflet/uJSLeaflet.pas
Normal file
168
packages/wasm-job/examples/leaflet/uJSLeaflet.pas
Normal file
@ -0,0 +1,168 @@
|
||||
unit uJSLeaflet;
|
||||
|
||||
{$mode Delphi}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, JOB.Shared, JOB_Web, JOB.JS;
|
||||
|
||||
type
|
||||
TOnMapClickCallback = procedure (_e: IJSEvent) of object;
|
||||
|
||||
{ IJSLeafletMap }
|
||||
|
||||
IJSLeafletMap
|
||||
=
|
||||
interface(IJSObject)
|
||||
['{622B2D01-0F15-480B-BC46-FCB926059823}']
|
||||
procedure Set_onClick(const _Callback: TOnMapClickCallback);
|
||||
procedure setView( _Latitude, _Longitude, _Zoom: Extended);
|
||||
end;
|
||||
|
||||
{ TJSLeafletMap }
|
||||
|
||||
TJSLeafletMap
|
||||
=
|
||||
class(TJSObject,IJSLeafletMap)
|
||||
public
|
||||
procedure Set_onClick(const _Callback: TOnMapClickCallback);
|
||||
procedure setView( _Latitude, _Longitude, _Zoom: Extended);
|
||||
class function JSClassName: UnicodeString; override;
|
||||
class function Cast(const Intf: IJSObject): IJSLeafletMap;
|
||||
end;
|
||||
|
||||
function JOBCallOnMapClickCallback(const _Method: TMethod; var _H: TJOBCallbackHelper): PByte;
|
||||
|
||||
type
|
||||
{ IJSLeafletTileLayer }
|
||||
|
||||
IJSLeafletTileLayer
|
||||
=
|
||||
interface(IJSObject)
|
||||
['{54AD2D36-7A4B-4718-9DFE-653CE6754DFA}']
|
||||
procedure addTo( const _map: IJSLeafletMap);
|
||||
end;
|
||||
TJSLeafletTileLayer
|
||||
=
|
||||
class(TJSObject,IJSLeafletTileLayer)
|
||||
public
|
||||
procedure addTo( const _map: IJSLeafletMap);
|
||||
class function JSClassName: UnicodeString; override;
|
||||
class function Cast(const Intf: IJSObject): IJSLeafletTileLayer;
|
||||
end;
|
||||
|
||||
type
|
||||
{ IJSLeaflet }
|
||||
|
||||
IJSLeaflet
|
||||
=
|
||||
interface(IJSObject)
|
||||
['{778EC20D-A7FB-4D52-90E2-D02A31A1607F}']
|
||||
function map(const _idMap: String; _params: IJSObject= nil): IJSLeafletMap;
|
||||
function tileLayer( const _urlTemplate: String; _options: IJSObject= nil): IJSLeafletTileLayer;
|
||||
end;
|
||||
|
||||
{ TJSLeafletMap }
|
||||
|
||||
TJSLeaflet
|
||||
=
|
||||
class(TJSObject,IJSLeaflet)
|
||||
public
|
||||
function map(const _idMap: String; _params: IJSObject= nil): IJSLeafletMap;
|
||||
function tileLayer( const _urlTemplate: String; _options: IJSObject= nil): IJSLeafletTileLayer;
|
||||
class function JSClassName: UnicodeString; override;
|
||||
class function Cast(const Intf: IJSObject): IJSLeaflet;
|
||||
class function _from_id(const _id: String): IJSLeaflet;
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
function JOBCallOnMapClickCallback(const _Method: TMethod; var _H: TJOBCallbackHelper): PByte;
|
||||
var
|
||||
o: TJSObject;
|
||||
e: IJSEvent;
|
||||
begin
|
||||
o:=_H.GetObject(TJSObject);
|
||||
e:= TJSEvent.Cast( o);
|
||||
TOnMapClickCallback(_Method)( e);
|
||||
Result:=_H.AllocUndefined;
|
||||
end;
|
||||
|
||||
|
||||
procedure TJSLeafletMap.Set_onClick(const _Callback: TOnMapClickCallback);
|
||||
var
|
||||
m: TJOB_Method;
|
||||
begin
|
||||
m:=TJOB_Method.Create(TMethod(_Callback),@JOBCallOnMapClickCallback);
|
||||
try
|
||||
InvokeJSNoResult('on',['click',m]);
|
||||
finally
|
||||
m.free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSLeafletMap.setView( _Latitude, _Longitude, _Zoom: Extended);
|
||||
var
|
||||
latlng: TJOB_ArrayOfDouble;
|
||||
begin
|
||||
latlng:= TJOB_ArrayOfDouble.Create( [_Latitude, _Longitude]);
|
||||
InvokeJSObjectResult( 'setView',[latlng, _Zoom],TJSObject);
|
||||
end;
|
||||
|
||||
class function TJSLeafletMap.JSClassName: UnicodeString;
|
||||
begin
|
||||
Result:= 'Map';
|
||||
end;
|
||||
class function TJSLeafletMap.Cast(const Intf: IJSObject): IJSLeafletMap;
|
||||
begin
|
||||
Result:= TJSLeafletMap.JOBCast(Intf);
|
||||
end;
|
||||
|
||||
{ TJSLeafletTileLayer }
|
||||
|
||||
class function TJSLeafletTileLayer.JSClassName: UnicodeString;
|
||||
begin
|
||||
Result:=inherited JSClassName;
|
||||
end;
|
||||
|
||||
class function TJSLeafletTileLayer.Cast(const Intf: IJSObject): IJSLeafletTileLayer;
|
||||
begin
|
||||
Result:= TJSLeafletTileLayer.JOBCast(Intf);
|
||||
end;
|
||||
|
||||
procedure TJSLeafletTileLayer.addTo( const _map: IJSLeafletMap);
|
||||
begin
|
||||
InvokeJSNoResult('addTo', [_map]);
|
||||
end;
|
||||
|
||||
{ TJSLeaflet }
|
||||
|
||||
function TJSLeaflet.map(const _idMap: String; _params: IJSObject= nil): IJSLeafletMap;
|
||||
begin
|
||||
Result:= TJSLeafletMap.Cast( InvokeJSObjectResult( 'map',[_idMap, _params], TJSObject));
|
||||
end;
|
||||
|
||||
function TJSLeaflet.tileLayer(const _urlTemplate: String; _options: IJSObject= nil): IJSLeafletTileLayer;
|
||||
begin
|
||||
Result:= TJSLeafletTileLayer.Cast(InvokeJSObjectResult( 'tileLayer', [_urlTemplate, _options], TJSObject));
|
||||
end;
|
||||
|
||||
class function TJSLeaflet.JSClassName: UnicodeString;
|
||||
begin
|
||||
Result:=inherited JSClassName;
|
||||
end;
|
||||
|
||||
class function TJSLeaflet.Cast(const Intf: IJSObject): IJSLeaflet;
|
||||
begin
|
||||
Result:= TJSLeaflet.JOBCast(Intf);
|
||||
end;
|
||||
|
||||
class function TJSLeaflet._from_id(const _id: String): IJSLeaflet;
|
||||
begin
|
||||
Result:= TJSLeaflet.Cast(JSWindow.ReadJSPropertyObject( _id, TJSObject));
|
||||
end;
|
||||
|
||||
end.
|
||||
|
92
packages/wasm-job/examples/leaflet/wasm_leaflet.lpi
Normal file
92
packages/wasm-job/examples/leaflet/wasm_leaflet.lpi
Normal file
@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="12"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasTitleStatement Value="False"/>
|
||||
<MainUnitHasScaledStatement Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<Title Value="wasm_leaflet"/>
|
||||
<UseAppBundle Value="False"/>
|
||||
<ResourceType Value="res"/>
|
||||
</General>
|
||||
<BuildModes>
|
||||
<Item Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<UseFileFilters Value="True"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
</RunParams>
|
||||
<Units>
|
||||
<Unit>
|
||||
<Filename Value="wasm_leaflet.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="job_web.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="uCoordinate.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="uJSLeaflet.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="wasm_leaflet.wasm"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<SyntaxMode Value="Delphi"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
<CodeGeneration>
|
||||
<TargetCPU Value="wasm32"/>
|
||||
<TargetOS Value="wasi"/>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<GenerateDebugInfo Value="False"/>
|
||||
</Debugging>
|
||||
<Options>
|
||||
<ExecutableType Value="Library"/>
|
||||
</Options>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CustomOptions Value="-dLCLLINUX
|
||||
-djsCiel_DEFINE"/>
|
||||
<CompilerPath Value="ppcrosswasm32.exe"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions>
|
||||
<Item>
|
||||
<Name Value="EAbort"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
266
packages/wasm-job/examples/leaflet/wasm_leaflet.lpr
Normal file
266
packages/wasm-job/examples/leaflet/wasm_leaflet.lpr
Normal file
@ -0,0 +1,266 @@
|
||||
library wasm_leaflet;
|
||||
|
||||
{$mode objfpc}
|
||||
{$h+}
|
||||
{$codepage UTF8}
|
||||
|
||||
uses
|
||||
uJSLeaflet,
|
||||
uCoordinate,
|
||||
NoThreads, SysUtils, StrUtils, JOB.Shared, JOB_Web, JOB.JS;
|
||||
|
||||
type
|
||||
|
||||
{ Twasm_leaflet }
|
||||
|
||||
Twasm_leaflet
|
||||
=
|
||||
class
|
||||
//Lifecycle Management
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
//Parameters
|
||||
private
|
||||
Latitude, Longitude: T_Coordinate;
|
||||
iParameters_Latitude : IJSHTMLInputElement;
|
||||
iParameters_Longitude: IJSHTMLInputElement;
|
||||
bCalculation: IJSHTMLButtonElement;
|
||||
procedure bCalculation_Show;
|
||||
procedure bCalculation_Hide;
|
||||
procedure iParameters_LatitudeInput (Event: IJSEvent);
|
||||
procedure iParameters_LongitudeInput(Event: IJSEvent);
|
||||
procedure bCalculationClick(Event: IJSEvent);
|
||||
procedure _from_Parameters;
|
||||
//Result
|
||||
private
|
||||
dCalculation_Result: IJSHTMLDivElement;
|
||||
procedure Display;
|
||||
//Leaflet Map
|
||||
private
|
||||
LeafLet_initialized: Boolean;
|
||||
Leaflet: IJSLeaflet;
|
||||
map: IJSLeafletMap;
|
||||
procedure mapClick(_e: IJSEvent);
|
||||
procedure RefreshMap;
|
||||
procedure Set_Map_to( _Latitude, _Longitude: Extended);
|
||||
procedure Ensure_LeafLet_initialized;
|
||||
//GeoLocation
|
||||
private
|
||||
procedure DoGeoLocation;
|
||||
procedure successCallback(_Position : IJSGeolocationPosition);
|
||||
procedure errorCallback(_Value : IJSGeolocationPositionError);
|
||||
procedure Process_the_location( _Latitude_Degrees, _Longitude_Degrees: Extended);
|
||||
//Execution
|
||||
public
|
||||
procedure Run;
|
||||
end;
|
||||
|
||||
{ Twasm_leaflet }
|
||||
|
||||
constructor Twasm_leaflet.Create;
|
||||
begin
|
||||
inherited;
|
||||
LeafLet_initialized:= False;
|
||||
Latitude := T_Coordinate.Create( True);
|
||||
Longitude:= T_Coordinate.Create( False);
|
||||
Latitude.Longitude_from_LatitudeOverflow:= @Longitude.Longitude_Turnaround;
|
||||
end;
|
||||
|
||||
destructor Twasm_leaflet.Destroy;
|
||||
begin
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure Twasm_leaflet.Display;
|
||||
var
|
||||
sResult: String;
|
||||
begin
|
||||
//WriteLn(ClassName+'.Display: Latitude: ',UTF8Encode(iParameters_Latitude.value));
|
||||
iParameters_Latitude.value:= UTF8Decode(Latitude.Str);
|
||||
//WriteLn(ClassName+'.Display: Longitude: ',UTF8Encode(iParameters_Longitude.value));
|
||||
iParameters_Longitude.value:= UTF8Decode(Longitude.Str);
|
||||
|
||||
DefaultFormatSettings.ThousandSeparator:= ' ';
|
||||
DefaultFormatSettings.DecimalSeparator:= ',';
|
||||
|
||||
sResult
|
||||
:=
|
||||
'Latitude:' +Latitude .Str+'<br/>'
|
||||
+'Longitude:'+Longitude.Str+'<br/>'
|
||||
;
|
||||
dCalculation_Result.innerHTML:= UTF8Decode( sResult);
|
||||
|
||||
RefreshMap;
|
||||
end;
|
||||
|
||||
procedure Twasm_leaflet._from_Parameters;
|
||||
begin
|
||||
//WriteLn(ClassName+'._from_Parameters: Latitude: ',UTF8Encode(iParameters_Latitude.value));
|
||||
Latitude.Set_Str( UTF8Encode(iParameters_Latitude.value));
|
||||
|
||||
//WriteLn(ClassName+'._from_Parameters: Longitude: ',UTF8Encode(iParameters_Longitude.value));
|
||||
Longitude.Set_Str( UTF8Encode(iParameters_Longitude.value));
|
||||
|
||||
Display;
|
||||
bCalculation_Hide;
|
||||
end;
|
||||
|
||||
procedure Twasm_leaflet.bCalculationClick(Event: IJSEvent);
|
||||
begin
|
||||
_from_Parameters;
|
||||
end;
|
||||
|
||||
procedure Twasm_leaflet.bCalculation_Show;
|
||||
begin
|
||||
//WriteLn(ClassName+'.bCalculation_Show');
|
||||
WriteLn(ClassName+'.bCalculation_Show: bCalculation.style.cssText:' ,bCalculation.style.cssText);
|
||||
bCalculation.style.cssText:= 'visibility: visible;';
|
||||
end;
|
||||
|
||||
procedure Twasm_leaflet.bCalculation_Hide;
|
||||
begin
|
||||
bCalculation.style.cssText:= 'visibility: hidden;';
|
||||
end;
|
||||
|
||||
procedure Twasm_leaflet.iParameters_LatitudeInput(Event: IJSEvent);
|
||||
begin
|
||||
bCalculation_Show;
|
||||
end;
|
||||
|
||||
procedure Twasm_leaflet.iParameters_LongitudeInput(Event: IJSEvent);
|
||||
begin
|
||||
bCalculation_Show;
|
||||
end;
|
||||
|
||||
procedure Twasm_leaflet.mapClick(_e: IJSEvent);
|
||||
var
|
||||
latlng: TJSObject;
|
||||
lat, lng: double;
|
||||
procedure dump_latlng_variables;
|
||||
var
|
||||
latlng_variables: TJSObject;
|
||||
begin
|
||||
latlng_variables:= JSObject.InvokeJSObjectResult( 'keys' ,[latlng],TJSObject);
|
||||
WriteLn( ClassName+'.Set_Map_To global_variables: type', latlng_variables.JSClassName, 'value: ', latlng_variables.toString);
|
||||
end;
|
||||
begin
|
||||
//WriteLn( Classname+'.mapClick: _e.type_:',_e.type_);
|
||||
latlng:= _e.ReadJSPropertyObject('latlng', TJSObject);
|
||||
//dump_latlng_variables;
|
||||
lat:= latlng.ReadJSPropertyDouble('lat');
|
||||
lng:= latlng.ReadJSPropertyDouble('lng');
|
||||
Process_the_location( lat, lng);
|
||||
end;
|
||||
|
||||
procedure Twasm_leaflet.Ensure_LeafLet_initialized;
|
||||
procedure L_tileLayer;
|
||||
var
|
||||
params: TJSObject;
|
||||
begin
|
||||
//L
|
||||
// .tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
// {
|
||||
// attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors',
|
||||
// maxZoom: 19,
|
||||
// }
|
||||
// )
|
||||
// .addTo(map);
|
||||
|
||||
params:= TJSObject.JOBCreate([]);
|
||||
params.Properties['attribution']:= 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors';
|
||||
params.Properties['maxZoom' ]:= 19;
|
||||
|
||||
Leaflet
|
||||
.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', params)
|
||||
.addTo( map);
|
||||
end;
|
||||
begin
|
||||
if LeafLet_initialized then exit;
|
||||
|
||||
Leaflet:= TJSLeaflet._from_id( 'L');
|
||||
map:= Leaflet.map('dMap'); //dMap is the container <div> id
|
||||
L_tileLayer;
|
||||
map.Set_onClick(@mapClick);
|
||||
|
||||
LeafLet_initialized:= True;
|
||||
end;
|
||||
|
||||
procedure Twasm_leaflet.Set_Map_to(_Latitude, _Longitude: Extended);
|
||||
procedure dump_global_variables;
|
||||
var
|
||||
global_variables: TJSObject;
|
||||
begin
|
||||
global_variables:= JSObject.InvokeJSObjectResult( 'keys',[JSWindow],TJSObject);
|
||||
WriteLn( ClassName+'.Set_Map_To global_variables: type',
|
||||
global_variables.JSClassName, 'valeur: ', global_variables.toString);
|
||||
end;
|
||||
begin
|
||||
Ensure_LeafLet_initialized;
|
||||
//dump_global_variables;
|
||||
|
||||
//const map = L.map('map').setView([latitude, longitude], 13);
|
||||
map.setView( _Latitude, _Longitude, 13);
|
||||
end;
|
||||
|
||||
procedure Twasm_leaflet.RefreshMap;
|
||||
begin
|
||||
Set_Map_to( Latitude.Degrees, Longitude.Degrees);
|
||||
end;
|
||||
|
||||
procedure Twasm_leaflet.Process_the_location( _Latitude_Degrees, _Longitude_Degrees: Extended);
|
||||
begin
|
||||
Latitude .Degrees:= _Latitude_Degrees ;
|
||||
Longitude.Degrees:= _Longitude_Degrees;
|
||||
Display;
|
||||
end;
|
||||
|
||||
procedure Twasm_leaflet.successCallback(_Position : IJSGeolocationPosition);
|
||||
//procedure dump_latlng_variables;
|
||||
//var
|
||||
// latlng_variables: TJSObject;
|
||||
//begin
|
||||
// latlng_variables:= JSObject.InvokeJSObjectResult( 'keys' ,[latlng],TJSObject);
|
||||
// WriteLn( ClassName+'.Set_Map_To global_variables: type', latlng_variables.JSClassName, 'valeur: ', latlng_variables.toString);
|
||||
//end;
|
||||
begin
|
||||
//The longitude given by the navigator is negative towards the West
|
||||
Process_the_location( _Position.coords.latitude, _Position.coords.longitude);
|
||||
|
||||
end;
|
||||
procedure Twasm_leaflet.errorCallback(_Value : IJSGeolocationPositionError);
|
||||
begin
|
||||
WriteLn( ClassName+'.b_Click: geolocation.getCurrentPosition: ', _Value.message);
|
||||
Process_the_location( 43.604312,1.4436825);//Toulouse, France
|
||||
end;
|
||||
|
||||
procedure Twasm_leaflet.DoGeoLocation;
|
||||
begin
|
||||
if true//window.navigator.hasOwnProperty('geoLocation')
|
||||
then
|
||||
JSWindow.navigator.geolocation.getCurrentPosition(@successCallback, @errorCallback)
|
||||
else
|
||||
WriteLn(ClassName+'.b_Click: GeoLocation unavailable');
|
||||
end;
|
||||
|
||||
procedure Twasm_leaflet.Run;
|
||||
begin
|
||||
iParameters_Latitude :=TJSHTMLInputElement .Cast(JSDocument.getElementById('iParameters_Latitude' ));
|
||||
iParameters_Longitude:=TJSHTMLInputElement .Cast(JSDocument.getElementById('iParameters_Longitude'));
|
||||
bCalculation :=TJSHTMLButtonElement.Cast(JSDocument.getElementById('bCalculation' ));
|
||||
dCalculation_Result :=TJSHTMLDivElement .Cast(JSDocument.getElementById('dCalculation_Result' ));
|
||||
|
||||
iParameters_Latitude .addEventListener('input', @iParameters_LatitudeInput );
|
||||
iParameters_Longitude.addEventListener('input', @iParameters_LongitudeInput);
|
||||
bCalculation .addEventListener('click' ,@bCalculationClick );
|
||||
|
||||
DoGeoLocation;
|
||||
end;
|
||||
|
||||
var
|
||||
Application: Twasm_leaflet;
|
||||
begin
|
||||
Application:=Twasm_leaflet.Create;
|
||||
Application.Run;
|
||||
end.
|
||||
|
BIN
packages/wasm-job/examples/leaflet/wasm_leaflet.wasm
Normal file
BIN
packages/wasm-job/examples/leaflet/wasm_leaflet.wasm
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user