Challenge: Override Color by Category
Summary
By completing this you will learn how to:
- Clone, install, and run a basic desktop viewer app.
- Modify the application with custom behavior.
- Write code that overrides the color of elements in the view.
- For the bonus, write your own ECSQL query
- For the bonus, send a message to the user
Setup
-
Install the required tools
-
Clone the repo from github
-
npm install
-
npm start
-
The app should run and display a small model of a plant.
Note: The app will be built automatically in step 3, and will be automatically updated anytime you make code changes. There is no need to stop and restart the app manually when making code changes.
Goals
Goal Add code to the skeleton app such that whenever the user selects an element, the app will override the color of that element and also every element that shares the same category as that element.
Bonus goal is to further extend the app so that a message is displayed to the user telling him the name of the category of the selected element.
Solution
The best way to learn is by doing! But, if you want to skip ahead you can go right to the full solution.
Instructions
-
Find the method ColorByCategoryListener.overrideElementColors.
-
Implement the method. Use the Emphasize Elements sample as a starting point.
If you need help try these hints.
Instructions for bonus goal
-
Find the method ColorByCategoryListener.showMessageForCategoryOfSelectedElement.
-
To complete the bonus, you need to implement both this method and the one above it to find the category name.
-
To show the message, use MessageManager.outputMessage as described here. The message type OutputMessageType.Toast works nicely for this case.
If you get stuck this hint will help.
-
To query for the category name, look at the other query method in the same file. Getting the category name requires a join between two tables bis.SpatialCategory and bis.GeometricElement3d.
Try these hints if you get stuck.
Conclusion
So, were you up to the challenge? Check out how we solved it by viewing our full solution. Let us know if you have a better way.
Feedback is welcome! Let us know via the iModel.js community.