@@ -28,12 +28,21 @@ interface ArcadeEditorModelProperties extends ComponentModelProperties {
2828@serializable
2929export default class ArcadeEditorModel extends ComponentModelBase < ArcadeEditorModelProperties > {
3030 @importModel ( "map-extension" )
31- map : MapModel ;
31+ get map ( ) : MapModel {
32+ return this . _map ;
33+ }
34+ set map ( value : MapModel ) {
35+ this . _map = value ;
36+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
37+ this . _onMapChanged ( ) ;
38+ }
3239
3340 data : ArcadeEditorData ;
3441 layerName : string ;
3542 featureLayer : __esri . FeatureLayer ;
3643
44+ private _map : MapModel ;
45+
3746 constructor ( props : ArcadeEditorModelProperties ) {
3847 super ( props ) ;
3948 this . layerName = props . layerName ;
@@ -58,22 +67,22 @@ export default class ArcadeEditorModel extends ComponentModelBase<ArcadeEditorMo
5867 } ;
5968 }
6069
61- protected override async _onInitialize ( ) : Promise < void > {
62- const watchHandle = this . watch ( " map" , async ( ) => {
63- if ( ! this . map ) {
64- return undefined ;
65- }
66- const extension = toLayerExtension ( this . layerName , this . map ) ;
67- if (
68- isLayerExtension ( extension ) &&
69- ( extension as FeatureLayerExtension ) . layer . type === "feature"
70- ) {
71- this . featureLayer = ( extension as FeatureLayerExtension ) . layer ;
72- }
73- watchHandle . remove ( ) ;
74- await this . messages
75- . command < HasFeatures > ( "arcade-editor.load-data" )
76- . execute ( { features : [ ] } ) ;
77- } ) ;
70+ protected async _onMapChanged ( ) : Promise < void > {
71+ if ( ! this . map ) {
72+ return undefined ;
73+ }
74+
75+ const extension = toLayerExtension ( this . layerName , this . map ) ;
76+
77+ if (
78+ isLayerExtension ( extension ) &&
79+ ( extension as FeatureLayerExtension ) . layer . type === "feature"
80+ ) {
81+ this . featureLayer = ( extension as FeatureLayerExtension ) . layer ;
82+ }
83+
84+ await this . messages
85+ . command < HasFeatures > ( "arcade-editor.load-data" )
86+ . execute ( { features : [ ] } ) ;
7887 }
7988}
0 commit comments