Comparing version 0.1.2 to 0.1.3
(function(GeoJSON) { | ||
GeoJSON.version = '0.1.2'; | ||
GeoJSON.version = '0.1.3'; | ||
@@ -9,3 +9,3 @@ // Allow user to specify default parameters | ||
// Converts an array of objects into a GeoJSON feature collection | ||
GeoJSON.parse = function(objects, params) { | ||
GeoJSON.parse = function(objects, params, callback) { | ||
if(objects.length === 0) { throw new Error('No data found'); } | ||
@@ -19,4 +19,4 @@ | ||
setGeom(settings); | ||
propFunc = getPropFunction(settings); | ||
objects.forEach(function(item){ | ||
@@ -27,3 +27,8 @@ geojson.features.push(getFeature(item, settings, propFunc)); | ||
addOptionals(geojson, settings); | ||
return geojson; | ||
if (callback && typeof callback === 'function') { | ||
callback(geojson); | ||
} else { | ||
return geojson; | ||
} | ||
}; | ||
@@ -30,0 +35,0 @@ |
@@ -1,3 +0,3 @@ | ||
// geojson.js - v0.1.2 | ||
// geojson.js - v0.1.3 | ||
// (c) 2012 Casey Thomas, MIT License | ||
(function(e){function r(e,t){var n=e||{};for(var r in t)t.hasOwnProperty(r)&&!n[r]&&(n[r]=t[r]);return n}function i(e,t){t.crs&&(e.crs={type:"name",properties:{name:t.crs}}),t.bbox&&(e.bbox=t.bbox)}function s(e){e.geom={};for(var n in e)e.hasOwnProperty(n)&&t.indexOf(n)!==-1&&(e.geom[n]=e[n],delete e[n]);o(e.geom)}function o(e){for(var t in e)e.hasOwnProperty(t)&&(typeof e[t]=="string"?n.push(e[t]):typeof e[t]=="object"&&(n.push(e[t][0]),n.push(e[t][1])));if(n.length===0)throw new Error("No geometry attributes specified")}function u(e,t,n){var r={type:"Feature"};return r.geometry=a(e,t),r.properties=n.call(e),r}function a(e,t){var n={},r;for(var i in t.geom)r=typeof t.geom[i]=="object"?t.geom[i][0]:t.geom[i],t.geom.hasOwnProperty(i)&&e[r]&&(n.type=i,typeof t.geom[i]=="string"?n.coordinates=e[t.geom[i]]:n.coordinates=[e[t.geom[i][1]],e[t.geom[i][0]]]);return n}function f(e){var t;return!e.exclude&&!e.include?t=function(e){for(var t in this)this.hasOwnProperty(t)&&n.indexOf(t)===-1&&(e[t]=this[t])}:e.include?t=function(t){e.include.forEach(function(e){t[e]=this[e]},this)}:e.exclude&&(t=function(t){for(var r in this)this.hasOwnProperty(r)&&n.indexOf(r)===-1&&e.exclude.indexOf(r)===-1&&(t[r]=this[r])}),function(){var n={};return t.call(this,n),e.extra&&l(n,e.extra),n}}function l(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e}e.version="0.1.2",e.defaults={},e.parse=function(e,t){if(e.length===0)throw new Error("No data found");var o={type:"FeatureCollection",features:[]},a=r(t,this.defaults),l;return n.length=0,s(a),l=f(a),e.forEach(function(e){o.features.push(u(e,a,l))}),i(o,a),o};var t=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],n=[]})(typeof module=="object"?module.exports:window.GeoJSON={}); | ||
(function(e){function r(e,t){var n=e||{};for(var r in t)t.hasOwnProperty(r)&&!n[r]&&(n[r]=t[r]);return n}function i(e,t){t.crs&&(e.crs={type:"name",properties:{name:t.crs}}),t.bbox&&(e.bbox=t.bbox)}function s(e){e.geom={};for(var n in e)e.hasOwnProperty(n)&&t.indexOf(n)!==-1&&(e.geom[n]=e[n],delete e[n]);o(e.geom)}function o(e){for(var t in e)e.hasOwnProperty(t)&&(typeof e[t]=="string"?n.push(e[t]):typeof e[t]=="object"&&(n.push(e[t][0]),n.push(e[t][1])));if(n.length===0)throw new Error("No geometry attributes specified")}function u(e,t,n){var r={type:"Feature"};return r.geometry=a(e,t),r.properties=n.call(e),r}function a(e,t){var n={},r;for(var i in t.geom)r=typeof t.geom[i]=="object"?t.geom[i][0]:t.geom[i],t.geom.hasOwnProperty(i)&&e[r]&&(n.type=i,typeof t.geom[i]=="string"?n.coordinates=e[t.geom[i]]:n.coordinates=[e[t.geom[i][1]],e[t.geom[i][0]]]);return n}function f(e){var t;return!e.exclude&&!e.include?t=function(e){for(var t in this)this.hasOwnProperty(t)&&n.indexOf(t)===-1&&(e[t]=this[t])}:e.include?t=function(t){e.include.forEach(function(e){t[e]=this[e]},this)}:e.exclude&&(t=function(t){for(var r in this)this.hasOwnProperty(r)&&n.indexOf(r)===-1&&e.exclude.indexOf(r)===-1&&(t[r]=this[r])}),function(){var n={};return t.call(this,n),e.extra&&l(n,e.extra),n}}function l(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e}e.version="0.1.3",e.defaults={},e.parse=function(e,t,o){if(e.length===0)throw new Error("No data found");var a={type:"FeatureCollection",features:[]},l=r(t,this.defaults),c;n.length=0,s(l),c=f(l),e.forEach(function(e){a.features.push(u(e,l,c))}),i(a,l);if(!o||typeof o!="function")return a;o(a)};var t=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],n=[]})(typeof module=="object"?module.exports:window.GeoJSON={}); |
@@ -5,3 +5,3 @@ { | ||
"author": "Casey Thomas <c@cpt.ph>", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"main": "./geojson", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -19,3 +19,3 @@ # GeoJSON.js | ||
The library has one method, `parse`, which takes an array of objects with geometry data as the first parameter, and an object consisting of settings for the second parameter. | ||
The library has one method, `parse`, which takes an array of objects with geometry data as the first parameter, an object consisting of settings for the second parameter, and an optional callback function as the third parameter. If a callback is not specified, the `parse` function returns the GeoJSON output. | ||
@@ -32,3 +32,5 @@ Take the example data below: | ||
GeoJSON.parse(data, {Point: ['lat', 'lng']}); | ||
GeoJSON.parse(data, {Point: ['lat', 'lng']}, function(geojson){ | ||
console.log(geojson); | ||
}); | ||
@@ -64,3 +66,5 @@ { | ||
GeoJSON.parse(data, {Point: ['lat', 'lng'], include: ['name']}); | ||
GeoJSON.parse(data, {Point: ['lat', 'lng'], include: ['name']}, function(geojson){ | ||
console.log(geojson); | ||
}); | ||
@@ -110,3 +114,5 @@ { | ||
GeoJSON.parse(data2, {'Point': ['x', 'y'], 'LineString': 'line', 'Polygon': 'polygon'}); | ||
GeoJSON.parse(data2, {'Point': ['x', 'y'], 'LineString': 'line', 'Polygon': 'polygon'}, function(geojson){ | ||
console.log(geojson); | ||
}); | ||
@@ -161,3 +167,5 @@ { | ||
GeoJSON.parse(data1); | ||
GeoJSON.parse(data1, {}, function(geojson){ | ||
console.log(geojson); | ||
}); | ||
@@ -180,3 +188,5 @@ { | ||
GeoJSON.parse(data2); | ||
GeoJSON.parse(data2, {}, function(geojson){ | ||
console.log(geojson.js) | ||
}); | ||
@@ -199,2 +209,8 @@ { | ||
If you specify a callback function, the GeoJSON output is set as the first parameter of the function | ||
GeoJSON.parse(data, {Point: ['lat', 'lng']}, function(geojson){ | ||
console.log(geojson); | ||
}); | ||
## Parameters | ||
@@ -256,2 +272,5 @@ | ||
} | ||
}, | ||
function(geojson){ | ||
console.log(geojson); | ||
}); | ||
@@ -258,0 +277,0 @@ |
@@ -159,3 +159,3 @@ if (typeof window === 'undefined') { | ||
var output = GeoJSON.parse(data); | ||
var output = GeoJSON.parse(data, {}); | ||
@@ -185,3 +185,3 @@ expect(output.crs.properties.name).to.be('urn:ogc:def:crs:EPSG::4326'); | ||
it('keeps the default settings until they have been explicity reset', function(){ | ||
var output = GeoJSON.parse(data); | ||
var output = GeoJSON.parse(data, {}); | ||
@@ -251,3 +251,29 @@ expect(output.crs.properties.name).to.be('urn:ogc:def:crs:EPSG::4326'); | ||
it("calls the calback function if one is provided", function(done){ | ||
GeoJSON.parse(data, {Point: ['lat', 'lng']}, function(geojson){ | ||
expect(geojson.features.length).to.be(3); | ||
geojson.features.forEach(function(feature){ | ||
expect(feature.properties.lat).to.not.be.ok(); | ||
expect(feature.properties.lng).to.not.be.ok(); | ||
expect(feature.geometry.coordinates[0]).to.be.ok(); | ||
expect(feature.geometry.coordinates[1]).to.be.ok(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it("returns the GeoJSON output if the callback parameter is not a function", function(){ | ||
var output = GeoJSON.parse(data, {Point: ['lat', 'lng']}, 'foo'); | ||
output.features.forEach(function(feature){ | ||
expect(feature.properties.lat).to.not.be.ok(); | ||
expect(feature.properties.lng).to.not.be.ok(); | ||
expect(feature.geometry.coordinates[0]).to.be.ok(); | ||
expect(feature.geometry.coordinates[1]).to.be.ok(); | ||
}); | ||
}); | ||
}); | ||
}); |
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
29116
407
299