diff --git a/tools/locmux.js b/tools/locmux.js new file mode 100644 index 0000000..1d42b04 --- /dev/null +++ b/tools/locmux.js @@ -0,0 +1,63 @@ +/** + * To run do as follows: + * + * $ npm install request + * $ node locmux.js 'text i want to search for' + * + * If you'd like more locations to be searched just add them to the list below. + * + */ + +var request = require('request'); +var colors = require('text-hex'); +var async = require('async'); + +var locations = [ + { + name: 'London', + lat: 51.507222, + lon: -0.1275 + }, + { + name: 'New York', + lat: 37.783333, + lon: -122.416667 + } +]; + +var text = process.argv[2]; +var geojsonio = true; //process.argv[2] === 'geojson'; + +var geojson = { + type: 'FeatureCollection', + features: [] +}; + +async.forEach(locations, function (loc, cb) { + request.get('http://pelias.bigdev.mapzen.com/v1/search?text=' + text + + '&focus.point.lat=' + loc.lat + '&focus.point.lon=' + loc.lon, function (err, res) { + var results = JSON.parse(res.body); + + if (!geojsonio) { + console.log('\n\n\nSearching for "' + text + '" near ' + loc.name); + console.log('> result count:', results.features.length); + } + + results.features.forEach(function (feature) { + feature.properties['marker-color'] = colors(loc.name); + feature.properties.query = loc.name; + + geojson.features.push(feature); + + if (!geojsonio) { + console.log(feature.properties.label); + } + }); + cb(); + }); + }, + function () { + if (geojsonio) { + console.log(JSON.stringify(geojson)); + } + }); \ No newline at end of file diff --git a/tools/package.json b/tools/package.json new file mode 100644 index 0000000..9265b15 --- /dev/null +++ b/tools/package.json @@ -0,0 +1,17 @@ +{ + "name": "tools", + "version": "1.0.0", + "description": "", + "main": "locmux.js", + "scripts": { + "start": "node locmux.js geojson" + }, + "author": "Diana Shkolnikov ", + "license": "MIT", + "dependencies": { + "async": "^1.4.2", + "geojsonio-cli": "^0.1.2", + "request": "^2.62.0", + "text-hex": "0.0.0" + } +}