When the Right Piece is Missing, Build Your Own!

When developing custom applications using the Esri JavaScript SDK, developers have access to a robust library of classes and widgets that streamline the creation of web mapping applications. These tools range from fundamental classes like Map, WebMap, Basemap Gallery Widget, and Feature Layer to more specialized ones like Geometry Engine, Request, Identity Manager, and Element Expression Info. The SDK is designed to provide these building blocks to facilitate the development process, but sometimes, the out-of-the-box (OOB) classes may not fully meet specific requirements. In such cases, developers can extend existing classes or create their own to achieve the desired functionality.

 

Utilizing Esri’s SDK Classes

Many classes within the Esri JS SDK are sub-classes, inheriting properties and methods from more generic parent classes. For instance, the Layer class is a parent class for more specific layers like FeatureLayer and MapImageLayer. At the core, most SDK classes inherit from the Accessor class, which allows developers to monitor and manipulate individual properties, define getters and setters, and specify read-only properties.

The Accessor class is particularly powerful as it lays the groundwork for extending existing classes. For example, the Bookmark class allows for saving names, thumbnails, time extents, and viewpoints. However, if we need to save the active basemap when a bookmark is created, we can extend the Bookmark class to include an activeBasemap property. This extensibility makes it possible to customize the behavior of the SDK’s components without starting from scratch.

 

Customizing and Extending Classes

When the SDK’s provided classes are insufficient or require additional functionality, extending these classes can save significant development time. For instance, in an application that displays tree data and allows users to filter by tree type, we can create a custom TreeFilterTracker class. This class, a sub-class of Accessor, can maintain a list of tree types and their inclusion in the filter. This centralizes the filtering logic, making it easier to manage and extend.

By leveraging the Accessor class, developers gain access to Reactive Utils. In our TreeFilterTracker example, if a user views Maple Trees and then enables Pine Trees, the application can use the reactiveUtils.when() method to update widgets dynamically based on the updated filter. This method ensures that the application reacts to changes in real time, enhancing user experience and application responsiveness.


Conclusion

The Esri JS SDK offers a wealth of classes and widgets that simplify the development of web mapping applications. By understanding and utilizing these tools, developers can enhance their applications efficiently. Extending existing classes using the Accessor class allows for significant customization and responsiveness, ensuring that applications meet specific needs without unnecessary redevelopment. Embracing these practices not only enhances development productivity but also delivers robust, feature-rich applications to end-users.

Previous
Previous

The Unintended Impacts of Public Safety Power Shutoff Events

Next
Next

Futureproofing Your Technology Investments