alt-route-labeller
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).altRouteLabeller={})}(this,(function(e){"use strict";var r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var t=function(e){var r={exports:{}};return e(r,r.exports),r.exports}((function(e,r){function t(e,r,t){void 0===t&&(t={});var n={type:"Feature"};return(0===t.id||t.id)&&(n.id=t.id),t.bbox&&(n.bbox=t.bbox),n.properties=r||{},n.geometry=e,n}function n(e,r,n){return void 0===n&&(n={}),t({type:"Point",coordinates:e},r,n)}function o(e,r,n){void 0===n&&(n={});for(var o=0,i=e;o<i.length;o++){var a=i[o];if(a.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");for(var u=0;u<a[a.length-1].length;u++)if(a[a.length-1][u]!==a[0][u])throw new Error("First and last Position are not equivalent.")}return t({type:"Polygon",coordinates:e},r,n)}function i(e,r,n){if(void 0===n&&(n={}),e.length<2)throw new Error("coordinates must be an array of two or more positions");return t({type:"LineString",coordinates:e},r,n)}function a(e,r){void 0===r&&(r={});var t={type:"FeatureCollection"};return r.id&&(t.id=r.id),r.bbox&&(t.bbox=r.bbox),t.features=e,t}function u(e,r,n){return void 0===n&&(n={}),t({type:"MultiLineString",coordinates:e},r,n)}function s(e,r,n){return void 0===n&&(n={}),t({type:"MultiPoint",coordinates:e},r,n)}function l(e,r,n){return void 0===n&&(n={}),t({type:"MultiPolygon",coordinates:e},r,n)}function c(e,t){void 0===t&&(t="kilometers");var n=r.factors[t];if(!n)throw new Error(t+" units is invalid");return e*n}function f(e,t){void 0===t&&(t="kilometers");var n=r.factors[t];if(!n)throw new Error(t+" units is invalid");return e/n}function d(e){return 180*(e%(2*Math.PI))/Math.PI}function g(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)&&!/^\s*$/.test(e)}Object.defineProperty(r,"__esModule",{value:!0}),r.earthRadius=6371008.8,r.factors={centimeters:100*r.earthRadius,centimetres:100*r.earthRadius,degrees:r.earthRadius/111325,feet:3.28084*r.earthRadius,inches:39.37*r.earthRadius,kilometers:r.earthRadius/1e3,kilometres:r.earthRadius/1e3,meters:r.earthRadius,metres:r.earthRadius,miles:r.earthRadius/1609.344,millimeters:1e3*r.earthRadius,millimetres:1e3*r.earthRadius,nauticalmiles:r.earthRadius/1852,radians:1,yards:r.earthRadius/1.0936},r.unitsFactors={centimeters:100,centimetres:100,degrees:1/111325,feet:3.28084,inches:39.37,kilometers:.001,kilometres:.001,meters:1,metres:1,miles:1/1609.344,millimeters:1e3,millimetres:1e3,nauticalmiles:1/1852,radians:1/r.earthRadius,yards:1/1.0936},r.areaFactors={acres:247105e-9,centimeters:1e4,centimetres:1e4,feet:10.763910417,inches:1550.003100006,kilometers:1e-6,kilometres:1e-6,meters:1,metres:1,miles:386e-9,millimeters:1e6,millimetres:1e6,yards:1.195990046},r.feature=t,r.geometry=function(e,r,t){switch(e){case"Point":return n(r).geometry;case"LineString":return i(r).geometry;case"Polygon":return o(r).geometry;case"MultiPoint":return s(r).geometry;case"MultiLineString":return u(r).geometry;case"MultiPolygon":return l(r).geometry;default:throw new Error(e+" is invalid")}},r.point=n,r.points=function(e,r,t){return void 0===t&&(t={}),a(e.map((function(e){return n(e,r)})),t)},r.polygon=o,r.polygons=function(e,r,t){return void 0===t&&(t={}),a(e.map((function(e){return o(e,r)})),t)},r.lineString=i,r.lineStrings=function(e,r,t){return void 0===t&&(t={}),a(e.map((function(e){return i(e,r)})),t)},r.featureCollection=a,r.multiLineString=u,r.multiPoint=s,r.multiPolygon=l,r.geometryCollection=function(e,r,n){return void 0===n&&(n={}),t({type:"GeometryCollection",geometries:e},r,n)},r.round=function(e,r){if(void 0===r&&(r=0),r&&!(r>=0))throw new Error("precision must be a positive number");var t=Math.pow(10,r||0);return Math.round(e*t)/t},r.radiansToLength=c,r.lengthToRadians=f,r.lengthToDegrees=function(e,r){return d(f(e,r))},r.bearingToAzimuth=function(e){var r=e%360;return r<0&&(r+=360),r},r.radiansToDegrees=d,r.degreesToRadians=function(e){return e%360*Math.PI/180},r.convertLength=function(e,r,t){if(void 0===r&&(r="kilometers"),void 0===t&&(t="kilometers"),!(e>=0))throw new Error("length must be a positive number");return c(f(e,r),t)},r.convertArea=function(e,t,n){if(void 0===t&&(t="meters"),void 0===n&&(n="kilometers"),!(e>=0))throw new Error("area must be a positive number");var o=r.areaFactors[t];if(!o)throw new Error("invalid original units");var i=r.areaFactors[n];if(!i)throw new Error("invalid final units");return e/o*i},r.isNumber=g,r.isObject=function(e){return!!e&&e.constructor===Object},r.validateBBox=function(e){if(!e)throw new Error("bbox is required");if(!Array.isArray(e))throw new Error("bbox must be an Array");if(4!==e.length&&6!==e.length)throw new Error("bbox must be an Array of 4 or 6 numbers");e.forEach((function(e){if(!g(e))throw new Error("bbox must only contain numbers")}))},r.validateId=function(e){if(!e)throw new Error("id is required");if(-1===["string","number"].indexOf(typeof e))throw new Error("id must be a number or a string")},r.radians2degrees=function(){throw new Error("method has been renamed to `radiansToDegrees`")},r.degrees2radians=function(){throw new Error("method has been renamed to `degreesToRadians`")},r.distanceToDegrees=function(){throw new Error("method has been renamed to `lengthToDegrees`")},r.distanceToRadians=function(){throw new Error("method has been renamed to `lengthToRadians`")},r.radiansToDistance=function(){throw new Error("method has been renamed to `radiansToLength`")},r.bearingToAngle=function(){throw new Error("method has been renamed to `bearingToAzimuth`")},r.convertDistance=function(){throw new Error("method has been renamed to `convertLength`")}}));function n(e,r,t){if(null!==e)for(var o,i,a,u,s,l,c,f,d=0,g=0,h=e.type,m="FeatureCollection"===h,y="Feature"===h,p=m?e.features.length:1,v=0;v<p;v++){s=(f=!!(c=m?e.features[v].geometry:y?e.geometry:e)&&"GeometryCollection"===c.type)?c.geometries.length:1;for(var w=0;w<s;w++){var b=0,M=0;if(null!==(u=f?c.geometries[w]:c)){l=u.coordinates;var P=u.type;switch(d=!t||"Polygon"!==P&&"MultiPolygon"!==P?0:1,P){case null:break;case"Point":if(!1===r(l,g,v,b,M))return!1;g++,b++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===r(l[o],g,v,b,M))return!1;g++,"MultiPoint"===P&&b++}"LineString"===P&&b++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-d;i++){if(!1===r(l[o][i],g,v,b,M))return!1;g++}"MultiLineString"===P&&b++,"Polygon"===P&&M++}"Polygon"===P&&b++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(M=0,i=0;i<l[o].length;i++){for(a=0;a<l[o][i].length-d;a++){if(!1===r(l[o][i][a],g,v,b,M))return!1;g++}M++}b++}break;case"GeometryCollection":for(o=0;o<u.geometries.length;o++)if(!1===n(u.geometries[o],r,t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function o(e,r){var t;switch(e.type){case"FeatureCollection":for(t=0;t<e.features.length&&!1!==r(e.features[t].properties,t);t++);break;case"Feature":r(e.properties,0)}}function i(e,r){if("Feature"===e.type)r(e,0);else if("FeatureCollection"===e.type)for(var t=0;t<e.features.length&&!1!==r(e.features[t],t);t++);}function a(e,r){var t,n,o,i,a,u,s,l,c,f,d=0,g="FeatureCollection"===e.type,h="Feature"===e.type,m=g?e.features.length:1;for(t=0;t<m;t++){for(u=g?e.features[t].geometry:h?e.geometry:e,l=g?e.features[t].properties:h?e.properties:{},c=g?e.features[t].bbox:h?e.bbox:void 0,f=g?e.features[t].id:h?e.id:void 0,a=(s=!!u&&"GeometryCollection"===u.type)?u.geometries.length:1,o=0;o<a;o++)if(null!==(i=s?u.geometries[o]:u))switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===r(i,d,l,c,f))return!1;break;case"GeometryCollection":for(n=0;n<i.geometries.length;n++)if(!1===r(i.geometries[n],d,l,c,f))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===r(null,d,l,c,f))return!1;d++}}function u(e,r){a(e,(function(e,n,o,i,a){var u,s=null===e?null:e.type;switch(s){case null:case"Point":case"LineString":case"Polygon":return!1!==r(t.feature(e,o,{bbox:i,id:a}),n,0)&&void 0}switch(s){case"MultiPoint":u="Point";break;case"MultiLineString":u="LineString";break;case"MultiPolygon":u="Polygon"}for(var l=0;l<e.coordinates.length;l++){var c={type:u,coordinates:e.coordinates[l]};if(!1===r(t.feature(c,o),n,l))return!1}}))}function s(e,r){u(e,(function(e,o,i){var a=0;if(e.geometry){var u=e.geometry.type;if("Point"!==u&&"MultiPoint"!==u){var s,l=0,c=0,f=0;return!1!==n(e,(function(n,u,d,g,h){if(void 0===s||o>l||g>c||h>f)return s=n,l=o,c=g,f=h,void(a=0);var m=t.lineString([s,n],e.properties);if(!1===r(m,o,i,h,a))return!1;a++,s=n}))&&void 0}}}))}function l(e,r){if(!e)throw new Error("geojson is required");u(e,(function(e,n,o){if(null!==e.geometry){var i=e.geometry.type,a=e.geometry.coordinates;switch(i){case"LineString":if(!1===r(e,n,o,0,0))return!1;break;case"Polygon":for(var u=0;u<a.length;u++)if(!1===r(t.lineString(a[u],e.properties),n,o,u))return!1}}}))}var c=n,f=function(e,r,t,o){var i=t;return n(e,(function(e,n,o,a,u){i=0===n&&void 0===t?e:r(i,e,n,o,a,u)}),o),i},d=o,g=function(e,r,t){var n=t;return o(e,(function(e,o){n=0===o&&void 0===t?e:r(n,e,o)})),n},h=i,m=function(e,r,t){var n=t;return i(e,(function(e,o){n=0===o&&void 0===t?e:r(n,e,o)})),n},y=function(e){var r=[];return n(e,(function(e){r.push(e)})),r},p=a,v=function(e,r,t){var n=t;return a(e,(function(e,o,i,a,u){n=0===o&&void 0===t?e:r(n,e,o,i,a,u)})),n},w=u,b=function(e,r,t){var n=t;return u(e,(function(e,o,i){n=0===o&&0===i&&void 0===t?e:r(n,e,o,i)})),n},M=s,P=function(e,r,t){var n=t,o=!1;return s(e,(function(e,i,a,u,s){n=!1===o&&void 0===t?e:r(n,e,i,a,u,s),o=!0})),n},E=l,R=function(e,r,t){var n=t;return l(e,(function(e,o,i,a){n=0===o&&void 0===t?e:r(n,e,o,i,a)})),n},T=function(e,r){if(r=r||{},!t.isObject(r))throw new Error("options is invalid");var n,o=r.featureIndex||0,i=r.multiFeatureIndex||0,a=r.geometryIndex||0,u=r.segmentIndex||0,s=r.properties;switch(e.type){case"FeatureCollection":o<0&&(o=e.features.length+o),s=s||e.features[o].properties,n=e.features[o].geometry;break;case"Feature":s=s||e.properties,n=e.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":n=e;break;default:throw new Error("geojson is invalid")}if(null===n)return null;var l=n.coordinates;switch(n.type){case"Point":case"MultiPoint":return null;case"LineString":return u<0&&(u=l.length+u-1),t.lineString([l[u],l[u+1]],s,r);case"Polygon":return a<0&&(a=l.length+a),u<0&&(u=l[a].length+u-1),t.lineString([l[a][u],l[a][u+1]],s,r);case"MultiLineString":return i<0&&(i=l.length+i),u<0&&(u=l[i].length+u-1),t.lineString([l[i][u],l[i][u+1]],s,r);case"MultiPolygon":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),u<0&&(u=l[i][a].length-u-1),t.lineString([l[i][a][u],l[i][a][u+1]],s,r)}throw new Error("geojson is invalid")},L=function(e,r){if(r=r||{},!t.isObject(r))throw new Error("options is invalid");var n,o=r.featureIndex||0,i=r.multiFeatureIndex||0,a=r.geometryIndex||0,u=r.coordIndex||0,s=r.properties;switch(e.type){case"FeatureCollection":o<0&&(o=e.features.length+o),s=s||e.features[o].properties,n=e.features[o].geometry;break;case"Feature":s=s||e.properties,n=e.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":n=e;break;default:throw new Error("geojson is invalid")}if(null===n)return null;var l=n.coordinates;switch(n.type){case"Point":return t.point(l,s,r);case"MultiPoint":return i<0&&(i=l.length+i),t.point(l[i],s,r);case"LineString":return u<0&&(u=l.length+u),t.point(l[u],s,r);case"Polygon":return a<0&&(a=l.length+a),u<0&&(u=l[a].length+u),t.point(l[a][u],s,r);case"MultiLineString":return i<0&&(i=l.length+i),u<0&&(u=l[i].length+u),t.point(l[i][u],s,r);case"MultiPolygon":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),u<0&&(u=l[i][a].length-u),t.point(l[i][a][u],s,r)}throw new Error("geojson is invalid")},S=Object.defineProperty({coordEach:c,coordReduce:f,propEach:d,propReduce:g,featureEach:h,featureReduce:m,coordAll:y,geomEach:p,geomReduce:v,flattenEach:w,flattenReduce:b,segmentEach:M,segmentReduce:P,lineEach:E,lineReduce:R,findSegment:T,findPoint:L},"__esModule",{value:!0});var F=function(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")};var k=function(e){if(Array.isArray(e))return e;if("Feature"===e.type){if(null!==e.geometry)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")};var x=function e(r){if(r.length>1&&t.isNumber(r[0])&&t.isNumber(r[1]))return!0;if(Array.isArray(r[0])&&r[0].length)return e(r[0]);throw new Error("coordinates must only contain numbers")};var C=function(e,r,t){if(!r||!t)throw new Error("type and name required");if(!e||e.type!==r)throw new Error("Invalid input to "+t+": must be a "+r+", given "+e.type)};var A=function(e,r,t){if(!e)throw new Error("No feature passed");if(!t)throw new Error(".featureOf() requires a name");if(!e||"Feature"!==e.type||!e.geometry)throw new Error("Invalid input to "+t+", Feature with geometry required");if(!e.geometry||e.geometry.type!==r)throw new Error("Invalid input to "+t+": must be a "+r+", given "+e.geometry.type)};var _=function(e,r,t){if(!e)throw new Error("No featureCollection passed");if(!t)throw new Error(".collectionOf() requires a name");if(!e||"FeatureCollection"!==e.type)throw new Error("Invalid input to "+t+", FeatureCollection required");for(var n=0,o=e.features;n<o.length;n++){var i=o[n];if(!i||"Feature"!==i.type||!i.geometry)throw new Error("Invalid input to "+t+", Feature with geometry required");if(!i.geometry||i.geometry.type!==r)throw new Error("Invalid input to "+t+": must be a "+r+", given "+i.geometry.type)}};var j=function(e){return"Feature"===e.type?e.geometry:e};var O=function(e,r){return"FeatureCollection"===e.type?"FeatureCollection":"GeometryCollection"===e.type?"GeometryCollection":"Feature"===e.type&&null!==e.geometry?e.geometry.type:e.type},I=Object.defineProperty({getCoord:F,getCoords:k,containsNumber:x,geojsonType:C,featureOf:A,collectionOf:_,getGeom:j,getType:O},"__esModule",{value:!0});function G(e,r,n){if(void 0===n&&(n={}),!0===n.final)return function(e,r){var t=G(r,e);return t=(t+180)%360}(e,r);var o=I.getCoord(e),i=I.getCoord(r),a=t.degreesToRadians(o[0]),u=t.degreesToRadians(i[0]),s=t.degreesToRadians(o[1]),l=t.degreesToRadians(i[1]),c=Math.sin(u-a)*Math.cos(l),f=Math.cos(s)*Math.sin(l)-Math.sin(s)*Math.cos(l)*Math.cos(u-a);return t.radiansToDegrees(Math.atan2(c,f))}var q=G,D=Object.defineProperty({default:q},"__esModule",{value:!0});var N=function(e,r,n,o){void 0===o&&(o={});var i=I.getCoord(e),a=t.degreesToRadians(i[0]),u=t.degreesToRadians(i[1]),s=t.degreesToRadians(n),l=t.lengthToRadians(r,o.units),c=Math.asin(Math.sin(u)*Math.cos(l)+Math.cos(u)*Math.sin(l)*Math.cos(s)),f=a+Math.atan2(Math.sin(s)*Math.sin(l)*Math.cos(u),Math.cos(l)-Math.sin(u)*Math.sin(c)),d=t.radiansToDegrees(f),g=t.radiansToDegrees(c);return t.point([d,g],o.properties)},B=Object.defineProperty({default:N},"__esModule",{value:!0});var z=function(e,r,n){void 0===n&&(n={});var o=I.getCoord(e),i=I.getCoord(r),a=t.degreesToRadians(i[1]-o[1]),u=t.degreesToRadians(i[0]-o[0]),s=t.degreesToRadians(o[1]),l=t.degreesToRadians(i[1]),c=Math.pow(Math.sin(a/2),2)+Math.pow(Math.sin(u/2),2)*Math.cos(s)*Math.cos(l);return t.radiansToLength(2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c)),n.units)},J=Object.defineProperty({default:z},"__esModule",{value:!0}),U=r&&r.__importDefault||function(e){return e&&e.__esModule?e:{default:e}},$=U(D),H=U(B),K=U(J);var Q=function(e,r,n){void 0===n&&(n={});for(var o=I.getGeom(e).coordinates,i=0,a=0;a<o.length&&!(r>=i&&a===o.length-1);a++){if(i>=r){var u=r-i;if(u){var s=$.default(o[a],o[a-1])-180;return H.default(o[a],u,s,n)}return t.point(o[a])}i+=K.default(o[a],o[a+1],n)}return t.point(o[o.length-1])},V=(r&&r.__importDefault||function(e){return e&&e.__esModule?e:{default:e}})(J);var W=function(e,r){return void 0===r&&(r={}),S.segmentReduce(e,(function(e,t){var n=t.geometry.coordinates;return e+V.default(n[0],n[1],r)}),0)};const X=(e,r)=>Math.abs(e-r)<1e-6,Y=e=>"".concat(e[0].toFixed(6),",").concat(e[1].toFixed(6)),Z=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return e[e.length-1]};function ee(e){if(e.length<2)return e;const r=e.map(y),n=new Map;return[].concat(...r).forEach((e=>{n.set(Y(e),(n.get(Y(e))||0)+1)})),r.map((e=>function(e,r){const n=[[]];e.forEach((e=>{r.get(Y(e))>1?n.push([]):Z(n).push(e)}));const o=n.filter((e=>e.length>0)).reduce(((e,r)=>r.length>e.length?r:e),[]);return t.lineString(0===o.length?e:o)}(e,n)))}function re(e){const r=y(e).reduce(((e,r)=>{const t=Z(e);return t&&function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return X(e[0],r[0])&&X(e[1],r[1])}(t,r)||e.push(r),e}),[]);return t.lineString(r)}function te(e){return e.map(((r,t)=>{const n=e.slice();n.splice(t,1);const o=function(e,r){return r.map((r=>q(r.lngLat,e.lngLat))).reduce(((e,r,t,n)=>{let{length:o}=n;return e+r/o}),0)||0}(r,n);return{lngLat:r.lngLat,anchor:ne(r,o)}}))}function ne(e,r){return"vertical"===(Math.abs(e.localLineBearing)<45||Math.abs(e.localLineBearing)>135?"vertical":"horizontal")?r>0?"left":"right":Math.abs(r)<90?"bottom":"top"}e.findDistinctSegments=ee,e.getLabelPositions=function(e){var r;return te(ee(e.features.map(re)).map((r=.5,e=>{const t=W(e);return{lngLat:F(Q(e,t*r)),localLineBearing:q(Q(e,t*(r-.1)),Q(e,t*(r+.1)))}})))},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).altRouteLabeller={})}(this,(function(e){"use strict";var r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var t=function(e){var r={exports:{}};return e(r,r.exports),r.exports}((function(e,r){function t(e,r,t){void 0===t&&(t={});var n={type:"Feature"};return(0===t.id||t.id)&&(n.id=t.id),t.bbox&&(n.bbox=t.bbox),n.properties=r||{},n.geometry=e,n}function n(e,r,n){return void 0===n&&(n={}),t({type:"Point",coordinates:e},r,n)}function o(e,r,n){void 0===n&&(n={});for(var o=0,i=e;o<i.length;o++){var a=i[o];if(a.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");for(var u=0;u<a[a.length-1].length;u++)if(a[a.length-1][u]!==a[0][u])throw new Error("First and last Position are not equivalent.")}return t({type:"Polygon",coordinates:e},r,n)}function i(e,r,n){if(void 0===n&&(n={}),e.length<2)throw new Error("coordinates must be an array of two or more positions");return t({type:"LineString",coordinates:e},r,n)}function a(e,r){void 0===r&&(r={});var t={type:"FeatureCollection"};return r.id&&(t.id=r.id),r.bbox&&(t.bbox=r.bbox),t.features=e,t}function u(e,r,n){return void 0===n&&(n={}),t({type:"MultiLineString",coordinates:e},r,n)}function s(e,r,n){return void 0===n&&(n={}),t({type:"MultiPoint",coordinates:e},r,n)}function l(e,r,n){return void 0===n&&(n={}),t({type:"MultiPolygon",coordinates:e},r,n)}function c(e,t){void 0===t&&(t="kilometers");var n=r.factors[t];if(!n)throw new Error(t+" units is invalid");return e*n}function f(e,t){void 0===t&&(t="kilometers");var n=r.factors[t];if(!n)throw new Error(t+" units is invalid");return e/n}function d(e){return 180*(e%(2*Math.PI))/Math.PI}function g(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)&&!/^\s*$/.test(e)}Object.defineProperty(r,"__esModule",{value:!0}),r.earthRadius=6371008.8,r.factors={centimeters:100*r.earthRadius,centimetres:100*r.earthRadius,degrees:r.earthRadius/111325,feet:3.28084*r.earthRadius,inches:39.37*r.earthRadius,kilometers:r.earthRadius/1e3,kilometres:r.earthRadius/1e3,meters:r.earthRadius,metres:r.earthRadius,miles:r.earthRadius/1609.344,millimeters:1e3*r.earthRadius,millimetres:1e3*r.earthRadius,nauticalmiles:r.earthRadius/1852,radians:1,yards:r.earthRadius/1.0936},r.unitsFactors={centimeters:100,centimetres:100,degrees:1/111325,feet:3.28084,inches:39.37,kilometers:.001,kilometres:.001,meters:1,metres:1,miles:1/1609.344,millimeters:1e3,millimetres:1e3,nauticalmiles:1/1852,radians:1/r.earthRadius,yards:1/1.0936},r.areaFactors={acres:247105e-9,centimeters:1e4,centimetres:1e4,feet:10.763910417,inches:1550.003100006,kilometers:1e-6,kilometres:1e-6,meters:1,metres:1,miles:386e-9,millimeters:1e6,millimetres:1e6,yards:1.195990046},r.feature=t,r.geometry=function(e,r,t){switch(e){case"Point":return n(r).geometry;case"LineString":return i(r).geometry;case"Polygon":return o(r).geometry;case"MultiPoint":return s(r).geometry;case"MultiLineString":return u(r).geometry;case"MultiPolygon":return l(r).geometry;default:throw new Error(e+" is invalid")}},r.point=n,r.points=function(e,r,t){return void 0===t&&(t={}),a(e.map((function(e){return n(e,r)})),t)},r.polygon=o,r.polygons=function(e,r,t){return void 0===t&&(t={}),a(e.map((function(e){return o(e,r)})),t)},r.lineString=i,r.lineStrings=function(e,r,t){return void 0===t&&(t={}),a(e.map((function(e){return i(e,r)})),t)},r.featureCollection=a,r.multiLineString=u,r.multiPoint=s,r.multiPolygon=l,r.geometryCollection=function(e,r,n){return void 0===n&&(n={}),t({type:"GeometryCollection",geometries:e},r,n)},r.round=function(e,r){if(void 0===r&&(r=0),r&&!(r>=0))throw new Error("precision must be a positive number");var t=Math.pow(10,r||0);return Math.round(e*t)/t},r.radiansToLength=c,r.lengthToRadians=f,r.lengthToDegrees=function(e,r){return d(f(e,r))},r.bearingToAzimuth=function(e){var r=e%360;return r<0&&(r+=360),r},r.radiansToDegrees=d,r.degreesToRadians=function(e){return e%360*Math.PI/180},r.convertLength=function(e,r,t){if(void 0===r&&(r="kilometers"),void 0===t&&(t="kilometers"),!(e>=0))throw new Error("length must be a positive number");return c(f(e,r),t)},r.convertArea=function(e,t,n){if(void 0===t&&(t="meters"),void 0===n&&(n="kilometers"),!(e>=0))throw new Error("area must be a positive number");var o=r.areaFactors[t];if(!o)throw new Error("invalid original units");var i=r.areaFactors[n];if(!i)throw new Error("invalid final units");return e/o*i},r.isNumber=g,r.isObject=function(e){return!!e&&e.constructor===Object},r.validateBBox=function(e){if(!e)throw new Error("bbox is required");if(!Array.isArray(e))throw new Error("bbox must be an Array");if(4!==e.length&&6!==e.length)throw new Error("bbox must be an Array of 4 or 6 numbers");e.forEach((function(e){if(!g(e))throw new Error("bbox must only contain numbers")}))},r.validateId=function(e){if(!e)throw new Error("id is required");if(-1===["string","number"].indexOf(typeof e))throw new Error("id must be a number or a string")},r.radians2degrees=function(){throw new Error("method has been renamed to `radiansToDegrees`")},r.degrees2radians=function(){throw new Error("method has been renamed to `degreesToRadians`")},r.distanceToDegrees=function(){throw new Error("method has been renamed to `lengthToDegrees`")},r.distanceToRadians=function(){throw new Error("method has been renamed to `lengthToRadians`")},r.radiansToDistance=function(){throw new Error("method has been renamed to `radiansToLength`")},r.bearingToAngle=function(){throw new Error("method has been renamed to `bearingToAzimuth`")},r.convertDistance=function(){throw new Error("method has been renamed to `convertLength`")}}));function n(e,r,t){if(null!==e)for(var o,i,a,u,s,l,c,f,d=0,g=0,h=e.type,m="FeatureCollection"===h,y="Feature"===h,p=m?e.features.length:1,v=0;v<p;v++){s=(f=!!(c=m?e.features[v].geometry:y?e.geometry:e)&&"GeometryCollection"===c.type)?c.geometries.length:1;for(var w=0;w<s;w++){var b=0,M=0;if(null!==(u=f?c.geometries[w]:c)){l=u.coordinates;var P=u.type;switch(d=!t||"Polygon"!==P&&"MultiPolygon"!==P?0:1,P){case null:break;case"Point":if(!1===r(l,g,v,b,M))return!1;g++,b++;break;case"LineString":case"MultiPoint":for(o=0;o<l.length;o++){if(!1===r(l[o],g,v,b,M))return!1;g++,"MultiPoint"===P&&b++}"LineString"===P&&b++;break;case"Polygon":case"MultiLineString":for(o=0;o<l.length;o++){for(i=0;i<l[o].length-d;i++){if(!1===r(l[o][i],g,v,b,M))return!1;g++}"MultiLineString"===P&&b++,"Polygon"===P&&M++}"Polygon"===P&&b++;break;case"MultiPolygon":for(o=0;o<l.length;o++){for(M=0,i=0;i<l[o].length;i++){for(a=0;a<l[o][i].length-d;a++){if(!1===r(l[o][i][a],g,v,b,M))return!1;g++}M++}b++}break;case"GeometryCollection":for(o=0;o<u.geometries.length;o++)if(!1===n(u.geometries[o],r,t))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function o(e,r){var t;switch(e.type){case"FeatureCollection":for(t=0;t<e.features.length&&!1!==r(e.features[t].properties,t);t++);break;case"Feature":r(e.properties,0)}}function i(e,r){if("Feature"===e.type)r(e,0);else if("FeatureCollection"===e.type)for(var t=0;t<e.features.length&&!1!==r(e.features[t],t);t++);}function a(e,r){var t,n,o,i,a,u,s,l,c,f,d=0,g="FeatureCollection"===e.type,h="Feature"===e.type,m=g?e.features.length:1;for(t=0;t<m;t++){for(u=g?e.features[t].geometry:h?e.geometry:e,l=g?e.features[t].properties:h?e.properties:{},c=g?e.features[t].bbox:h?e.bbox:void 0,f=g?e.features[t].id:h?e.id:void 0,a=(s=!!u&&"GeometryCollection"===u.type)?u.geometries.length:1,o=0;o<a;o++)if(null!==(i=s?u.geometries[o]:u))switch(i.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===r(i,d,l,c,f))return!1;break;case"GeometryCollection":for(n=0;n<i.geometries.length;n++)if(!1===r(i.geometries[n],d,l,c,f))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===r(null,d,l,c,f))return!1;d++}}function u(e,r){a(e,(function(e,n,o,i,a){var u,s=null===e?null:e.type;switch(s){case null:case"Point":case"LineString":case"Polygon":return!1!==r(t.feature(e,o,{bbox:i,id:a}),n,0)&&void 0}switch(s){case"MultiPoint":u="Point";break;case"MultiLineString":u="LineString";break;case"MultiPolygon":u="Polygon"}for(var l=0;l<e.coordinates.length;l++){var c={type:u,coordinates:e.coordinates[l]};if(!1===r(t.feature(c,o),n,l))return!1}}))}function s(e,r){u(e,(function(e,o,i){var a=0;if(e.geometry){var u=e.geometry.type;if("Point"!==u&&"MultiPoint"!==u){var s,l=0,c=0,f=0;return!1!==n(e,(function(n,u,d,g,h){if(void 0===s||o>l||g>c||h>f)return s=n,l=o,c=g,f=h,void(a=0);var m=t.lineString([s,n],e.properties);if(!1===r(m,o,i,h,a))return!1;a++,s=n}))&&void 0}}}))}function l(e,r){if(!e)throw new Error("geojson is required");u(e,(function(e,n,o){if(null!==e.geometry){var i=e.geometry.type,a=e.geometry.coordinates;switch(i){case"LineString":if(!1===r(e,n,o,0,0))return!1;break;case"Polygon":for(var u=0;u<a.length;u++)if(!1===r(t.lineString(a[u],e.properties),n,o,u))return!1}}}))}var c=n,f=function(e,r,t,o){var i=t;return n(e,(function(e,n,o,a,u){i=0===n&&void 0===t?e:r(i,e,n,o,a,u)}),o),i},d=o,g=function(e,r,t){var n=t;return o(e,(function(e,o){n=0===o&&void 0===t?e:r(n,e,o)})),n},h=i,m=function(e,r,t){var n=t;return i(e,(function(e,o){n=0===o&&void 0===t?e:r(n,e,o)})),n},y=function(e){var r=[];return n(e,(function(e){r.push(e)})),r},p=a,v=function(e,r,t){var n=t;return a(e,(function(e,o,i,a,u){n=0===o&&void 0===t?e:r(n,e,o,i,a,u)})),n},w=u,b=function(e,r,t){var n=t;return u(e,(function(e,o,i){n=0===o&&0===i&&void 0===t?e:r(n,e,o,i)})),n},M=s,P=function(e,r,t){var n=t,o=!1;return s(e,(function(e,i,a,u,s){n=!1===o&&void 0===t?e:r(n,e,i,a,u,s),o=!0})),n},E=l,R=function(e,r,t){var n=t;return l(e,(function(e,o,i,a){n=0===o&&void 0===t?e:r(n,e,o,i,a)})),n},T=function(e,r){if(r=r||{},!t.isObject(r))throw new Error("options is invalid");var n,o=r.featureIndex||0,i=r.multiFeatureIndex||0,a=r.geometryIndex||0,u=r.segmentIndex||0,s=r.properties;switch(e.type){case"FeatureCollection":o<0&&(o=e.features.length+o),s=s||e.features[o].properties,n=e.features[o].geometry;break;case"Feature":s=s||e.properties,n=e.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":n=e;break;default:throw new Error("geojson is invalid")}if(null===n)return null;var l=n.coordinates;switch(n.type){case"Point":case"MultiPoint":return null;case"LineString":return u<0&&(u=l.length+u-1),t.lineString([l[u],l[u+1]],s,r);case"Polygon":return a<0&&(a=l.length+a),u<0&&(u=l[a].length+u-1),t.lineString([l[a][u],l[a][u+1]],s,r);case"MultiLineString":return i<0&&(i=l.length+i),u<0&&(u=l[i].length+u-1),t.lineString([l[i][u],l[i][u+1]],s,r);case"MultiPolygon":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),u<0&&(u=l[i][a].length-u-1),t.lineString([l[i][a][u],l[i][a][u+1]],s,r)}throw new Error("geojson is invalid")},L=function(e,r){if(r=r||{},!t.isObject(r))throw new Error("options is invalid");var n,o=r.featureIndex||0,i=r.multiFeatureIndex||0,a=r.geometryIndex||0,u=r.coordIndex||0,s=r.properties;switch(e.type){case"FeatureCollection":o<0&&(o=e.features.length+o),s=s||e.features[o].properties,n=e.features[o].geometry;break;case"Feature":s=s||e.properties,n=e.geometry;break;case"Point":case"MultiPoint":return null;case"LineString":case"Polygon":case"MultiLineString":case"MultiPolygon":n=e;break;default:throw new Error("geojson is invalid")}if(null===n)return null;var l=n.coordinates;switch(n.type){case"Point":return t.point(l,s,r);case"MultiPoint":return i<0&&(i=l.length+i),t.point(l[i],s,r);case"LineString":return u<0&&(u=l.length+u),t.point(l[u],s,r);case"Polygon":return a<0&&(a=l.length+a),u<0&&(u=l[a].length+u),t.point(l[a][u],s,r);case"MultiLineString":return i<0&&(i=l.length+i),u<0&&(u=l[i].length+u),t.point(l[i][u],s,r);case"MultiPolygon":return i<0&&(i=l.length+i),a<0&&(a=l[i].length+a),u<0&&(u=l[i][a].length-u),t.point(l[i][a][u],s,r)}throw new Error("geojson is invalid")},S=Object.defineProperty({coordEach:c,coordReduce:f,propEach:d,propReduce:g,featureEach:h,featureReduce:m,coordAll:y,geomEach:p,geomReduce:v,flattenEach:w,flattenReduce:b,segmentEach:M,segmentReduce:P,lineEach:E,lineReduce:R,findSegment:T,findPoint:L},"__esModule",{value:!0});var F=function(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return e.geometry.coordinates;if("Point"===e.type)return e.coordinates}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return e;throw new Error("coord must be GeoJSON Point or an Array of numbers")};var k=function(e){if(Array.isArray(e))return e;if("Feature"===e.type){if(null!==e.geometry)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")};var x=function e(r){if(r.length>1&&t.isNumber(r[0])&&t.isNumber(r[1]))return!0;if(Array.isArray(r[0])&&r[0].length)return e(r[0]);throw new Error("coordinates must only contain numbers")};var C=function(e,r,t){if(!r||!t)throw new Error("type and name required");if(!e||e.type!==r)throw new Error("Invalid input to "+t+": must be a "+r+", given "+e.type)};var A=function(e,r,t){if(!e)throw new Error("No feature passed");if(!t)throw new Error(".featureOf() requires a name");if(!e||"Feature"!==e.type||!e.geometry)throw new Error("Invalid input to "+t+", Feature with geometry required");if(!e.geometry||e.geometry.type!==r)throw new Error("Invalid input to "+t+": must be a "+r+", given "+e.geometry.type)};var _=function(e,r,t){if(!e)throw new Error("No featureCollection passed");if(!t)throw new Error(".collectionOf() requires a name");if(!e||"FeatureCollection"!==e.type)throw new Error("Invalid input to "+t+", FeatureCollection required");for(var n=0,o=e.features;n<o.length;n++){var i=o[n];if(!i||"Feature"!==i.type||!i.geometry)throw new Error("Invalid input to "+t+", Feature with geometry required");if(!i.geometry||i.geometry.type!==r)throw new Error("Invalid input to "+t+": must be a "+r+", given "+i.geometry.type)}};var j=function(e){return"Feature"===e.type?e.geometry:e};var O=function(e,r){return"FeatureCollection"===e.type?"FeatureCollection":"GeometryCollection"===e.type?"GeometryCollection":"Feature"===e.type&&null!==e.geometry?e.geometry.type:e.type},I=Object.defineProperty({getCoord:F,getCoords:k,containsNumber:x,geojsonType:C,featureOf:A,collectionOf:_,getGeom:j,getType:O},"__esModule",{value:!0});function G(e,r,n){if(void 0===n&&(n={}),!0===n.final)return function(e,r){var t=G(r,e);return t=(t+180)%360}(e,r);var o=I.getCoord(e),i=I.getCoord(r),a=t.degreesToRadians(o[0]),u=t.degreesToRadians(i[0]),s=t.degreesToRadians(o[1]),l=t.degreesToRadians(i[1]),c=Math.sin(u-a)*Math.cos(l),f=Math.cos(s)*Math.sin(l)-Math.sin(s)*Math.cos(l)*Math.cos(u-a);return t.radiansToDegrees(Math.atan2(c,f))}var q=G,D=Object.defineProperty({default:q},"__esModule",{value:!0});var N=function(e,r,n,o){void 0===o&&(o={});var i=I.getCoord(e),a=t.degreesToRadians(i[0]),u=t.degreesToRadians(i[1]),s=t.degreesToRadians(n),l=t.lengthToRadians(r,o.units),c=Math.asin(Math.sin(u)*Math.cos(l)+Math.cos(u)*Math.sin(l)*Math.cos(s)),f=a+Math.atan2(Math.sin(s)*Math.sin(l)*Math.cos(u),Math.cos(l)-Math.sin(u)*Math.sin(c)),d=t.radiansToDegrees(f),g=t.radiansToDegrees(c);return t.point([d,g],o.properties)},B=Object.defineProperty({default:N},"__esModule",{value:!0});var z=function(e,r,n){void 0===n&&(n={});var o=I.getCoord(e),i=I.getCoord(r),a=t.degreesToRadians(i[1]-o[1]),u=t.degreesToRadians(i[0]-o[0]),s=t.degreesToRadians(o[1]),l=t.degreesToRadians(i[1]),c=Math.pow(Math.sin(a/2),2)+Math.pow(Math.sin(u/2),2)*Math.cos(s)*Math.cos(l);return t.radiansToLength(2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c)),n.units)},J=Object.defineProperty({default:z},"__esModule",{value:!0}),U=r&&r.__importDefault||function(e){return e&&e.__esModule?e:{default:e}},$=U(D),H=U(B),K=U(J);var Q=function(e,r,n){void 0===n&&(n={});for(var o=I.getGeom(e).coordinates,i=0,a=0;a<o.length&&!(r>=i&&a===o.length-1);a++){if(i>=r){var u=r-i;if(u){var s=$.default(o[a],o[a-1])-180;return H.default(o[a],u,s,n)}return t.point(o[a])}i+=K.default(o[a],o[a+1],n)}return t.point(o[o.length-1])},V=(r&&r.__importDefault||function(e){return e&&e.__esModule?e:{default:e}})(J);var W=function(e,r){return void 0===r&&(r={}),S.segmentReduce(e,(function(e,t){var n=t.geometry.coordinates;return e+V.default(n[0],n[1],r)}),0)};const X=(e,r)=>Math.abs(e-r)<1e-6,Y=e=>"".concat(e[0].toFixed(6),",").concat(e[1].toFixed(6)),Z=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return e[e.length-1]},ee=e=>r=>{const t=W(r);return{lngLat:F(Q(r,t*e)),localLineBearing:q(Q(r,t*(e-.1)),Q(r,t*(e+.1)))}};function re(e){if(e.length<2)return e;const r=e.map(y),n=new Map;return[].concat(...r).forEach((e=>{n.set(Y(e),(n.get(Y(e))||0)+1)})),r.map((e=>function(e,r){const n=[[]];e.forEach((e=>{r.get(Y(e))>1?n.push([]):Z(n).push(e)}));const o=n.filter((e=>e.length>0)).reduce(((e,r)=>r.length>e.length?r:e),[]);return t.lineString(0===o.length?e:o)}(e,n)))}function te(e){const r=y(e).reduce(((e,r)=>{const t=Z(e);return t&&function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return X(e[0],r[0])&&X(e[1],r[1])}(t,r)||e.push(r),e}),[]);return t.lineString(r)}function ne(e){return e.map(((r,t)=>{const n=e.slice();n.splice(t,1);const o=function(e,r){return r.map((r=>q(r.lngLat,e.lngLat))).reduce(((e,r,t,n)=>{let{length:o}=n;return e+r/o}),0)||0}(r,n);return{lngLat:r.lngLat,anchor:oe(r,o)}}))}function oe(e,r){return"vertical"===(Math.abs(e.localLineBearing)<45||Math.abs(e.localLineBearing)>135?"vertical":"horizontal")?r>0?"left":"right":Math.abs(r)<90?"bottom":"top"}e.findDistinctSegments=re,e.getLabelPositions=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];const r=Array.isArray(e)?e:e.features,t=r.map(te),n=re(t),o=n.map(ee(.5));return ne(o)},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=altRouteLabeller.js.map |
@@ -104,4 +104,6 @@ import { coordAll } from '@turf/meta'; | ||
export function getLabelPositions(featureCollection) { | ||
const lineStrings = featureCollection.features.map(toSimpleLinestring); | ||
// routes can be a FeatureCollection or an array of Feature or Geometry | ||
export function getLabelPositions(routes = []) { | ||
const featuresOrGeoms = Array.isArray(routes) ? routes : routes.features; | ||
const lineStrings = featuresOrGeoms.map(toSimpleLinestring); | ||
const segments = findDistinctSegments(lineStrings); | ||
@@ -108,0 +110,0 @@ const positions = segments.map(project(0.5)) |
{ | ||
"name": "alt-route-labeller", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "A library to compute the best position to put labels on multiple routes between two points", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
141914
189
0