Hi!
I want to use a number ob values (coordinates) in my widget because I want to draw predefined polygons over a background image.
I would need an advice whats the best way to do that? I have not managed to define the vars in the widget directly. Another option seems to be to go over Items that are initialized at OpenHab startup.
The coordinates do not change, but I need to reuse them several times inside the widget. What is the best way to do that?
Depending on how you plan to draw the polygons, item values are most likely the simplest way to go. Using items as global variables shouldn’t really be the fallback plan, it should be the default plan unless there’s some significant reason not to. That’s really what items are.
The second-best approach is probably to use an oh-repeater. You can manually define a 1-element array of an object that contains all your values and then wrap the entire widget code in that repeater. Because it’s only one element it will only draw one iteration of your widget but the loop variable of the repeater will contain your values.
You are correct. You cannot use variables except in an expression. That means 1) it has to start with an = and 2) the expression syntax has to be correct. The example I showed used the javascript string template syntax (only available as of 3.4)