Skip to content

Instantly share code, notes, and snippets.

@claustres
Created December 10, 2019 14:06
Show Gist options
  • Save claustres/038a206c2df5a8f06a911f10127f1155 to your computer and use it in GitHub Desktop.
Save claustres/038a206c2df5a8f06a911f10127f1155 to your computer and use it in GitHub Desktop.
Geospatial operator for sift
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