@opensystemslab/map 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
package/dist/map.es.js CHANGED
@@ -38,7 +38,7 @@ _d((function(t,e){!function(i){var n=e&&!e.nodeType&&e,r=t&&!t.nodeType&&t,o="ob
38
38
  * @license MIT
39
39
  * @preserve
40
40
  */
41
- var tm=function(t,e){this.next=null,this.key=t,this.data=e,this.left=null,this.right=null};function em(t,e){return t>e?1:t<e?-1:0}function im(t,e,i){for(var n=new tm(null,null),r=n,o=n;;){var s=i(t,e.key);if(s<0){if(null===e.left)break;if(i(t,e.left.key)<0){var a=e.left;if(e.left=a.right,a.right=e,null===(e=a).left)break}o.left=e,o=e,e=e.left}else{if(!(s>0))break;if(null===e.right)break;if(i(t,e.right.key)>0){a=e.right;if(e.right=a.left,a.left=e,null===(e=a).right)break}r.right=e,r=e,e=e.right}}return r.right=e.left,o.left=e.right,e.left=n.right,e.right=n.left,e}function nm(t,e,i,n){var r=new tm(t,e);if(null===i)return r.left=r.right=null,r;var o=n(t,(i=im(t,i,n)).key);return o<0?(r.left=i.left,r.right=i,i.left=null):o>=0&&(r.right=i.right,r.left=i,i.right=null),r}function rm(t,e,i){var n=null,r=null;if(e){var o=i((e=im(t,e,i)).key,t);0===o?(n=e.left,r=e.right):o<0?(r=e.right,e.right=null,n=e):(n=e.left,e.left=null,r=e)}return{left:n,right:r}}function om(t,e,i,n,r){if(t){n(e+(i?"└── ":"├── ")+r(t)+"\n");var o=e+(i?" ":"│ ");t.left&&om(t.left,o,!1,n,r),t.right&&om(t.right,o,!0,n,r)}}var sm=function(){function t(t){void 0===t&&(t=em),this._root=null,this._size=0,this._comparator=t}return t.prototype.insert=function(t,e){return this._size++,this._root=nm(t,e,this._root,this._comparator)},t.prototype.add=function(t,e){var i=new tm(t,e);null===this._root&&(i.left=i.right=null,this._size++,this._root=i);var n=this._comparator,r=im(t,this._root,n),o=n(t,r.key);return 0===o?this._root=r:(o<0?(i.left=r.left,i.right=r,r.left=null):o>0&&(i.right=r.right,i.left=r,r.right=null),this._size++,this._root=i),this._root},t.prototype.remove=function(t){this._root=this._remove(t,this._root,this._comparator)},t.prototype._remove=function(t,e,i){var n;return null===e?null:0===i(t,(e=im(t,e,i)).key)?(null===e.left?n=e.right:(n=im(t,e.left,i)).right=e.right,this._size--,n):e},t.prototype.pop=function(){var t=this._root;if(t){for(;t.left;)t=t.left;return this._root=im(t.key,this._root,this._comparator),this._root=this._remove(t.key,this._root,this._comparator),{key:t.key,data:t.data}}return null},t.prototype.findStatic=function(t){for(var e=this._root,i=this._comparator;e;){var n=i(t,e.key);if(0===n)return e;e=n<0?e.left:e.right}return null},t.prototype.find=function(t){return this._root&&(this._root=im(t,this._root,this._comparator),0!==this._comparator(t,this._root.key))?null:this._root},t.prototype.contains=function(t){for(var e=this._root,i=this._comparator;e;){var n=i(t,e.key);if(0===n)return!0;e=n<0?e.left:e.right}return!1},t.prototype.forEach=function(t,e){for(var i=this._root,n=[],r=!1;!r;)null!==i?(n.push(i),i=i.left):0!==n.length?(i=n.pop(),t.call(e,i),i=i.right):r=!0;return this},t.prototype.range=function(t,e,i,n){for(var r=[],o=this._comparator,s=this._root;0!==r.length||s;)if(s)r.push(s),s=s.left;else{if(o((s=r.pop()).key,e)>0)break;if(o(s.key,t)>=0&&i.call(n,s))return this;s=s.right}return this},t.prototype.keys=function(){var t=[];return this.forEach((function(e){var i=e.key;return t.push(i)})),t},t.prototype.values=function(){var t=[];return this.forEach((function(e){var i=e.data;return t.push(i)})),t},t.prototype.min=function(){return this._root?this.minNode(this._root).key:null},t.prototype.max=function(){return this._root?this.maxNode(this._root).key:null},t.prototype.minNode=function(t){if(void 0===t&&(t=this._root),t)for(;t.left;)t=t.left;return t},t.prototype.maxNode=function(t){if(void 0===t&&(t=this._root),t)for(;t.right;)t=t.right;return t},t.prototype.at=function(t){for(var e=this._root,i=!1,n=0,r=[];!i;)if(e)r.push(e),e=e.left;else if(r.length>0){if(e=r.pop(),n===t)return e;n++,e=e.right}else i=!0;return null},t.prototype.next=function(t){var e=this._root,i=null;if(t.right){for(i=t.right;i.left;)i=i.left;return i}for(var n=this._comparator;e;){var r=n(t.key,e.key);if(0===r)break;r<0?(i=e,e=e.left):e=e.right}return i},t.prototype.prev=function(t){var e=this._root,i=null;if(null!==t.left){for(i=t.left;i.right;)i=i.right;return i}for(var n=this._comparator;e;){var r=n(t.key,e.key);if(0===r)break;r<0?e=e.left:(i=e,e=e.right)}return i},t.prototype.clear=function(){return this._root=null,this._size=0,this},t.prototype.toList=function(){return function(t){var e=t,i=[],n=!1,r=new tm(null,null),o=r;for(;!n;)e?(i.push(e),e=e.left):i.length>0?e=(e=o=o.next=i.pop()).right:n=!0;return o.next=null,r.next}(this._root)},t.prototype.load=function(t,e,i){void 0===e&&(e=[]),void 0===i&&(i=!1);var n=t.length,r=this._comparator;if(i&&um(t,e,0,n-1,r),null===this._root)this._root=am(t,e,0,n),this._size=n;else{var o=function(t,e,i){var n=new tm(null,null),r=n,o=t,s=e;for(;null!==o&&null!==s;)i(o.key,s.key)<0?(r.next=o,o=o.next):(r.next=s,s=s.next),r=r.next;null!==o?r.next=o:null!==s&&(r.next=s);return n.next}(this.toList(),function(t,e){for(var i=new tm(null,null),n=i,r=0;r<t.length;r++)n=n.next=new tm(t[r],e[r]);return n.next=null,i.next}(t,e),r);n=this._size+n,this._root=lm({head:o},0,n)}return this},t.prototype.isEmpty=function(){return null===this._root},Object.defineProperty(t.prototype,"size",{get:function(){return this._size},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"root",{get:function(){return this._root},enumerable:!0,configurable:!0}),t.prototype.toString=function(t){void 0===t&&(t=function(t){return String(t.key)});var e=[];return om(this._root,"",!0,(function(t){return e.push(t)}),t),e.join("")},t.prototype.update=function(t,e,i){var n=this._comparator,r=rm(t,this._root,n),o=r.left,s=r.right;n(t,e)<0?s=nm(e,i,s,n):o=nm(e,i,o,n),this._root=function(t,e,i){return null===e?t:(null===t||((e=im(t.key,e,i)).left=t),e)}(o,s,n)},t.prototype.split=function(t){return rm(t,this._root,this._comparator)},t}();function am(t,e,i,n){var r=n-i;if(r>0){var o=i+Math.floor(r/2),s=t[o],a=e[o],l=new tm(s,a);return l.left=am(t,e,i,o),l.right=am(t,e,o+1,n),l}return null}function lm(t,e,i){var n=i-e;if(n>0){var r=e+Math.floor(n/2),o=lm(t,e,r),s=t.head;return s.left=o,t.head=t.head.next,s.right=lm(t,r+1,i),s}return null}function um(t,e,i,n,r){if(!(i>=n)){for(var o=t[i+n>>1],s=i-1,a=n+1;;){do{s++}while(r(t[s],o)<0);do{a--}while(r(t[a],o)>0);if(s>=a)break;var l=t[s];t[s]=t[a],t[a]=l,l=e[s],e[s]=e[a],e[a]=l}um(t,e,i,a,r),um(t,e,a+1,n,r)}}function hm(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function cm(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function pm(t,e,i){return e&&cm(t.prototype,e),i&&cm(t,i),t}var dm=function(t,e){return t.ll.x<=e.x&&e.x<=t.ur.x&&t.ll.y<=e.y&&e.y<=t.ur.y},fm=function(t,e){if(e.ur.x<t.ll.x||t.ur.x<e.ll.x||e.ur.y<t.ll.y||t.ur.y<e.ll.y)return null;var i=t.ll.x<e.ll.x?e.ll.x:t.ll.x,n=t.ur.x<e.ur.x?t.ur.x:e.ur.x;return{ll:{x:i,y:t.ll.y<e.ll.y?e.ll.y:t.ll.y},ur:{x:n,y:t.ur.y<e.ur.y?t.ur.y:e.ur.y}}},ym=Number.EPSILON;void 0===ym&&(ym=Math.pow(2,-52));var gm=ym*ym,mm=function(t,e){if(-ym<t&&t<ym&&-ym<e&&e<ym)return 0;var i=t-e;return i*i<gm*t*e?0:t<e?-1:1},vm=function(){function t(){hm(this,t),this.reset()}return pm(t,[{key:"reset",value:function(){this.xRounder=new _m,this.yRounder=new _m}},{key:"round",value:function(t,e){return{x:this.xRounder.round(t),y:this.yRounder.round(e)}}}]),t}(),_m=function(){function t(){hm(this,t),this.tree=new sm,this.round(0)}return pm(t,[{key:"round",value:function(t){var e=this.tree.add(t),i=this.tree.prev(e);if(null!==i&&0===mm(e.key,i.key))return this.tree.remove(t),i.key;var n=this.tree.next(e);return null!==n&&0===mm(e.key,n.key)?(this.tree.remove(t),n.key):t}}]),t}(),xm=new vm,bm=function(t,e){return t.x*e.y-t.y*e.x},wm=function(t,e){return t.x*e.x+t.y*e.y},Sm=function(t,e,i){var n={x:e.x-t.x,y:e.y-t.y},r={x:i.x-t.x,y:i.y-t.y},o=bm(n,r);return mm(o,0)},Cm=function(t){return Math.sqrt(wm(t,t))},Tm=function(t,e,i){var n={x:e.x-t.x,y:e.y-t.y},r={x:i.x-t.x,y:i.y-t.y};return wm(r,n)/Cm(r)/Cm(n)},Em=function(t,e,i){return 0===e.y?null:{x:t.x+e.x/e.y*(i-t.y),y:i}},km=function(t,e,i){return 0===e.x?null:{x:i,y:t.y+e.y/e.x*(i-t.x)}},Pm=function(){function t(e,i){hm(this,t),void 0===e.events?e.events=[this]:e.events.push(this),this.point=e,this.isLeft=i}return pm(t,null,[{key:"compare",value:function(e,i){var n=t.comparePoints(e.point,i.point);return 0!==n?n:(e.point!==i.point&&e.link(i),e.isLeft!==i.isLeft?e.isLeft?1:-1:Rm.compare(e.segment,i.segment))}},{key:"comparePoints",value:function(t,e){return t.x<e.x?-1:t.x>e.x?1:t.y<e.y?-1:t.y>e.y?1:0}}]),pm(t,[{key:"link",value:function(t){if(t.point===this.point)throw new Error("Tried to link already linked events");for(var e=t.point.events,i=0,n=e.length;i<n;i++){var r=e[i];this.point.events.push(r),r.point=this.point}this.checkForConsuming()}},{key:"checkForConsuming",value:function(){for(var t=this.point.events.length,e=0;e<t;e++){var i=this.point.events[e];if(void 0===i.segment.consumedBy)for(var n=e+1;n<t;n++){var r=this.point.events[n];void 0===r.consumedBy&&(i.otherSE.point.events===r.otherSE.point.events&&i.segment.consume(r.segment))}}}},{key:"getAvailableLinkedEvents",value:function(){for(var t=[],e=0,i=this.point.events.length;e<i;e++){var n=this.point.events[e];n!==this&&!n.segment.ringOut&&n.segment.isInResult()&&t.push(n)}return t}},{key:"getLeftmostComparator",value:function(t){var e=this,i=new Map,n=function(n){var r,o,s,a,l,u=n.otherSE;i.set(n,{sine:(r=e.point,o=t.point,s=u.point,a={x:o.x-r.x,y:o.y-r.y},l={x:s.x-r.x,y:s.y-r.y},bm(l,a)/Cm(l)/Cm(a)),cosine:Tm(e.point,t.point,u.point)})};return function(t,e){i.has(t)||n(t),i.has(e)||n(e);var r=i.get(t),o=r.sine,s=r.cosine,a=i.get(e),l=a.sine,u=a.cosine;return o>=0&&l>=0?s<u?1:s>u?-1:0:o<0&&l<0?s<u?-1:s>u?1:0:l<o?-1:l>o?1:0}}}]),t}(),Om=0,Rm=function(){function t(e,i,n,r){hm(this,t),this.id=++Om,this.leftSE=e,e.segment=this,e.otherSE=i,this.rightSE=i,i.segment=this,i.otherSE=e,this.rings=n,this.windings=r}return pm(t,null,[{key:"compare",value:function(t,e){var i=t.leftSE.point.x,n=e.leftSE.point.x,r=t.rightSE.point.x,o=e.rightSE.point.x;if(o<i)return 1;if(r<n)return-1;var s=t.leftSE.point.y,a=e.leftSE.point.y,l=t.rightSE.point.y,u=e.rightSE.point.y;if(i<n){if(a<s&&a<l)return 1;if(a>s&&a>l)return-1;var h=t.comparePoint(e.leftSE.point);if(h<0)return 1;if(h>0)return-1;var c=e.comparePoint(t.rightSE.point);return 0!==c?c:-1}if(i>n){if(s<a&&s<u)return-1;if(s>a&&s>u)return 1;var p=e.comparePoint(t.leftSE.point);if(0!==p)return p;var d=t.comparePoint(e.rightSE.point);return d<0?1:d>0?-1:1}if(s<a)return-1;if(s>a)return 1;if(r<o){var f=e.comparePoint(t.rightSE.point);if(0!==f)return f}if(r>o){var y=t.comparePoint(e.rightSE.point);if(y<0)return 1;if(y>0)return-1}if(r!==o){var g=l-s,m=r-i,v=u-a,_=o-n;if(g>m&&v<_)return 1;if(g<m&&v>_)return-1}return r>o?1:r<o||l<u?-1:l>u?1:t.id<e.id?-1:t.id>e.id?1:0}}]),pm(t,[{key:"replaceRightSE",value:function(t){this.rightSE=t,this.rightSE.segment=this,this.rightSE.otherSE=this.leftSE,this.leftSE.otherSE=this.rightSE}},{key:"bbox",value:function(){var t=this.leftSE.point.y,e=this.rightSE.point.y;return{ll:{x:this.leftSE.point.x,y:t<e?t:e},ur:{x:this.rightSE.point.x,y:t>e?t:e}}}},{key:"vector",value:function(){return{x:this.rightSE.point.x-this.leftSE.point.x,y:this.rightSE.point.y-this.leftSE.point.y}}},{key:"isAnEndpoint",value:function(t){return t.x===this.leftSE.point.x&&t.y===this.leftSE.point.y||t.x===this.rightSE.point.x&&t.y===this.rightSE.point.y}},{key:"comparePoint",value:function(t){if(this.isAnEndpoint(t))return 0;var e=this.leftSE.point,i=this.rightSE.point,n=this.vector();if(e.x===i.x)return t.x===e.x?0:t.x<e.x?1:-1;var r=(t.y-e.y)/n.y,o=e.x+r*n.x;if(t.x===o)return 0;var s=(t.x-e.x)/n.x,a=e.y+s*n.y;return t.y===a?0:t.y<a?-1:1}},{key:"getIntersection",value:function(t){var e=this.bbox(),i=t.bbox(),n=fm(e,i);if(null===n)return null;var r=this.leftSE.point,o=this.rightSE.point,s=t.leftSE.point,a=t.rightSE.point,l=dm(e,s)&&0===this.comparePoint(s),u=dm(i,r)&&0===t.comparePoint(r),h=dm(e,a)&&0===this.comparePoint(a),c=dm(i,o)&&0===t.comparePoint(o);if(u&&l)return c&&!h?o:!c&&h?a:null;if(u)return h&&r.x===a.x&&r.y===a.y?null:r;if(l)return c&&o.x===s.x&&o.y===s.y?null:s;if(c&&h)return null;if(c)return o;if(h)return a;var p=function(t,e,i,n){if(0===e.x)return km(i,n,t.x);if(0===n.x)return km(t,e,i.x);if(0===e.y)return Em(i,n,t.y);if(0===n.y)return Em(t,e,i.y);var r=bm(e,n);if(0==r)return null;var o={x:i.x-t.x,y:i.y-t.y},s=bm(o,e)/r,a=bm(o,n)/r;return{x:(t.x+a*e.x+(i.x+s*n.x))/2,y:(t.y+a*e.y+(i.y+s*n.y))/2}}(r,this.vector(),s,t.vector());return null===p?null:dm(n,p)?xm.round(p.x,p.y):null}},{key:"split",value:function(e){var i=[],n=void 0!==e.events,r=new Pm(e,!0),o=new Pm(e,!1),s=this.rightSE;this.replaceRightSE(o),i.push(o),i.push(r);var a=new t(r,s,this.rings.slice(),this.windings.slice());return Pm.comparePoints(a.leftSE.point,a.rightSE.point)>0&&a.swapEvents(),Pm.comparePoints(this.leftSE.point,this.rightSE.point)>0&&this.swapEvents(),n&&(r.checkForConsuming(),o.checkForConsuming()),i}},{key:"swapEvents",value:function(){var t=this.rightSE;this.rightSE=this.leftSE,this.leftSE=t,this.leftSE.isLeft=!0,this.rightSE.isLeft=!1;for(var e=0,i=this.windings.length;e<i;e++)this.windings[e]*=-1}},{key:"consume",value:function(e){for(var i=this,n=e;i.consumedBy;)i=i.consumedBy;for(;n.consumedBy;)n=n.consumedBy;var r=t.compare(i,n);if(0!==r){if(r>0){var o=i;i=n,n=o}if(i.prev===n){var s=i;i=n,n=s}for(var a=0,l=n.rings.length;a<l;a++){var u=n.rings[a],h=n.windings[a],c=i.rings.indexOf(u);-1===c?(i.rings.push(u),i.windings.push(h)):i.windings[c]+=h}n.rings=null,n.windings=null,n.consumedBy=i,n.leftSE.consumedBy=i.leftSE,n.rightSE.consumedBy=i.rightSE}}},{key:"prevInResult",value:function(){return void 0!==this._prevInResult||(this.prev?this.prev.isInResult()?this._prevInResult=this.prev:this._prevInResult=this.prev.prevInResult():this._prevInResult=null),this._prevInResult}},{key:"beforeState",value:function(){if(void 0!==this._beforeState)return this._beforeState;if(this.prev){var t=this.prev.consumedBy||this.prev;this._beforeState=t.afterState()}else this._beforeState={rings:[],windings:[],multiPolys:[]};return this._beforeState}},{key:"afterState",value:function(){if(void 0!==this._afterState)return this._afterState;var t=this.beforeState();this._afterState={rings:t.rings.slice(0),windings:t.windings.slice(0),multiPolys:[]};for(var e=this._afterState.rings,i=this._afterState.windings,n=this._afterState.multiPolys,r=0,o=this.rings.length;r<o;r++){var s=this.rings[r],a=this.windings[r],l=e.indexOf(s);-1===l?(e.push(s),i.push(a)):i[l]+=a}for(var u=[],h=[],c=0,p=e.length;c<p;c++)if(0!==i[c]){var d=e[c],f=d.poly;if(-1===h.indexOf(f))if(d.isExterior)u.push(f);else{-1===h.indexOf(f)&&h.push(f);var y=u.indexOf(d.poly);-1!==y&&u.splice(y,1)}}for(var g=0,m=u.length;g<m;g++){var v=u[g].multiPoly;-1===n.indexOf(v)&&n.push(v)}return this._afterState}},{key:"isInResult",value:function(){if(this.consumedBy)return!1;if(void 0!==this._isInResult)return this._isInResult;var t=this.beforeState().multiPolys,e=this.afterState().multiPolys;switch(Nm.type){case"union":var i=0===t.length,n=0===e.length;this._isInResult=i!==n;break;case"intersection":var r,o;t.length<e.length?(r=t.length,o=e.length):(r=e.length,o=t.length),this._isInResult=o===Nm.numMultiPolys&&r<o;break;case"xor":var s=Math.abs(t.length-e.length);this._isInResult=s%2==1;break;case"difference":var a=function(t){return 1===t.length&&t[0].isSubject};this._isInResult=a(t)!==a(e);break;default:throw new Error("Unrecognized operation type found ".concat(Nm.type))}return this._isInResult}}],[{key:"fromRing",value:function(e,i,n){var r,o,s,a=Pm.comparePoints(e,i);if(a<0)r=e,o=i,s=1;else{if(!(a>0))throw new Error("Tried to create degenerate segment at [".concat(e.x,", ").concat(e.y,"]"));r=i,o=e,s=-1}return new t(new Pm(r,!0),new Pm(o,!1),[n],[s])}}]),t}(),Im=function(){function t(e,i,n){if(hm(this,t),!Array.isArray(e)||0===e.length)throw new Error("Input geometry is not a valid Polygon or MultiPolygon");if(this.poly=i,this.isExterior=n,this.segments=[],"number"!=typeof e[0][0]||"number"!=typeof e[0][1])throw new Error("Input geometry is not a valid Polygon or MultiPolygon");var r=xm.round(e[0][0],e[0][1]);this.bbox={ll:{x:r.x,y:r.y},ur:{x:r.x,y:r.y}};for(var o=r,s=1,a=e.length;s<a;s++){if("number"!=typeof e[s][0]||"number"!=typeof e[s][1])throw new Error("Input geometry is not a valid Polygon or MultiPolygon");var l=xm.round(e[s][0],e[s][1]);l.x===o.x&&l.y===o.y||(this.segments.push(Rm.fromRing(o,l,this)),l.x<this.bbox.ll.x&&(this.bbox.ll.x=l.x),l.y<this.bbox.ll.y&&(this.bbox.ll.y=l.y),l.x>this.bbox.ur.x&&(this.bbox.ur.x=l.x),l.y>this.bbox.ur.y&&(this.bbox.ur.y=l.y),o=l)}r.x===o.x&&r.y===o.y||this.segments.push(Rm.fromRing(o,r,this))}return pm(t,[{key:"getSweepEvents",value:function(){for(var t=[],e=0,i=this.segments.length;e<i;e++){var n=this.segments[e];t.push(n.leftSE),t.push(n.rightSE)}return t}}]),t}(),Fm=function(){function t(e,i){if(hm(this,t),!Array.isArray(e))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");this.exteriorRing=new Im(e[0],this,!0),this.bbox={ll:{x:this.exteriorRing.bbox.ll.x,y:this.exteriorRing.bbox.ll.y},ur:{x:this.exteriorRing.bbox.ur.x,y:this.exteriorRing.bbox.ur.y}},this.interiorRings=[];for(var n=1,r=e.length;n<r;n++){var o=new Im(e[n],this,!1);o.bbox.ll.x<this.bbox.ll.x&&(this.bbox.ll.x=o.bbox.ll.x),o.bbox.ll.y<this.bbox.ll.y&&(this.bbox.ll.y=o.bbox.ll.y),o.bbox.ur.x>this.bbox.ur.x&&(this.bbox.ur.x=o.bbox.ur.x),o.bbox.ur.y>this.bbox.ur.y&&(this.bbox.ur.y=o.bbox.ur.y),this.interiorRings.push(o)}this.multiPoly=i}return pm(t,[{key:"getSweepEvents",value:function(){for(var t=this.exteriorRing.getSweepEvents(),e=0,i=this.interiorRings.length;e<i;e++)for(var n=this.interiorRings[e].getSweepEvents(),r=0,o=n.length;r<o;r++)t.push(n[r]);return t}}]),t}(),jm=function(){function t(e,i){if(hm(this,t),!Array.isArray(e))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");try{"number"==typeof e[0][0][0]&&(e=[e])}catch(s){}this.polys=[],this.bbox={ll:{x:Number.POSITIVE_INFINITY,y:Number.POSITIVE_INFINITY},ur:{x:Number.NEGATIVE_INFINITY,y:Number.NEGATIVE_INFINITY}};for(var n=0,r=e.length;n<r;n++){var o=new Fm(e[n],this);o.bbox.ll.x<this.bbox.ll.x&&(this.bbox.ll.x=o.bbox.ll.x),o.bbox.ll.y<this.bbox.ll.y&&(this.bbox.ll.y=o.bbox.ll.y),o.bbox.ur.x>this.bbox.ur.x&&(this.bbox.ur.x=o.bbox.ur.x),o.bbox.ur.y>this.bbox.ur.y&&(this.bbox.ur.y=o.bbox.ur.y),this.polys.push(o)}this.isSubject=i}return pm(t,[{key:"getSweepEvents",value:function(){for(var t=[],e=0,i=this.polys.length;e<i;e++)for(var n=this.polys[e].getSweepEvents(),r=0,o=n.length;r<o;r++)t.push(n[r]);return t}}]),t}(),Mm=function(){function t(e){hm(this,t),this.events=e;for(var i=0,n=e.length;i<n;i++)e[i].segment.ringOut=this;this.poly=null}return pm(t,null,[{key:"factory",value:function(e){for(var i=[],n=0,r=e.length;n<r;n++){var o=e[n];if(o.isInResult()&&!o.ringOut){for(var s=null,a=o.leftSE,l=o.rightSE,u=[a],h=a.point,c=[];s=a,a=l,u.push(a),a.point!==h;)for(;;){var p=a.getAvailableLinkedEvents();if(0===p.length){var d=u[0].point,f=u[u.length-1].point;throw new Error("Unable to complete output ring starting at [".concat(d.x,",")+" ".concat(d.y,"]. Last matching segment found ends at")+" [".concat(f.x,", ").concat(f.y,"]."))}if(1===p.length){l=p[0].otherSE;break}for(var y=null,g=0,m=c.length;g<m;g++)if(c[g].point===a.point){y=g;break}if(null===y){c.push({index:u.length,point:a.point});var v=a.getLeftmostComparator(s);l=p.sort(v)[0].otherSE;break}var _=c.splice(y)[0],x=u.splice(_.index);x.unshift(x[0].otherSE),i.push(new t(x.reverse()))}i.push(new t(u))}}return i}}]),pm(t,[{key:"getGeom",value:function(){for(var t=this.events[0].point,e=[t],i=1,n=this.events.length-1;i<n;i++){var r=this.events[i].point,o=this.events[i+1].point;0!==Sm(r,t,o)&&(e.push(r),t=r)}if(1===e.length)return null;var s=e[0],a=e[1];0===Sm(s,t,a)&&e.shift(),e.push(e[0]);for(var l=this.isExteriorRing()?1:-1,u=this.isExteriorRing()?0:e.length-1,h=this.isExteriorRing()?e.length:-1,c=[],p=u;p!=h;p+=l)c.push([e[p].x,e[p].y]);return c}},{key:"isExteriorRing",value:function(){if(void 0===this._isExteriorRing){var t=this.enclosingRing();this._isExteriorRing=!t||!t.isExteriorRing()}return this._isExteriorRing}},{key:"enclosingRing",value:function(){return void 0===this._enclosingRing&&(this._enclosingRing=this._calcEnclosingRing()),this._enclosingRing}},{key:"_calcEnclosingRing",value:function(){for(var t=this.events[0],e=1,i=this.events.length;e<i;e++){var n=this.events[e];Pm.compare(t,n)>0&&(t=n)}for(var r=t.segment.prevInResult(),o=r?r.prevInResult():null;;){if(!r)return null;if(!o)return r.ringOut;if(o.ringOut!==r.ringOut)return o.ringOut.enclosingRing()!==r.ringOut?r.ringOut:r.ringOut.enclosingRing();r=o.prevInResult(),o=r?r.prevInResult():null}}}]),t}(),Am=function(){function t(e){hm(this,t),this.exteriorRing=e,e.poly=this,this.interiorRings=[]}return pm(t,[{key:"addInterior",value:function(t){this.interiorRings.push(t),t.poly=this}},{key:"getGeom",value:function(){var t=[this.exteriorRing.getGeom()];if(null===t[0])return null;for(var e=0,i=this.interiorRings.length;e<i;e++){var n=this.interiorRings[e].getGeom();null!==n&&t.push(n)}return t}}]),t}(),Lm=function(){function t(e){hm(this,t),this.rings=e,this.polys=this._composePolys(e)}return pm(t,[{key:"getGeom",value:function(){for(var t=[],e=0,i=this.polys.length;e<i;e++){var n=this.polys[e].getGeom();null!==n&&t.push(n)}return t}},{key:"_composePolys",value:function(t){for(var e=[],i=0,n=t.length;i<n;i++){var r=t[i];if(!r.poly)if(r.isExteriorRing())e.push(new Am(r));else{var o=r.enclosingRing();o.poly||e.push(new Am(o)),o.poly.addInterior(r)}}return e}}]),t}(),zm=function(){function t(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Rm.compare;hm(this,t),this.queue=e,this.tree=new sm(i),this.segments=[]}return pm(t,[{key:"process",value:function(t){var e=t.segment,i=[];if(t.consumedBy)return t.isLeft?this.queue.remove(t.otherSE):this.tree.remove(e),i;var n=t.isLeft?this.tree.insert(e):this.tree.find(e);if(!n)throw new Error("Unable to find segment #".concat(e.id," ")+"[".concat(e.leftSE.point.x,", ").concat(e.leftSE.point.y,"] -> ")+"[".concat(e.rightSE.point.x,", ").concat(e.rightSE.point.y,"] ")+"in SweepLine tree. Please submit a bug report.");for(var r=n,o=n,s=void 0,a=void 0;void 0===s;)null===(r=this.tree.prev(r))?s=null:void 0===r.key.consumedBy&&(s=r.key);for(;void 0===a;)null===(o=this.tree.next(o))?a=null:void 0===o.key.consumedBy&&(a=o.key);if(t.isLeft){var l=null;if(s){var u=s.getIntersection(e);if(null!==u&&(e.isAnEndpoint(u)||(l=u),!s.isAnEndpoint(u)))for(var h=this._splitSafely(s,u),c=0,p=h.length;c<p;c++)i.push(h[c])}var d=null;if(a){var f=a.getIntersection(e);if(null!==f&&(e.isAnEndpoint(f)||(d=f),!a.isAnEndpoint(f)))for(var y=this._splitSafely(a,f),g=0,m=y.length;g<m;g++)i.push(y[g])}if(null!==l||null!==d){var v=null;if(null===l)v=d;else if(null===d)v=l;else{v=Pm.comparePoints(l,d)<=0?l:d}this.queue.remove(e.rightSE),i.push(e.rightSE);for(var _=e.split(v),x=0,b=_.length;x<b;x++)i.push(_[x])}i.length>0?(this.tree.remove(e),i.push(t)):(this.segments.push(e),e.prev=s)}else{if(s&&a){var w=s.getIntersection(a);if(null!==w){if(!s.isAnEndpoint(w))for(var S=this._splitSafely(s,w),C=0,T=S.length;C<T;C++)i.push(S[C]);if(!a.isAnEndpoint(w))for(var E=this._splitSafely(a,w),k=0,P=E.length;k<P;k++)i.push(E[k])}}this.tree.remove(e)}return i}},{key:"_splitSafely",value:function(t,e){this.tree.remove(t);var i=t.rightSE;this.queue.remove(i);var n=t.split(e);return n.push(i),void 0===t.consumedBy&&this.tree.insert(t),n}}]),t}(),Dm="undefined"!=typeof process&&{}.POLYGON_CLIPPING_MAX_QUEUE_SIZE||1e6,Gm="undefined"!=typeof process&&{}.POLYGON_CLIPPING_MAX_SWEEPLINE_SEGMENTS||1e6,Nm=new(function(){function t(){hm(this,t)}return pm(t,[{key:"run",value:function(t,e,i){Nm.type=t,xm.reset();for(var n=[new jm(e,!0)],r=0,o=i.length;r<o;r++)n.push(new jm(i[r],!1));if(Nm.numMultiPolys=n.length,"difference"===Nm.type)for(var s=n[0],a=1;a<n.length;)null!==fm(n[a].bbox,s.bbox)?a++:n.splice(a,1);if("intersection"===Nm.type)for(var l=0,u=n.length;l<u;l++)for(var h=n[l],c=l+1,p=n.length;c<p;c++)if(null===fm(h.bbox,n[c].bbox))return[];for(var d=new sm(Pm.compare),f=0,y=n.length;f<y;f++)for(var g=n[f].getSweepEvents(),m=0,v=g.length;m<v;m++)if(d.insert(g[m]),d.size>Dm)throw new Error("Infinite loop when putting segment endpoints in a priority queue (queue size too big). Please file a bug report.");for(var _=new zm(d),x=d.size,b=d.pop();b;){var w=b.key;if(d.size===x){var S=w.segment;throw new Error("Unable to pop() ".concat(w.isLeft?"left":"right"," SweepEvent ")+"[".concat(w.point.x,", ").concat(w.point.y,"] from segment #").concat(S.id," ")+"[".concat(S.leftSE.point.x,", ").concat(S.leftSE.point.y,"] -> ")+"[".concat(S.rightSE.point.x,", ").concat(S.rightSE.point.y,"] from queue. ")+"Please file a bug report.")}if(d.size>Dm)throw new Error("Infinite loop when passing sweep line over endpoints (queue size too big). Please file a bug report.");if(_.segments.length>Gm)throw new Error("Infinite loop when passing sweep line over endpoints (too many sweep line segments). Please file a bug report.");for(var C=_.process(w),T=0,E=C.length;T<E;T++){var k=C[T];void 0===k.consumedBy&&d.insert(k)}x=d.size,b=d.pop()}xm.reset();var P=Mm.factory(_.segments);return new Lm(P).getGeom()}}]),t}()),Bm=function(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),n=1;n<e;n++)i[n-1]=arguments[n];return Nm.run("union",t,i)};function Wm(t,e,i){void 0===i&&(i={});var n={type:"Feature"};return(0===i.id||i.id)&&(n.id=i.id),i.bbox&&(n.bbox=i.bbox),n.properties=e||{},n.geometry=t,n}function qm(t){return"Feature"===t.type?t.geometry:t}function Vm(t,e,i){void 0===i&&(i={});var n=qm(t),r=qm(e),o=Bm(n.coordinates,r.coordinates);return 0===o.length?null:1===o.length?function(t,e,i){void 0===i&&(i={});for(var n=0,r=t;n<r.length;n++){var o=r[n];if(o.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");for(var s=0;s<o[o.length-1].length;s++)if(o[o.length-1][s]!==o[0][s])throw new Error("First and last Position are not equivalent.")}return Wm({type:"Polygon",coordinates:t},e,i)}(o[0],i.properties):function(t,e,i){return void 0===i&&(i={}),Wm({type:"MultiPolygon",coordinates:t},e,i)}(o,i.properties)}function Um(t,e){const i=Dn(t),n=Math.round(100*i)/100;let r;return"m2"===e?r=n+" m²":"ha"===e&&(r=n/1e4+" ha"),r}function Xm(t,e,i){const n=e.getExtent();return t.getView().fit(Yi(n,i))}function Km(t,e){const[i,n,r]=Array.from(kr(t));return Sr([i,n,r,e])}const Ym=new Cc,Zm=new Cc;function Hm(t,e){const i=`\n <ogc:Filter>\n <ogc:Contains>\n <ogc:PropertyName>SHAPE</ogc:PropertyName>\n <gml:Point srsName="urn:ogc:def:crs:EPSG::4326">\n <gml:coordinates>${(n=t,o=nr(n,void 0!==r?r:"EPSG:3857","EPSG:4326"),s=o[0],(s<-180||s>180)&&(o[0]=De(s+180,360)-180),o).reverse().join(",")}</gml:coordinates>\n </gml:Point>\n </ogc:Contains>\n </ogc:Filter>\n `;var n,r,o,s;fetch(function(t){const e=Object.keys(t).map((e=>e+"="+encodeURI(t[e]))).join("&");return`https://api.os.uk/features/v1/wfs?${e}`}({key:e,service:"WFS",request:"GetFeature",version:"2.0.0",typeNames:"Topography_TopographicArea",propertyName:"TOID,DescriptiveGroup,SHAPE",outputFormat:"GEOJSON",srsName:"urn:ogc:def:crs:EPSG::4326",filter:i,count:1})).then((t=>t.json())).then((t=>{if(!t.features.length)return;const e=t.features[0].properties,i=["TOID","DescriptiveGroup"];Object.keys(e).forEach((t=>i.includes(t)||delete e[t]));const n=new Ta;n.readFeatures(t,{featureProjection:"EPSG:3857"}).forEach((t=>{const e=t.getProperties().TOID,i=Ym.getFeatureById(e);i?Ym.removeFeature(i):(t.setId(e),Ym.addFeature(t))})),Zm.clear(),Zm.addFeature(n.readFeature(Ym.getFeatures().reduce(((t,e)=>{const i=n.writeFeatureObject(e).geometry;return t?Vm(t,i):i}),null)))})).catch((t=>console.log(t)))}const $m="© Crown copyright and database rights 2021 OS (0)100019252";var Jm,Qm=Object.freeze,tv=Object.defineProperty,ev=Object.getOwnPropertyDescriptor,iv=(t,e,i,n)=>{for(var r,o=n>1?void 0:n?ev(e,i):e,s=t.length-1;s>=0;s--)(r=t[s])&&(o=(n?r(e,i,o):r(o))||o);return n&&o&&tv(e,i,o),o};let nv=class extends ht{constructor(){super(...arguments),this.latitude=51.507351,this.longitude=-.127758,this.zoom=10,this.minZoom=7,this.maxZoom=22,this.drawMode=!1,this.drawGeojsonData={type:"Feature",geometry:{}},this.drawGeojsonDataBuffer=100,this.drawPointer="crosshair",this.showFeaturesAtPoint=!1,this.clickFeatures=!1,this.featureColor="#0000ff",this.featureFill=!1,this.featureBuffer=40,this.geojsonData={type:"FeatureCollection",features:[]},this.geojsonColor="#ff0000",this.geojsonFill=!1,this.geojsonBuffer=12,this.disableVectorTiles=!1,this.osVectorTilesApiKey="",this.osFeaturesApiKey="",this.hideResetControl=!1,this.staticMode=!1,this.areaUnit="m2",this.showScale=!1,this.useScaleBarStyle=!1,this.dispatch=(t,e)=>this.dispatchEvent(new CustomEvent(t,{detail:e}))}firstUpdated(){var t;const e=null==(t=this.shadowRoot)?void 0:t.querySelector("#map"),i=!this.disableVectorTiles&&Boolean(this.osVectorTilesApiKey),n=(r=this.osVectorTilesApiKey,new dd({source:r?new Ag({url:"https://api.os.uk/maps/raster/v1/zxy/Light_3857/{z}/{x}/{y}.png?key="+r,attributions:[$m],attributionsCollapsible:!1,maxZoom:20}):new Dg({attributions:[zg]})}));var r;const o=function(t){let e=new pp({declutter:!0,source:new Xp({format:new Ll,url:"https://api.os.uk/maps/vector/v1/vts/tile/{z}/{y}/{x}.pbf?srs=3857&key="+t,attributions:[$m],attributionsCollapsible:!1})});return t&&fetch("https://api.os.uk/maps/vector/v1/vts/resources/styles?srs=3857&key="+t).then((t=>t.json())).then((t=>jg(e,t,"esri"))).catch((t=>console.log(t))),e}(this.osVectorTilesApiKey),s=new Zp({target:e,layers:[i?o:n],view:new Ls({projection:"EPSG:3857",extent:(l=[-10.76418,49.528423,1.9134116,61.331151],u="EPSG:4326",h="EPSG:3857",En(l,ir(u,h),void 0,c)),minZoom:this.minZoom,maxZoom:this.maxZoom,center:Qn([this.longitude,this.latitude]),zoom:this.zoom,enableRotation:!1}),controls:Zs({attribution:!0,zoom:!this.staticMode}).extend(this.showScale?[(a=this.useScaleBarStyle,new Ys({units:"metric",bar:a,steps:4,text:!0,minWidth:140}))]:[]),interactions:Zc({doubleClickZoom:!this.staticMode,dragPan:!this.staticMode,mouseWheelZoom:!this.staticMode})});var a,l,u,h,c;const p=(d=this.drawPointer,new Mc({source:$g,type:"Polygon",style:new rl({stroke:Xg,fill:Kg,image:"crosshair"===d?Yg:Zg})}));var d;const f=function(t){return new Vc({source:$g,style:new rl({image:"crosshair"===t?Yg:Zg})})}(this.drawPointer),y=document.createElement("button");y.innerHTML="↻",y.title="Reset map view";y.addEventListener("click",(()=>{this.showFeaturesAtPoint?Xm(s,Zm,this.featureBuffer):v.getFeatures().length>0?Xm(s,v,this.geojsonBuffer):(s.getView().setCenter(Qn([this.longitude,this.latitude])),s.getView().setZoom(this.zoom)),this.drawMode&&($g.clear(),s.addInteraction(p),s.addInteraction(Qg))}),!1);const g=document.createElement("div");g.className="reset-control ol-unselectable ol-control",g.appendChild(y);var m=new ge({element:g});this.hideResetControl||s.addControl(m),s.on("pointerdrag",(()=>{s.getViewport().style.cursor="grabbing"})),s.on("pointermove",(()=>{s.getViewport().style.cursor="grab"}));const v=new Cc;if("FeatureCollection"===this.geojsonData.type){let t=(new Ta).readFeatures(this.geojsonData,{featureProjection:"EPSG:3857"});v.addFeatures(t)}else if("Feature"===this.geojsonData.type){let t=(new Ta).readFeature(this.geojsonData,{featureProjection:"EPSG:3857"});v.addFeature(t)}const _=new ac({source:v,style:new rl({stroke:new Ka({color:this.geojsonColor,width:3}),fill:new Ea({color:this.geojsonFill?Km(this.geojsonColor,.2):Km(this.geojsonColor,0)})})});if(s.addLayer(_),v.getFeatures().length>0){Xm(s,v,this.geojsonBuffer);const t=v.getFeatures()[0].getGeometry();this.dispatch("geojsonDataArea",Um(t,this.areaUnit))}if(this.drawMode){const t=Object.keys(this.drawGeojsonData.geometry).length>0;if(t){let t=(new Ta).readFeature(this.drawGeojsonData,{featureProjection:"EPSG:3857"});$g.addFeature(t),Xm(s,$g,this.drawGeojsonDataBuffer)}else $g.clear();s.addLayer(Jg),t||s.addInteraction(p),s.addInteraction(f),s.addInteraction(Qg),$g.on("change",(()=>{const t=$g.getFeatures();if(t.length>0){const i=(e=t,"string"==typeof e?e[e.length-1]||"":e[e.length-1]).getGeometry();this.dispatch("geojsonChange",(new Ta).writeFeaturesObject(t,{featureProjection:"EPSG:3857"})),this.dispatch("areaChange",Um(i,this.areaUnit)),s.removeInteraction(p)}var e}))}if(this.drawMode&&Boolean(this.osVectorTilesApiKey)&&!this.disableVectorTiles&&(s.addLayer(Wg),Jg.setZIndex(1001),s.on("moveend",(()=>{s.getView().getZoom()<20?Bg.clear():setTimeout((()=>{Bg.clear();const t=s.getView().calculateExtent(s.getSize());qg(o,t)}),200)}))),this.showFeaturesAtPoint&&Boolean(this.osFeaturesApiKey)){Hm(Qn([this.longitude,this.latitude]),this.osFeaturesApiKey),this.clickFeatures&&s.on("singleclick",(t=>{Hm(t.coordinate,this.osFeaturesApiKey)}));const t=(x=this.featureColor,b=this.featureFill,new ac({source:Zm,style:new rl({stroke:new Ka({width:3,color:x}),fill:new Ea({color:Km(x,b?.2:0)})})}));s.addLayer(t),Zm.on("change",(()=>{if("ready"===Zm.getState()&&Zm.getFeatures().length>0){Xm(s,Zm,this.featureBuffer),this.dispatch("featuresGeojsonChange",(new Ta).writeFeaturesObject(Zm.getFeatures(),{featureProjection:"EPSG:3857"}));const t=Zm.getFeatures()[0].getGeometry();this.dispatch("featuresAreaChange",Um(t,this.areaUnit))}}))}var x,b;setTimeout((()=>{window.dispatchEvent(new Event("resize")),e.style.opacity="1",this.dispatch("ready")}),500)}render(){return q(Jm||(Jm=Qm(tv(t=['<script src="https://cdn.polyfill.io/v2/polyfill.min.js"><\/script>\n <link rel="stylesheet" href="https://cdn.skypack.dev/ol@^6.6.1/ol.css" />\n <div id="map" tabindex="0" />'],"raw",{value:Qm(e||t.slice())}))));var t,e}};var rv;nv.styles=((t,...e)=>{const i=1===t.length?t[0]:e.reduce(((e,i,n)=>e+(t=>{if(t instanceof c)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+t[n+1]),t[0]);return d(i)})`
41
+ var tm=function(t,e){this.next=null,this.key=t,this.data=e,this.left=null,this.right=null};function em(t,e){return t>e?1:t<e?-1:0}function im(t,e,i){for(var n=new tm(null,null),r=n,o=n;;){var s=i(t,e.key);if(s<0){if(null===e.left)break;if(i(t,e.left.key)<0){var a=e.left;if(e.left=a.right,a.right=e,null===(e=a).left)break}o.left=e,o=e,e=e.left}else{if(!(s>0))break;if(null===e.right)break;if(i(t,e.right.key)>0){a=e.right;if(e.right=a.left,a.left=e,null===(e=a).right)break}r.right=e,r=e,e=e.right}}return r.right=e.left,o.left=e.right,e.left=n.right,e.right=n.left,e}function nm(t,e,i,n){var r=new tm(t,e);if(null===i)return r.left=r.right=null,r;var o=n(t,(i=im(t,i,n)).key);return o<0?(r.left=i.left,r.right=i,i.left=null):o>=0&&(r.right=i.right,r.left=i,i.right=null),r}function rm(t,e,i){var n=null,r=null;if(e){var o=i((e=im(t,e,i)).key,t);0===o?(n=e.left,r=e.right):o<0?(r=e.right,e.right=null,n=e):(n=e.left,e.left=null,r=e)}return{left:n,right:r}}function om(t,e,i,n,r){if(t){n(e+(i?"└── ":"├── ")+r(t)+"\n");var o=e+(i?" ":"│ ");t.left&&om(t.left,o,!1,n,r),t.right&&om(t.right,o,!0,n,r)}}var sm=function(){function t(t){void 0===t&&(t=em),this._root=null,this._size=0,this._comparator=t}return t.prototype.insert=function(t,e){return this._size++,this._root=nm(t,e,this._root,this._comparator)},t.prototype.add=function(t,e){var i=new tm(t,e);null===this._root&&(i.left=i.right=null,this._size++,this._root=i);var n=this._comparator,r=im(t,this._root,n),o=n(t,r.key);return 0===o?this._root=r:(o<0?(i.left=r.left,i.right=r,r.left=null):o>0&&(i.right=r.right,i.left=r,r.right=null),this._size++,this._root=i),this._root},t.prototype.remove=function(t){this._root=this._remove(t,this._root,this._comparator)},t.prototype._remove=function(t,e,i){var n;return null===e?null:0===i(t,(e=im(t,e,i)).key)?(null===e.left?n=e.right:(n=im(t,e.left,i)).right=e.right,this._size--,n):e},t.prototype.pop=function(){var t=this._root;if(t){for(;t.left;)t=t.left;return this._root=im(t.key,this._root,this._comparator),this._root=this._remove(t.key,this._root,this._comparator),{key:t.key,data:t.data}}return null},t.prototype.findStatic=function(t){for(var e=this._root,i=this._comparator;e;){var n=i(t,e.key);if(0===n)return e;e=n<0?e.left:e.right}return null},t.prototype.find=function(t){return this._root&&(this._root=im(t,this._root,this._comparator),0!==this._comparator(t,this._root.key))?null:this._root},t.prototype.contains=function(t){for(var e=this._root,i=this._comparator;e;){var n=i(t,e.key);if(0===n)return!0;e=n<0?e.left:e.right}return!1},t.prototype.forEach=function(t,e){for(var i=this._root,n=[],r=!1;!r;)null!==i?(n.push(i),i=i.left):0!==n.length?(i=n.pop(),t.call(e,i),i=i.right):r=!0;return this},t.prototype.range=function(t,e,i,n){for(var r=[],o=this._comparator,s=this._root;0!==r.length||s;)if(s)r.push(s),s=s.left;else{if(o((s=r.pop()).key,e)>0)break;if(o(s.key,t)>=0&&i.call(n,s))return this;s=s.right}return this},t.prototype.keys=function(){var t=[];return this.forEach((function(e){var i=e.key;return t.push(i)})),t},t.prototype.values=function(){var t=[];return this.forEach((function(e){var i=e.data;return t.push(i)})),t},t.prototype.min=function(){return this._root?this.minNode(this._root).key:null},t.prototype.max=function(){return this._root?this.maxNode(this._root).key:null},t.prototype.minNode=function(t){if(void 0===t&&(t=this._root),t)for(;t.left;)t=t.left;return t},t.prototype.maxNode=function(t){if(void 0===t&&(t=this._root),t)for(;t.right;)t=t.right;return t},t.prototype.at=function(t){for(var e=this._root,i=!1,n=0,r=[];!i;)if(e)r.push(e),e=e.left;else if(r.length>0){if(e=r.pop(),n===t)return e;n++,e=e.right}else i=!0;return null},t.prototype.next=function(t){var e=this._root,i=null;if(t.right){for(i=t.right;i.left;)i=i.left;return i}for(var n=this._comparator;e;){var r=n(t.key,e.key);if(0===r)break;r<0?(i=e,e=e.left):e=e.right}return i},t.prototype.prev=function(t){var e=this._root,i=null;if(null!==t.left){for(i=t.left;i.right;)i=i.right;return i}for(var n=this._comparator;e;){var r=n(t.key,e.key);if(0===r)break;r<0?e=e.left:(i=e,e=e.right)}return i},t.prototype.clear=function(){return this._root=null,this._size=0,this},t.prototype.toList=function(){return function(t){var e=t,i=[],n=!1,r=new tm(null,null),o=r;for(;!n;)e?(i.push(e),e=e.left):i.length>0?e=(e=o=o.next=i.pop()).right:n=!0;return o.next=null,r.next}(this._root)},t.prototype.load=function(t,e,i){void 0===e&&(e=[]),void 0===i&&(i=!1);var n=t.length,r=this._comparator;if(i&&um(t,e,0,n-1,r),null===this._root)this._root=am(t,e,0,n),this._size=n;else{var o=function(t,e,i){var n=new tm(null,null),r=n,o=t,s=e;for(;null!==o&&null!==s;)i(o.key,s.key)<0?(r.next=o,o=o.next):(r.next=s,s=s.next),r=r.next;null!==o?r.next=o:null!==s&&(r.next=s);return n.next}(this.toList(),function(t,e){for(var i=new tm(null,null),n=i,r=0;r<t.length;r++)n=n.next=new tm(t[r],e[r]);return n.next=null,i.next}(t,e),r);n=this._size+n,this._root=lm({head:o},0,n)}return this},t.prototype.isEmpty=function(){return null===this._root},Object.defineProperty(t.prototype,"size",{get:function(){return this._size},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"root",{get:function(){return this._root},enumerable:!0,configurable:!0}),t.prototype.toString=function(t){void 0===t&&(t=function(t){return String(t.key)});var e=[];return om(this._root,"",!0,(function(t){return e.push(t)}),t),e.join("")},t.prototype.update=function(t,e,i){var n=this._comparator,r=rm(t,this._root,n),o=r.left,s=r.right;n(t,e)<0?s=nm(e,i,s,n):o=nm(e,i,o,n),this._root=function(t,e,i){return null===e?t:(null===t||((e=im(t.key,e,i)).left=t),e)}(o,s,n)},t.prototype.split=function(t){return rm(t,this._root,this._comparator)},t}();function am(t,e,i,n){var r=n-i;if(r>0){var o=i+Math.floor(r/2),s=t[o],a=e[o],l=new tm(s,a);return l.left=am(t,e,i,o),l.right=am(t,e,o+1,n),l}return null}function lm(t,e,i){var n=i-e;if(n>0){var r=e+Math.floor(n/2),o=lm(t,e,r),s=t.head;return s.left=o,t.head=t.head.next,s.right=lm(t,r+1,i),s}return null}function um(t,e,i,n,r){if(!(i>=n)){for(var o=t[i+n>>1],s=i-1,a=n+1;;){do{s++}while(r(t[s],o)<0);do{a--}while(r(t[a],o)>0);if(s>=a)break;var l=t[s];t[s]=t[a],t[a]=l,l=e[s],e[s]=e[a],e[a]=l}um(t,e,i,a,r),um(t,e,a+1,n,r)}}function hm(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function cm(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function pm(t,e,i){return e&&cm(t.prototype,e),i&&cm(t,i),t}var dm=function(t,e){return t.ll.x<=e.x&&e.x<=t.ur.x&&t.ll.y<=e.y&&e.y<=t.ur.y},fm=function(t,e){if(e.ur.x<t.ll.x||t.ur.x<e.ll.x||e.ur.y<t.ll.y||t.ur.y<e.ll.y)return null;var i=t.ll.x<e.ll.x?e.ll.x:t.ll.x,n=t.ur.x<e.ur.x?t.ur.x:e.ur.x;return{ll:{x:i,y:t.ll.y<e.ll.y?e.ll.y:t.ll.y},ur:{x:n,y:t.ur.y<e.ur.y?t.ur.y:e.ur.y}}},ym=Number.EPSILON;void 0===ym&&(ym=Math.pow(2,-52));var gm=ym*ym,mm=function(t,e){if(-ym<t&&t<ym&&-ym<e&&e<ym)return 0;var i=t-e;return i*i<gm*t*e?0:t<e?-1:1},vm=function(){function t(){hm(this,t),this.reset()}return pm(t,[{key:"reset",value:function(){this.xRounder=new _m,this.yRounder=new _m}},{key:"round",value:function(t,e){return{x:this.xRounder.round(t),y:this.yRounder.round(e)}}}]),t}(),_m=function(){function t(){hm(this,t),this.tree=new sm,this.round(0)}return pm(t,[{key:"round",value:function(t){var e=this.tree.add(t),i=this.tree.prev(e);if(null!==i&&0===mm(e.key,i.key))return this.tree.remove(t),i.key;var n=this.tree.next(e);return null!==n&&0===mm(e.key,n.key)?(this.tree.remove(t),n.key):t}}]),t}(),xm=new vm,bm=function(t,e){return t.x*e.y-t.y*e.x},wm=function(t,e){return t.x*e.x+t.y*e.y},Sm=function(t,e,i){var n={x:e.x-t.x,y:e.y-t.y},r={x:i.x-t.x,y:i.y-t.y},o=bm(n,r);return mm(o,0)},Cm=function(t){return Math.sqrt(wm(t,t))},Tm=function(t,e,i){var n={x:e.x-t.x,y:e.y-t.y},r={x:i.x-t.x,y:i.y-t.y};return wm(r,n)/Cm(r)/Cm(n)},Em=function(t,e,i){return 0===e.y?null:{x:t.x+e.x/e.y*(i-t.y),y:i}},km=function(t,e,i){return 0===e.x?null:{x:i,y:t.y+e.y/e.x*(i-t.x)}},Pm=function(){function t(e,i){hm(this,t),void 0===e.events?e.events=[this]:e.events.push(this),this.point=e,this.isLeft=i}return pm(t,null,[{key:"compare",value:function(e,i){var n=t.comparePoints(e.point,i.point);return 0!==n?n:(e.point!==i.point&&e.link(i),e.isLeft!==i.isLeft?e.isLeft?1:-1:Rm.compare(e.segment,i.segment))}},{key:"comparePoints",value:function(t,e){return t.x<e.x?-1:t.x>e.x?1:t.y<e.y?-1:t.y>e.y?1:0}}]),pm(t,[{key:"link",value:function(t){if(t.point===this.point)throw new Error("Tried to link already linked events");for(var e=t.point.events,i=0,n=e.length;i<n;i++){var r=e[i];this.point.events.push(r),r.point=this.point}this.checkForConsuming()}},{key:"checkForConsuming",value:function(){for(var t=this.point.events.length,e=0;e<t;e++){var i=this.point.events[e];if(void 0===i.segment.consumedBy)for(var n=e+1;n<t;n++){var r=this.point.events[n];void 0===r.consumedBy&&(i.otherSE.point.events===r.otherSE.point.events&&i.segment.consume(r.segment))}}}},{key:"getAvailableLinkedEvents",value:function(){for(var t=[],e=0,i=this.point.events.length;e<i;e++){var n=this.point.events[e];n!==this&&!n.segment.ringOut&&n.segment.isInResult()&&t.push(n)}return t}},{key:"getLeftmostComparator",value:function(t){var e=this,i=new Map,n=function(n){var r,o,s,a,l,u=n.otherSE;i.set(n,{sine:(r=e.point,o=t.point,s=u.point,a={x:o.x-r.x,y:o.y-r.y},l={x:s.x-r.x,y:s.y-r.y},bm(l,a)/Cm(l)/Cm(a)),cosine:Tm(e.point,t.point,u.point)})};return function(t,e){i.has(t)||n(t),i.has(e)||n(e);var r=i.get(t),o=r.sine,s=r.cosine,a=i.get(e),l=a.sine,u=a.cosine;return o>=0&&l>=0?s<u?1:s>u?-1:0:o<0&&l<0?s<u?-1:s>u?1:0:l<o?-1:l>o?1:0}}}]),t}(),Om=0,Rm=function(){function t(e,i,n,r){hm(this,t),this.id=++Om,this.leftSE=e,e.segment=this,e.otherSE=i,this.rightSE=i,i.segment=this,i.otherSE=e,this.rings=n,this.windings=r}return pm(t,null,[{key:"compare",value:function(t,e){var i=t.leftSE.point.x,n=e.leftSE.point.x,r=t.rightSE.point.x,o=e.rightSE.point.x;if(o<i)return 1;if(r<n)return-1;var s=t.leftSE.point.y,a=e.leftSE.point.y,l=t.rightSE.point.y,u=e.rightSE.point.y;if(i<n){if(a<s&&a<l)return 1;if(a>s&&a>l)return-1;var h=t.comparePoint(e.leftSE.point);if(h<0)return 1;if(h>0)return-1;var c=e.comparePoint(t.rightSE.point);return 0!==c?c:-1}if(i>n){if(s<a&&s<u)return-1;if(s>a&&s>u)return 1;var p=e.comparePoint(t.leftSE.point);if(0!==p)return p;var d=t.comparePoint(e.rightSE.point);return d<0?1:d>0?-1:1}if(s<a)return-1;if(s>a)return 1;if(r<o){var f=e.comparePoint(t.rightSE.point);if(0!==f)return f}if(r>o){var y=t.comparePoint(e.rightSE.point);if(y<0)return 1;if(y>0)return-1}if(r!==o){var g=l-s,m=r-i,v=u-a,_=o-n;if(g>m&&v<_)return 1;if(g<m&&v>_)return-1}return r>o?1:r<o||l<u?-1:l>u?1:t.id<e.id?-1:t.id>e.id?1:0}}]),pm(t,[{key:"replaceRightSE",value:function(t){this.rightSE=t,this.rightSE.segment=this,this.rightSE.otherSE=this.leftSE,this.leftSE.otherSE=this.rightSE}},{key:"bbox",value:function(){var t=this.leftSE.point.y,e=this.rightSE.point.y;return{ll:{x:this.leftSE.point.x,y:t<e?t:e},ur:{x:this.rightSE.point.x,y:t>e?t:e}}}},{key:"vector",value:function(){return{x:this.rightSE.point.x-this.leftSE.point.x,y:this.rightSE.point.y-this.leftSE.point.y}}},{key:"isAnEndpoint",value:function(t){return t.x===this.leftSE.point.x&&t.y===this.leftSE.point.y||t.x===this.rightSE.point.x&&t.y===this.rightSE.point.y}},{key:"comparePoint",value:function(t){if(this.isAnEndpoint(t))return 0;var e=this.leftSE.point,i=this.rightSE.point,n=this.vector();if(e.x===i.x)return t.x===e.x?0:t.x<e.x?1:-1;var r=(t.y-e.y)/n.y,o=e.x+r*n.x;if(t.x===o)return 0;var s=(t.x-e.x)/n.x,a=e.y+s*n.y;return t.y===a?0:t.y<a?-1:1}},{key:"getIntersection",value:function(t){var e=this.bbox(),i=t.bbox(),n=fm(e,i);if(null===n)return null;var r=this.leftSE.point,o=this.rightSE.point,s=t.leftSE.point,a=t.rightSE.point,l=dm(e,s)&&0===this.comparePoint(s),u=dm(i,r)&&0===t.comparePoint(r),h=dm(e,a)&&0===this.comparePoint(a),c=dm(i,o)&&0===t.comparePoint(o);if(u&&l)return c&&!h?o:!c&&h?a:null;if(u)return h&&r.x===a.x&&r.y===a.y?null:r;if(l)return c&&o.x===s.x&&o.y===s.y?null:s;if(c&&h)return null;if(c)return o;if(h)return a;var p=function(t,e,i,n){if(0===e.x)return km(i,n,t.x);if(0===n.x)return km(t,e,i.x);if(0===e.y)return Em(i,n,t.y);if(0===n.y)return Em(t,e,i.y);var r=bm(e,n);if(0==r)return null;var o={x:i.x-t.x,y:i.y-t.y},s=bm(o,e)/r,a=bm(o,n)/r;return{x:(t.x+a*e.x+(i.x+s*n.x))/2,y:(t.y+a*e.y+(i.y+s*n.y))/2}}(r,this.vector(),s,t.vector());return null===p?null:dm(n,p)?xm.round(p.x,p.y):null}},{key:"split",value:function(e){var i=[],n=void 0!==e.events,r=new Pm(e,!0),o=new Pm(e,!1),s=this.rightSE;this.replaceRightSE(o),i.push(o),i.push(r);var a=new t(r,s,this.rings.slice(),this.windings.slice());return Pm.comparePoints(a.leftSE.point,a.rightSE.point)>0&&a.swapEvents(),Pm.comparePoints(this.leftSE.point,this.rightSE.point)>0&&this.swapEvents(),n&&(r.checkForConsuming(),o.checkForConsuming()),i}},{key:"swapEvents",value:function(){var t=this.rightSE;this.rightSE=this.leftSE,this.leftSE=t,this.leftSE.isLeft=!0,this.rightSE.isLeft=!1;for(var e=0,i=this.windings.length;e<i;e++)this.windings[e]*=-1}},{key:"consume",value:function(e){for(var i=this,n=e;i.consumedBy;)i=i.consumedBy;for(;n.consumedBy;)n=n.consumedBy;var r=t.compare(i,n);if(0!==r){if(r>0){var o=i;i=n,n=o}if(i.prev===n){var s=i;i=n,n=s}for(var a=0,l=n.rings.length;a<l;a++){var u=n.rings[a],h=n.windings[a],c=i.rings.indexOf(u);-1===c?(i.rings.push(u),i.windings.push(h)):i.windings[c]+=h}n.rings=null,n.windings=null,n.consumedBy=i,n.leftSE.consumedBy=i.leftSE,n.rightSE.consumedBy=i.rightSE}}},{key:"prevInResult",value:function(){return void 0!==this._prevInResult||(this.prev?this.prev.isInResult()?this._prevInResult=this.prev:this._prevInResult=this.prev.prevInResult():this._prevInResult=null),this._prevInResult}},{key:"beforeState",value:function(){if(void 0!==this._beforeState)return this._beforeState;if(this.prev){var t=this.prev.consumedBy||this.prev;this._beforeState=t.afterState()}else this._beforeState={rings:[],windings:[],multiPolys:[]};return this._beforeState}},{key:"afterState",value:function(){if(void 0!==this._afterState)return this._afterState;var t=this.beforeState();this._afterState={rings:t.rings.slice(0),windings:t.windings.slice(0),multiPolys:[]};for(var e=this._afterState.rings,i=this._afterState.windings,n=this._afterState.multiPolys,r=0,o=this.rings.length;r<o;r++){var s=this.rings[r],a=this.windings[r],l=e.indexOf(s);-1===l?(e.push(s),i.push(a)):i[l]+=a}for(var u=[],h=[],c=0,p=e.length;c<p;c++)if(0!==i[c]){var d=e[c],f=d.poly;if(-1===h.indexOf(f))if(d.isExterior)u.push(f);else{-1===h.indexOf(f)&&h.push(f);var y=u.indexOf(d.poly);-1!==y&&u.splice(y,1)}}for(var g=0,m=u.length;g<m;g++){var v=u[g].multiPoly;-1===n.indexOf(v)&&n.push(v)}return this._afterState}},{key:"isInResult",value:function(){if(this.consumedBy)return!1;if(void 0!==this._isInResult)return this._isInResult;var t=this.beforeState().multiPolys,e=this.afterState().multiPolys;switch(Nm.type){case"union":var i=0===t.length,n=0===e.length;this._isInResult=i!==n;break;case"intersection":var r,o;t.length<e.length?(r=t.length,o=e.length):(r=e.length,o=t.length),this._isInResult=o===Nm.numMultiPolys&&r<o;break;case"xor":var s=Math.abs(t.length-e.length);this._isInResult=s%2==1;break;case"difference":var a=function(t){return 1===t.length&&t[0].isSubject};this._isInResult=a(t)!==a(e);break;default:throw new Error("Unrecognized operation type found ".concat(Nm.type))}return this._isInResult}}],[{key:"fromRing",value:function(e,i,n){var r,o,s,a=Pm.comparePoints(e,i);if(a<0)r=e,o=i,s=1;else{if(!(a>0))throw new Error("Tried to create degenerate segment at [".concat(e.x,", ").concat(e.y,"]"));r=i,o=e,s=-1}return new t(new Pm(r,!0),new Pm(o,!1),[n],[s])}}]),t}(),Im=function(){function t(e,i,n){if(hm(this,t),!Array.isArray(e)||0===e.length)throw new Error("Input geometry is not a valid Polygon or MultiPolygon");if(this.poly=i,this.isExterior=n,this.segments=[],"number"!=typeof e[0][0]||"number"!=typeof e[0][1])throw new Error("Input geometry is not a valid Polygon or MultiPolygon");var r=xm.round(e[0][0],e[0][1]);this.bbox={ll:{x:r.x,y:r.y},ur:{x:r.x,y:r.y}};for(var o=r,s=1,a=e.length;s<a;s++){if("number"!=typeof e[s][0]||"number"!=typeof e[s][1])throw new Error("Input geometry is not a valid Polygon or MultiPolygon");var l=xm.round(e[s][0],e[s][1]);l.x===o.x&&l.y===o.y||(this.segments.push(Rm.fromRing(o,l,this)),l.x<this.bbox.ll.x&&(this.bbox.ll.x=l.x),l.y<this.bbox.ll.y&&(this.bbox.ll.y=l.y),l.x>this.bbox.ur.x&&(this.bbox.ur.x=l.x),l.y>this.bbox.ur.y&&(this.bbox.ur.y=l.y),o=l)}r.x===o.x&&r.y===o.y||this.segments.push(Rm.fromRing(o,r,this))}return pm(t,[{key:"getSweepEvents",value:function(){for(var t=[],e=0,i=this.segments.length;e<i;e++){var n=this.segments[e];t.push(n.leftSE),t.push(n.rightSE)}return t}}]),t}(),Fm=function(){function t(e,i){if(hm(this,t),!Array.isArray(e))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");this.exteriorRing=new Im(e[0],this,!0),this.bbox={ll:{x:this.exteriorRing.bbox.ll.x,y:this.exteriorRing.bbox.ll.y},ur:{x:this.exteriorRing.bbox.ur.x,y:this.exteriorRing.bbox.ur.y}},this.interiorRings=[];for(var n=1,r=e.length;n<r;n++){var o=new Im(e[n],this,!1);o.bbox.ll.x<this.bbox.ll.x&&(this.bbox.ll.x=o.bbox.ll.x),o.bbox.ll.y<this.bbox.ll.y&&(this.bbox.ll.y=o.bbox.ll.y),o.bbox.ur.x>this.bbox.ur.x&&(this.bbox.ur.x=o.bbox.ur.x),o.bbox.ur.y>this.bbox.ur.y&&(this.bbox.ur.y=o.bbox.ur.y),this.interiorRings.push(o)}this.multiPoly=i}return pm(t,[{key:"getSweepEvents",value:function(){for(var t=this.exteriorRing.getSweepEvents(),e=0,i=this.interiorRings.length;e<i;e++)for(var n=this.interiorRings[e].getSweepEvents(),r=0,o=n.length;r<o;r++)t.push(n[r]);return t}}]),t}(),jm=function(){function t(e,i){if(hm(this,t),!Array.isArray(e))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");try{"number"==typeof e[0][0][0]&&(e=[e])}catch(s){}this.polys=[],this.bbox={ll:{x:Number.POSITIVE_INFINITY,y:Number.POSITIVE_INFINITY},ur:{x:Number.NEGATIVE_INFINITY,y:Number.NEGATIVE_INFINITY}};for(var n=0,r=e.length;n<r;n++){var o=new Fm(e[n],this);o.bbox.ll.x<this.bbox.ll.x&&(this.bbox.ll.x=o.bbox.ll.x),o.bbox.ll.y<this.bbox.ll.y&&(this.bbox.ll.y=o.bbox.ll.y),o.bbox.ur.x>this.bbox.ur.x&&(this.bbox.ur.x=o.bbox.ur.x),o.bbox.ur.y>this.bbox.ur.y&&(this.bbox.ur.y=o.bbox.ur.y),this.polys.push(o)}this.isSubject=i}return pm(t,[{key:"getSweepEvents",value:function(){for(var t=[],e=0,i=this.polys.length;e<i;e++)for(var n=this.polys[e].getSweepEvents(),r=0,o=n.length;r<o;r++)t.push(n[r]);return t}}]),t}(),Mm=function(){function t(e){hm(this,t),this.events=e;for(var i=0,n=e.length;i<n;i++)e[i].segment.ringOut=this;this.poly=null}return pm(t,null,[{key:"factory",value:function(e){for(var i=[],n=0,r=e.length;n<r;n++){var o=e[n];if(o.isInResult()&&!o.ringOut){for(var s=null,a=o.leftSE,l=o.rightSE,u=[a],h=a.point,c=[];s=a,a=l,u.push(a),a.point!==h;)for(;;){var p=a.getAvailableLinkedEvents();if(0===p.length){var d=u[0].point,f=u[u.length-1].point;throw new Error("Unable to complete output ring starting at [".concat(d.x,",")+" ".concat(d.y,"]. Last matching segment found ends at")+" [".concat(f.x,", ").concat(f.y,"]."))}if(1===p.length){l=p[0].otherSE;break}for(var y=null,g=0,m=c.length;g<m;g++)if(c[g].point===a.point){y=g;break}if(null===y){c.push({index:u.length,point:a.point});var v=a.getLeftmostComparator(s);l=p.sort(v)[0].otherSE;break}var _=c.splice(y)[0],x=u.splice(_.index);x.unshift(x[0].otherSE),i.push(new t(x.reverse()))}i.push(new t(u))}}return i}}]),pm(t,[{key:"getGeom",value:function(){for(var t=this.events[0].point,e=[t],i=1,n=this.events.length-1;i<n;i++){var r=this.events[i].point,o=this.events[i+1].point;0!==Sm(r,t,o)&&(e.push(r),t=r)}if(1===e.length)return null;var s=e[0],a=e[1];0===Sm(s,t,a)&&e.shift(),e.push(e[0]);for(var l=this.isExteriorRing()?1:-1,u=this.isExteriorRing()?0:e.length-1,h=this.isExteriorRing()?e.length:-1,c=[],p=u;p!=h;p+=l)c.push([e[p].x,e[p].y]);return c}},{key:"isExteriorRing",value:function(){if(void 0===this._isExteriorRing){var t=this.enclosingRing();this._isExteriorRing=!t||!t.isExteriorRing()}return this._isExteriorRing}},{key:"enclosingRing",value:function(){return void 0===this._enclosingRing&&(this._enclosingRing=this._calcEnclosingRing()),this._enclosingRing}},{key:"_calcEnclosingRing",value:function(){for(var t=this.events[0],e=1,i=this.events.length;e<i;e++){var n=this.events[e];Pm.compare(t,n)>0&&(t=n)}for(var r=t.segment.prevInResult(),o=r?r.prevInResult():null;;){if(!r)return null;if(!o)return r.ringOut;if(o.ringOut!==r.ringOut)return o.ringOut.enclosingRing()!==r.ringOut?r.ringOut:r.ringOut.enclosingRing();r=o.prevInResult(),o=r?r.prevInResult():null}}}]),t}(),Am=function(){function t(e){hm(this,t),this.exteriorRing=e,e.poly=this,this.interiorRings=[]}return pm(t,[{key:"addInterior",value:function(t){this.interiorRings.push(t),t.poly=this}},{key:"getGeom",value:function(){var t=[this.exteriorRing.getGeom()];if(null===t[0])return null;for(var e=0,i=this.interiorRings.length;e<i;e++){var n=this.interiorRings[e].getGeom();null!==n&&t.push(n)}return t}}]),t}(),Lm=function(){function t(e){hm(this,t),this.rings=e,this.polys=this._composePolys(e)}return pm(t,[{key:"getGeom",value:function(){for(var t=[],e=0,i=this.polys.length;e<i;e++){var n=this.polys[e].getGeom();null!==n&&t.push(n)}return t}},{key:"_composePolys",value:function(t){for(var e=[],i=0,n=t.length;i<n;i++){var r=t[i];if(!r.poly)if(r.isExteriorRing())e.push(new Am(r));else{var o=r.enclosingRing();o.poly||e.push(new Am(o)),o.poly.addInterior(r)}}return e}}]),t}(),zm=function(){function t(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Rm.compare;hm(this,t),this.queue=e,this.tree=new sm(i),this.segments=[]}return pm(t,[{key:"process",value:function(t){var e=t.segment,i=[];if(t.consumedBy)return t.isLeft?this.queue.remove(t.otherSE):this.tree.remove(e),i;var n=t.isLeft?this.tree.insert(e):this.tree.find(e);if(!n)throw new Error("Unable to find segment #".concat(e.id," ")+"[".concat(e.leftSE.point.x,", ").concat(e.leftSE.point.y,"] -> ")+"[".concat(e.rightSE.point.x,", ").concat(e.rightSE.point.y,"] ")+"in SweepLine tree. Please submit a bug report.");for(var r=n,o=n,s=void 0,a=void 0;void 0===s;)null===(r=this.tree.prev(r))?s=null:void 0===r.key.consumedBy&&(s=r.key);for(;void 0===a;)null===(o=this.tree.next(o))?a=null:void 0===o.key.consumedBy&&(a=o.key);if(t.isLeft){var l=null;if(s){var u=s.getIntersection(e);if(null!==u&&(e.isAnEndpoint(u)||(l=u),!s.isAnEndpoint(u)))for(var h=this._splitSafely(s,u),c=0,p=h.length;c<p;c++)i.push(h[c])}var d=null;if(a){var f=a.getIntersection(e);if(null!==f&&(e.isAnEndpoint(f)||(d=f),!a.isAnEndpoint(f)))for(var y=this._splitSafely(a,f),g=0,m=y.length;g<m;g++)i.push(y[g])}if(null!==l||null!==d){var v=null;if(null===l)v=d;else if(null===d)v=l;else{v=Pm.comparePoints(l,d)<=0?l:d}this.queue.remove(e.rightSE),i.push(e.rightSE);for(var _=e.split(v),x=0,b=_.length;x<b;x++)i.push(_[x])}i.length>0?(this.tree.remove(e),i.push(t)):(this.segments.push(e),e.prev=s)}else{if(s&&a){var w=s.getIntersection(a);if(null!==w){if(!s.isAnEndpoint(w))for(var S=this._splitSafely(s,w),C=0,T=S.length;C<T;C++)i.push(S[C]);if(!a.isAnEndpoint(w))for(var E=this._splitSafely(a,w),k=0,P=E.length;k<P;k++)i.push(E[k])}}this.tree.remove(e)}return i}},{key:"_splitSafely",value:function(t,e){this.tree.remove(t);var i=t.rightSE;this.queue.remove(i);var n=t.split(e);return n.push(i),void 0===t.consumedBy&&this.tree.insert(t),n}}]),t}(),Dm="undefined"!=typeof process&&{}.POLYGON_CLIPPING_MAX_QUEUE_SIZE||1e6,Gm="undefined"!=typeof process&&{}.POLYGON_CLIPPING_MAX_SWEEPLINE_SEGMENTS||1e6,Nm=new(function(){function t(){hm(this,t)}return pm(t,[{key:"run",value:function(t,e,i){Nm.type=t,xm.reset();for(var n=[new jm(e,!0)],r=0,o=i.length;r<o;r++)n.push(new jm(i[r],!1));if(Nm.numMultiPolys=n.length,"difference"===Nm.type)for(var s=n[0],a=1;a<n.length;)null!==fm(n[a].bbox,s.bbox)?a++:n.splice(a,1);if("intersection"===Nm.type)for(var l=0,u=n.length;l<u;l++)for(var h=n[l],c=l+1,p=n.length;c<p;c++)if(null===fm(h.bbox,n[c].bbox))return[];for(var d=new sm(Pm.compare),f=0,y=n.length;f<y;f++)for(var g=n[f].getSweepEvents(),m=0,v=g.length;m<v;m++)if(d.insert(g[m]),d.size>Dm)throw new Error("Infinite loop when putting segment endpoints in a priority queue (queue size too big). Please file a bug report.");for(var _=new zm(d),x=d.size,b=d.pop();b;){var w=b.key;if(d.size===x){var S=w.segment;throw new Error("Unable to pop() ".concat(w.isLeft?"left":"right"," SweepEvent ")+"[".concat(w.point.x,", ").concat(w.point.y,"] from segment #").concat(S.id," ")+"[".concat(S.leftSE.point.x,", ").concat(S.leftSE.point.y,"] -> ")+"[".concat(S.rightSE.point.x,", ").concat(S.rightSE.point.y,"] from queue. ")+"Please file a bug report.")}if(d.size>Dm)throw new Error("Infinite loop when passing sweep line over endpoints (queue size too big). Please file a bug report.");if(_.segments.length>Gm)throw new Error("Infinite loop when passing sweep line over endpoints (too many sweep line segments). Please file a bug report.");for(var C=_.process(w),T=0,E=C.length;T<E;T++){var k=C[T];void 0===k.consumedBy&&d.insert(k)}x=d.size,b=d.pop()}xm.reset();var P=Mm.factory(_.segments);return new Lm(P).getGeom()}}]),t}()),Bm=function(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),n=1;n<e;n++)i[n-1]=arguments[n];return Nm.run("union",t,i)};function Wm(t,e,i){void 0===i&&(i={});var n={type:"Feature"};return(0===i.id||i.id)&&(n.id=i.id),i.bbox&&(n.bbox=i.bbox),n.properties=e||{},n.geometry=t,n}function qm(t){return"Feature"===t.type?t.geometry:t}function Vm(t,e,i){void 0===i&&(i={});var n=qm(t),r=qm(e),o=Bm(n.coordinates,r.coordinates);return 0===o.length?null:1===o.length?function(t,e,i){void 0===i&&(i={});for(var n=0,r=t;n<r.length;n++){var o=r[n];if(o.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");for(var s=0;s<o[o.length-1].length;s++)if(o[o.length-1][s]!==o[0][s])throw new Error("First and last Position are not equivalent.")}return Wm({type:"Polygon",coordinates:t},e,i)}(o[0],i.properties):function(t,e,i){return void 0===i&&(i={}),Wm({type:"MultiPolygon",coordinates:t},e,i)}(o,i.properties)}function Um(t,e){const i=Dn(t),n=Math.round(100*i)/100;let r;return"m2"===e?r=n+" m²":"ha"===e&&(r=n/1e4+" ha"),r}function Xm(t,e,i){const n=e.getExtent();return t.getView().fit(Yi(n,i))}function Km(t,e){const[i,n,r]=Array.from(kr(t));return Sr([i,n,r,e])}const Ym=new Cc,Zm=new Cc;function Hm(t,e){const i=`\n <ogc:Filter>\n <ogc:Contains>\n <ogc:PropertyName>SHAPE</ogc:PropertyName>\n <gml:Point srsName="urn:ogc:def:crs:EPSG::4326">\n <gml:coordinates>${(n=t,o=nr(n,void 0!==r?r:"EPSG:3857","EPSG:4326"),s=o[0],(s<-180||s>180)&&(o[0]=De(s+180,360)-180),o).reverse().join(",")}</gml:coordinates>\n </gml:Point>\n </ogc:Contains>\n </ogc:Filter>\n `;var n,r,o,s;fetch(function(t){const e=Object.keys(t).map((e=>e+"="+encodeURI(t[e]))).join("&");return`https://api.os.uk/features/v1/wfs?${e}`}({key:e,service:"WFS",request:"GetFeature",version:"2.0.0",typeNames:"Topography_TopographicArea",propertyName:"TOID,DescriptiveGroup,SHAPE",outputFormat:"GEOJSON",srsName:"urn:ogc:def:crs:EPSG::4326",filter:i,count:1})).then((t=>t.json())).then((t=>{if(!t.features.length)return;const e=t.features[0].properties,i=["TOID","DescriptiveGroup"];Object.keys(e).forEach((t=>i.includes(t)||delete e[t]));const n=new Ta;n.readFeatures(t,{featureProjection:"EPSG:3857"}).forEach((t=>{const e=t.getProperties().TOID,i=Ym.getFeatureById(e);i?Ym.removeFeature(i):(t.setId(e),Ym.addFeature(t))})),Zm.clear(),Zm.addFeature(n.readFeature(Ym.getFeatures().reduce(((t,e)=>{const i=n.writeFeatureObject(e).geometry;return t?Vm(t,i):i}),null)))})).catch((t=>console.log(t)))}var $m,Jm=Object.freeze,Qm=Object.defineProperty,tv=Object.getOwnPropertyDescriptor,ev=(t,e,i,n)=>{for(var r,o=n>1?void 0:n?tv(e,i):e,s=t.length-1;s>=0;s--)(r=t[s])&&(o=(n?r(e,i,o):r(o))||o);return n&&o&&Qm(e,i,o),o};let iv=class extends ht{constructor(){super(...arguments),this.latitude=51.507351,this.longitude=-.127758,this.zoom=10,this.minZoom=7,this.maxZoom=22,this.drawMode=!1,this.drawGeojsonData={type:"Feature",geometry:{}},this.drawGeojsonDataBuffer=100,this.drawPointer="crosshair",this.showFeaturesAtPoint=!1,this.clickFeatures=!1,this.featureColor="#0000ff",this.featureFill=!1,this.featureBuffer=40,this.geojsonData={type:"FeatureCollection",features:[]},this.geojsonColor="#ff0000",this.geojsonFill=!1,this.geojsonBuffer=12,this.disableVectorTiles=!1,this.osVectorTilesApiKey="",this.osFeaturesApiKey="",this.osCopyright=`© Crown copyright and database rights ${(new Date).getFullYear()} OS (0)100024857`,this.hideResetControl=!1,this.staticMode=!1,this.areaUnit="m2",this.showScale=!1,this.useScaleBarStyle=!1,this.dispatch=(t,e)=>this.dispatchEvent(new CustomEvent(t,{detail:e}))}firstUpdated(){var t;const e=null==(t=this.shadowRoot)?void 0:t.querySelector("#map"),i=!this.disableVectorTiles&&Boolean(this.osVectorTilesApiKey),n=(r=this.osCopyright,o=this.osVectorTilesApiKey,new dd({source:o?new Ag({url:"https://api.os.uk/maps/raster/v1/zxy/Light_3857/{z}/{x}/{y}.png?key="+o,attributions:[r],attributionsCollapsible:!1,maxZoom:20}):new Dg({attributions:[zg]})}));var r,o;const s=function(t,e){let i=new pp({declutter:!0,source:new Xp({format:new Ll,url:"https://api.os.uk/maps/vector/v1/vts/tile/{z}/{y}/{x}.pbf?srs=3857&key="+e,attributions:[t],attributionsCollapsible:!1})});return e&&fetch("https://api.os.uk/maps/vector/v1/vts/resources/styles?srs=3857&key="+e).then((t=>t.json())).then((t=>jg(i,t,"esri"))).catch((t=>console.log(t))),i}(this.osCopyright,this.osVectorTilesApiKey),a=new Zp({target:e,layers:[i?s:n],view:new Ls({projection:"EPSG:3857",extent:(u=[-10.76418,49.528423,1.9134116,61.331151],h="EPSG:4326",c="EPSG:3857",En(u,ir(h,c),void 0,p)),minZoom:this.minZoom,maxZoom:this.maxZoom,center:Qn([this.longitude,this.latitude]),zoom:this.zoom,enableRotation:!1}),controls:Zs({attribution:!0,zoom:!this.staticMode}).extend(this.showScale?[(l=this.useScaleBarStyle,new Ys({units:"metric",bar:l,steps:4,text:!0,minWidth:140}))]:[]),interactions:Zc({doubleClickZoom:!this.staticMode,dragPan:!this.staticMode,mouseWheelZoom:!this.staticMode})});var l,u,h,c,p;const d=(f=this.drawPointer,new Mc({source:$g,type:"Polygon",style:new rl({stroke:Xg,fill:Kg,image:"crosshair"===f?Yg:Zg})}));var f;const y=function(t){return new Vc({source:$g,style:new rl({image:"crosshair"===t?Yg:Zg})})}(this.drawPointer),g=document.createElement("button");g.innerHTML="↻",g.title="Reset map view";g.addEventListener("click",(()=>{this.showFeaturesAtPoint?Xm(a,Zm,this.featureBuffer):_.getFeatures().length>0?Xm(a,_,this.geojsonBuffer):(a.getView().setCenter(Qn([this.longitude,this.latitude])),a.getView().setZoom(this.zoom)),this.drawMode&&($g.clear(),a.addInteraction(d),a.addInteraction(Qg))}),!1);const m=document.createElement("div");m.className="reset-control ol-unselectable ol-control",m.appendChild(g);var v=new ge({element:m});this.hideResetControl||a.addControl(v),a.on("pointerdrag",(()=>{a.getViewport().style.cursor="grabbing"})),a.on("pointermove",(()=>{a.getViewport().style.cursor="grab"}));const _=new Cc;if("FeatureCollection"===this.geojsonData.type){let t=(new Ta).readFeatures(this.geojsonData,{featureProjection:"EPSG:3857"});_.addFeatures(t)}else if("Feature"===this.geojsonData.type){let t=(new Ta).readFeature(this.geojsonData,{featureProjection:"EPSG:3857"});_.addFeature(t)}const x=new ac({source:_,style:new rl({stroke:new Ka({color:this.geojsonColor,width:3}),fill:new Ea({color:this.geojsonFill?Km(this.geojsonColor,.2):Km(this.geojsonColor,0)})})});if(a.addLayer(x),_.getFeatures().length>0){Xm(a,_,this.geojsonBuffer);const t=_.getFeatures()[0].getGeometry();this.dispatch("geojsonDataArea",Um(t,this.areaUnit))}if(this.drawMode){const t=Object.keys(this.drawGeojsonData.geometry).length>0;if(t){let t=(new Ta).readFeature(this.drawGeojsonData,{featureProjection:"EPSG:3857"});$g.addFeature(t),Xm(a,$g,this.drawGeojsonDataBuffer)}else $g.clear();a.addLayer(Jg),t||a.addInteraction(d),a.addInteraction(y),a.addInteraction(Qg),$g.on("change",(()=>{const t=$g.getFeatures();if(t.length>0){const i=(e=t,"string"==typeof e?e[e.length-1]||"":e[e.length-1]).getGeometry();this.dispatch("geojsonChange",(new Ta).writeFeaturesObject(t,{featureProjection:"EPSG:3857"})),this.dispatch("areaChange",Um(i,this.areaUnit)),a.removeInteraction(d)}var e}))}if(this.drawMode&&Boolean(this.osVectorTilesApiKey)&&!this.disableVectorTiles&&(a.addLayer(Wg),Jg.setZIndex(1001),a.on("moveend",(()=>{a.getView().getZoom()<20?Bg.clear():setTimeout((()=>{Bg.clear();const t=a.getView().calculateExtent(a.getSize());qg(s,t)}),200)}))),this.showFeaturesAtPoint&&Boolean(this.osFeaturesApiKey)){Hm(Qn([this.longitude,this.latitude]),this.osFeaturesApiKey),this.clickFeatures&&a.on("singleclick",(t=>{Hm(t.coordinate,this.osFeaturesApiKey)}));const t=(b=this.featureColor,w=this.featureFill,new ac({source:Zm,style:new rl({stroke:new Ka({width:3,color:b}),fill:new Ea({color:Km(b,w?.2:0)})})}));a.addLayer(t),Zm.on("change",(()=>{if("ready"===Zm.getState()&&Zm.getFeatures().length>0){Xm(a,Zm,this.featureBuffer),this.dispatch("featuresGeojsonChange",(new Ta).writeFeaturesObject(Zm.getFeatures(),{featureProjection:"EPSG:3857"}));const t=Zm.getFeatures()[0].getGeometry();this.dispatch("featuresAreaChange",Um(t,this.areaUnit))}}))}var b,w;setTimeout((()=>{window.dispatchEvent(new Event("resize")),e.style.opacity="1",this.dispatch("ready")}),500)}render(){return q($m||($m=Jm(Qm(t=['<script src="https://cdn.polyfill.io/v2/polyfill.min.js"><\/script>\n <link rel="stylesheet" href="https://cdn.skypack.dev/ol@^6.6.1/ol.css" />\n <div id="map" tabindex="0" />'],"raw",{value:Jm(e||t.slice())}))));var t,e}};var nv;iv.styles=((t,...e)=>{const i=1===t.length?t[0]:e.reduce(((e,i,n)=>e+(t=>{if(t instanceof c)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+t[n+1]),t[0]);return d(i)})`
42
42
  :host {
43
43
  display: block;
44
44
  width: 800px;
@@ -72,4 +72,4 @@ var tm=function(t,e){this.next=null,this.key=t,this.data=e,this.left=null,this.r
72
72
  z-index: 100;
73
73
  background: white;
74
74
  }
75
- `,iv([pt({type:Number})],nv.prototype,"latitude",2),iv([pt({type:Number})],nv.prototype,"longitude",2),iv([pt({type:Number})],nv.prototype,"zoom",2),iv([pt({type:Number})],nv.prototype,"minZoom",2),iv([pt({type:Number})],nv.prototype,"maxZoom",2),iv([pt({type:Boolean})],nv.prototype,"drawMode",2),iv([pt({type:Object})],nv.prototype,"drawGeojsonData",2),iv([pt({type:Number})],nv.prototype,"drawGeojsonDataBuffer",2),iv([pt({type:String})],nv.prototype,"drawPointer",2),iv([pt({type:Boolean})],nv.prototype,"showFeaturesAtPoint",2),iv([pt({type:Boolean})],nv.prototype,"clickFeatures",2),iv([pt({type:String})],nv.prototype,"featureColor",2),iv([pt({type:Boolean})],nv.prototype,"featureFill",2),iv([pt({type:Number})],nv.prototype,"featureBuffer",2),iv([pt({type:Object})],nv.prototype,"geojsonData",2),iv([pt({type:String})],nv.prototype,"geojsonColor",2),iv([pt({type:Boolean})],nv.prototype,"geojsonFill",2),iv([pt({type:Number})],nv.prototype,"geojsonBuffer",2),iv([pt({type:Boolean})],nv.prototype,"disableVectorTiles",2),iv([pt({type:String})],nv.prototype,"osVectorTilesApiKey",2),iv([pt({type:String})],nv.prototype,"osFeaturesApiKey",2),iv([pt({type:Boolean})],nv.prototype,"hideResetControl",2),iv([pt({type:Boolean})],nv.prototype,"staticMode",2),iv([pt({type:String})],nv.prototype,"areaUnit",2),iv([pt({type:Boolean})],nv.prototype,"showScale",2),iv([pt({type:Boolean})],nv.prototype,"useScaleBarStyle",2),nv=iv([(rv="my-map",t=>{return"function"==typeof t?(e=rv,i=t,window.customElements.define(e,i),i):((t,e)=>{const{kind:i,elements:n}=e;return{kind:i,elements:n,finisher(e){window.customElements.define(t,e)}}})(rv,t);var e,i})],nv);export{nv as MyMap};
75
+ `,ev([pt({type:Number})],iv.prototype,"latitude",2),ev([pt({type:Number})],iv.prototype,"longitude",2),ev([pt({type:Number})],iv.prototype,"zoom",2),ev([pt({type:Number})],iv.prototype,"minZoom",2),ev([pt({type:Number})],iv.prototype,"maxZoom",2),ev([pt({type:Boolean})],iv.prototype,"drawMode",2),ev([pt({type:Object})],iv.prototype,"drawGeojsonData",2),ev([pt({type:Number})],iv.prototype,"drawGeojsonDataBuffer",2),ev([pt({type:String})],iv.prototype,"drawPointer",2),ev([pt({type:Boolean})],iv.prototype,"showFeaturesAtPoint",2),ev([pt({type:Boolean})],iv.prototype,"clickFeatures",2),ev([pt({type:String})],iv.prototype,"featureColor",2),ev([pt({type:Boolean})],iv.prototype,"featureFill",2),ev([pt({type:Number})],iv.prototype,"featureBuffer",2),ev([pt({type:Object})],iv.prototype,"geojsonData",2),ev([pt({type:String})],iv.prototype,"geojsonColor",2),ev([pt({type:Boolean})],iv.prototype,"geojsonFill",2),ev([pt({type:Number})],iv.prototype,"geojsonBuffer",2),ev([pt({type:Boolean})],iv.prototype,"disableVectorTiles",2),ev([pt({type:String})],iv.prototype,"osVectorTilesApiKey",2),ev([pt({type:String})],iv.prototype,"osFeaturesApiKey",2),ev([pt({type:String})],iv.prototype,"osCopyright",2),ev([pt({type:Boolean})],iv.prototype,"hideResetControl",2),ev([pt({type:Boolean})],iv.prototype,"staticMode",2),ev([pt({type:String})],iv.prototype,"areaUnit",2),ev([pt({type:Boolean})],iv.prototype,"showScale",2),ev([pt({type:Boolean})],iv.prototype,"useScaleBarStyle",2),iv=ev([(nv="my-map",t=>{return"function"==typeof t?(e=nv,i=t,window.customElements.define(e,i),i):((t,e)=>{const{kind:i,elements:n}=e;return{kind:i,elements:n,finisher(e){window.customElements.define(t,e)}}})(nv,t);var e,i})],iv);export{iv as MyMap};