iwmlib/lib/3rdparty/d3/topojson.v2.min.js

2 lines
21 KiB
JavaScript
Raw Normal View History

2019-03-21 09:57:27 +01:00
// https://github.com/topojson/topojson Version 2.2.0. Copyright 2016 Mike Bostock.
(function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(n.topojson=n.topojson||{})})(this,function(n){"use strict";function r(n,r,e,o){t(n,r,e),t(n,r,r+o),t(n,r+o,e)}function t(n,r,t){for(var e,o=r+(t-- -r>>1);r<o;++r,--t)e=n[r],n[r]=n[t],n[t]=e}function e(n){return(n&&U.hasOwnProperty(n.type)?U[n.type]:a)(n)}function o(n){var r=n.geometry;return null==r?n.type=null:(a(r),n.type=r.type,r.geometries?n.geometries=r.geometries:r.coordinates&&(n.coordinates=r.coordinates),r.bbox&&(n.bbox=r.bbox)),delete n.geometry,n}function a(n){return n?(z.hasOwnProperty(n.type)&&z[n.type](n),n):{type:null}}function i(n){var r,t=n[0],e=n[1];return e<t&&(r=t,t=e,e=r),t+31*e}function c(n,r){var t,e=n[0],o=n[1],a=r[0],i=r[1];return o<e&&(t=e,e=o,o=t),i<a&&(t=a,a=i,i=t),e===a&&o===i}function u(){return!0}function f(n){return n}function l(n){return null!=n.type}function s(n,r){var t=r.id,e=r.bbox,o=null==r.properties?{}:r.properties,a=h(n,r);return null==t&&null==e?{type:"Feature",properties:o,geometry:a}:null==e?{type:"Feature",id:t,properties:o,geometry:a}:{type:"Feature",id:t,bbox:e,properties:o,geometry:a}}function h(n,r){function t(n,r){r.length&&r.pop();for(var t=f[n<0?~n:n],e=0,o=t.length;e<o;++e)r.push(u(t[e].slice(),e));n<0&&Q(r,o)}function e(n){return u(n.slice())}function o(n){for(var r=[],e=0,o=n.length;e<o;++e)t(n[e],r);return r.length<2&&r.push(r[0].slice()),r}function a(n){for(var r=o(n);r.length<4;)r.push(r[0].slice());return r}function i(n){return n.map(a)}function c(n){var r,t=n.type;switch(t){case"GeometryCollection":return{type:t,geometries:n.geometries.map(c)};case"Point":r=e(n.coordinates);break;case"MultiPoint":r=n.coordinates.map(e);break;case"LineString":r=o(n.arcs);break;case"MultiLineString":r=n.arcs.map(o);break;case"Polygon":r=i(n.arcs);break;case"MultiPolygon":r=n.arcs.map(i);break;default:return null}return{type:t,coordinates:r}}var u=J(n),f=n.arcs;return c(r)}function g(n,r,t){var e,o,a;if(arguments.length>1)e=v(n,r,t);else for(o=0,e=new Array(a=n.arcs.length);o<a;++o)e[o]=o;return{type:"MultiLineString",arcs:Y(n,e)}}function v(n,r,t){function e(n){var r=n<0?~n:n;(l[r]||(l[r]=[])).push({i:n,g:u})}function o(n){n.forEach(e)}function a(n){n.forEach(o)}function i(n){n.forEach(a)}function c(n){switch(u=n,n.type){case"GeometryCollection":n.geometries.forEach(c);break;case"LineString":o(n.arcs);break;case"MultiLineString":case"Polygon":a(n.arcs);break;case"MultiPolygon":i(n.arcs)}}var u,f=[],l=[];return c(r),l.forEach(null==t?function(n){f.push(n[0].i)}:function(n){t(n[0].g,n[n.length-1].g)&&f.push(n[0].i)}),f}function p(n){for(var r,t=-1,e=n.length,o=n[e-1],a=0;++t<e;)r=o,o=n[t],a+=r[0]*o[1]-r[1]*o[0];return Math.abs(a)}function y(n,r){function t(n){switch(n.type){case"GeometryCollection":n.geometries.forEach(t);break;case"Polygon":e(n.arcs);break;case"MultiPolygon":n.arcs.forEach(e)}}function e(n){n.forEach(function(r){r.forEach(function(r){(a[r=r<0?~r:r]||(a[r]=[])).push(n)})}),i.push(n)}function o(r){return p(h(n,{type:"Polygon",arcs:[r]}).coordinates[0])}var a={},i=[],c=[];return r.forEach(t),i.forEach(function(n){if(!n._){var r=[],t=[n];for(n._=1,c.push(r);n=t.pop();)r.push(n),n.forEach(function(n){n.forEach(function(n){a[n<0?~n:n].forEach(function(n){n._||(n._=1,t.push(n))})})})}}),i.forEach(function(n){delete n._}),{type:"MultiPolygon",arcs:c.map(function(r){var t,e=[];if(r.forEach(function(n){n.forEach(function(n){n.forEach(function(n){a[n<0?~n:n].length<2&&e.push(n)})})}),e=Y(n,e),(t=e.length)>1)for(var i,c,u=1,f=o(e[0]);u<t;++u)(i=o(e[u]))>f&&(c=e[0],e[0]=e[u],e[u]=c,f=i);return e})}}function d(n){var r=n[0],t=n[1],e=n[2];return Math.abs((r[0]-e[0])*(t[1]-r[1])-(r[0]-t[0])*(e[1]-r[1]))}function m(n){for(var r,t=-1,e=n.length,o=n[e-1],a=0;++t<e;)r=o,o=n[t],a+=r[0]*o[1]-r[1]*o[0];return Math.abs(a)/2}function b(n,r){return n[1][2]-r[1][2]}function E(n,r){if(t=n.length){if((r=+r)<=0||t<2)return n[0];if(r>=1)return n[t-1];var t,e=(t-1)*r,o=Math.floor(e),a=n[o],i=n[o+1];return a+(i-a)*(e-o)}}function M(n,r){return r-n}function P