Comparing version 0.1.5 to 0.2.0
(function(GeoJSON) { | ||
GeoJSON.version = '0.1.5'; | ||
GeoJSON.version = '0.2.0'; | ||
@@ -10,3 +10,2 @@ // Allow user to specify default parameters | ||
GeoJSON.parse = function(objects, params, callback) { | ||
if(objects.length === 0) { throw new Error('No data found'); } | ||
@@ -193,2 +192,2 @@ var geojson = {"type": "FeatureCollection", "features": []}, | ||
}(typeof module == 'object' ? module.exports : window.GeoJSON = {})); | ||
}(typeof module == 'object' ? module.exports : window.GeoJSON = {})); |
@@ -1,3 +0,3 @@ | ||
// geojson.js - v0.1.5 | ||
// geojson.js - v0.2.0 | ||
// (c) 2014 Casey Thomas, MIT License | ||
!function(a){function b(a,b){var c=a||{};for(var d in b)b.hasOwnProperty(d)&&!c[d]&&(c[d]=b[d]);return c}function c(a,b){if(b.crs&&(a.crs={type:"name",properties:{name:b.crs}}),b.bbox&&(a.bbox=b.bbox),b.extraGlobal){a.properties={};for(var c in b.extraGlobal)a.properties[c]=b.extraGlobal[c]}}function d(a){a.geom={};for(var b in a)a.hasOwnProperty(b)&&-1!==j.indexOf(b)&&(a.geom[b]=a[b],delete a[b]);e(a.geom)}function e(a){for(var b in a)a.hasOwnProperty(b)&&("string"==typeof a[b]?k.push(a[b]):"object"==typeof a[b]&&(k.push(a[b][0]),k.push(a[b][1])));if(0===k.length)throw new Error("No geometry attributes specified")}function f(a,b,c){var d={type:"Feature"};return d.geometry=g(a,b),d.properties=c.call(a),d}function g(a,b){var c,d={};for(var e in b.geom)c="object"==typeof b.geom[e]?b.geom[e][0]:b.geom[e],b.geom.hasOwnProperty(e)&&a[c]&&(d.type=e,d.coordinates="string"==typeof b.geom[e]?a[b.geom[e]]:[a[b.geom[e][1]],a[b.geom[e][0]]]);return d}function h(a){var b;return a.exclude||a.include?a.include?b=function(b){a.include.forEach(function(a){b[a]=this[a]},this)}:a.exclude&&(b=function(b){for(var c in this)this.hasOwnProperty(c)&&-1===k.indexOf(c)&&-1===a.exclude.indexOf(c)&&(b[c]=this[c])}):b=function(a){for(var b in this)this.hasOwnProperty(b)&&-1===k.indexOf(b)&&(a[b]=this[b])},function(){var c={};return b.call(this,c),a.extra&&i(c,a.extra),c}}function i(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}a.version="0.1.5",a.defaults={},a.parse=function(a,e,g){if(0===a.length)throw new Error("No data found");var i,j={type:"FeatureCollection",features:[]},l=b(e,this.defaults);return k.length=0,d(l),i=h(l),a.forEach(function(a){j.features.push(f(a,l,i))}),c(j,l),g&&"function"==typeof g?void g(j):j};var j=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],k=[]}("object"==typeof module?module.exports:window.GeoJSON={}); | ||
!function(a){function b(a,b){var c=a||{};for(var d in b)b.hasOwnProperty(d)&&!c[d]&&(c[d]=b[d]);return c}function c(a,b){if(b.crs&&(a.crs={type:"name",properties:{name:b.crs}}),b.bbox&&(a.bbox=b.bbox),b.extraGlobal){a.properties={};for(var c in b.extraGlobal)a.properties[c]=b.extraGlobal[c]}}function d(a){a.geom={};for(var b in a)a.hasOwnProperty(b)&&-1!==j.indexOf(b)&&(a.geom[b]=a[b],delete a[b]);e(a.geom)}function e(a){for(var b in a)a.hasOwnProperty(b)&&("string"==typeof a[b]?k.push(a[b]):"object"==typeof a[b]&&(k.push(a[b][0]),k.push(a[b][1])));if(0===k.length)throw new Error("No geometry attributes specified")}function f(a,b,c){var d={type:"Feature"};return d.geometry=g(a,b),d.properties=c.call(a),d}function g(a,b){var c,d={};for(var e in b.geom)c="object"==typeof b.geom[e]?b.geom[e][0]:b.geom[e],b.geom.hasOwnProperty(e)&&a[c]&&(d.type=e,d.coordinates="string"==typeof b.geom[e]?a[b.geom[e]]:[a[b.geom[e][1]],a[b.geom[e][0]]]);return d}function h(a){var b;return a.exclude||a.include?a.include?b=function(b){a.include.forEach(function(a){b[a]=this[a]},this)}:a.exclude&&(b=function(b){for(var c in this)this.hasOwnProperty(c)&&-1===k.indexOf(c)&&-1===a.exclude.indexOf(c)&&(b[c]=this[c])}):b=function(a){for(var b in this)this.hasOwnProperty(b)&&-1===k.indexOf(b)&&(a[b]=this[b])},function(){var c={};return b.call(this,c),a.extra&&i(c,a.extra),c}}function i(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}a.version="0.2.0",a.defaults={},a.parse=function(a,e,g){var i,j={type:"FeatureCollection",features:[]},l=b(e,this.defaults);return k.length=0,d(l),i=h(l),a.forEach(function(a){j.features.push(f(a,l,i))}),c(j,l),g&&"function"==typeof g?void g(j):j};var j=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],k=[]}("object"==typeof module?module.exports:window.GeoJSON={}); |
@@ -5,3 +5,3 @@ { | ||
"author": "Casey Thomas <caseypthomas@gmail.com>", | ||
"version": "0.1.5", | ||
"version": "0.2.0", | ||
"main": "./geojson", | ||
@@ -24,3 +24,3 @@ "repository": { | ||
"engines": { | ||
"node": "0.8.x" | ||
"node": "0.10.x" | ||
}, | ||
@@ -27,0 +27,0 @@ "scripts": { |
@@ -31,5 +31,3 @@ # GeoJSON.js | ||
GeoJSON.parse(data, {Point: ['lat', 'lng']}, function(geojson){ | ||
console.log(JSON.stringify(geojson)); | ||
}); | ||
GeoJSON.parse(data, {Point: ['lat', 'lng']}); | ||
@@ -65,5 +63,3 @@ { | ||
GeoJSON.parse(data, {Point: ['lat', 'lng'], include: ['name']}, function(geojson){ | ||
console.log(JSON.stringify(geojson)); | ||
}); | ||
GeoJSON.parse(data, {Point: ['lat', 'lng'], include: ['name']}); | ||
@@ -89,30 +85,3 @@ { | ||
Convert the example data to GeoJSON, and include some dataset attributes. | ||
GeoJSON.parse(data, {Point: ['lat', 'lng'], attrs: {'Creator': 'Mr. Example', 'records': data.length, 'summary': 'A few example points'}}, function(geojson){ | ||
console.log(geojson); | ||
}); | ||
{ | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ "type": "Feature", | ||
"geometry": {"type": "Point", "coordinates": [-75.343, 39.984]}, | ||
"properties": { | ||
"name": "Location A" | ||
} | ||
}, | ||
... | ||
{ "type": "Feature", | ||
"geometry": {"type": "Point", "coordinates": [ -75.534, 39.123]}, | ||
"properties": { | ||
"name": "Location C" | ||
} | ||
} | ||
], | ||
"Creator": "Mr. Example", | ||
"records": 2, | ||
"summary": "A few example points" | ||
} | ||
The `parse` method can handle data with different geometry types. Consider the following sample data: | ||
@@ -142,5 +111,3 @@ | ||
GeoJSON.parse(data2, {'Point': ['x', 'y'], 'LineString': 'line', 'Polygon': 'polygon'}, function(geojson){ | ||
console.log(JSON.stringify(geojson)); | ||
}); | ||
GeoJSON.parse(data2, {'Point': ['x', 'y'], 'LineString': 'line', 'Polygon': 'polygon'}); | ||
@@ -195,5 +162,3 @@ { | ||
GeoJSON.parse(data1, {}, function(geojson){ | ||
console.log(JSON.stringify(geojson)); | ||
}); | ||
GeoJSON.parse(data1, {}); | ||
@@ -216,5 +181,3 @@ { | ||
GeoJSON.parse(data2, {}, function(geojson){ | ||
console.log(geojson.js) | ||
}); | ||
GeoJSON.parse(data2, {}); | ||
@@ -237,3 +200,3 @@ { | ||
If you specify a callback function, the GeoJSON output is set as the first parameter of the function | ||
You can specify a callback function as an option third parameter. | ||
@@ -300,5 +263,2 @@ GeoJSON.parse(data, {Point: ['lat', 'lng']}, function(geojson){ | ||
} | ||
}, | ||
function(geojson){ | ||
console.log(JSON.stringify(geojson)); | ||
}); | ||
@@ -326,3 +286,3 @@ | ||
You can also add dataset properties using the `extraGlobal` param. The value for `extraGlobal` must be an object. For example, see below: | ||
You can also add dataset properties using the `extraGlobal` param. The value for `extraGlobal` must be an object. | ||
@@ -336,4 +296,2 @@ GeoJSON.parse(data, { | ||
} | ||
}, function(geojson){ | ||
console.log(geojson); | ||
}); | ||
@@ -340,0 +298,0 @@ |
@@ -280,6 +280,9 @@ if (typeof window === 'undefined') { | ||
it("throws an error if the objects parameter is empty", function(){ | ||
var data = []; | ||
expect(function(){ GeoJSON.parse(data); }).to.throwException(/No data found/); | ||
it("returns valid GeoJSON output when input length is 0", function(done){ | ||
GeoJSON.parse([], {Point: ['lat', 'lng']}, function(geojson){ | ||
expect(geojson.type).to.be('FeatureCollection'); | ||
expect(geojson.features).to.be.an('array'); | ||
expect(geojson.features.length).to.be(0); | ||
done(); | ||
}); | ||
}); | ||
@@ -286,0 +289,0 @@ |
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
460
31704
328