TiddlyWiki5/plugins/tiddlywiki/geospatial/operators/olc.js
Saq Imtiaz 785086e0a5
Fixes ESLint errors (#9668)
* fix: apply automatic eslint fixes

* lint: allow hashbang comment for tiddlywiki.js

* lint: first back of manual lint fixes for unused vars

* lint: added more fixes for unused vars

* lint: missed files

* lint: updated eslint config with selected rules from #9669
2026-02-20 08:38:42 +00:00

49 lines
1.3 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");
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];
};