-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Limit the number of regions to one? #1681
Comments
To answer my own question:
|
klodoma, I am using this same functionality in my own website, and I had a question about the regions.clear() function that perhaps you can answer. I assume region-created is fired after a new region has been created. The documentation says that the clear() function removes all regions. However, when using regions.clear with the region-created event, it doesn't clear the last created region, giving the functionality of only allowing one region on the screen at a time. I'm wondering if you could clarify how this event works? I don't like using code without understanding the ins and outs of how it works, and I can't seem to find any documentation describing it in detail. Thanks for your time. |
From a quick look in the code, I see that 'region-created' is also used to add a region to the regions list
Now, it seems that the "region-created" I add later is fired earlier and the regions get cleared before the new one is added.
I don't think it's a very "solid" solution, but it works for the moment. |
@klodoma @Sepulchre49 wsRegions.on('region-created', (region) => {
wsRegions.getRegions().forEach((r) => {
if (r.id !== region.id) {
r.remove();
}
});
}); |
Is there a way to limit the number of regions?
My idea would be to have only one region and if a new one is "created" then this will replace the previous one. So, practically to have one region only.
I assume I can implement this by listening to the events, but maybe it's already possible.
The text was updated successfully, but these errors were encountered: