Last active
August 29, 2015 14:05
-
-
Save ryanj/ae89aa07598108ff0e75 to your computer and use it in GitHub Desktop.
common/models/park.js - extending the model with a custom query and endpoint
This file contains 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
module.exports = function(Park) { | |
Park.within = function(lat1, lon1, lat2, lon2, limit, fn) { | |
var = default_result_count = 40; | |
var pos1 = [Number(lat1), Number(lon1)]; | |
var pos2 = [Number(lat2), Number(lon2)]; | |
if (typeof limit === 'function') { | |
fn = limit; | |
} | |
limit = Number(limit) || 40; | |
Park.find({ | |
// find locations within the bounding box: | |
where: {pos: {within: {$box: [pos1,pos2]}}}, | |
// throttling: | |
limit: limit | |
}, fn); | |
}; | |
Park.setup = function() { | |
Park.base.setup.apply(this, arguments); | |
// load our data here? | |
this.remoteMethod('within', { | |
description: 'Find locations within the area defined by a two map points', | |
accepts: [ | |
{arg: 'lat1', type: 'Number', required: true, | |
description: 'geo coordinate lat1'}, | |
{arg: 'lon1', type: 'Number', required: true, | |
description: 'geo coordinate lon1'}, | |
{arg: 'lat2', type: 'Number', required: true, | |
description: 'geo coordinate lat2'}, | |
{arg: 'lon2', type: 'Number', required: true, | |
description: 'geo coordinate lon1'}, | |
{arg: 'limit', type: 'Number', | |
description: 'max number of results'} | |
], | |
returns: {arg: 'locations', root: true}, | |
http: { verb: 'GET' } | |
}); | |
}; | |
Park.setup(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment