forked from caseycesari/GeoJSON.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeojson.min.js
3 lines (3 loc) · 2.29 KB
/
geojson.min.js
1
2
3
// geojson.js - v0.4.1
// (c) 2016 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&&d(b.crs)&&(a.crs=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){if("name"===a.type){if(a.properties&&a.properties.name)return!0;throw new Error('Invalid CRS. Properties must contain "name" key')}if("link"===a.type){if(a.properties&&a.properties.href&&a.properties.type)return!0;throw new Error('Invalid CRS. Properties must contain "href" and "type" key')}throw new Error('Invald CRS. Type attribute must be "name" or "link"')}function e(a){a.geom={};for(var b in a)a.hasOwnProperty(b)&&-1!==k.indexOf(b)&&(a.geom[b]=a[b],delete a[b]);f(a.geom)}function f(a){for(var b in a)a.hasOwnProperty(b)&&("string"==typeof a[b]?l.push(a[b]):"object"==typeof a[b]&&(l.push(a[b][0]),l.push(a[b][1])));if(0===l.length)throw new Error("No geometry attributes specified")}function g(a,b,c){var d={type:"Feature"};return d.geometry=h(a,b),d.properties=c.call(a),d}function h(a,b){var c={};for(var d in b.geom){var e=b.geom[d];"string"==typeof e&&a.hasOwnProperty(e)?"GeoJSON"===d?c=a[e]:(c.type=d,c.coordinates=a[e]):Array.isArray(e)&&a.hasOwnProperty(e[0])&&a.hasOwnProperty(e[1])&&(c.type=d,c.coordinates=[Number(a[e[1]]),Number(a[e[0]])])}return c}function i(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===l.indexOf(c)&&-1===a.exclude.indexOf(c)&&(b[c]=this[c])}):b=function(a){for(var b in this)this.hasOwnProperty(b)&&-1===l.indexOf(b)&&(a[b]=this[b])},function(){var c={};return b.call(this,c),a.extra&&j(c,a.extra),c}}function j(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}a.version="0.4.1",a.defaults={},a.parse=function(a,d,f){var h,j,k=b(d,this.defaults);return l.length=0,e(k),j=i(k),Array.isArray(a)?(h={type:"FeatureCollection",features:[]},a.forEach(function(a){h.features.push(g(a,k,j))}),c(h,k)):h=g(a,k,j),f&&"function"==typeof f?void f(h):h};var k=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon","GeoJSON"],l=[]}("object"==typeof module?module.exports:window.GeoJSON={});