33 LineExtLayoutArray ,
44 LinePatternLayoutArray ,
55 LineZOffsetExtArray ,
6+ LineElevationGroundScaleArray ,
67} from '../array_types' ;
7- import { members as layoutAttributes , lineZOffsetAttributes } from './line_attributes' ;
8+ import { members as layoutAttributes , lineZOffsetAttributes , lineElevationGroundScaleAttributes } from './line_attributes' ;
89import { members as layoutAttributesExt } from './line_attributes_ext' ;
910import { members as layoutAttributesPattern } from './line_attributes_pattern' ;
1011import SegmentVector from '../segment' ;
@@ -99,6 +100,7 @@ type GradientTexture = {
99100type LineProgressFeatures = {
100101 zOffset : number ;
101102 variableWidth : number ;
103+ elevationGroundScale : number ;
102104} ;
103105
104106interface Subsegment {
@@ -121,6 +123,7 @@ class LineBucket implements Bucket {
121123 lineClips : LineClips | null | undefined ;
122124 zOffsetValue : PossiblyEvaluatedValue < number > ;
123125 variableWidthValue : PossiblyEvaluatedValue < number > ;
126+ elevationGroundScaleValue : PossiblyEvaluatedValue < number > ;
124127 lineFeature : BucketFeature ;
125128
126129 e1 : number ;
@@ -155,6 +158,9 @@ class LineBucket implements Bucket {
155158 zOffsetVertexArray : LineZOffsetExtArray ;
156159 zOffsetVertexBuffer : VertexBuffer ;
157160
161+ elevationGroundScaleVertexArray : LineElevationGroundScaleArray ;
162+ elevationGroundScaleVertexBuffer : VertexBuffer ;
163+
158164 indexArray : TriangleIndexArray ;
159165 indexBuffer : IndexBuffer ;
160166
@@ -172,6 +178,7 @@ class LineBucket implements Bucket {
172178 evaluationGlobals = { 'zoom' : 0 , 'lineProgress' : undefined } ;
173179
174180 elevationType : ElevationType = 'none' ;
181+ isSeaLevelReference : boolean = false ;
175182 heightRange : Range | undefined ;
176183
177184 worldview : string ;
@@ -203,6 +210,7 @@ class LineBucket implements Bucket {
203210 this . segments = new SegmentVector ( ) ;
204211 this . maxLineLength = 0 ;
205212 this . zOffsetVertexArray = new LineZOffsetExtArray ( ) ;
213+ this . elevationGroundScaleVertexArray = new LineElevationGroundScaleArray ( ) ;
206214 this . stateDependentLayerIds = this . layers . filter ( ( l ) => l . isStateDependent ( ) ) . map ( ( l ) => l . id ) ;
207215 // A vector tile is usually rendered over 128x128 terrain grid. Half of that frequency (step is EXTENT / 64)
208216 // should be enough since line elevation over terrain samples neighboring points.
@@ -238,6 +246,7 @@ class LineBucket implements Bucket {
238246 if ( this . elevationType === 'offset' && elevationReference === 'none' ) {
239247 warnOnce ( `line-elevation-reference: ground is used for the layer ${ this . layerIds [ 0 ] } because non-zero line-z-offset value was found.` ) ;
240248 }
249+ this . isSeaLevelReference = elevationReference === 'sea' ;
241250 }
242251
243252 const crossSlope = this . layers [ 0 ] . layout . get ( 'line-cross-slope' ) ;
@@ -397,6 +406,10 @@ class LineBucket implements Bucket {
397406 this . zOffsetVertexBuffer = context . createVertexBuffer ( this . zOffsetVertexArray , lineZOffsetAttributes . members , true ) ;
398407 }
399408
409+ if ( ! this . elevationGroundScaleVertexBuffer && this . elevationGroundScaleVertexArray . length > 0 ) {
410+ this . elevationGroundScaleVertexBuffer = context . createVertexBuffer ( this . elevationGroundScaleVertexArray , lineElevationGroundScaleAttributes . members , true ) ;
411+ }
412+
400413 this . layoutVertexBuffer = context . createVertexBuffer ( this . layoutVertexArray , layoutAttributes ) ;
401414 this . indexBuffer = context . createIndexBuffer ( this . indexArray ) ;
402415 }
@@ -409,6 +422,9 @@ class LineBucket implements Bucket {
409422 if ( this . zOffsetVertexBuffer ) {
410423 this . zOffsetVertexBuffer . destroy ( ) ;
411424 }
425+ if ( this . elevationGroundScaleVertexBuffer ) {
426+ this . elevationGroundScaleVertexBuffer . destroy ( ) ;
427+ }
412428 this . layoutVertexBuffer . destroy ( ) ;
413429 this . indexBuffer . destroy ( ) ;
414430 this . programConfigurations . destroy ( ) ;
@@ -455,6 +471,14 @@ class LineBucket implements Bucket {
455471 this . variableWidthValue = lineWidth ;
456472 }
457473
474+ // Only set elevationGroundScaleValue for sea level reference lines with non-default value
475+ if ( this . isSeaLevelReference ) {
476+ const elevationGroundScaleExpr = layout . get ( 'line-elevation-ground-scale' ) . value ;
477+ if ( elevationGroundScaleExpr . kind !== 'constant' || elevationGroundScaleExpr . value !== 0 ) {
478+ this . elevationGroundScaleValue = elevationGroundScaleExpr ;
479+ }
480+ }
481+
458482 if ( this . elevationType === 'road' ) {
459483 const vertexOffset = this . layoutVertexArray . length ;
460484 const added = this . addElevatedRoadFeature ( feature , geometry , canonical , elevationFeatures , join , cap , miterLimit , roundLimit ) ;
@@ -1032,14 +1056,25 @@ class LineBucket implements Bucket {
10321056 if ( this . variableWidthValue && this . variableWidthValue . kind !== 'constant' ) {
10331057 variableWidth = this . variableWidthValue . evaluate ( this . evaluationGlobals , this . lineFeature ) || 0.0 ;
10341058 }
1059+ const elevationGroundScale = this . evaluateElevationGroundScale ( ) ;
10351060 if ( this . elevationType !== 'offset' ) {
1036- return { zOffset : 0.0 , variableWidth} ;
1061+ return { zOffset : 0.0 , variableWidth, elevationGroundScale } ;
10371062 }
10381063 if ( this . zOffsetValue . kind === 'constant' ) {
1039- return { zOffset : this . zOffsetValue . value , variableWidth} ;
1064+ return { zOffset : this . zOffsetValue . value , variableWidth, elevationGroundScale } ;
10401065 }
10411066 const zOffset : number = this . zOffsetValue . evaluate ( this . evaluationGlobals , this . lineFeature ) || 0.0 ;
1042- return { zOffset, variableWidth} ;
1067+ return { zOffset, variableWidth, elevationGroundScale} ;
1068+ }
1069+
1070+ evaluateElevationGroundScale ( ) : number {
1071+ if ( ! this . elevationGroundScaleValue ) {
1072+ return 0.0 ;
1073+ }
1074+ if ( this . elevationGroundScaleValue . kind === 'constant' ) {
1075+ return this . elevationGroundScaleValue . value ;
1076+ }
1077+ return this . elevationGroundScaleValue . evaluate ( this . evaluationGlobals , this . lineFeature ) || 0.0 ;
10431078 }
10441079
10451080 /**
@@ -1184,6 +1219,11 @@ class LineBucket implements Bucket {
11841219 lineProgressFeatures . variableWidth
11851220 ) ;
11861221 }
1222+ // Populate elevationGroundScaleVertexArray only when the property is used
1223+ if ( this . elevationGroundScaleValue ) {
1224+ const elevationGroundScale = lineProgressFeatures ? lineProgressFeatures . elevationGroundScale : this . evaluateElevationGroundScale ( ) ;
1225+ this . elevationGroundScaleVertexArray . emplaceBack ( elevationGroundScale ) ;
1226+ }
11871227 assert ( this . zOffsetVertexArray . length === this . layoutVertexArray . length || this . elevationType !== 'offset' ) ;
11881228 }
11891229
0 commit comments