123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.GeojsonEquality=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
- //index.js
- var deepEqual = require('deep-equal');
- var Equality = function(opt) {
- this.precision = opt && opt.precision ? opt.precision : 17;
- this.direction = opt && opt.direction ? opt.direction : false;
- this.pseudoNode = opt && opt.pseudoNode ? opt.pseudoNode : false;
- this.objectComparator = opt && opt.objectComparator ? opt.objectComparator : objectComparator;
- };
- Equality.prototype.compare = function(g1,g2) {
- if (g1.type !== g2.type || !sameLength(g1,g2)) return false;
- switch(g1.type) {
- case 'Point':
- return this.compareCoord(g1.coordinates, g2.coordinates);
- break;
- case 'LineString':
- return this.compareLine(g1.coordinates, g2.coordinates,0,false);
- break;
- case 'Polygon':
- return this.comparePolygon(g1,g2);
- break;
- case 'Feature':
- return this.compareFeature(g1, g2);
- default:
- if (g1.type.indexOf('Multi') === 0) {
- var context = this;
- var g1s = explode(g1);
- var g2s = explode(g2);
- return g1s.every(function(g1part) {
- return this.some(function(g2part) {
- return context.compare(g1part,g2part);
- });
- },g2s);
- }
- }
- return false;
- };
- function explode(g) {
- return g.coordinates.map(function(part) {
- return {
- type: g.type.replace('Multi', ''),
- coordinates: part}
- });
- }
- //compare length of coordinates/array
- function sameLength(g1,g2) {
- return g1.hasOwnProperty('coordinates') ?
- g1.coordinates.length === g2.coordinates.length
- : g1.length === g2.length;
- }
- // compare the two coordinates [x,y]
- Equality.prototype.compareCoord = function(c1,c2) {
- if (c1.length !== c2.length) {
- return false;
- }
- for (var i=0; i < c1.length; i++) {
- if (c1[i].toFixed(this.precision) !== c2[i].toFixed(this.precision)) {
- return false;
- }
- }
- return true;
- };
- Equality.prototype.compareLine = function(path1,path2,ind,isPoly) {
- if (!sameLength(path1,path2)) return false;
- var p1 = this.pseudoNode ? path1 : this.removePseudo(path1);
- var p2 = this.pseudoNode ? path2 : this.removePseudo(path2);
- if (isPoly && !this.compareCoord(p1[0],p2[0])) {
- // fix start index of both to same point
- p2 = this.fixStartIndex(p2,p1);
- if(!p2) return;
- }
- // for linestring ind =0 and for polygon ind =1
- var sameDirection = this.compareCoord(p1[ind],p2[ind]);
- if (this.direction || sameDirection
- ) {
- return this.comparePath(p1, p2);
- } else {
- if (this.compareCoord(p1[ind],p2[p2.length - (1+ind)])
- ) {
- return this.comparePath(p1.slice().reverse(), p2);
- }
- return false;
- }
- };
- Equality.prototype.fixStartIndex = function(sourcePath,targetPath) {
- //make sourcePath first point same as of targetPath
- var correctPath,ind = -1;
- for (var i=0; i< sourcePath.length; i++) {
- if(this.compareCoord(sourcePath[i],targetPath[0])) {
- ind = i;
- break;
- }
- }
- if (ind >= 0) {
- correctPath = [].concat(
- sourcePath.slice(ind,sourcePath.length),
- sourcePath.slice(1,ind+1));
- }
- return correctPath;
- };
- Equality.prototype.comparePath = function (p1,p2) {
- var cont = this;
- return p1.every(function(c,i) {
- return cont.compareCoord(c,this[i]);
- },p2);
- };
- Equality.prototype.comparePolygon = function(g1,g2) {
- if (this.compareLine(g1.coordinates[0],g2.coordinates[0],1,true)) {
- var holes1 = g1.coordinates.slice(1,g1.coordinates.length);
- var holes2 = g2.coordinates.slice(1,g2.coordinates.length);
- var cont = this;
- return holes1.every(function(h1) {
- return this.some(function(h2) {
- return cont.compareLine(h1,h2,1,true);
- });
- },holes2);
- } else {
- return false;
- }
- };
- Equality.prototype.compareFeature = function(g1,g2) {
- if (
- g1.id !== g2.id ||
- !this.objectComparator(g1.properties, g2.properties) ||
- !this.compareBBox(g1,g2)
- ) {
- return false;
- }
- return this.compare(g1.geometry, g2.geometry);
- };
- Equality.prototype.compareBBox = function(g1,g2) {
- if (
- (!g1.bbox && !g2.bbox) ||
- (
- g1.bbox && g2.bbox &&
- this.compareCoord(g1.bbox, g2.bbox)
- )
- ) {
- return true;
- }
- return false;
- };
- Equality.prototype.removePseudo = function(path) {
- //TODO to be implement
- return path;
- };
- function objectComparator(obj1, obj2) {
- return deepEqual(obj1, obj2, {strict: true});
- }
- module.exports = Equality;
- },{"deep-equal":2}],2:[function(require,module,exports){
- var pSlice = Array.prototype.slice;
- var objectKeys = require('./lib/keys.js');
- var isArguments = require('./lib/is_arguments.js');
- var deepEqual = module.exports = function (actual, expected, opts) {
- if (!opts) opts = {};
- // 7.1. All identical values are equivalent, as determined by ===.
- if (actual === expected) {
- return true;
- } else if (actual instanceof Date && expected instanceof Date) {
- return actual.getTime() === expected.getTime();
- // 7.3. Other pairs that do not both pass typeof value == 'object',
- // equivalence is determined by ==.
- } else if (typeof actual != 'object' && typeof expected != 'object') {
- return opts.strict ? actual === expected : actual == expected;
- // 7.4. For all other Object pairs, including Array objects, equivalence is
- // determined by having the same number of owned properties (as verified
- // with Object.prototype.hasOwnProperty.call), the same set of keys
- // (although not necessarily the same order), equivalent values for every
- // corresponding key, and an identical 'prototype' property. Note: this
- // accounts for both named and indexed properties on Arrays.
- } else {
- return objEquiv(actual, expected, opts);
- }
- }
- function isUndefinedOrNull(value) {
- return value === null || value === undefined;
- }
- function isBuffer (x) {
- if (!x || typeof x !== 'object' || typeof x.length !== 'number') return false;
- if (typeof x.copy !== 'function' || typeof x.slice !== 'function') {
- return false;
- }
- if (x.length > 0 && typeof x[0] !== 'number') return false;
- return true;
- }
- function objEquiv(a, b, opts) {
- var i, key;
- if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
- return false;
- // an identical 'prototype' property.
- if (a.prototype !== b.prototype) return false;
- //~~~I've managed to break Object.keys through screwy arguments passing.
- // Converting to array solves the problem.
- if (isArguments(a)) {
- if (!isArguments(b)) {
- return false;
- }
- a = pSlice.call(a);
- b = pSlice.call(b);
- return deepEqual(a, b, opts);
- }
- if (isBuffer(a)) {
- if (!isBuffer(b)) {
- return false;
- }
- if (a.length !== b.length) return false;
- for (i = 0; i < a.length; i++) {
- if (a[i] !== b[i]) return false;
- }
- return true;
- }
- try {
- var ka = objectKeys(a),
- kb = objectKeys(b);
- } catch (e) {//happens when one is a string literal and the other isn't
- return false;
- }
- // having the same number of owned properties (keys incorporates
- // hasOwnProperty)
- if (ka.length != kb.length)
- return false;
- //the same set of keys (although not necessarily the same order),
- ka.sort();
- kb.sort();
- //~~~cheap key test
- for (i = ka.length - 1; i >= 0; i--) {
- if (ka[i] != kb[i])
- return false;
- }
- //equivalent values for every corresponding key, and
- //~~~possibly expensive deep test
- for (i = ka.length - 1; i >= 0; i--) {
- key = ka[i];
- if (!deepEqual(a[key], b[key], opts)) return false;
- }
- return typeof a === typeof b;
- }
- },{"./lib/is_arguments.js":3,"./lib/keys.js":4}],3:[function(require,module,exports){
- var supportsArgumentsClass = (function(){
- return Object.prototype.toString.call(arguments)
- })() == '[object Arguments]';
- exports = module.exports = supportsArgumentsClass ? supported : unsupported;
- exports.supported = supported;
- function supported(object) {
- return Object.prototype.toString.call(object) == '[object Arguments]';
- };
- exports.unsupported = unsupported;
- function unsupported(object){
- return object &&
- typeof object == 'object' &&
- typeof object.length == 'number' &&
- Object.prototype.hasOwnProperty.call(object, 'callee') &&
- !Object.prototype.propertyIsEnumerable.call(object, 'callee') ||
- false;
- };
- },{}],4:[function(require,module,exports){
- exports = module.exports = typeof Object.keys === 'function'
- ? Object.keys : shim;
- exports.shim = shim;
- function shim (obj) {
- var keys = [];
- for (var key in obj) keys.push(key);
- return keys;
- }
- },{}]},{},[1])(1)
- });
- //# sourceMappingURL=geojson-equality.js.map
|