@@ -2,6 +2,7 @@ import {Color} from './values';
22import type { FormattedSection } from './types/formatted' ;
33import type { GlobalProperties , Feature , FeatureState } from './index' ;
44import { ICanonicalTileID } from '../tiles_and_coordinates' ;
5+ import { calculateSignedArea } from '../util/classify_rings' ;
56
67const geometryTypes = [ 'Unknown' , 'Point' , 'LineString' , 'Polygon' ] ;
78const simpleGeometryType = {
@@ -39,18 +40,6 @@ class EvaluationContext {
3940 return this . feature && 'id' in this . feature ? this . feature . id : null ;
4041 }
4142
42- // Bluntly copied from
43- // https://github.com/mapbox/vector-tile-js/blob/77851380b63b07fd0af3d5a3f144cc86fb39fdd1/lib/vectortilefeature.js#L225-L233
44- _signedArea ( ring ) {
45- let sum = 0 ;
46- for ( let i = 0 , len = ring . length , j = len - 1 , p1 , p2 ; i < len ; j = i ++ ) {
47- p1 = ring [ i ] ;
48- p2 = ring [ j ] ;
49- sum += ( p2 . x - p1 . x ) * ( p1 . y + p2 . y ) ;
50- }
51- return sum ;
52- }
53-
5443 geometryDollarType ( ) {
5544 return this . feature ?
5645 typeof this . feature . type === 'number' ? geometryTypes [ this . feature . type ] : simpleGeometryType [ this . feature . type ] :
@@ -75,7 +64,7 @@ class EvaluationContext {
7564 case 'Polygon' :
7665 // Following https://github.com/mapbox/vector-tile-js/blob/77851380b63b07fd0af3d5a3f144cc86fb39fdd1/lib/vectortilefeature.js#L197
7766 for ( let i = 0 , ccw ; i < len ; i ++ ) {
78- const area = this . _signedArea ( geom [ i ] ) ;
67+ const area = calculateSignedArea ( geom [ i ] ) ;
7968 if ( area === 0 ) continue ;
8069 if ( ccw === undefined ) {
8170 ccw = area < 0 ;
0 commit comments