@@ -76,10 +76,126 @@ describe('L7LayerUtil', () => {
7676 options
7777 } ;
7878
79+ async function addLineTextureForVersion ( mapVersion , textureLayerUtil = l7LayerUtil ) {
80+ const sourcePixels = new Uint8ClampedArray ( [
81+ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ,
82+ 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16
83+ ] ) ;
84+ let uploadedPixels ;
85+ const context = {
86+ drawImage : jasmine . createSpy ( 'drawImage' ) ,
87+ getImageData : ( ) => ( { width : 2 , height : 2 , data : sourcePixels . slice ( ) } ) ,
88+ createImageData : ( width , height ) => ( { width, height, data : new Uint8ClampedArray ( width * height * 4 ) } ) ,
89+ putImageData : ( imageData ) => {
90+ uploadedPixels = Array . from ( imageData . data ) ;
91+ }
92+ } ;
93+ spyOn ( window , 'XMLHttpRequest' ) . and . callFake ( ( ) => ( {
94+ open : jasmine . createSpy ( 'open' ) ,
95+ setRequestHeader : jasmine . createSpy ( 'setRequestHeader' ) ,
96+ send : function ( ) {
97+ this . readyState = 4 ;
98+ this . status = 200 ;
99+ this . response = { } ;
100+ this . onreadystatechange ( ) ;
101+ }
102+ } ) ) ;
103+ spyOn ( window . URL , 'createObjectURL' ) . and . returnValue ( 'blob:test-sprite' ) ;
104+ spyOn ( window , 'Image' ) . and . callFake ( function ( ) {
105+ return {
106+ width : 2 ,
107+ height : 2 ,
108+ set src ( value ) {
109+ this . source = value ;
110+ setTimeout ( ( ) => this . onload && this . onload ( ) , 0 ) ;
111+ }
112+ } ;
113+ } ) ;
114+ spyOn ( HTMLCanvasElement . prototype , 'getContext' ) . and . returnValue ( context ) ;
115+ spyOn ( HTMLCanvasElement . prototype , 'toDataURL' ) . and . returnValue ( 'data:image/png;base64,test' ) ;
116+
117+ const line = {
118+ id : 'line-texture' ,
119+ type : 'line-extrusion' ,
120+ source : 'line-source' ,
121+ layout : { } ,
122+ paint : {
123+ 'line-extrusion-pattern' : 'line-pattern' ,
124+ 'line-extrusion-width' : 1
125+ }
126+ } ;
127+ const scene = new mockL7 . Scene ( ) ;
128+ const map = {
129+ getL7Scene : ( ) => Promise . resolve ( scene ) ,
130+ getLayer : ( ) => false ,
131+ addLayer : jasmine . createSpy ( 'addLayer' )
132+ } ;
133+ await textureLayerUtil . addL7Layers ( {
134+ map,
135+ webMapInfo : {
136+ version : mapVersion ,
137+ sprite : '/sprite' ,
138+ layers : [ line ] ,
139+ sources : {
140+ 'line-source' : {
141+ type : 'geojson' ,
142+ data : { type : 'FeatureCollection' , features : [ ] }
143+ }
144+ }
145+ } ,
146+ l7Layers : [ line ] ,
147+ spriteDatas : {
148+ 'line-pattern' : { x : 0 , y : 0 , width : 2 , height : 2 }
149+ } ,
150+ options : {
151+ withCredentials : false ,
152+ emitterEvent : jasmine . createSpy ( 'emitterEvent' )
153+ }
154+ } ) ;
155+ return { uploadedPixels, layer : map . addLayer . calls . first ( ) . args [ 0 ] } ;
156+ }
157+
79158 afterEach ( ( ) => {
80159 layerMaplist = { } ;
81160 } ) ;
82161
162+ it ( 'vertically flips L7 line textures through version 3.3.7' , async ( ) => {
163+ const westToEastL7LayerUtil = L7LayerUtil ( {
164+ featureFilter,
165+ expression,
166+ spec,
167+ L7Layer,
168+ L7 ,
169+ webMapService : mockWebMapService ,
170+ linePatternOrientation : 'west-to-east'
171+ } ) ;
172+ const { uploadedPixels, layer } = await addLineTextureForVersion ( '3.3.7' , westToEastL7LayerUtil ) ;
173+
174+ expect ( uploadedPixels ) . toEqual ( [
175+ 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ,
176+ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8
177+ ] ) ;
178+ expect ( layer . getLayer ( ) . linePatternOrientation ) . toBe ( 'west-to-east' ) ;
179+ } ) ;
180+
181+ it ( 'keeps newer L7 line textures unchanged' , async ( ) => {
182+ const { uploadedPixels } = await addLineTextureForVersion ( '3.3.8' ) ;
183+ const originalPixels = [
184+ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ,
185+ 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16
186+ ] ;
187+
188+ expect ( uploadedPixels ) . toEqual ( originalPixels ) ;
189+ } ) ;
190+
191+ it ( 'keeps unversioned L7 line textures unchanged' , async ( ) => {
192+ const { uploadedPixels } = await addLineTextureForVersion ( undefined ) ;
193+ expect ( uploadedPixels ) . toEqual ( [
194+ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ,
195+ 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16
196+ ] ) ;
197+ } ) ;
198+
83199 it ( 'add od layer' , ( done ) => {
84200 spyOn ( FetchRequest , 'get' ) . and . callFake ( ( url , _ , nextOptions ) => {
85201 expect ( nextOptions . withCredentials ) . toBe ( options . withCredentials ) ;
0 commit comments