1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-11-14 22:37:13 +00:00
Files
TiddlyWiki5/plugins/tiddlywiki/geospatial/operators/lookup.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

40 lines
1.1 KiB
JavaScript

/*\
title: $:/plugins/tiddlywiki/geospatial/operators/lookup.js
type: application/javascript
module-type: filteroperator
Filter operators for geospatial lookup
\*/
"use strict";
var turf = require("$:/plugins/tiddlywiki/geospatial/turf.js"),
geotools = require("$:/plugins/tiddlywiki/geospatial/geotools.js");
exports.geolookup = function(source,operator,options) {
// Get the GeoJSON object
var output = [],
jsonObject = $tw.utils.parseJSONSafe(operator.operands[0],null);
if(jsonObject) {
// Process the input points
source(function(tiddler,title) {
var point = geotools.parsePoint(title),
result = getPolygonsContainingPoint(jsonObject,point);
output.push(JSON.stringify(result))
});
}
// Perform the transformation
return output;
};
function getPolygonsContainingPoint(featureCollection,point) {
// Filter the GeoJSON feature collection to only include polygon features containing the point
const properties = [];
turf.featureEach(featureCollection,function(feature) {
if(feature.geometry.type === "Polygon" && turf.booleanPointInPolygon(point,feature)) {
properties.push(feature.properties);
}
});
return properties;
}