1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-11-15 06:47:25 +00:00
Files
TiddlyWiki5/plugins/tiddlywiki/geospatial/operators/olc.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

51 lines
1.4 KiB
JavaScript

/*\
title: $:/plugins/tiddlywiki/geospatial/operators/olc.js
type: application/javascript
module-type: filteroperator
Filter operators for open location code conversions
\*/
"use strict";
var openlocationcode = require("$:/plugins/tiddlywiki/geospatial/openlocationcode.js"),
turf = require("$:/plugins/tiddlywiki/geospatial/turf.js"),
geotools = require("$:/plugins/tiddlywiki/geospatial/geotools.js");
exports["olc-decode"] = function(source,operator,options) {
var olc;
try {
olc = openlocationcode.decode(operator.operands[0] || "")
} catch(e) {
return [];
}
var suffixes = (operator.suffixes || [])[0] || [],
obj;
if(suffixes.indexOf("bounds") !== -1) {
obj = turf.polygon([[
[olc.longitudeLo, olc.latitudeLo],
[olc.longitudeLo, olc.latitudeHi],
[olc.longitudeHi, olc.latitudeHi],
[olc.longitudeHi, olc.latitudeLo],
[olc.longitudeLo, olc.latitudeLo]
]]);
} else {
obj = turf.point([olc.longitudeCenter,olc.latitudeCenter]);
}
return [JSON.stringify(obj)];
};
exports["olc-encode"] = function(source,operator,options) {
var lat = $tw.utils.parseNumber(operator.operands[0] || "0"),
long = $tw.utils.parseNumber(operator.operands[1] || "0"),
codelength = $tw.utils.parseNumber(operator.operands[2] || "0") || openlocationcode.CODE_PRECISION_NORMAL,
olc;
try {
olc = openlocationcode.encode(lat,long,codelength);
} catch(e) {
return []
}
return [olc];
};