TiddlyWiki5/plugins/tiddlywiki/geospatial/operators/lookup.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

39 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;
}