Created
December 10, 2019 14:06
-
-
Save claustres/038a206c2df5a8f06a911f10127f1155 to your computer and use it in GitHub Desktop.
Geospatial operator for sift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import memory from 'feathers-memory' | |
import intersect from '@turf/intersect' | |
// Create a sift filter supporting a geospatial operator | |
const matcher = (query) => sift(query, { | |
expressions: { | |
$geoIntersects: function(query, value) { | |
const polygon1 = _.get(query, '$geometry') | |
const polygon2 = value | |
if (!polygon1 || !polygon2) return false | |
return intersect(polygon1, polygon2) | |
} | |
} | |
}) | |
// Set the mocked service as usual using the custom matcher | |
app.use('/service', memory({ matcher })) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment