@@ -23,7 +23,7 @@ module.exports = function (item, deps) {
2323 var labelLen = getLabelLen ( item . tags )
2424 var buf = Buffer . alloc ( 9 + typeLen + idLen + labelLen )
2525 var offset = 0
26- buf . writeUInt8 ( 0x01 , offset )
26+ buf . writeUInt8 ( 0x01 , offset )
2727 offset += 1
2828 varint . encode ( type , buf , offset )
2929 offset += varint . encode . bytes
@@ -47,16 +47,11 @@ module.exports = function (item, deps) {
4747 coords . push ( deps [ ref ] . lat )
4848 } )
4949 var cells = earcut ( coords )
50- var coords = [ ]
51- item . refs . forEach ( function ( ref ) {
52- coords . push ( deps [ ref ] . lon )
53- coords . push ( deps [ ref ] . lat )
54- } )
55- var cells = earcut ( coords )
56- var cLen = varint . encodingLength ( earcut . length / 3 )
50+ var cLen = varint . encodingLength ( cells . length / 3 )
51+ var cLenData = cells . reduce ( ( acc , cell ) => acc + varint . encodingLength ( cell ) , 0 )
5752 var labelLen = getLabelLen ( item . tags )
5853 var buf = Buffer . alloc ( 1 + typeLen + idLen + pCount + cLen + n * 4 * 2
59- + ( n - 2 ) * 3 * 2 + labelLen )
54+ + cLenData + labelLen )
6055 var offset = 0
6156 buf . writeUInt8 ( 0x03 , 0 )
6257 offset += 1
@@ -74,8 +69,8 @@ module.exports = function (item, deps) {
7469 } )
7570 varint . encode ( cells . length / 3 , buf , offset )
7671 offset += varint . encode . bytes
77- cells . forEach ( function ( item ) {
78- varint . encode ( item , buf , offset )
72+ cells . forEach ( function ( cell ) {
73+ varint . encode ( cell , buf , offset )
7974 offset += varint . encode . bytes
8075 } )
8176 writeLabelData ( item . tags , buf , offset )
@@ -117,7 +112,7 @@ function getLabelLen (tags) {
117112 if ( ! / ^ ( [ ^ : ] + _ | ) n a m e ( $ | : ) / . test ( key ) ) { return }
118113 var pre = key . replace ( / ^ ( | [ ^ : ] + _ ) n a m e ( $ | : ) / , '' )
119114 var dataLen = Buffer . byteLength ( pre ) + 1
120- + Buffer . byteLength ( tags [ key ] )
115+ + Buffer . byteLength ( tags [ key ] )
121116 labelLen += varint . encodingLength ( dataLen ) + dataLen
122117 } )
123118 return labelLen
0 commit comments