@@ -24,11 +24,34 @@ import {
2424
2525import { validateZoomSettings , injectMapPropsIntoSpec } from './utils' ;
2626
27- // @ts -ignore
27+ // @ts -expect-error
2828import { vega } from '../../lib/vega' ;
2929
3030import './vega_map_view.scss' ;
3131
32+ async function updateVegaView ( mapBoxInstance : Map , vegaView : vega . View ) {
33+ const mapCanvas = mapBoxInstance . getCanvas ( ) ;
34+ const { lat, lng } = mapBoxInstance . getCenter ( ) ;
35+ let shouldRender = false ;
36+
37+ const sendSignal = ( sig : string , value : any ) => {
38+ if ( vegaView . signal ( sig ) !== value ) {
39+ vegaView . signal ( sig , value ) ;
40+ shouldRender = true ;
41+ }
42+ } ;
43+
44+ sendSignal ( 'width' , mapCanvas . clientWidth ) ;
45+ sendSignal ( 'height' , mapCanvas . clientHeight ) ;
46+ sendSignal ( 'latitude' , lat ) ;
47+ sendSignal ( 'longitude' , lng ) ;
48+ sendSignal ( 'zoom' , mapBoxInstance . getZoom ( ) ) ;
49+
50+ if ( shouldRender ) {
51+ await vegaView . runAsync ( ) ;
52+ }
53+ }
54+
3255export class VegaMapView extends VegaBaseView {
3356 private mapServiceSettings : MapServiceSettings = getMapServiceSettings ( ) ;
3457 private mapStyle = this . getMapStyle ( ) ;
@@ -110,29 +133,6 @@ export class VegaMapView extends VegaBaseView {
110133 mapBoxInstance . once ( 'load' , initMapComponents ) ;
111134 }
112135
113- private async updateVegaView ( mapBoxInstance : Map , vegaView : vega . View ) {
114- const mapCanvas = mapBoxInstance . getCanvas ( ) ;
115- const { lat, lng } = mapBoxInstance . getCenter ( ) ;
116- let shouldRender = false ;
117-
118- const sendSignal = ( sig : string , value : any ) => {
119- if ( vegaView . signal ( sig ) !== value ) {
120- vegaView . signal ( sig , value ) ;
121- shouldRender = true ;
122- }
123- } ;
124-
125- sendSignal ( 'width' , mapCanvas . clientWidth ) ;
126- sendSignal ( 'height' , mapCanvas . clientHeight ) ;
127- sendSignal ( 'latitude' , lat ) ;
128- sendSignal ( 'longitude' , lng ) ;
129- sendSignal ( 'zoom' , mapBoxInstance . getZoom ( ) ) ;
130-
131- if ( shouldRender ) {
132- await vegaView . runAsync ( ) ;
133- }
134- }
135-
136136 private initControls ( mapBoxInstance : Map ) {
137137 if ( this . shouldShowZoomControl ) {
138138 mapBoxInstance . addControl ( new NavigationControl ( { showCompass : false } ) , 'top-left' ) ;
@@ -162,12 +162,12 @@ export class VegaMapView extends VegaBaseView {
162162 map : mapBoxInstance ,
163163 context : {
164164 vegaView,
165- updateVegaView : this . updateVegaView ,
165+ updateVegaView,
166166 } ,
167167 } ) ;
168168 }
169169
170- public async _initViewCustomizations ( ) {
170+ protected async _initViewCustomizations ( ) {
171171 const vegaView = new vega . View (
172172 vega . parse ( injectMapPropsIntoSpec ( this . _parser . spec ) ) ,
173173 this . _vegaViewConfig
0 commit comments