Social Distancing
This plugin provides some tools that will help you comply with social distancing restrictions.
Warning
Not all maps are compatible with this plugin. Please contact with our support team if you need more information.
- Plugin name:
"social_distancing"
- Plugin namespace:
"social_distancing"
Loading the plugin
| var input_options = {
container: "container-id",
plugins: ["social_distancing"]
};
DVM.loadModule("map_viewer", input_options)
.then(function(viewer) {
start(viewer);
})
.catch(function(err) {
console.error(err);
});
function start(viewer) {
// ...
}
|
If this plugin is loaded, the module will have the following additional features:
Methods
getNeighbors()
Returns the quantity count
(or less) of adjacent seats within neighbor_distance
range.
- The introduced node state must be
available
or selected
.
- The returned nodes will have
available
or selected
as state.
Info
You can use the original getNeighbors
method too. The difference between this method
and the original method is that the original uses the map rows information and the social_distancing
method use geometric information.
Note that some maps might not have rows information.
Input
options
(Object):
count
(number): number of adjacent seats to get. It might return less if it is not possible to form a
group with that number.
neighbor_distance
(number) [optional]: maximum distance to consider a seat adjacent.
seat
(MapViewerNode | string): seat from where the adjacent seats will be searched.
Output
Example
| var options = { count: 3 };
var seat = "S_123-1-1";
viewer.social_distancing.getNeighbors(options, seat)
.then(function(result1) {
// if you don't want groups with less than 'count' you can check here
// if (result1.length === options.count) ...
viewer.unselectAll();
viewer.select(result1);
})
.catch(function(err) {
console.error(err);
});
|
filterNearest()
Asynchronous method that returns a list of seats that are within security_distance
range, close
to the input seats.
Input
options
(Object):
security_distance
(number) [optional]: Security distance. Any node within this range will be added to
the output.
seats
(MapViewerNode | MapViewerNode[] | string | string[]): List of seats from which the computation is made.
Output
result
(Promise<MapViewerNode[]>
): returns a promise that resolves in array with the seats that
are within range.
Example
| var options = { security_distance: 1.5 };
var seats = ["S_123-1-1", "S_123-1-2", "S_123-1-3"]
viewer.social_distancing.filterNearest(options, seats)
.then(function(result) {
viewer.setUnavailable("seat", result);
})
.catch(function(err) {
console.error(err);
});
|
Along with getNeighbors
:
| var options = { security_distance: 1.5, count: 3 };
var seat = "S_123-1-1";
viewer.social_distancing.getNeighbors(options, seat)
.then(function(result1) {
viewer.unselectAll();
return viewer.social_distancing.filterNearest(options, result1)
.then(function(result2) {
viewer.select(result1);
viewer.setUnavailable("seat", result2);
});
})
.catch(function(err) {
console.error(err);
});
|
Example of getNeighbors
and filterNearest
:
Code
| var input_options = {
container: "viewer-container",
plugins: ["social_distancing"]
};
DVM.loadModule("map_viewer", input_options)
.then(function(viewer) {
start(viewer);
})
.catch(function(err) {
console.error(err);
});
function start(viewer) {
viewer.flags.automatic_selection = false;
var load_options = { venue_id: "nam-us-00107", map_id: "socialdistancing" };
viewer.subscribe("click", onClick);
// Load the map
viewer.loadMap(load_options)
.then(function(obj) {
// Successfully loaded
obj.instance.setAvailability("section", viewer.getNodesByType("section"));
obj.instance.setAvailability("seat", viewer.getNodesByType("seat"));
})
.catch(function(err) {
// Error while loading
console.error(err);
});
function onClick(obj) {
var instance = obj.instance;
var node = obj.nodes[0];
if (node != null && node.type === "seat" && (node.state === "available" || node.state === "selected")) {
var input = { security_distance: 1.5, count: 3 };
instance.social_distancing.getNeighbors(input, node)
.then(function(result1) {
instance.unselectAll();
return instance.social_distancing.filterNearest(input, result1)
.then(function(result2) {
instance.select(result1);
instance.setUnavailable("seat", result2);
});
});
} else {
instance.unselectAll();
}
}
}
|