Routing and Special Zones
This example will display an alert whenever a route traverses a site model that has the attribute secure:true
.
Download the Routing and Special Zones sample app here.
Creating Source and Destination Coordinates
Define the source and destination coordinates:
// ./src/index.ts
...
class TestApp
{
public iv: ApiInterface;
private readonly fromCoordinate: number[] = [5, 2, 3];
private readonly toCoordinate: number[] = [1, 2, 3];
constructor()
{
}
}
...
Note: The x, y, and z values depend on your specific data.
Connecting a Route Event Listener
Using the onRouteChanged signal of the RouteApi, connect an event listener that receives a RouteData object, which contains information about the route:
// ./src/index.ts
...
constructor()
{
this.loadApi(url)
.then(() =>
{
// Retrieve the list of sites
const sites = await this.iv.site.repository.findAll();
// Load a site
await this.iv.site.service.loadSite(sites[0]);
this.iv.routing.onRouteChanged.connect((routeData:RouteDataInterface) =>
{
});
)}
.catch((error) => console.error(error));
}
...
Searching for Special Site Model Attributes
Using the RouteData object, you can search for any site model that contains the key-value attribute secure:true
. When found, raise a standard alert that notifies the user.
Creating Route Generator Function
Entering Data
In order for this application to work, you must create a site model that contains the attribute you wish to use as a flag. For this example, secure:true
is used.