@@ -10,7 +10,6 @@ import { AbstractLayer } from './layer';
1010import { VectorStyle } from './styles/vector/vector_style' ;
1111import { InnerJoin } from './joins/inner_join' ;
1212import {
13- GEO_JSON_TYPE ,
1413 FEATURE_ID_PROPERTY_NAME ,
1514 SOURCE_DATA_ID_ORIGIN ,
1615 FEATURE_VISIBLE_PROPERTY_NAME ,
@@ -24,41 +23,11 @@ import { EuiIcon } from '@elastic/eui';
2423import { i18n } from '@kbn/i18n' ;
2524import { DataRequestAbortError } from './util/data_request' ;
2625import { assignFeatureIds } from './util/assign_feature_ids' ;
27-
28- const VISIBILITY_FILTER_CLAUSE = [ 'all' ,
29- [
30- '==' ,
31- [ 'get' , FEATURE_VISIBLE_PROPERTY_NAME ] ,
32- true
33- ]
34- ] ;
35-
36- const FILL_LAYER_MB_FILTER = [
37- ...VISIBILITY_FILTER_CLAUSE ,
38- [
39- 'any' ,
40- [ '==' , [ 'geometry-type' ] , GEO_JSON_TYPE . POLYGON ] ,
41- [ '==' , [ 'geometry-type' ] , GEO_JSON_TYPE . MULTI_POLYGON ]
42- ]
43- ] ;
44-
45- const LINE_LAYER_MB_FILTER = [ ...VISIBILITY_FILTER_CLAUSE ,
46- [
47- 'any' ,
48- [ '==' , [ 'geometry-type' ] , GEO_JSON_TYPE . POLYGON ] ,
49- [ '==' , [ 'geometry-type' ] , GEO_JSON_TYPE . MULTI_POLYGON ] ,
50- [ '==' , [ 'geometry-type' ] , GEO_JSON_TYPE . LINE_STRING ] ,
51- [ '==' , [ 'geometry-type' ] , GEO_JSON_TYPE . MULTI_LINE_STRING ]
52- ]
53- ] ;
54-
55- const POINT_LAYER_MB_FILTER = [ ...VISIBILITY_FILTER_CLAUSE ,
56- [
57- 'any' ,
58- [ '==' , [ 'geometry-type' ] , GEO_JSON_TYPE . POINT ] ,
59- [ '==' , [ 'geometry-type' ] , GEO_JSON_TYPE . MULTI_POINT ]
60- ]
61- ] ;
26+ import {
27+ getFillFilterExpression ,
28+ getLineFilterExpression ,
29+ getPointFilterExpression ,
30+ } from './util/mb_filter_expressions' ;
6231
6332export class VectorLayer extends AbstractLayer {
6433
@@ -107,6 +76,10 @@ export class VectorLayer extends AbstractLayer {
10776 } ) ;
10877 }
10978
79+ _hasJoins ( ) {
80+ return this . getValidJoins ( ) . length > 0 ;
81+ }
82+
11083 isDataLoaded ( ) {
11184 const sourceDataRequest = this . getSourceDataRequest ( ) ;
11285 if ( ! sourceDataRequest || ! sourceDataRequest . hasData ( ) ) {
@@ -495,12 +468,14 @@ export class VectorLayer extends AbstractLayer {
495468 }
496469
497470 const sourceResult = await this . _syncSource ( syncContext ) ;
498- if ( ! sourceResult . featureCollection || ! sourceResult . featureCollection . features . length ) {
471+ if (
472+ ! sourceResult . featureCollection ||
473+ ! sourceResult . featureCollection . features . length ||
474+ ! this . _hasJoins ( ) ) {
499475 return ;
500476 }
501477
502478 const joinStates = await this . _syncJoins ( syncContext ) ;
503-
504479 await this . _performInnerJoins ( sourceResult , joinStates , syncContext . updateSourceData ) ;
505480 }
506481
@@ -571,7 +546,11 @@ export class VectorLayer extends AbstractLayer {
571546 source : sourceId ,
572547 paint : { }
573548 } ) ;
574- mbMap . setFilter ( pointLayerId , POINT_LAYER_MB_FILTER ) ;
549+ }
550+
551+ const filterExpr = getPointFilterExpression ( this . _hasJoins ( ) ) ;
552+ if ( filterExpr !== mbMap . getFilter ( pointLayerId ) ) {
553+ mbMap . setFilter ( pointLayerId , filterExpr ) ;
575554 }
576555
577556 this . _style . setMBPaintPropertiesForPoints ( {
@@ -592,7 +571,11 @@ export class VectorLayer extends AbstractLayer {
592571 type : 'symbol' ,
593572 source : sourceId ,
594573 } ) ;
595- mbMap . setFilter ( symbolLayerId , POINT_LAYER_MB_FILTER ) ;
574+ }
575+
576+ const filterExpr = getPointFilterExpression ( this . _hasJoins ( ) ) ;
577+ if ( filterExpr !== mbMap . getFilter ( symbolLayerId ) ) {
578+ mbMap . setFilter ( symbolLayerId , filterExpr ) ;
596579 }
597580
598581 this . _style . setMBSymbolPropertiesForPoints ( {
@@ -606,14 +589,14 @@ export class VectorLayer extends AbstractLayer {
606589 const sourceId = this . getId ( ) ;
607590 const fillLayerId = this . _getMbPolygonLayerId ( ) ;
608591 const lineLayerId = this . _getMbLineLayerId ( ) ;
592+ const hasJoins = this . _hasJoins ( ) ;
609593 if ( ! mbMap . getLayer ( fillLayerId ) ) {
610594 mbMap . addLayer ( {
611595 id : fillLayerId ,
612596 type : 'fill' ,
613597 source : sourceId ,
614598 paint : { }
615599 } ) ;
616- mbMap . setFilter ( fillLayerId , FILL_LAYER_MB_FILTER ) ;
617600 }
618601 if ( ! mbMap . getLayer ( lineLayerId ) ) {
619602 mbMap . addLayer ( {
@@ -622,7 +605,6 @@ export class VectorLayer extends AbstractLayer {
622605 source : sourceId ,
623606 paint : { }
624607 } ) ;
625- mbMap . setFilter ( lineLayerId , LINE_LAYER_MB_FILTER ) ;
626608 }
627609 this . _style . setMBPaintProperties ( {
628610 alpha : this . getAlpha ( ) ,
@@ -632,9 +614,18 @@ export class VectorLayer extends AbstractLayer {
632614 } ) ;
633615
634616 this . syncVisibilityWithMb ( mbMap , fillLayerId ) ;
617+ mbMap . setLayerZoomRange ( fillLayerId , this . _descriptor . minZoom , this . _descriptor . maxZoom ) ;
618+ const fillFilterExpr = getFillFilterExpression ( hasJoins ) ;
619+ if ( fillFilterExpr !== mbMap . getFilter ( fillLayerId ) ) {
620+ mbMap . setFilter ( fillLayerId , fillFilterExpr ) ;
621+ }
622+
635623 this . syncVisibilityWithMb ( mbMap , lineLayerId ) ;
636624 mbMap . setLayerZoomRange ( lineLayerId , this . _descriptor . minZoom , this . _descriptor . maxZoom ) ;
637- mbMap . setLayerZoomRange ( fillLayerId , this . _descriptor . minZoom , this . _descriptor . maxZoom ) ;
625+ const lineFilterExpr = getLineFilterExpression ( hasJoins ) ;
626+ if ( lineFilterExpr !== mbMap . getFilter ( lineLayerId ) ) {
627+ mbMap . setFilter ( lineLayerId , lineFilterExpr ) ;
628+ }
638629 }
639630
640631 _syncStylePropertiesWithMb ( mbMap ) {
0 commit comments