TiddlyWiki5/plugins/tiddlywiki/geospatial/startup.js
Mario Pietsch 8aa558eb2c
Remove module function wrapper and add matching configurations for dprint and eslint (#7596)
* remove blks first try

* dprint.json seems to be OK, some forgotten functions

* add some more space-after-keyword settings

* server remove blks

* add **/files to dprint exclude

* dprint.js fixes a typo

* add boot.js and bootprefix.js to dprint exclude

* dprint change dprint.json

* add dprint fmt as script

* remove jslint comments

* fix whitespace

* fix whitespace

* remove function-wrapper from geospatial plugin

* fix whitespace

* add function wrapper to dyannotate-startup

* remove dpring.json
2025-03-21 17:22:57 +00:00

73 lines
2.3 KiB
JavaScript

/*\
title: $:/plugins/tiddlywiki/geospatial/startup.js
type: application/javascript
module-type: startup
Geospatial initialisation
\*/
"use strict";
// Export name and synchronous status
exports.name = "geospatial";
exports.after = ["rootwidget"];
exports.before = ["render"];
exports.synchronous = true;
exports.startup = function() {
// var openlocationcode = require("$:/plugins/tiddlywiki/geospatial/openlocationcode.js");
// var turf = require("$:/plugins/tiddlywiki/geospatial/turf.js");
// Load Leaflet
if($tw.browser) {
$tw.Leaflet = require("$:/plugins/tiddlywiki/geospatial/leaflet.js");
// Add Leaflet Marker Cluster Plugin
require("$:/plugins/tiddlywiki/geospatial/leaflet.markercluster.js");
}
// Install geolocation message handler
$tw.rootWidget.addEventListener("tm-request-geolocation",function(event) {
var widget = event.widget,
wiki = widget.wiki || $tw.wiki,
params = event.paramObject || {},
actionsSuccess = params.actionsSuccess,
actionsError = params.actionsError;
// Assemble the options for getCurrentPosition()
const opts = {
enableHighAccuracy: params.accuracy !== "low",
timeout: Infinity,
maximumAge: 0
};
if(params.timeout !== undefined) {
opts.timeout = $tw.utils.parseInt(params.timeout);
}
if(params.maximumAge !== undefined) {
opts.maximumAge = $tw.utils.parseInt(params.maximumAge);
}
// Get the current position
try {
navigator.geolocation.getCurrentPosition(function successHandler(pos) {
// Invoke the success actions
wiki.invokeActionString(actionsSuccess,undefined,{
timestamp: $tw.utils.stringifyDate(new Date(pos.timestamp)),
latitude: "" + pos.coords.latitude,
longitude: "" + pos.coords.longitude,
altitude: "" + pos.coords.altitude,
accuracy: "" + pos.coords.accuracy,
altitudeAccuracy: "" + pos.coords.altitudeAccuracy,
heading: "" + pos.coords.heading,
speed: "" + pos.coords.speed
},{parentWidget: $tw.rootWidget});
},function errorHandler(err) {
// Invoke the error actions
wiki.invokeActionString(actionsError,undefined,{
"error": "" + err.message
},{parentWidget: $tw.rootWidget});
},opts);
} catch(ex) {
// Invoke the error actions
wiki.invokeActionString(actionsError,undefined,{
"error": "" + ex
},{parentWidget: $tw.rootWidget});
}
});
};