Comparing version 0.1.2 to 0.1.3
@@ -1,1 +0,1 @@ | ||
"use strict";function JsonOdm(){var t=this;this.sources={},this.selectedSource={},this.addSource=function(e,o,n){"object"==typeof o&&("undefined"==typeof t.sources[e]&&(t.sources[e]=o),n&&(t.selectedSource=o))},this.selectSource=function(e){"undefined"!=typeof t.sources[e]&&(t.selectedSource=t.sources[e])}}var root="undefined"!=typeof window?window:global,odm=new JsonOdm;root.jsonOdm||(root.jsonOdm=odm),"undefined"!=typeof module&&module.exports&&(module.exports=odm),jsonOdm.Util=function(){},jsonOdm.Util.prototype.isArray=function(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)},jsonOdm.Util.prototype.is=function(t,e){e="string"==typeof e?[e]:e;var o=Object.prototype.toString.call(t);o=o.substring(8,o.length-1).toLowerCase();for(var n=0;n<e.length;n++){var r=e[n].toLowerCase();if("array"==r&&this.isArray(t))return!0;if(r==o)return!0;if(typeof t==r)return!0}return!1},jsonOdm.Util.prototype.objectKeys=Object.keys||function(){var t=Object.prototype.hasOwnProperty,e=!{toString:null}.propertyIsEnumerable("toString"),o=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],n=o.length;return function(r){if("object"!=typeof r&&("function"!=typeof r||null===r))throw new TypeError("Object.keys called on non-object");var i,s,u=[];for(i in r)t.call(r,i)&&u.push(i);if(e)for(s=0;n>s;s++)t.call(r,o[s])&&u.push(o[s]);return u}}(),jsonOdm.Util.prototype.branch=function(t,e){function o(){if(arguments&&arguments.length&&this){var t=this[arguments[0]];return t?o.apply(t,Array.prototype.slice.call(arguments,1)):t}return this}return o.apply(t,e)},jsonOdm.Util.prototype.projectElement=function(t,e,o){var n,r={};for(var i in t)if(t.hasOwnProperty(i))if(1==t[i])r[i]=e[i];else if("function"==typeof t[i])r[i]=t[i](o||e);else if(t[i]instanceof jsonOdm.Query)for(n=0;n<t[i].$$commandQueue.length;n++)r[i]=t[i].$$commandQueue[n](0===n?e:r[i]);else"object"==typeof t[i]&&(r[i]=this.projectElement(t[i],e[i],o||e));return r},jsonOdm.util=new jsonOdm.Util,jsonOdm.Geo=function(){},jsonOdm.Geo.detectAsGeometry=function(t){if(!t.type)if(jsonOdm.util.isArray(t)&&2==t.length&&!jsonOdm.util.isArray(t[0]))t=new jsonOdm.Geo.Point(t);else if(jsonOdm.util.isArray(t)&&4==t.length&&!jsonOdm.util.isArray(t[0]))t=new jsonOdm.Geo.BoundaryBox(t);else if(jsonOdm.util.isArray(t)&&t.length>=1&&jsonOdm.util.isArray(t[0])&&2==t[0].length&&!jsonOdm.util.isArray(t[0][0]))t=new jsonOdm.Geo.LineString(t);else if(jsonOdm.util.isArray(t)&&t.length>=1&&jsonOdm.util.isArray(t[0])&&t[0].length>=1&&jsonOdm.util.isArray(t[0][0])&&2==t[0][0].length&&!jsonOdm.util.isArray(t[0][0][0]))t=new jsonOdm.Geo.Polygon(t);else{if(!(jsonOdm.util.isArray(t)&&t.length>=1&&jsonOdm.util.isArray(t[0])&&t[0].length>=1&&jsonOdm.util.isArray(t[0][0])&&t[0][0].length>=1&&jsonOdm.util.isArray(t[0][0][0])&&2==t[0][0][0].length)||jsonOdm.util.isArray(t[0][0][0][0]))return!1;t=new jsonOdm.Geo.MultiPolygon(t)}return t},jsonOdm.Geo.FeatureCollection=function(t,e){this.type="FeatureCollection",this.features=t||[],e&&(this.bbox=e)},jsonOdm.Geo.Feature=function(t,e,o,n){this.geometry=t||{},e&&(this.properties=e),o&&(this.bbox=o),n&&(this.id=n)},jsonOdm.Geo.BoundaryBox=function(t){var e=Object.create(Array.prototype);return e=Array.apply(e)||e,jsonOdm.util.isArray(t)?(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3]):(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e},jsonOdm.Geo.BoundaryBox.within=function(t,e){return jsonOdm.util.isArray(t)&&4==t.length?jsonOdm.Geo.Polygon.within(new jsonOdm.Geo.Polygon([[[t[0],t[1]],[t[2],t[1]],[t[2],t[3]],[t[0],t[3]],[t[0],t[1]]]]),e):!1},jsonOdm.Geo.Point=function(t,e){this.type="Point",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.Point.within=function(t,e){var o,n;if(!t.coordinates)return!1;if("Point"==e.type)return e.coordinates[0]==t.coordinates[0]&&e.coordinates[1]==t.coordinates[1];if("MultiPoint"==e.type||"LineString"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(e.coordinates[o][0]==t.coordinates[0]&&e.coordinates[o][1]==t.coordinates[1])return!0;return!1}if("MultiLineString"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;e.coordinates[o]&&n<e.coordinates[o].length;n++)if(e.coordinates[o][n][0]==t.coordinates[0]&&e.coordinates[o][n][1]==t.coordinates[1])return!0;return!1}if("Polygon"==e.type)return jsonOdm.Geo.pointWithinPolygon(t.coordinates,e.coordinates?e.coordinates[0]:null);if("MultiPolygon"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates,e.coordinates[o]?e.coordinates[o][0]:null))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.Point.within(t,e.geometries[o]))return!0;return!1}return jsonOdm.Geo.pointWithinBounds(t.coordinates,e)},jsonOdm.Geo.Point.intersects=jsonOdm.Geo.Point.within,jsonOdm.Geo.MultiPoint=function(t,e){this.type="MultiPoint",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.MultiPoint.within=function(t,e){var o,n,r,i;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return 1==t.coordinates.length&&t.coordinates[0][0]==e.coordinates[0]&&t.coordinates[0][1]==e.coordinates[1];if("MultiPoint"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++){for(i=!1,o=0;e.coordinates&&o<e.coordinates.length;o++)if(e.coordinates[o][0]==t.coordinates[n][0]&&e.coordinates[o][1]==t.coordinates[n][1]){i=!0;break}if(!i)return!1}return!0}if("LineString"==e.type){for(r=0;t.coordinates&&r<t.coordinates.length;r++)if(!jsonOdm.Geo.pointWithinLineString(t.coordinates[r],e.coordinates))return!1;return!0}if("MultiLineString"==e.type){for(r=0;t.coordinates&&r<t.coordinates.length;r++){for(i=!1,o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.pointWithinLineString(t.coordinates[r],e.coordinates[o])){i=!0;break}if(!i)return!1}return!0}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)if(!jsonOdm.Geo.pointWithinPolygon(t.coordinates[o],e.coordinates?e.coordinates[0]:null))return!1;return!0}if("MultiPolygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++){for(i=!1,o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates[n],e.coordinates[o]?e.coordinates[o][0]:null)){i=!0;break}if(!i)return!1}return!0}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiPoint.within(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[o],e))return!1;return!0},jsonOdm.Geo.MultiPoint.intersects=function(t,e){var o,n,r;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(e.coordinates[o][0]==t.coordinates[n][0]&&e.coordinates[o][1]==t.coordinates[n][1])return!0;return!1}if("LineString"==e.type){for(r=0;t.coordinates&&r<t.coordinates.length;r++)if(jsonOdm.Geo.pointWithinLineString(t.coordinates[r],e.coordinates))return!0;return!1}if("MultiLineString"==e.type){for(r=0;t.coordinates&&r<t.coordinates.length;r++)for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.pointWithinLineString(t.coordinates[r],e.coordinates[o]))return!0;return!1}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates[o],e.coordinates?e.coordinates[0]:null))return!0;return!1}if("MultiPolygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates[n],e.coordinates[o]?e.coordinates[o][0]:null))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiPoint.intersects(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)if(jsonOdm.Geo.pointWithinBounds(t.coordinates[o],e))return!0;return!1},jsonOdm.Geo.LineString=function(t,e){this.type="LineString",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.LineString.within=function(t,e){var o,n;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type||"MultiPoint"==e.type)return!1;if("LineString"==e.type)return jsonOdm.Geo.lineStringWithinLineString(t.coordinates,e.coordinates);if("MultiLineString"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.lineStringWithinLineString(t.coordinates,e.coordinates[o]))return!0;return!1}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length-1;o++)if(!jsonOdm.Geo.edgeWithinPolygon([t.coordinates[o],t.coordinates[o+1]],e.coordinates[0]))return!1;return!0}if("MultiPolygon"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;t.coordinates&&n<t.coordinates.length-1;n++)if(jsonOdm.Geo.edgeWithinPolygon([t.coordinates[n],t.coordinates[n+1]],e.coordinates[o][0])&&n+1==t.coordinates.length-1)return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.LineString.within(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[o],e))return!1;return!0},jsonOdm.Geo.LineString.intersects=function(t,e){var o,n;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type)return jsonOdm.Geo.MultiPoint.intersects(e,t);if("LineString"==e.type){for(o=0;o<t.coordinates.length-1;o++)if(jsonOdm.Geo.edgeIntersectsLineString([t.coordinates[o],t.coordinates[o+1]],e.coordinates))return!0;return!1}if("MultiLineString"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;n<t.coordinates.length-1;n++)if(jsonOdm.Geo.edgeIntersectsLineString([t.coordinates[n],t.coordinates[n+1]],e.coordinates[o]))return!0;return!1}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length-1;o++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[o],t.coordinates[o+1]],e.coordinates[0]))return!0;return!1}if("MultiPolygon"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;t.coordinates&&n<t.coordinates.length-1;n++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[n],t.coordinates[n+1]],e.coordinates[o][0]))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.LineString.intersects(t,e.geometries[o]))return!0;return!1}for(o=0;t.coordinates&&o<t.coordinates.length-1;o++)if(jsonOdm.Geo.edgeIntersectsBounds([t.coordinates[o],t.coordinates[o+1]],e))return!0;return!1},jsonOdm.Geo.MultiLineString=function(t,e){this.type="MultiLineString",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.MultiLineString.within=function(t,e){var o,n,r,i;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type||"MultiPoint"==e.type)return!1;if("LineString"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)if(!jsonOdm.Geo.lineStringWithinLineString(t.coordinates[o],e.coordinates))return!1;return!0}if("MultiLineString"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++){for(i=!1,o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.lineStringWithinLineString(t.coordinates[n],e.coordinates[o])){i=!0;break}if(!i)return!1}return!0}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;t.coordinates&&n<t.coordinates[o].length-1;n++)if(!jsonOdm.Geo.edgeWithinPolygon([t.coordinates[o][n],t.coordinates[o][n+1]],e.coordinates[0]))return!1;return!0}if("MultiPolygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++){for(i=!1,o=0;e.coordinates&&o<e.coordinates.length;o++)for(r=0;t.coordinates[n]&&r<t.coordinates[n].length-1;r++)if(jsonOdm.Geo.edgeWithinPolygon([t.coordinates[n][r],t.coordinates[n][r+1]],e.coordinates[o][0])&&r+1==t.coordinates[n].length-1){i=!0;break}if(!i)return!1}return!0}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiLineString.within(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)for(n=0;n<t.coordinates[o].length;n++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[o][n],e))return!1;return!0},jsonOdm.Geo.MultiLineString.intersects=function(t,e){var o,n,r;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type)return jsonOdm.Geo.MultiPoint.intersects(e,t);if("LineString"==e.type)return jsonOdm.Geo.LineString.intersects(e,t);if("MultiLineString"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(r=0;t.coordinates[n]&&r<t.coordinates[n].length-1;r++)for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.edgeIntersectsLineString([t.coordinates[n][r],t.coordinates[n][r+1]],e.coordinates[o]))return!0;return!1}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;t.coordinates&&n<t.coordinates[o].length-1;n++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[o][n],t.coordinates[o][n+1]],e.coordinates[0]))return!0;return!1}if("MultiPolygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(r=0;t.coordinates[n]&&r<t.coordinates[n].length-1;r++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[n][r],t.coordinates[n][r+1]],e.coordinates[o][0]))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiLineString.intersects(t,e.geometries[o]))return!0;return!1}for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;n<t.coordinates[o].length-1;n++)if(jsonOdm.Geo.edgeIntersectsBounds([t.coordinates[o][n],t.coordinates[o][n+1]],e))return!0;return!1},jsonOdm.Geo.Polygon=function(t,e){this.type="Polygon",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.Polygon.within=function(t,e){var o,n;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type||"MultiPoint"==e.type||"LineString"==e.type||"MultiLineString"==e.type)return!1;if("Polygon"==e.type){for(o=0;t.coordinates[0]&&o<t.coordinates[0].length-1;o++)if(!jsonOdm.Geo.edgeWithinPolygon([t.coordinates[0][o],t.coordinates[0][o+1]],e.coordinates[0]))return!1;return!0}if("MultiPolygon"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;t.coordinates[0]&&n<t.coordinates[0].length-1;n++){var r=jsonOdm.Geo.edgeWithinPolygon([t.coordinates[0][n],t.coordinates[0][n+1]],e.coordinates[o][0]);if(!r)break;if(r&&n+1==t.coordinates[0].length-1)return!0}return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.Polygon.within(t,e.geometries[o]))return!0;return!1}for(o=0;t.coordinates[0]&&o<t.coordinates[0].length;o++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[0][o],e))return!1;return!0},jsonOdm.Geo.Polygon.intersects=function(t,e){var o,n;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type)return jsonOdm.Geo.MultiPoint.intersects(e,t);if("LineString"==e.type)return jsonOdm.Geo.LineString.intersects(e,t);if("MultiLineString"==e.type)return jsonOdm.Geo.MultiLineString.intersects(e,t);if("Polygon"==e.type){for(o=0;t.coordinates[0]&&o<t.coordinates[0].length-1;o++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[0][o],t.coordinates[0][o+1]],e.coordinates[0]))return!0;return!1}if("MultiPolygon"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;t.coordinates[0]&&n<t.coordinates[0].length-1;n++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[0][n],t.coordinates[0][n+1]],e.coordinates[o][0]))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.Polygon.intersects(t,e.geometries[o]))return!0;return!1}for(o=0;t.coordinates[0]&&o<t.coordinates[0].length-1;o++)if(jsonOdm.Geo.edgeIntersectsBounds([t.coordinates[0][o],t.coordinates[0][o+1]],e))return!0;return!1},jsonOdm.Geo.MultiPolygon=function(t,e){this.type="MultiPolygon",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.MultiPolygon.within=function(t,e){var o,n,r,i;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type||"MultiPoint"==e.type||"LineString"==e.type||"MultiLineString"==e.type)return!1;if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;n<t.coordinates[o][0].length-1;n++)if(!jsonOdm.Geo.edgeWithinPolygon([t.coordinates[o][0][n],t.coordinates[o][0][n+1]],e.coordinates[0]))return!1;return!0}if("MultiPolygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++){for(i=!1,n=0;e.coordinates&&n<e.coordinates.length;n++)for(r=0;t.coordinates[o][0]&&r<t.coordinates[o][0].length-1;r++){var s=jsonOdm.Geo.edgeWithinPolygon([t.coordinates[o][0][r],t.coordinates[o][0][r+1]],e.coordinates[n][0]);if(!s)break;if(s&&r+1==t.coordinates[o][0].length-1){i=!0;break}}if(!i)return!1}return!0}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiPolygon.within(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)for(n=0;n<t.coordinates[o][0].length;n++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[o][0][n],e))return!1;return!0},jsonOdm.Geo.MultiPolygon.intersects=function(t,e){var o,n,r;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type)return jsonOdm.Geo.MultiPoint.intersects(e,t);if("LineString"==e.type)return jsonOdm.Geo.LineString.intersects(e,t);if("MultiLineString"==e.type)return jsonOdm.Geo.MultiLineString.intersects(e,t);if("Polygon"==e.type)return jsonOdm.Geo.Polygon.intersects(e,t);if("MultiPolygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;e.coordinates&&n<e.coordinates.length;n++)for(r=0;t.coordinates[o][0]&&r<t.coordinates[o][0].length-1;r++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates[o][0][r],e.coordinates[n][0]))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiPolygon.intersects(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)for(n=0;n<t.coordinates[o][0].length-1;n++)if(jsonOdm.Geo.edgeIntersectsBounds([t.coordinates[o][0][n],t.coordinates[o][0][n+1]],e))return!0;return!1},jsonOdm.Geo.GeometryCollection=function(t,e){this.type="GeometryCollection",this.geometries=t,e&&(this.bbox=e)},jsonOdm.Geo.GeometryCollection.within=function(t,e){if(!jsonOdm.util.isArray(t.geometries)||!t.geometries.length||!e.type)return!1;for(var o=0;o<t.geometries.length;o++){if(!jsonOdm.Geo[t.geometries[o].type]||!jsonOdm.Geo[t.geometries[o].type].within)return!1;if(!jsonOdm.Geo[t.geometries[o].type].within(t.geometries[o],e))return!1}return!0},jsonOdm.Geo.GeometryCollection.intersects=function(t,e){if(!jsonOdm.util.isArray(t.geometries)||!t.geometries.length||!e.type)return!1;for(var o=0;o<t.geometries.length;o++)if(jsonOdm.Geo[t.geometries[o].type]&&jsonOdm.Geo[t.geometries[o].type].intersects&&jsonOdm.Geo[t.geometries[o].type].intersects(t.geometries[o],e))return!0;return!1},jsonOdm.Geo.pointWithinPolygon=function(t,e){if(!(jsonOdm.util.isArray(t)&&jsonOdm.util.isArray(e)&&e.length>2))return!1;var o,n=0;(e[0][0]!=e[e.length-1][0]||e[0][1]!=e[e.length-1][1])&&(e=e.concat([e[0]]));for(var r=0;r<e.length-1;r++){if(e[r][0]==t[0]&&e[r][1]==t[1])return!0;if(!(e[r][0]<t[0]&&e[r+1][0]<t[0]||e[r][1]<t[1]&&e[r+1][1]<t[1]||e[r][1]>t[1]&&e[r+1][1]>t[1])){if(o=(e[r][0]-e[r+1][0])*((t[1]-e[r+1][1])/(e[r][1]-e[r+1][1]))+e[r+1][0],o==t[0]&&t[1]<=Math.max(e[r][1],e[r+1][1])&&t[1]>=Math.min(e[r][1],e[r+1][1]))return!0;o>t[0]&&n++}}return n%2==1},jsonOdm.Geo.edgeWithinPolygon=function(t,e){if(!(jsonOdm.util.isArray(t)&&2==t.length&&jsonOdm.util.isArray(e)&&e.length>=2))return!1;if((e[0][0]!=e[e.length-1][0]||e[0][1]!=e[e.length-1][1])&&(e=e.concat([e[0]])),!jsonOdm.Geo.pointWithinPolygon(t[0],e)||!jsonOdm.Geo.pointWithinPolygon(t[1],e))return!1;for(var o=0;o<e.length-1;o++)if(jsonOdm.Geo.edgeIntersectsEdge(t,[e[o],e[o+1]],!1))return!1;return!0},jsonOdm.Geo.edgeIntersectsPolygon=function(t,e){if(!(jsonOdm.util.isArray(t)&&2==t.length&&jsonOdm.util.isArray(e)&&e.length>=2))return!1;if((e[0][0]!=e[e.length-1][0]||e[0][1]!=e[e.length-1][1])&&(e=e.concat([e[0]])),jsonOdm.Geo.pointWithinPolygon(t[0],e)||jsonOdm.Geo.pointWithinPolygon(t[1],e))return!0;for(var o=0;o<e.length-1;o++)if(jsonOdm.Geo.edgeIntersectsEdge(t,[e[o],e[o+1]]))return!0;return!1},jsonOdm.Geo.edgeIntersectsLineString=function(t,e){if(!jsonOdm.util.isArray(t)||2!=t.length||!jsonOdm.util.isArray(e))return!1;for(var o=0;o<e.length-1;o++)if(jsonOdm.Geo.edgeIntersectsEdge(t,[e[o],e[o+1]]))return!0;return!1},jsonOdm.Geo.edgeIntersectsEdge=function(t,e,o){o="undefined"==typeof o?!0:o;var n=[t[1][0]-t[0][0],t[1][1]-t[0][1]],r=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])],i=[e[1][0]-e[0][0],e[1][1]-e[0][1]],s=[Math.min(e[0][0],e[1][0]),Math.min(e[0][1],e[1][1]),Math.max(e[0][0],e[1][0]),Math.max(e[0][1],e[1][1])];if(r[0]>s[0]&&r[0]>s[2]||r[1]>s[1]&&r[1]>s[3]||s[0]>r[0]&&s[0]>r[2]||s[1]>r[1]&&s[1]>r[3])return!1;if(i[0]*n[1]-n[0]*i[1]==0)return o&&t[0][1]+(e[0][0]-t[0][0])/n[0]*n[1]==e[0][1];var u=(e[0][1]*i[0]+t[0][0]*i[1]-e[0][0]*i[1]-t[0][1]*i[0])/(n[1]*i[0]-n[0]*i[1]),d=t[0][0]+u*n[0],c=t[0][1]+u*n[1];return o?d>=r[0]&&d<=r[2]&&c>=r[1]&&c<=r[3]&&d>=s[0]&&d<=s[2]&&c>=s[1]&&c<=s[3]:d>r[0]&&d<r[2]&&c>r[1]&&c<r[3]&&d>s[0]&&d<s[2]&&c>s[1]&&c<s[3]},jsonOdm.Geo.pointWithinLineString=function(t,e){if(!(jsonOdm.util.isArray(t)&&jsonOdm.util.isArray(e)&&e.length>=2))return!1;for(var o=0;o<e.length-1;o++)if((t[0]>=e[o][0]&&t[0]<=e[o+1][0]&&e[o][0]<=e[o+1][0]||t[0]<=e[o][0]&&t[0]>=e[o+1][0]&&e[o][0]>=e[o+1][0])&&(t[1]>=e[o][1]&&t[1]<=e[o+1][1]&&e[o][1]<=e[o+1][1]||t[1]<=e[o][1]&&t[1]>=e[o+1][1]&&e[o][1]>=e[o+1][1])&&(e[o][0]==t[0]&&e[o][1]==t[1]||e[o+1][0]==t[0]&&e[o+1][1]==t[1]||e[o][1]-e[o+1][1]!=0&&(e[o][0]-e[o+1][0])*((t[1]-e[o+1][1])/(e[o][1]-e[o+1][1]))+e[o+1][0]==t[0]||e[o][0]-e[o+1][0]!=0&&(e[o][1]-e[o+1][1])*((t[0]-e[o+1][0])/(e[o][0]-e[o+1][0]))+e[o+1][1]==t[1]))return!0;return!1},jsonOdm.Geo.pointWithinBounds=function(t,e){return jsonOdm.util.isArray(t)&&jsonOdm.util.isArray(e)&&4==e.length?t[0]>=e[0]&&t[1]>=e[1]&&t[0]<=e[2]&&t[1]<=e[3]:!1},jsonOdm.Geo.edgeIntersectsBounds=function(t,e){return jsonOdm.util.isArray(t)&&jsonOdm.util.isArray(e)&&4==e.length?jsonOdm.Geo.edgeIntersectsPolygon(t,[[e[0],e[1]],[e[2],e[1]],[e[2],e[3]],[e[0],e[3]]]):!1},jsonOdm.Geo.lineStringWithinLineString=function(t,e){if(!jsonOdm.util.isArray(t)||!jsonOdm.util.isArray(e))return!1;var o,n;for(o=0;t&&o<t.length;o++){var r=!1;for(n=0;e&&n<e.length;n++)if(t[o][0]==e[n][0]&&t[o][1]==e[n][1]){if(o+1==t.length)return!0;if(!(e[n+1]&&t[o+1][0]==e[n+1][0]&&t[o+1][1]==e[n+1][1]||t[o+1][0]==e[n][0]&&t[o+1][1]==e[n][1]||n>0&&t[o+1][0]==e[n-1][0]&&t[o+1][1]==e[n-1][1]))return!1;r=!0}if(!r)return!1}return!0},jsonOdm.Collection=function(t){var e=Object.create(Array.prototype);return e=Array.apply(e)||e,"undefined"!=typeof t&&jsonOdm.selectedSource&&jsonOdm.selectedSource[t]&&(e=e.concat(jsonOdm.selectedSource[t])),jsonOdm.Collection.decorate(e),e.$branch=function(){var t=jsonOdm.util.branch(e,arguments);return jsonOdm.Collection.decorate(t),t},e},jsonOdm.Collection.decorate=function(t){var e=function(t){jsonOdm.util.isArray(t)&&(t.$hasMany=function(e,o,n,r){"string"==typeof n&&(r=r||n);var i=n;"string"==typeof n&&jsonOdm.selectedSource&&jsonOdm.selectedSource[n]&&(i=jsonOdm.selectedSource[n]);for(var s=0;s<t.length;s++){var u=e;if(t[s].hasOwnProperty(e)&&(u=t[s][e]),"undefined"==typeof t[s][r])for(var d=0;u.length&&d<u.length;d++){for(var c=null,l=0;l<i.length;l++)if(u[d]==i[l][o]){c=i[l];break}null!=c&&(t[s][r]||(t[s][r]=[]),t[s][r].push(c))}}},t.$hasOne=function(e,o,n,r){"string"==typeof n&&(r=r||n);var i=n;"string"==typeof n&&jsonOdm.selectedSource&&jsonOdm.selectedSource[n]&&(i=jsonOdm.selectedSource[n]);for(var s=0;s<t.length;s++){var u;if(t[s].hasOwnProperty(e)&&(u=t[s][e]),"undefined"==typeof t[s][r]){for(var d=null,c=0;c<i.length;c++)if(u==i[c][o]){d=i[c];break}null!=d&&(t[s][r]=d)}}},t.$query=function(){return new jsonOdm.Query(t)})};e(t)},jsonOdm.Query=function(t){this.$$commandQueue=[],this.$$aggregationBeforeCollectQueue=[],this.$$aggregationResultQueue=[],this.$$collection=t},jsonOdm.Query.prototype.$delete=function(){if(this.$$commandQueue.length<1)return this;for(var t=0;t<this.$$collection.length;){for(var e=!0,o=0;o<this.$$commandQueue.length&&(e=e&&this.$$commandQueue[o](this.$$collection[t]));o++);e?this.$$collection.splice(t,1):t++}return this},jsonOdm.Query.prototype.$result=function(t,e){if(this.$$commandQueue.length<1)return this.$$collection;t="undefined"==typeof t?0:t,e="undefined"==typeof e?this.$$collection.length:e;var o,n,r,i=new jsonOdm.Collection;for(n=0;n<this.$$collection.length;n++){var s=!0;for(r=0;r<this.$$commandQueue.length&&(s=s&&this.$$commandQueue[r](this.$$collection[n]));r++);if(s){if(t>0){t--;continue}if(0>=e)return i;for(o=this.$$collection[n],r=0;r<this.$$aggregationBeforeCollectQueue.length;r++)o=this.$$aggregationBeforeCollectQueue[r](o);i.push(o),e--}}return i},jsonOdm.Query.prototype.$all=function(){return this.$result()},jsonOdm.Query.prototype.$first=function(){return this.$result(0,1)[0]},jsonOdm.Query.prototype.$aggregateCollection=function(){},jsonOdm.Query.prototype.$project=function(t){return this.$aggregateCollection(null,function(e,o){return jsonOdm.util.projectElement(t,o)})},jsonOdm.Query.prototype.$testCollection=function(t,e){var o=this.$$commandQueue.pop(),n=function(){return function(n){if(!(o instanceof jsonOdm.Collection||"function"==typeof o||"undefined"==typeof o)||"function"!=typeof e)return!1;var r="undefined"==typeof o?n:o instanceof jsonOdm.Collection?o:o(n);return!!e(r,t)}}();return this.$$commandQueue.push(n),this},jsonOdm.Query.prototype.$binaryOperator=function(t,e){var o=function(t,o){return function(n){if("function"!=typeof o)return!1;for(var r=[],i=0;i<t.length;i++)for(var s=0;s<t[i].$$commandQueue.length;s++)r.push(t[i].$$commandQueue[s](n));return!!e(r)}}(t,e),n=new jsonOdm.Query(this.$$collection);return n.$$commandQueue.push(o),n},jsonOdm.Query.prototype.$branch=function(){var t=function(t){return function(e){return jsonOdm.util.branch(e,t)}}(arguments),e=new jsonOdm.Query(this.$$collection);return e.$$commandQueue.push(t),e},jsonOdm.Query.prototype.$modifyField=function(t){var e=function(t,e){return function(o){return o=null!==e?e(o):o,"function"==typeof t?t(o):o}}(t,this.$$commandQueue.length?this.$$commandQueue[this.$$commandQueue.length-1]:null);return this.$$commandQueue.push(e),this},jsonOdm.Query.prototype.$substr=function(t,e){return this.$modifyField(function(t,e){return function(o){return"string"==typeof o?o.substr(t,e):o}}(t,e))},jsonOdm.Query.prototype.$eq=function(){return this.$testCollection(arguments,function(t,e){for(var o=0;o<e.length;o++)if(e[o]==t)return!0;return!1})},jsonOdm.Query.prototype.$in=function(t){return this.$testCollection(t,function(t,e){for(var o=0;o<e.length;o++)if(e[o]==t)return!0;return!1})},jsonOdm.Query.prototype.$ne=function(){return this.$testCollection(arguments,function(t,e){for(var o=0;o<e.length;o++)if(e[o]==t)return!1;return!0})},jsonOdm.Query.prototype.$nin=function(t){return this.$testCollection(t,function(t,e){for(var o=0;o<e.length;o++)if(e[o]==t)return!1;return!0})},jsonOdm.Query.prototype.$gt=function(t){return this.$testCollection(t,function(t,e){return t>e})},jsonOdm.Query.prototype.$gte=function(t){return this.$testCollection(t,function(t,e){return t>=e})},jsonOdm.Query.prototype.$lt=function(t){return this.$testCollection(t,function(t,e){return e>t})},jsonOdm.Query.prototype.$lte=function(t){return this.$testCollection(t,function(t,e){return e>=t})},jsonOdm.Query.prototype.$isNull=function(){return this.$testCollection(null,function(t){return"undefined"==typeof t||null===t})},jsonOdm.Query.prototype.$exists=function(){return this.$testCollection(null,function(t){return"undefined"!=typeof t})},jsonOdm.Query.prototype.$type=function(){return this.$testCollection(arguments,function(t,e){return jsonOdm.util.is(t,e)})},jsonOdm.Query.prototype.$mod=function(){return this.$testCollection(arguments,function(t,e){return t%e[0]==e[1]})},jsonOdm.Query.prototype.$regex=function(t,e){return"string"==typeof t&&(t="string"==typeof e?new RegExp(t,e):new RegExp(t)),this.$testCollection(t,function(t,e){return e.test(t)})},jsonOdm.Query.prototype.$text=function(t){for(var e,o,n=/(^| )-([^ ]+)( |$)/g,r=/"([^"]+)"/g,i=[],s=[];null!==(e=n.exec(t));)i.push(e[2]);for(t=t.replace(n,"");null!==(o=r.exec(t));)s.push(o[1]);t=t.replace(r,"");var u=t.split(" ");return this.$testCollection([i,s,u],function(t,e){for(var o=0;o<e[0].length;o++)if(t.indexOf(e[0][o])>-1)return!1;for(o=0;o<e[1].length;o++)if(t.indexOf(e[1][o])<0)return!1;for(o=0;o<e[2].length;o++)if(t.indexOf(e[2][o])>-1)return!0;return!!e[1].length})},jsonOdm.Query.prototype.$where=function(t){return"string"==typeof t&&(t=new Function(t)),this.$testCollection(t,function(t,e){return"function"!=typeof e?!1:e.apply(t)})},jsonOdm.Query.prototype.$geoWithin=function(t){return this.$testCollection(jsonOdm.Geo.detectAsGeometry(t),function(t,e){return jsonOdm.Geo[t.type]&&jsonOdm.Geo[t.type].within&&jsonOdm.Geo[t.type].within(t,e)})},jsonOdm.Query.prototype.$geoIntersects=function(t){return this.$testCollection(jsonOdm.Geo.detectAsGeometry(t),function(t,e){return jsonOdm.Geo[t.type]&&jsonOdm.Geo[t.type].intersects&&jsonOdm.Geo[t.type].intersects(t,e)})},jsonOdm.Query.prototype.$and=function(){return this.$binaryOperator(arguments,function(t){for(var e=0;e<t.length;e++)if(!t[e])return!1;return!0})},jsonOdm.Query.prototype.$nand=function(){return this.$binaryOperator(arguments,function(t){for(var e=0;e<t.length;e++)if(!t[e])return!0;return!1})},jsonOdm.Query.prototype.$not=jsonOdm.Query.prototype.$nand,jsonOdm.Query.prototype.$or=function(){return this.$binaryOperator(arguments,function(t){for(var e=0;e<t.length;e++)if(t[e])return!0;return!1})},jsonOdm.Query.prototype.$nor=function(){return this.$binaryOperator(arguments,function(t){for(var e=0;e<t.length;e++)if(t[e])return!1;return!0})}; | ||
"use strict";function JsonOdm(){var t=this;this.sources={},this.selectedSource={},this.addSource=function(e,o,n){"object"==typeof o&&("undefined"==typeof t.sources[e]&&(t.sources[e]=o),n&&(t.selectedSource=o))},this.selectSource=function(e){"undefined"!=typeof t.sources[e]&&(t.selectedSource=t.sources[e])}}var root="undefined"!=typeof window?window:global,odm=new JsonOdm;root.jsonOdm||(root.jsonOdm=odm),"undefined"!=typeof module&&module.exports&&(module.exports=odm),jsonOdm.Util=function(){},jsonOdm.Util.prototype.isArray=function(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(t)},jsonOdm.Util.prototype.is=function(t,e){e="string"==typeof e?[e]:e;var o=Object.prototype.toString.call(t);o=o.substring(8,o.length-1).toLowerCase();for(var n=0;n<e.length;n++){var r=e[n].toLowerCase();if("array"==r&&this.isArray(t))return!0;if(r==o)return!0;if(typeof t==r)return!0}return!1},jsonOdm.Util.prototype.objectKeys=Object.keys||function(){var t=Object.prototype.hasOwnProperty,e=!{toString:null}.propertyIsEnumerable("toString"),o=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],n=o.length;return function(r){if("object"!=typeof r&&("function"!=typeof r||null===r))throw new TypeError("Object.keys called on non-object");var i,s,u=[];for(i in r)t.call(r,i)&&u.push(i);if(e)for(s=0;n>s;s++)t.call(r,o[s])&&u.push(o[s]);return u}}(),jsonOdm.Util.prototype.branch=function(t,e){function o(){if(arguments&&arguments.length&&this){var t=this[arguments[0]];return t?o.apply(t,Array.prototype.slice.call(arguments,1)):t}return this}return o.apply(t,e)},jsonOdm.Util.prototype.projectElement=function(t,e,o){var n={};for(var r in t)t.hasOwnProperty(r)&&(1==t[r]?n[r]=e[r]:"function"==typeof t[r]?n[r]=t[r](o||e):t[r]instanceof jsonOdm.Query?n[r]=t[r].$$commandQueue[t[r].$$commandQueue.length-1](e):"object"==typeof t[r]&&(n[r]=this.projectElement(t[r],e[r],o||e)));return n},jsonOdm.util=new jsonOdm.Util,jsonOdm.Geo=function(){},jsonOdm.Geo.detectAsGeometry=function(t){if(!t.type)if(jsonOdm.util.isArray(t)&&2==t.length&&!jsonOdm.util.isArray(t[0]))t=new jsonOdm.Geo.Point(t);else if(jsonOdm.util.isArray(t)&&4==t.length&&!jsonOdm.util.isArray(t[0]))t=new jsonOdm.Geo.BoundaryBox(t);else if(jsonOdm.util.isArray(t)&&t.length>=1&&jsonOdm.util.isArray(t[0])&&2==t[0].length&&!jsonOdm.util.isArray(t[0][0]))t=new jsonOdm.Geo.LineString(t);else if(jsonOdm.util.isArray(t)&&t.length>=1&&jsonOdm.util.isArray(t[0])&&t[0].length>=1&&jsonOdm.util.isArray(t[0][0])&&2==t[0][0].length&&!jsonOdm.util.isArray(t[0][0][0]))t=new jsonOdm.Geo.Polygon(t);else{if(!(jsonOdm.util.isArray(t)&&t.length>=1&&jsonOdm.util.isArray(t[0])&&t[0].length>=1&&jsonOdm.util.isArray(t[0][0])&&t[0][0].length>=1&&jsonOdm.util.isArray(t[0][0][0])&&2==t[0][0][0].length)||jsonOdm.util.isArray(t[0][0][0][0]))return!1;t=new jsonOdm.Geo.MultiPolygon(t)}return t},jsonOdm.Geo.FeatureCollection=function(t,e){this.type="FeatureCollection",this.features=t||[],e&&(this.bbox=e)},jsonOdm.Geo.Feature=function(t,e,o,n){this.geometry=t||{},e&&(this.properties=e),o&&(this.bbox=o),n&&(this.id=n)},jsonOdm.Geo.BoundaryBox=function(t){var e=Object.create(Array.prototype);return e=Array.apply(e)||e,jsonOdm.util.isArray(t)?(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3]):(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e},jsonOdm.Geo.BoundaryBox.within=function(t,e){return jsonOdm.util.isArray(t)&&4==t.length?jsonOdm.Geo.Polygon.within(new jsonOdm.Geo.Polygon([[[t[0],t[1]],[t[2],t[1]],[t[2],t[3]],[t[0],t[3]],[t[0],t[1]]]]),e):!1},jsonOdm.Geo.Point=function(t,e){this.type="Point",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.Point.within=function(t,e){var o,n;if(!t.coordinates)return!1;if("Point"==e.type)return e.coordinates[0]==t.coordinates[0]&&e.coordinates[1]==t.coordinates[1];if("MultiPoint"==e.type||"LineString"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(e.coordinates[o][0]==t.coordinates[0]&&e.coordinates[o][1]==t.coordinates[1])return!0;return!1}if("MultiLineString"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;e.coordinates[o]&&n<e.coordinates[o].length;n++)if(e.coordinates[o][n][0]==t.coordinates[0]&&e.coordinates[o][n][1]==t.coordinates[1])return!0;return!1}if("Polygon"==e.type)return jsonOdm.Geo.pointWithinPolygon(t.coordinates,e.coordinates?e.coordinates[0]:null);if("MultiPolygon"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates,e.coordinates[o]?e.coordinates[o][0]:null))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.Point.within(t,e.geometries[o]))return!0;return!1}return jsonOdm.Geo.pointWithinBounds(t.coordinates,e)},jsonOdm.Geo.Point.intersects=jsonOdm.Geo.Point.within,jsonOdm.Geo.MultiPoint=function(t,e){this.type="MultiPoint",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.MultiPoint.within=function(t,e){var o,n,r,i;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return 1==t.coordinates.length&&t.coordinates[0][0]==e.coordinates[0]&&t.coordinates[0][1]==e.coordinates[1];if("MultiPoint"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++){for(i=!1,o=0;e.coordinates&&o<e.coordinates.length;o++)if(e.coordinates[o][0]==t.coordinates[n][0]&&e.coordinates[o][1]==t.coordinates[n][1]){i=!0;break}if(!i)return!1}return!0}if("LineString"==e.type){for(r=0;t.coordinates&&r<t.coordinates.length;r++)if(!jsonOdm.Geo.pointWithinLineString(t.coordinates[r],e.coordinates))return!1;return!0}if("MultiLineString"==e.type){for(r=0;t.coordinates&&r<t.coordinates.length;r++){for(i=!1,o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.pointWithinLineString(t.coordinates[r],e.coordinates[o])){i=!0;break}if(!i)return!1}return!0}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)if(!jsonOdm.Geo.pointWithinPolygon(t.coordinates[o],e.coordinates?e.coordinates[0]:null))return!1;return!0}if("MultiPolygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++){for(i=!1,o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates[n],e.coordinates[o]?e.coordinates[o][0]:null)){i=!0;break}if(!i)return!1}return!0}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiPoint.within(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[o],e))return!1;return!0},jsonOdm.Geo.MultiPoint.intersects=function(t,e){var o,n,r;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(e.coordinates[o][0]==t.coordinates[n][0]&&e.coordinates[o][1]==t.coordinates[n][1])return!0;return!1}if("LineString"==e.type){for(r=0;t.coordinates&&r<t.coordinates.length;r++)if(jsonOdm.Geo.pointWithinLineString(t.coordinates[r],e.coordinates))return!0;return!1}if("MultiLineString"==e.type){for(r=0;t.coordinates&&r<t.coordinates.length;r++)for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.pointWithinLineString(t.coordinates[r],e.coordinates[o]))return!0;return!1}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates[o],e.coordinates?e.coordinates[0]:null))return!0;return!1}if("MultiPolygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates[n],e.coordinates[o]?e.coordinates[o][0]:null))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiPoint.intersects(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)if(jsonOdm.Geo.pointWithinBounds(t.coordinates[o],e))return!0;return!1},jsonOdm.Geo.LineString=function(t,e){this.type="LineString",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.LineString.within=function(t,e){var o,n;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type||"MultiPoint"==e.type)return!1;if("LineString"==e.type)return jsonOdm.Geo.lineStringWithinLineString(t.coordinates,e.coordinates);if("MultiLineString"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.lineStringWithinLineString(t.coordinates,e.coordinates[o]))return!0;return!1}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length-1;o++)if(!jsonOdm.Geo.edgeWithinPolygon([t.coordinates[o],t.coordinates[o+1]],e.coordinates[0]))return!1;return!0}if("MultiPolygon"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;t.coordinates&&n<t.coordinates.length-1;n++)if(jsonOdm.Geo.edgeWithinPolygon([t.coordinates[n],t.coordinates[n+1]],e.coordinates[o][0])&&n+1==t.coordinates.length-1)return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.LineString.within(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[o],e))return!1;return!0},jsonOdm.Geo.LineString.intersects=function(t,e){var o,n;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type)return jsonOdm.Geo.MultiPoint.intersects(e,t);if("LineString"==e.type){for(o=0;o<t.coordinates.length-1;o++)if(jsonOdm.Geo.edgeIntersectsLineString([t.coordinates[o],t.coordinates[o+1]],e.coordinates))return!0;return!1}if("MultiLineString"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;n<t.coordinates.length-1;n++)if(jsonOdm.Geo.edgeIntersectsLineString([t.coordinates[n],t.coordinates[n+1]],e.coordinates[o]))return!0;return!1}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length-1;o++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[o],t.coordinates[o+1]],e.coordinates[0]))return!0;return!1}if("MultiPolygon"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;t.coordinates&&n<t.coordinates.length-1;n++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[n],t.coordinates[n+1]],e.coordinates[o][0]))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.LineString.intersects(t,e.geometries[o]))return!0;return!1}for(o=0;t.coordinates&&o<t.coordinates.length-1;o++)if(jsonOdm.Geo.edgeIntersectsBounds([t.coordinates[o],t.coordinates[o+1]],e))return!0;return!1},jsonOdm.Geo.MultiLineString=function(t,e){this.type="MultiLineString",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.MultiLineString.within=function(t,e){var o,n,r,i;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type||"MultiPoint"==e.type)return!1;if("LineString"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)if(!jsonOdm.Geo.lineStringWithinLineString(t.coordinates[o],e.coordinates))return!1;return!0}if("MultiLineString"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++){for(i=!1,o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.lineStringWithinLineString(t.coordinates[n],e.coordinates[o])){i=!0;break}if(!i)return!1}return!0}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;t.coordinates&&n<t.coordinates[o].length-1;n++)if(!jsonOdm.Geo.edgeWithinPolygon([t.coordinates[o][n],t.coordinates[o][n+1]],e.coordinates[0]))return!1;return!0}if("MultiPolygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++){for(i=!1,o=0;e.coordinates&&o<e.coordinates.length;o++)for(r=0;t.coordinates[n]&&r<t.coordinates[n].length-1;r++)if(jsonOdm.Geo.edgeWithinPolygon([t.coordinates[n][r],t.coordinates[n][r+1]],e.coordinates[o][0])&&r+1==t.coordinates[n].length-1){i=!0;break}if(!i)return!1}return!0}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiLineString.within(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)for(n=0;n<t.coordinates[o].length;n++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[o][n],e))return!1;return!0},jsonOdm.Geo.MultiLineString.intersects=function(t,e){var o,n,r;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type)return jsonOdm.Geo.MultiPoint.intersects(e,t);if("LineString"==e.type)return jsonOdm.Geo.LineString.intersects(e,t);if("MultiLineString"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(r=0;t.coordinates[n]&&r<t.coordinates[n].length-1;r++)for(o=0;e.coordinates&&o<e.coordinates.length;o++)if(jsonOdm.Geo.edgeIntersectsLineString([t.coordinates[n][r],t.coordinates[n][r+1]],e.coordinates[o]))return!0;return!1}if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;t.coordinates&&n<t.coordinates[o].length-1;n++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[o][n],t.coordinates[o][n+1]],e.coordinates[0]))return!0;return!1}if("MultiPolygon"==e.type){for(n=0;t.coordinates&&n<t.coordinates.length;n++)for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(r=0;t.coordinates[n]&&r<t.coordinates[n].length-1;r++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[n][r],t.coordinates[n][r+1]],e.coordinates[o][0]))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiLineString.intersects(t,e.geometries[o]))return!0;return!1}for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;n<t.coordinates[o].length-1;n++)if(jsonOdm.Geo.edgeIntersectsBounds([t.coordinates[o][n],t.coordinates[o][n+1]],e))return!0;return!1},jsonOdm.Geo.Polygon=function(t,e){this.type="Polygon",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.Polygon.within=function(t,e){var o,n;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type||"MultiPoint"==e.type||"LineString"==e.type||"MultiLineString"==e.type)return!1;if("Polygon"==e.type){for(o=0;t.coordinates[0]&&o<t.coordinates[0].length-1;o++)if(!jsonOdm.Geo.edgeWithinPolygon([t.coordinates[0][o],t.coordinates[0][o+1]],e.coordinates[0]))return!1;return!0}if("MultiPolygon"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;t.coordinates[0]&&n<t.coordinates[0].length-1;n++){var r=jsonOdm.Geo.edgeWithinPolygon([t.coordinates[0][n],t.coordinates[0][n+1]],e.coordinates[o][0]);if(!r)break;if(r&&n+1==t.coordinates[0].length-1)return!0}return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.Polygon.within(t,e.geometries[o]))return!0;return!1}for(o=0;t.coordinates[0]&&o<t.coordinates[0].length;o++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[0][o],e))return!1;return!0},jsonOdm.Geo.Polygon.intersects=function(t,e){var o,n;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type)return jsonOdm.Geo.MultiPoint.intersects(e,t);if("LineString"==e.type)return jsonOdm.Geo.LineString.intersects(e,t);if("MultiLineString"==e.type)return jsonOdm.Geo.MultiLineString.intersects(e,t);if("Polygon"==e.type){for(o=0;t.coordinates[0]&&o<t.coordinates[0].length-1;o++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[0][o],t.coordinates[0][o+1]],e.coordinates[0]))return!0;return!1}if("MultiPolygon"==e.type){for(o=0;e.coordinates&&o<e.coordinates.length;o++)for(n=0;t.coordinates[0]&&n<t.coordinates[0].length-1;n++)if(jsonOdm.Geo.edgeIntersectsPolygon([t.coordinates[0][n],t.coordinates[0][n+1]],e.coordinates[o][0]))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.Polygon.intersects(t,e.geometries[o]))return!0;return!1}for(o=0;t.coordinates[0]&&o<t.coordinates[0].length-1;o++)if(jsonOdm.Geo.edgeIntersectsBounds([t.coordinates[0][o],t.coordinates[0][o+1]],e))return!0;return!1},jsonOdm.Geo.MultiPolygon=function(t,e){this.type="MultiPolygon",this.coordinates=t,e&&(this.bbox=e)},jsonOdm.Geo.MultiPolygon.within=function(t,e){var o,n,r,i;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type||"MultiPoint"==e.type||"LineString"==e.type||"MultiLineString"==e.type)return!1;if("Polygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;n<t.coordinates[o][0].length-1;n++)if(!jsonOdm.Geo.edgeWithinPolygon([t.coordinates[o][0][n],t.coordinates[o][0][n+1]],e.coordinates[0]))return!1;return!0}if("MultiPolygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++){for(i=!1,n=0;e.coordinates&&n<e.coordinates.length;n++)for(r=0;t.coordinates[o][0]&&r<t.coordinates[o][0].length-1;r++){var s=jsonOdm.Geo.edgeWithinPolygon([t.coordinates[o][0][r],t.coordinates[o][0][r+1]],e.coordinates[n][0]);if(!s)break;if(s&&r+1==t.coordinates[o][0].length-1){i=!0;break}}if(!i)return!1}return!0}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiPolygon.within(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)for(n=0;n<t.coordinates[o][0].length;n++)if(!jsonOdm.Geo.pointWithinBounds(t.coordinates[o][0][n],e))return!1;return!0},jsonOdm.Geo.MultiPolygon.intersects=function(t,e){var o,n,r;if(!t.coordinates||!jsonOdm.util.isArray(t.coordinates))return!1;if("Point"==e.type)return jsonOdm.Geo.Point.intersects(e,t);if("MultiPoint"==e.type)return jsonOdm.Geo.MultiPoint.intersects(e,t);if("LineString"==e.type)return jsonOdm.Geo.LineString.intersects(e,t);if("MultiLineString"==e.type)return jsonOdm.Geo.MultiLineString.intersects(e,t);if("Polygon"==e.type)return jsonOdm.Geo.Polygon.intersects(e,t);if("MultiPolygon"==e.type){for(o=0;t.coordinates&&o<t.coordinates.length;o++)for(n=0;e.coordinates&&n<e.coordinates.length;n++)for(r=0;t.coordinates[o][0]&&r<t.coordinates[o][0].length-1;r++)if(jsonOdm.Geo.pointWithinPolygon(t.coordinates[o][0][r],e.coordinates[n][0]))return!0;return!1}if("GeometryCollection"==e.type&&jsonOdm.util.isArray(e.geometries)){for(o=0;o<e.geometries.length;o++)if(jsonOdm.Geo.MultiPolygon.intersects(t,e.geometries[o]))return!0;return!1}for(o=0;o<t.coordinates.length;o++)for(n=0;n<t.coordinates[o][0].length-1;n++)if(jsonOdm.Geo.edgeIntersectsBounds([t.coordinates[o][0][n],t.coordinates[o][0][n+1]],e))return!0;return!1},jsonOdm.Geo.GeometryCollection=function(t,e){this.type="GeometryCollection",this.geometries=t,e&&(this.bbox=e)},jsonOdm.Geo.GeometryCollection.within=function(t,e){if(!jsonOdm.util.isArray(t.geometries)||!t.geometries.length||!e.type)return!1;for(var o=0;o<t.geometries.length;o++){if(!jsonOdm.Geo[t.geometries[o].type]||!jsonOdm.Geo[t.geometries[o].type].within)return!1;if(!jsonOdm.Geo[t.geometries[o].type].within(t.geometries[o],e))return!1}return!0},jsonOdm.Geo.GeometryCollection.intersects=function(t,e){if(!jsonOdm.util.isArray(t.geometries)||!t.geometries.length||!e.type)return!1;for(var o=0;o<t.geometries.length;o++)if(jsonOdm.Geo[t.geometries[o].type]&&jsonOdm.Geo[t.geometries[o].type].intersects&&jsonOdm.Geo[t.geometries[o].type].intersects(t.geometries[o],e))return!0;return!1},jsonOdm.Geo.pointWithinPolygon=function(t,e){if(!(jsonOdm.util.isArray(t)&&jsonOdm.util.isArray(e)&&e.length>2))return!1;var o,n=0;(e[0][0]!=e[e.length-1][0]||e[0][1]!=e[e.length-1][1])&&(e=e.concat([e[0]]));for(var r=0;r<e.length-1;r++){if(e[r][0]==t[0]&&e[r][1]==t[1])return!0;if(!(e[r][0]<t[0]&&e[r+1][0]<t[0]||e[r][1]<t[1]&&e[r+1][1]<t[1]||e[r][1]>t[1]&&e[r+1][1]>t[1])){if(o=(e[r][0]-e[r+1][0])*((t[1]-e[r+1][1])/(e[r][1]-e[r+1][1]))+e[r+1][0],o==t[0]&&t[1]<=Math.max(e[r][1],e[r+1][1])&&t[1]>=Math.min(e[r][1],e[r+1][1]))return!0;o>t[0]&&n++}}return n%2==1},jsonOdm.Geo.edgeWithinPolygon=function(t,e){if(!(jsonOdm.util.isArray(t)&&2==t.length&&jsonOdm.util.isArray(e)&&e.length>=2))return!1;if((e[0][0]!=e[e.length-1][0]||e[0][1]!=e[e.length-1][1])&&(e=e.concat([e[0]])),!jsonOdm.Geo.pointWithinPolygon(t[0],e)||!jsonOdm.Geo.pointWithinPolygon(t[1],e))return!1;for(var o=0;o<e.length-1;o++)if(jsonOdm.Geo.edgeIntersectsEdge(t,[e[o],e[o+1]],!1))return!1;return!0},jsonOdm.Geo.edgeIntersectsPolygon=function(t,e){if(!(jsonOdm.util.isArray(t)&&2==t.length&&jsonOdm.util.isArray(e)&&e.length>=2))return!1;if((e[0][0]!=e[e.length-1][0]||e[0][1]!=e[e.length-1][1])&&(e=e.concat([e[0]])),jsonOdm.Geo.pointWithinPolygon(t[0],e)||jsonOdm.Geo.pointWithinPolygon(t[1],e))return!0;for(var o=0;o<e.length-1;o++)if(jsonOdm.Geo.edgeIntersectsEdge(t,[e[o],e[o+1]]))return!0;return!1},jsonOdm.Geo.edgeIntersectsLineString=function(t,e){if(!jsonOdm.util.isArray(t)||2!=t.length||!jsonOdm.util.isArray(e))return!1;for(var o=0;o<e.length-1;o++)if(jsonOdm.Geo.edgeIntersectsEdge(t,[e[o],e[o+1]]))return!0;return!1},jsonOdm.Geo.edgeIntersectsEdge=function(t,e,o){o="undefined"==typeof o?!0:o;var n=[t[1][0]-t[0][0],t[1][1]-t[0][1]],r=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])],i=[e[1][0]-e[0][0],e[1][1]-e[0][1]],s=[Math.min(e[0][0],e[1][0]),Math.min(e[0][1],e[1][1]),Math.max(e[0][0],e[1][0]),Math.max(e[0][1],e[1][1])];if(r[0]>s[0]&&r[0]>s[2]||r[1]>s[1]&&r[1]>s[3]||s[0]>r[0]&&s[0]>r[2]||s[1]>r[1]&&s[1]>r[3])return!1;if(i[0]*n[1]-n[0]*i[1]==0)return o&&t[0][1]+(e[0][0]-t[0][0])/n[0]*n[1]==e[0][1];var u=(e[0][1]*i[0]+t[0][0]*i[1]-e[0][0]*i[1]-t[0][1]*i[0])/(n[1]*i[0]-n[0]*i[1]),d=t[0][0]+u*n[0],c=t[0][1]+u*n[1];return o?d>=r[0]&&d<=r[2]&&c>=r[1]&&c<=r[3]&&d>=s[0]&&d<=s[2]&&c>=s[1]&&c<=s[3]:d>r[0]&&d<r[2]&&c>r[1]&&c<r[3]&&d>s[0]&&d<s[2]&&c>s[1]&&c<s[3]},jsonOdm.Geo.pointWithinLineString=function(t,e){if(!(jsonOdm.util.isArray(t)&&jsonOdm.util.isArray(e)&&e.length>=2))return!1;for(var o=0;o<e.length-1;o++)if((t[0]>=e[o][0]&&t[0]<=e[o+1][0]&&e[o][0]<=e[o+1][0]||t[0]<=e[o][0]&&t[0]>=e[o+1][0]&&e[o][0]>=e[o+1][0])&&(t[1]>=e[o][1]&&t[1]<=e[o+1][1]&&e[o][1]<=e[o+1][1]||t[1]<=e[o][1]&&t[1]>=e[o+1][1]&&e[o][1]>=e[o+1][1])&&(e[o][0]==t[0]&&e[o][1]==t[1]||e[o+1][0]==t[0]&&e[o+1][1]==t[1]||e[o][1]-e[o+1][1]!=0&&(e[o][0]-e[o+1][0])*((t[1]-e[o+1][1])/(e[o][1]-e[o+1][1]))+e[o+1][0]==t[0]||e[o][0]-e[o+1][0]!=0&&(e[o][1]-e[o+1][1])*((t[0]-e[o+1][0])/(e[o][0]-e[o+1][0]))+e[o+1][1]==t[1]))return!0;return!1},jsonOdm.Geo.pointWithinBounds=function(t,e){return jsonOdm.util.isArray(t)&&jsonOdm.util.isArray(e)&&4==e.length?t[0]>=e[0]&&t[1]>=e[1]&&t[0]<=e[2]&&t[1]<=e[3]:!1},jsonOdm.Geo.edgeIntersectsBounds=function(t,e){return jsonOdm.util.isArray(t)&&jsonOdm.util.isArray(e)&&4==e.length?jsonOdm.Geo.edgeIntersectsPolygon(t,[[e[0],e[1]],[e[2],e[1]],[e[2],e[3]],[e[0],e[3]]]):!1},jsonOdm.Geo.lineStringWithinLineString=function(t,e){if(!jsonOdm.util.isArray(t)||!jsonOdm.util.isArray(e))return!1;var o,n;for(o=0;t&&o<t.length;o++){var r=!1;for(n=0;e&&n<e.length;n++)if(t[o][0]==e[n][0]&&t[o][1]==e[n][1]){if(o+1==t.length)return!0;if(!(e[n+1]&&t[o+1][0]==e[n+1][0]&&t[o+1][1]==e[n+1][1]||t[o+1][0]==e[n][0]&&t[o+1][1]==e[n][1]||n>0&&t[o+1][0]==e[n-1][0]&&t[o+1][1]==e[n-1][1]))return!1;r=!0}if(!r)return!1}return!0},jsonOdm.Collection=function(t){var e=Object.create(Array.prototype);return e=Array.apply(e)||e,"undefined"!=typeof t&&jsonOdm.selectedSource&&jsonOdm.selectedSource[t]&&(e=e.concat(jsonOdm.selectedSource[t])),jsonOdm.Collection.decorate(e),e.$branch=function(){var t=jsonOdm.util.branch(e,arguments);return jsonOdm.Collection.decorate(t),t},e},jsonOdm.Collection.decorate=function(t){var e=function(t){jsonOdm.util.isArray(t)&&(t.$hasMany=function(e,o,n,r){"string"==typeof n&&(r=r||n);var i=n;"string"==typeof n&&jsonOdm.selectedSource&&jsonOdm.selectedSource[n]&&(i=jsonOdm.selectedSource[n]);for(var s=0;s<t.length;s++){var u=e;if(t[s].hasOwnProperty(e)&&(u=t[s][e]),"undefined"==typeof t[s][r])for(var d=0;u.length&&d<u.length;d++){for(var c=null,a=0;a<i.length;a++)if(u[d]==i[a][o]){c=i[a];break}null!=c&&(t[s][r]||(t[s][r]=[]),t[s][r].push(c))}}},t.$hasOne=function(e,o,n,r){"string"==typeof n&&(r=r||n);var i=n;"string"==typeof n&&jsonOdm.selectedSource&&jsonOdm.selectedSource[n]&&(i=jsonOdm.selectedSource[n]);for(var s=0;s<t.length;s++){var u;if(t[s].hasOwnProperty(e)&&(u=t[s][e]),"undefined"==typeof t[s][r]){for(var d=null,c=0;c<i.length;c++)if(u==i[c][o]){d=i[c];break}null!=d&&(t[s][r]=d)}}},t.$query=function(){return new jsonOdm.Query(t)})};e(t)},jsonOdm.Query=function(t){this.$$commandQueue=[],this.$$aggregationBeforeCollectQueue=[],this.$$aggregationResultQueue=[],this.$$collection=t||[]},jsonOdm.Query.prototype.$delete=function(){if(this.$$commandQueue.length<1)return this;for(var t=0;t<this.$$collection.length;){for(var e=!0,o=0;o<this.$$commandQueue.length&&(e=e&&this.$$commandQueue[o](this.$$collection[t]));o++);e?this.$$collection.splice(t,1):t++}return this},jsonOdm.Query.prototype.$result=function(t,e){if(this.$$commandQueue.length<1&&this.$$aggregationBeforeCollectQueue<1)return this.$$collection;t="undefined"==typeof t?0:t,e="undefined"==typeof e?this.$$collection.length:e;var o,n,r,i=new jsonOdm.Collection;for(n=0;n<this.$$collection.length;n++){var s=!0;for(r=0;r<this.$$commandQueue.length&&(s=s&&this.$$commandQueue[r](this.$$collection[n]));r++);if(s){if(t>0){t--;continue}if(0>=e)return i;for(o=this.$$collection[n],r=0;r<this.$$aggregationBeforeCollectQueue.length;r++)o=this.$$aggregationBeforeCollectQueue[r](n,o);i.push(o),e--}}for(n=0;n<this.$$aggregationResultQueue.length;n++)i=this.$$aggregationResultQueue[n](i);return i},jsonOdm.Query.prototype.$all=function(){return this.$result()},jsonOdm.Query.prototype.$first=function(){return this.$result(0,1)[0]},jsonOdm.Query.prototype.$aggregateCollection=function(t,e,o){return"function"==typeof t&&(t=[t]),"function"==typeof e&&(e=[e]),"function"==typeof o&&(o=[o]),jsonOdm.util.isArray(t)&&(this.$$commandQueue=this.$$commandQueue.concat(t)),jsonOdm.util.isArray(e)&&(this.$$aggregationBeforeCollectQueue=this.$$aggregationBeforeCollectQueue.concat(e)),jsonOdm.util.isArray(o)&&(this.$$aggregationResultQueue=this.$$aggregationResultQueue.concat(o)),this},jsonOdm.Query.prototype.$project=function(t){return this.$aggregateCollection(null,function(e,o){return jsonOdm.util.projectElement(t,o)})},jsonOdm.Query.prototype.$testCollection=function(t,e){var o=this.$$commandQueue.pop(),n=function(){return function(n){if(!(o instanceof jsonOdm.Collection||"function"==typeof o||"undefined"==typeof o)||"function"!=typeof e)return!1;var r="undefined"==typeof o?n:o instanceof jsonOdm.Collection?o:o(n);return!!e(r,t)}}();return this.$$commandQueue.push(n),this},jsonOdm.Query.prototype.$binaryOperator=function(t,e){var o=function(t,o){return function(n){if("function"!=typeof o)return!1;for(var r=[],i=0;i<t.length;i++)for(var s=0;s<t[i].$$commandQueue.length;s++)r.push(t[i].$$commandQueue[s](n));return!!e(r)}}(t,e),n=new jsonOdm.Query(this.$$collection);return n.$$commandQueue.push(o),n},jsonOdm.Query.prototype.$branch=function(){var t=function(t){return function(e){return jsonOdm.util.branch(e,t)}}(arguments),e=new jsonOdm.Query(this.$$collection);return e.$$commandQueue.push(t),e},jsonOdm.Query.prototype.$modifyField=function(t){var e=function(t,e){return function(o){return o=null!==e?e(o):o,"function"==typeof t?t(o):o}}(t,this.$$commandQueue.length?this.$$commandQueue[this.$$commandQueue.length-1]:null);return this.$$commandQueue.push(e),this},jsonOdm.Query.stringFiledModifyer=["charAt","charCodeAt","concat","fromCharCode","indexOf","lastIndexOf","localeCompare","match","replace","search","slice","split","substr","substring","toLocaleLowerCase","toLocaleUpperCase","toLowerCase","toUpperCase","trim","valueOf"];for(var i=0;i<jsonOdm.Query.stringFiledModifyer.length;i++)jsonOdm.Query.prototype["$"+jsonOdm.Query.stringFiledModifyer[i]]=function(t){return function(){return this.$modifyField(function(t,e){return function(o){return"string"==typeof o&&String.prototype.hasOwnProperty(e)?String.prototype[e].apply(o,t):o}}(arguments,t))}}(jsonOdm.Query.stringFiledModifyer[i]);jsonOdm.Query.prototype.$eq=function(){return this.$testCollection(arguments,function(t,e){for(var o=0;o<e.length;o++)if(e[o]==t)return!0;return!1})},jsonOdm.Query.prototype.$in=function(t){return this.$testCollection(t,function(t,e){for(var o=0;o<e.length;o++)if(e[o]==t)return!0;return!1})},jsonOdm.Query.prototype.$ne=function(){return this.$testCollection(arguments,function(t,e){for(var o=0;o<e.length;o++)if(e[o]==t)return!1;return!0})},jsonOdm.Query.prototype.$nin=function(t){return this.$testCollection(t,function(t,e){for(var o=0;o<e.length;o++)if(e[o]==t)return!1;return!0})},jsonOdm.Query.prototype.$gt=function(t){return this.$testCollection(t,function(t,e){return t>e})},jsonOdm.Query.prototype.$gte=function(t){return this.$testCollection(t,function(t,e){return t>=e})},jsonOdm.Query.prototype.$lt=function(t){return this.$testCollection(t,function(t,e){return e>t})},jsonOdm.Query.prototype.$lte=function(t){return this.$testCollection(t,function(t,e){return e>=t})},jsonOdm.Query.prototype.$isNull=function(){return this.$testCollection(null,function(t){return"undefined"==typeof t||null===t})},jsonOdm.Query.prototype.$exists=function(){return this.$testCollection(null,function(t){return"undefined"!=typeof t})},jsonOdm.Query.prototype.$type=function(){return this.$testCollection(arguments,function(t,e){return jsonOdm.util.is(t,e)})},jsonOdm.Query.prototype.$mod=function(){return this.$testCollection(arguments,function(t,e){return t%e[0]==e[1]})},jsonOdm.Query.prototype.$regex=function(t,e){return"string"==typeof t&&(t="string"==typeof e?new RegExp(t,e):new RegExp(t)),this.$testCollection(t,function(t,e){return e.test(t)})},jsonOdm.Query.prototype.$text=function(t){for(var e,o,n=/(^| )-([^ ]+)( |$)/g,r=/"([^"]+)"/g,i=[],s=[];null!==(e=n.exec(t));)i.push(e[2]);for(t=t.replace(n,"");null!==(o=r.exec(t));)s.push(o[1]);t=t.replace(r,"");var u=t.split(" ");return this.$testCollection([i,s,u],function(t,e){for(var o=0;o<e[0].length;o++)if(t.indexOf(e[0][o])>-1)return!1;for(o=0;o<e[1].length;o++)if(t.indexOf(e[1][o])<0)return!1;for(o=0;o<e[2].length;o++)if(t.indexOf(e[2][o])>-1)return!0;return!!e[1].length})},jsonOdm.Query.prototype.$where=function(t){return"string"==typeof t&&(t=new Function(t)),this.$testCollection(t,function(t,e){return"function"!=typeof e?!1:e.apply(t)})},jsonOdm.Query.prototype.$geoWithin=function(t){return this.$testCollection(jsonOdm.Geo.detectAsGeometry(t),function(t,e){return jsonOdm.Geo[t.type]&&jsonOdm.Geo[t.type].within&&jsonOdm.Geo[t.type].within(t,e)})},jsonOdm.Query.prototype.$geoIntersects=function(t){return this.$testCollection(jsonOdm.Geo.detectAsGeometry(t),function(t,e){return jsonOdm.Geo[t.type]&&jsonOdm.Geo[t.type].intersects&&jsonOdm.Geo[t.type].intersects(t,e)})},jsonOdm.Query.prototype.$and=function(){return this.$binaryOperator(arguments,function(t){for(var e=0;e<t.length;e++)if(!t[e])return!1;return!0})},jsonOdm.Query.prototype.$nand=function(){return this.$binaryOperator(arguments,function(t){for(var e=0;e<t.length;e++)if(!t[e])return!0;return!1})},jsonOdm.Query.prototype.$not=jsonOdm.Query.prototype.$nand,jsonOdm.Query.prototype.$or=function(){return this.$binaryOperator(arguments,function(t){for(var e=0;e<t.length;e++)if(t[e])return!0;return!1})},jsonOdm.Query.prototype.$nor=function(){return this.$binaryOperator(arguments,function(t){for(var e=0;e<t.length;e++)if(t[e])return!1;return!0})}; |
@@ -26,3 +26,3 @@ "use strict"; | ||
description:"A light weight but fast object document mapper for JavaScript objects.", | ||
version:"0.1.2" | ||
version:"0.1.3" | ||
}, "jsonOdm")) | ||
@@ -29,0 +29,0 @@ .pipe(jsdoc.generator('./doc', |
{ | ||
"name": "json-odm", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Object document mapper for JSON data that provides mongodb methods for querying and transformation as well as additional joining that is not provided by mongodb", | ||
@@ -5,0 +5,0 @@ "main": " ./bin/json.odm.min.js", |
@@ -30,5 +30,7 @@ JSON ODM v0.1.2 | ||
- Array ($all,$elementMatch,$size) 0% // i may not implement the first two | ||
- Projection Operators ($,$elemMatch,$meta,$slice) 5% in experimental state | ||
- Aggregation | ||
- Pipeline (~~$project~~,$match,$redact,~~$limit~~,~~$skip~~,$unwind,$group,$sort,$geoNear,$out) 30% ($limit and $skip is implemented as $result(skip,limit)) | ||
- Operators (Boolean,Set,Comparison,Arithmetic,~~String~~,Array,Date,Conditional,Variable,Grouping) 10% | ||
- Support Promise/A+ sources for the odm.addSource | ||
- Full ~~CR~~U~~D~~ support | ||
- Full CRUD support | ||
- Aggregation | ||
@@ -35,0 +37,0 @@ |
@@ -293,2 +293,24 @@ "use strict"; | ||
CollectionTest.prototype.testProjection = function () { | ||
var collection = new jsonOdm.Collection("goldenRuleCollection"), | ||
query = collection.$query(); | ||
var projected = query.$project({ | ||
concat: function (element) { | ||
return element.id + element.lang | ||
}, | ||
firstFour : query.$branch("cite").$substr(0,4), | ||
firstTen : query.$branch("cite").$substr(0,10), | ||
lang:1, | ||
language:query.$branch("lang") | ||
}).$all(); | ||
assertEquals("Should have concat id and language",collection[0].id+collection[0].lang,projected[0].concat); | ||
assertEquals("Should have the first four cite letters",collection[0].cite.substr(0,4),projected[0].firstFour); | ||
assertEquals("Should have the first four cite letters",collection[5].cite.substr(0,4),projected[5].firstFour); | ||
assertEquals("Should have the first ten cite letters",collection[5].cite.substr(0,10),projected[5].firstTen); | ||
assertEquals("Should have the lang","en",projected[5].lang); | ||
assertEquals("Should have the lang equal to language",projected[5].language,projected[5].lang); | ||
assertUndefined("Should not have a cite field",projected[5].cite); | ||
assertUndefined("Should not have a id field",projected[5].id); | ||
}; | ||
CollectionTest.prototype.testTextSearch = function() { | ||
@@ -295,0 +317,0 @@ var collection = new jsonOdm.Collection("goldenRuleCollection"); |
@@ -5,3 +5,3 @@ "use strict"; | ||
* The query object that holds the collection to be queried | ||
* @param {jsonOdm.Collection} collection | ||
* @param {jsonOdm.Collection} [collection] | ||
* @constructor | ||
@@ -27,3 +27,3 @@ * @example //This example shows how to query a collection | ||
this.$$aggregationResultQueue = []; | ||
this.$$collection = collection; | ||
this.$$collection = collection || []; | ||
}; | ||
@@ -59,3 +59,8 @@ | ||
/** | ||
* Returns a collection containing all matching elements within a certain range | ||
* Returns a collection containing all matching elements within the given range | ||
* @example | ||
* var collection = new jsonOdm.Collection("myCollection"); | ||
* collection.$query() | ||
* .$branch("id").$eq(2,9) | ||
* .$result(1,3); | ||
* @param {int} [start] return a subset starting at n; default = 0 | ||
@@ -66,3 +71,3 @@ * @param {int} [length] return a subset with the length n; default = collection length | ||
jsonOdm.Query.prototype.$result = function (start,length) { | ||
if(this.$$commandQueue.length < 1) return this.$$collection; | ||
if(this.$$commandQueue.length < 1 && this.$$aggregationBeforeCollectQueue < 1) return this.$$collection; | ||
start = typeof start == "undefined" ? 0 : start; | ||
@@ -84,5 +89,6 @@ length = typeof length == "undefined" ? this.$$collection.length : length; | ||
if(length <= 0){return filterCollection} | ||
resultingElement = this.$$collection[i]; | ||
for(j = 0; j < this.$$aggregationBeforeCollectQueue.length; j++){ | ||
resultingElement = this.$$aggregationBeforeCollectQueue[j](resultingElement); | ||
resultingElement = this.$$aggregationBeforeCollectQueue[j](i,resultingElement); | ||
} | ||
@@ -93,2 +99,5 @@ filterCollection.push(resultingElement); | ||
} | ||
for(i = 0; i < this.$$aggregationResultQueue.length; i++){ | ||
filterCollection = this.$$aggregationResultQueue[i](filterCollection); | ||
} | ||
return filterCollection; | ||
@@ -121,22 +130,45 @@ }; | ||
/** | ||
* | ||
* Helper method for aggregation methods | ||
* @param {function[]|function} afterValidation Push into the query queue after all commands have been executed. Returning false will result in a skip of this value | ||
* @param {function[]|function} [beforeCollect] Push into the before collect queue to change or replace the collection element | ||
* @param {function[]|function} [aggregation] If the result of the whole aggregation changes, i.e. for searching | ||
* @param {function[]|function} [aggregation] If the result of the whole aggregation changes, i.e. for searching, or ordering | ||
* @return {jsonOdm.Query} | ||
*/ | ||
jsonOdm.Query.prototype.$aggregateCollection = function (afterValidation,beforeCollect,aggregation) { | ||
var i; | ||
if(typeof afterValidation == "function") afterValidation = [afterValidation]; | ||
if(typeof beforeCollect == "function") beforeCollect = [beforeCollect]; | ||
if(typeof aggregation == "function") aggregation = [aggregation]; | ||
if(jsonOdm.util.isArray(afterValidation)){ | ||
this.$$commandQueue = this.$$commandQueue.concat(afterValidation); | ||
} | ||
if(jsonOdm.util.isArray(beforeCollect)){ | ||
this.$$aggregationBeforeCollectQueue = this.$$aggregationBeforeCollectQueue.concat(beforeCollect); | ||
} | ||
if(jsonOdm.util.isArray(aggregation)){ | ||
this.$$aggregationResultQueue = this.$$aggregationResultQueue.concat(aggregation); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Projects all elements of the collection into a given schema | ||
* @param {*} projection The projection definition with nested definitions | ||
* @return jsonOdm.Query | ||
* @example | ||
* var collection = new jsonOdm.Collection("myCollection"); | ||
* var collection = new jsonOdm.Collection("myBooks"); | ||
* var $query = collection.$query() | ||
* .$branch("id").$gt(12) // querying | ||
* .$branch("id").$gt(12) // query before project | ||
* .$project({ | ||
* "name" : 1, | ||
* "value" : 1, | ||
* "newValue" : $query.$branch("name").$subString(0,4) // should return a function | ||
* }).$group("name").$orderBy("id","ASC") | ||
* title: 1, | ||
* isbn: { | ||
* prefix: $query.$branch("isbn").$subString(0,3), | ||
* group: $query.$branch("isbn").$subString(3,2), | ||
* publisher: $query.$branch("isbn").$subString(5,4), | ||
* title: $query.$branch("isbn").$subString(9,3), | ||
* checkDigit: $query.$branch("isbn").$subString(12,1) | ||
* }, | ||
* lastName: function(element){return element.author.last}, // functions can be used as well | ||
* copiesSold: $query.$branch("copies") | ||
* }) | ||
* | ||
@@ -147,3 +179,3 @@ */ | ||
return jsonOdm.util.projectElement(projection,element) | ||
}) | ||
}); | ||
}; | ||
@@ -219,3 +251,3 @@ | ||
jsonOdm.Query.prototype.$modifyField = function (modifier) { | ||
var $subStr = (function(modifier,lastCommand){ | ||
var $modifyer = (function(modifier,lastCommand){ | ||
/** | ||
@@ -230,18 +262,31 @@ * @param {*} The collection to go down | ||
})(modifier,this.$$commandQueue.length?this.$$commandQueue[this.$$commandQueue.length-1]:null); | ||
this.$$commandQueue.push($subStr); | ||
this.$$commandQueue.push($modifyer); | ||
return this; | ||
}; | ||
/** A wrapper for the native String.substr method | ||
* @param {Number} start Index of the first character | ||
* @param {Number} length Length of the resulting string | ||
/** A generation for all native String.prototype methods to make them available via $modifyField <br/> | ||
* Supported Methods are: "charAt", "charCodeAt", "concat", "fromCharCode", "indexOf", "lastIndexOf", "localeCompare", "match", "replace", "search", "slice", "split", "substr", "substring", "toLocaleLowerCase", "toLocaleUpperCase", "toLowerCase", "toUpperCase", "trim", "valueOf" | ||
* @param {*} [args] The string methods parameter | ||
* @return {jsonOdm.Query} | ||
* @method StringPrototype | ||
* @memberof jsonOdm.Query.prototype | ||
* @example | ||
* var collection = new jsonOdm.Collection("myCollection"); | ||
* var $query = collection.$query(); | ||
* $query.$branch("explosionBy").$trim().$substr(0,3).$toUpperCase().$eq("TNT").$all(); | ||
*/ | ||
jsonOdm.Query.prototype.$substr = function (start,length) { | ||
return this.$modifyField((function (start, length) { | ||
return function (value) { | ||
return typeof value == "string"?value.substr(start,length):value; | ||
jsonOdm.Query.stringFiledModifyer = ["charAt","charCodeAt","concat","fromCharCode","indexOf","lastIndexOf","localeCompare","match","replace","search","slice","split","substr","substring","toLocaleLowerCase","toLocaleUpperCase","toLowerCase","toUpperCase","trim","valueOf"]; | ||
for(var i = 0; i < jsonOdm.Query.stringFiledModifyer.length; i++){ | ||
jsonOdm.Query.prototype["$"+jsonOdm.Query.stringFiledModifyer[i]] = ( | ||
function (modifyer) { | ||
return function () { | ||
return this.$modifyField((function (args,modifyer) { | ||
return function (value) { | ||
return typeof value == "string" && String.prototype.hasOwnProperty(modifyer)?String.prototype[modifyer].apply(value,args):value; | ||
} | ||
})(arguments,modifyer)) | ||
} | ||
} | ||
})(start, length)); | ||
}; | ||
)(jsonOdm.Query.stringFiledModifyer[i]); | ||
} | ||
@@ -248,0 +293,0 @@ /** |
@@ -121,2 +121,3 @@ "use strict"; | ||
* key12:function(element){return element.key1 + element.key2} | ||
* // only field modifying queries are allowed | ||
* key2:collection.$query.$branch("key2").$substr(0,3) | ||
@@ -135,5 +136,3 @@ * }) | ||
}else if(projection[key] instanceof jsonOdm.Query){ | ||
for(i = 0; i < projection[key].$$commandQueue.length; i++ ){ | ||
projectionResult[key] = projection[key].$$commandQueue[i](i===0 ? element : projectionResult[key]); | ||
} | ||
projectionResult[key] = projection[key].$$commandQueue[projection[key].$$commandQueue.length-1](element); | ||
}else if(typeof projection[key] === 'object'){ | ||
@@ -140,0 +139,0 @@ projectionResult[key] = this.projectElement(projection[key],element[key],parentElement || element); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
2095508
9376
117