@@ -87,13 +87,17 @@ export class CropLegendControl extends Control {
8787 this . render ( ) ;
8888 }
8989
90- tileLoadEnd ( e ) {
91- const features = e . tile . getFeatures ( ) ;
92- const m = this . mapping . at ( - 1 ) ;
90+ updateColors ( tile ) {
91+ const features = tile . getFeatures ( ) ;
92+ const m = this . mapping . at ( this . level ) ;
9393 for ( const feature of features ) {
9494 const p = feature . getProperties ( ) ;
9595 p . color = m [ p [ this . attribute ] ] ?. color || "#99bbccaa" ;
9696 }
97+ }
98+
99+ tileLoadEnd ( e ) {
100+ this . updateColors ( e . tile )
97101 this . updateFeatureCount ( e )
98102 }
99103
@@ -118,17 +122,19 @@ export class CropLegendControl extends Control {
118122 }
119123 }
120124 render ( ) {
125+ const map = this . getMap ( ) ;
121126 const element = this . element ;
122127 if ( ! this . legendItems ?. length ) {
123128 element . innerHTML = "" ;
124129 return ;
125130 }
126131 let levels = "" ;
127132 if ( this . mapping . length ) {
128- levels = `<span style="font-weight: normal">Level : </span>` ;
133+ levels = `<span style="font-weight: normal">Hcat level : </span>` ;
129134 for ( let i = 0 ; i < this . mapping . length ; i ++ ) {
130135 levels += `<button class="legend-level${ i === this . level ?" active" :"" } ">${ i } </button>` ;
131136 }
137+ levels = `<div style="float:right;">${ levels } </div>` ;
132138 }
133139 element . innerHTML = `
134140 <div class="legend-title">Legend ${ levels } </div>
@@ -143,6 +149,19 @@ export class CropLegendControl extends Control {
143149 ` ;
144150 this . element . querySelectorAll ( ".legend-level" ) . forEach ( e => e . addEventListener ( "click" , ( e ) => {
145151 this . level = parseInt ( e . target . innerText ) ;
152+ for ( const vt of map . getLayers ( ) . getArray ( ) ) {
153+ let changed = false ;
154+ if ( vt instanceof VectorTile ) {
155+ vt . getRenderer ( ) . getTileCache ( ) . forEach ( ( tile ) => {
156+ if ( tile . getState ( ) !== TileState . LOADED ) return ;
157+ for ( const sourceTile of tile . getSourceTiles ( ) ) {
158+ this . updateColors ( sourceTile )
159+ changed = true ;
160+ }
161+ } )
162+ }
163+ if ( changed ) vt . changed ( ) ;
164+ }
146165 this . updateFeatureCount ( ) ;
147166 } ) )
148167 }
0 commit comments