mirror of
https://github.com/Jermolene/TiddlyWiki5.git
synced 2026-03-15 03:01:58 -07:00
* 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
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
/*\
|
|
title: $:/plugins/tiddlywiki/geospatial/operators/measurement.js
|
|
type: application/javascript
|
|
module-type: filteroperator
|
|
|
|
Filter operators for geospatial measurement
|
|
|
|
\*/
|
|
|
|
"use strict";
|
|
|
|
var turf = require("$:/plugins/tiddlywiki/geospatial/turf.js"),
|
|
geotools = require("$:/plugins/tiddlywiki/geospatial/geotools.js");
|
|
|
|
var VALID_UNITS = ["miles","kilometers","radians","degrees"],
|
|
DEFAULT_UNITS = "miles";
|
|
|
|
exports.geodistance = function(source,operator,options) {
|
|
var from = geotools.parsePoint(operator.operands[0]),
|
|
to = geotools.parsePoint(operator.operands[1]),
|
|
units = operator.operands[2] || DEFAULT_UNITS;
|
|
if(VALID_UNITS.indexOf(units) === -1) {
|
|
units = DEFAULT_UNITS;
|
|
}
|
|
return [JSON.stringify(turf.distance(from,to,{units: units}))];
|
|
};
|
|
|
|
exports.geonearestpoint = function(source,operator,options) {
|
|
var target = geotools.parsePoint(operator.operands[0]),
|
|
featureCollection = {
|
|
"type": "FeatureCollection",
|
|
"features": []
|
|
};
|
|
source(function(tiddler,title) {
|
|
var fc = $tw.utils.parseJSONSafe(title);
|
|
if(fc) {
|
|
if(fc.type === "FeatureCollection" && $tw.utils.isArray(fc.features)) {
|
|
Array.prototype.push.apply(featureCollection.features,fc.features);
|
|
} else if(fc.type === "Feature") {
|
|
featureCollection.features.push(fc);
|
|
}
|
|
}
|
|
});
|
|
if(featureCollection.features.length > 0) {
|
|
return [JSON.stringify(turf.nearestPoint(target,featureCollection))];
|
|
} else {
|
|
return [];
|
|
}
|
|
};
|