@@ -347,6 +347,22 @@ GEOComp = class extends GEOComp {
347
347
}
348
348
} ;
349
349
350
+ const parseFilter = function ( data : any , defFilter = [ 'layers' ] ) {
351
+ var filter = data || defFilter
352
+ if ( ! Array . isArray ( filter ) ) {
353
+ try {
354
+ filter = JSON . parse ( "[" + filter + "]" )
355
+ } catch ( e ) {
356
+ try {
357
+ filter = JSON . parse ( '["' + filter + '"]' )
358
+ } catch ( ee ) {
359
+ filter = defFilter
360
+ }
361
+ }
362
+ }
363
+ return filter
364
+ }
365
+
350
366
/**
351
367
* Exposes methods on GEOComp component to allow calling from parent component.
352
368
* Includes animate, notify, showPopup, addFeatures, and readFeatures methods.
@@ -506,24 +522,43 @@ GEOComp = withMethodExposing(GEOComp, [
506
522
{
507
523
name : "json" ,
508
524
type : "JSONValue" ,
509
- }
525
+ } ,
526
+ {
527
+ name : "filter" ,
528
+ type : "JSONValue" ,
529
+ } ,
510
530
]
511
531
} ,
512
532
execute : async ( comp : any , params : any ) => {
513
533
if ( params . length == 0 ) return
534
+ //Create filter based on param
535
+ const filter = parseFilter ( params [ 1 ] )
514
536
try {
515
537
var data = params [ 0 ]
516
- console . log ( "Configure 1" , params [ 0 ] )
517
538
if ( typeof data === 'string' || data instanceof String ) {
518
539
// @ts -ignore
519
540
data = JSON . parse ( data )
520
541
}
542
+ //Filter out data not needed
543
+ if ( filter . length != 0 ) {
544
+ for ( const [ key , value ] of Object . entries ( data ) ) {
545
+ if ( ! filter . includes ( key ) ) {
546
+ delete data [ key ]
547
+ }
548
+ }
549
+ }
521
550
for ( const [ key , value ] of Object . entries ( data ) ) {
522
- console . log ( key , comp . children [ key ] )
523
- //comp.children[key].value(value)
551
+ var child = comp . children [ key ]
552
+ console . log ( key , child )
553
+ if ( child . value ) {
554
+ child . value ( value )
555
+ } else {
556
+ console . debug ( "setConfig not supported for " , child )
557
+ }
524
558
}
525
559
} catch ( e ) {
526
560
console . error ( "Failed to parse config data" , e )
561
+ return false
527
562
}
528
563
}
529
564
} ,
@@ -532,17 +567,32 @@ GEOComp = withMethodExposing(GEOComp, [
532
567
name : "getConfig" ,
533
568
description : "Get configuration the plugin by json" ,
534
569
params : [
570
+ {
571
+ name : "filter" ,
572
+ type : "JSONValue" ,
573
+ } ,
535
574
{
536
575
name : "asString" ,
537
576
type : "boolean" ,
538
- }
577
+ } ,
539
578
]
540
579
} ,
541
580
execute : ( comp : any , params : any ) => {
581
+ //Create filter based on param
582
+ const filter = parseFilter ( params [ 0 ] )
583
+ //Get the json config data
542
584
var data = comp . toJsonValue ( ) ;
543
- delete data . onEvent
544
- data = params [ 0 ] !== true ? data : JSON . stringify ( data , null )
545
- // @ts -ignore
585
+ //Filter out data not needed
586
+ if ( filter . length != 0 ) {
587
+ for ( const [ key , value ] of Object . entries ( data ) ) {
588
+ if ( ! filter . includes ( key ) ) {
589
+ delete data [ key ]
590
+ }
591
+ }
592
+ }
593
+
594
+ //Should we convert the data into string
595
+ data = params [ 1 ] !== true ? data : JSON . stringify ( data , null )
546
596
if ( geoContext . previewMode )
547
597
console . debug ( data )
548
598
//Event config needs to be added
0 commit comments