Let's say I want to create a custom UI component / widget to add some functionality to a web app (build with the ArcGIS Maps SDK for JavaScript). And let's say I want to implement this as a standard Web Component (https://developer.mozilla.org/en-US/docs/Web/API/Web_components).
Then I create a JavaScript module and I write a class that extends HTMLElement. In that class I can build the UI of the component. That works without problems.
But in my custom component I also want to access the classes of the Maps SDK like the MapView and the Map. Maybe I want to create a GraphicsLayer and some Graphics in the component and add the layer to the map.
This leeds to some questions:
- What is the best way to import the classes of the Maps SDK in my module? Using the import statement or using the AMD style with require?
- What is the best way to get a reference to the mapView or map object defined in the main HTML / JavaScript file of the web app in my new JavaScript module? The new module is separate from the main JS file and so I don't have direct access to objects defined in this main JS file. Somehow I have to get the reference over to the module file. How can that be done?
Is there a sample showing how to do this?