1var DECODING_TABLE = [ 2 62, 3 -1, 4 -1, 5 52, 6 53, 7 54, 8 55, 9 56, 10 57, 11 58, 12 59, 13 60, 14 61, 15 -1, 16 -1, 17 -1, 18 -1, 19 -1, 20 -1, 21 -1, 22 0, 23 1, 24 2, 25 3, 26 4, 27 5, 28 6, 29 7, 30 8, 31 9, 32 10, 33 11, 34 12, 35 13, 36 14, 37 15, 38 16, 39 17, 40 18, 41 19, 42 20, 43 21, 44 22, 45 23, 46 24, 47 25, 48 -1, 49 -1, 50 -1, 51 -1, 52 63, 53 -1, 54 26, 55 27, 56 28, 57 29, 58 30, 59 31, 60 32, 61 33, 62 34, 63 35, 64 36, 65 37, 66 38, 67 39, 68 40, 69 41, 70 42, 71 43, 72 44, 73 45, 74 46, 75 47, 76 48, 77 49, 78 50, 79 51 80]; 81var FORMAT_VERSION = 1; 82var decodeChar = (char) => { 83 const charCode = char.charCodeAt(0); 84 const idx = DECODING_TABLE[charCode - 45]; 85 if (idx === -1) throw new Error("Invalid flexible polyline character."); 86 return idx; 87}; 88var decodeUnsignedValues = (encoded) => { 89 let result = 0; 90 let shift = 0; 91 const resList = []; 92 for (let i = 0; i < encoded.length; i++) { 93 const value = decodeChar(encoded[i]); 94 result |= (value & 31) << shift; 95 if ((value & 32) === 0) { 96 resList.push(result); 97 result = 0; 98 shift = 0; 99 } else shift += 5; 100 } 101 if (shift > 0) throw new Error("Invalid encoding"); 102 return resList; 103}; 104var decodeHeader = (version, encodedHeader) => { 105 if (version !== FORMAT_VERSION) throw new Error("Invalid format version"); 106 const precision = encodedHeader & 15; 107 const thirdDim = encodedHeader >> 4 & 7; 108 const thirdDimPrecision = encodedHeader >> 7 & 15; 109 return { 110 precision, 111 thirdDim, 112 thirdDimPrecision 113 }; 114}; 115var toSigned = (val) => { 116 let res = val; 117 if (res & 1) res = ~res; 118 res >>= 1; 119 return res; 120}; 121const decode = (encoded) => { 122 if (!encoded || typeof encoded !== "string") throw new Error("Encoded polyline must be a non-empty string."); 123 const decoder = decodeUnsignedValues(encoded); 124 if (decoder.length < 2) throw new Error("Invalid encoding. Missing header"); 125 const header = decodeHeader(decoder[0], decoder[1]); 126 const factorDegree = Math.pow(10, header.precision); 127 const factorZ = Math.pow(10, header.thirdDimPrecision); 128 const { thirdDim } = header; 129 let lastLat = 0; 130 let lastLng = 0; 131 let lastZ = 0; 132 const res = []; 133 let i = 2; 134 for (; i < decoder.length;) { 135 const deltaLat = toSigned(decoder[i]) / factorDegree; 136 const deltaLng = toSigned(decoder[i + 1]) / factorDegree; 137 lastLat += deltaLat; 138 lastLng += deltaLng; 139 if (thirdDim) { 140 if (i + 2 >= decoder.length) throw new Error("Invalid encoding. Premature ending reached"); 141 const deltaZ = toSigned(decoder[i + 2]) / factorZ; 142 lastZ += deltaZ; 143 res.push([ 144 lastLat, 145 lastLng, 146 lastZ 147 ]); 148 i += 3; 149 } else { 150 res.push([lastLat, lastLng]); 151 i += 2; 152 } 153 } 154 if (i !== decoder.length) throw new Error("Invalid encoding. Premature ending reached"); 155 return { 156 ...header, 157 polyline: res 158 }; 159}; 160export { decode as t };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.