Comparing version 0.0.2 to 0.0.3
@@ -96,3 +96,4 @@ var module = module || {} | ||
/** | ||
* Executes HTTP request to ArcGIS REST API | ||
* Main wrapper for library | ||
* Generates bounding box, executes HTTP request to ArcGIS REST API, sorts by distance | ||
* @param {String} service Which ArcGIS service to query | ||
@@ -103,9 +104,15 @@ * @param {Array} boundingBox The xmin,ymin,xmax,ymax bounding box to look for features within | ||
*/ | ||
app.query = function(service, boundingBox, successCallback, errorCallback) { | ||
var params = _.clone(app.options.params); | ||
params.geometry = boundingBox; | ||
var url = app.options.apiHost + app.options.apiPath + (app.options.services[service] || "") + "?" + app.serialize(params); | ||
app.getNearby = function(service, coords, radius, successCallback, errorCallback) { | ||
var url = url = app.options.apiHost + app.options.apiPath + (app.options.services[service] || "") | ||
,params = _.clone(app.options.params); | ||
params.geometry = app.getBoundingBox(coords, radius); // Get bounding box | ||
url += "?" + app.serialize(params); | ||
console.log(url); | ||
request(url, function(error, response, body) { | ||
(error) ? errorCallback(response, body) : successCallback(response, body); | ||
request(url, function(error, response, body) { // Query REST service | ||
if(error) { | ||
errorCallback(response, body); | ||
} else { | ||
var data = JSON.parse(body); | ||
successCallback((data.features !== undefined) ? app.sortByDistance(data.features, coords) : {}); // Sort by distance | ||
} | ||
}); | ||
@@ -112,0 +119,0 @@ }; |
26
main.js
@@ -0,18 +1,14 @@ | ||
/** | ||
* Example usage of arcnearby | ||
*/ | ||
var arcnearby = require("./arcnearby") | ||
,_ = require("underscore"); | ||
(function(arcnearby) { | ||
var coords = [39.9365,-75.1661] | ||
,boundingBox = arcnearby.getBoundingBox(coords, 1.0); | ||
arcnearby.query("cornerStores", boundingBox, function(response, body) { | ||
var data = JSON.parse(body); | ||
console.log("Found " + data.features.length + " results"); | ||
var sorted = arcnearby.sortByDistance(data.features, coords); | ||
_.each(sorted, function(result) { | ||
console.log(result.attributes); | ||
}); | ||
}, function(resopnse) { | ||
console.log("Error"); | ||
var coords = [39.9365,-75.1661]; | ||
arcnearby.getNearby("cornerStores", coords, 0.25, function(results) { | ||
_.each(results, function(result) { | ||
console.log(result.attributes); | ||
}); | ||
})(arcnearby); | ||
}, function(response, body) { | ||
console.log("Error"); | ||
}); |
{ | ||
"name": "arcnearby", | ||
"description": "Generate bounding box around center point and search ArcGIS REST service for features within it, sorted by distance", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"homepage": "https://github.com/timwis/ArcNearby", | ||
@@ -6,0 +6,0 @@ "author": "Tim Wisniewski, Sarah Cordivano, David Walk", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7044
122