UNPKG

@jibestream-dev/jmap-zone-kit

Version:

Kit for the Jibestream SDK to utilize Zones plotted in the CMS

401 lines (314 loc) 15 kB
## Classes <dl> <dt><a href="#Zone">Zone</a></dt> <dd></dd> <dt><a href="#ZoneCollection">ZoneCollection</a><code>jmap.core.BaseCollection</code></dt> <dd><p>Class representing a collection of Devices.</p> </dd> <dt><a href="#ZoneKit">ZoneKit</a></dt> <dd><p>Kit for working with Jibestream Zones</p> </dd> </dl> <a name="Zone"></a> ## Zone **Kind**: global class * [Zone](#Zone) * [new Zone()](#new_Zone_new) * [.name](#Zone+name) : <code>String</code> * [.description](#Zone+description) : <code>String</code> * [.color](#Zone+color) : <code>String</code> <a name="new_Zone_new"></a> ### new Zone() Class representing a Zone <a name="Zone+name"></a> ### zone.name : <code>String</code> **Kind**: instance property of [<code>Zone</code>](#Zone) <a name="Zone+description"></a> ### zone.description : <code>String</code> **Kind**: instance property of [<code>Zone</code>](#Zone) <a name="Zone+color"></a> ### zone.color : <code>String</code> **Kind**: instance property of [<code>Zone</code>](#Zone) <a name="ZoneCollection"></a> ## ZoneCollection ⇐ <code>jmap.core.BaseCollection</code> Class representing a collection of Devices. **Kind**: global class **Extends**: <code>jmap.core.BaseCollection</code> * [ZoneCollection](#ZoneCollection) ⇐ <code>jmap.core.BaseCollection</code> * [new ZoneCollection()](#new_ZoneCollection_new) * [.isZone(item)](#ZoneCollection+isZone) ⇒ <code>Boolean</code> * [.getByName(name)](#ZoneCollection+getByName) ⇒ [<code>Array.&lt;Zone&gt;</code>](#Zone) * [.getByWaypoint(waypoint)](#ZoneCollection+getByWaypoint) ⇒ [<code>Array.&lt;Zone&gt;</code>](#Zone) * [.getByMap(map)](#ZoneCollection+getByMap) ⇒ [<code>Array.&lt;Zone&gt;</code>](#Zone) <a name="new_ZoneCollection_new"></a> ### new ZoneCollection() Create a collection of Devices. <a name="ZoneCollection+isZone"></a> ### zoneCollection.isZone(item) ⇒ <code>Boolean</code> Returns a boolean for whather or not argument is constructed as an Device object **Kind**: instance method of [<code>ZoneCollection</code>](#ZoneCollection) **Returns**: <code>Boolean</code> - Boolean based on evaluation result | Param | Type | Description | | --- | --- | --- | | item | <code>Object</code> | Item to evaluate | <a name="ZoneCollection+getByName"></a> ### zoneCollection.getByName(name) ⇒ [<code>Array.&lt;Zone&gt;</code>](#Zone) - Returns Zone/s by their name (or returns an empty array) **Kind**: instance method of [<code>ZoneCollection</code>](#ZoneCollection) **Returns**: [<code>Array.&lt;Zone&gt;</code>](#Zone) - - The desired Zone/s (or an empty array if name is invalid) **Access**: public | Param | Type | Description | | --- | --- | --- | | name | <code>string</code> | The name of the desired Zone/s | **Example** ```js const name = 'Food Court' const zone = e(name) ``` <a name="ZoneCollection+getByWaypoint"></a> ### zoneCollection.getByWaypoint(waypoint) ⇒ [<code>Array.&lt;Zone&gt;</code>](#Zone) - Returns Zone/s by a given waypoint (or returns an empty array) **Kind**: instance method of [<code>ZoneCollection</code>](#ZoneCollection) **Returns**: [<code>Array.&lt;Zone&gt;</code>](#Zone) - - The desired Zone/s (or an empty array if waypoint is invalid) **Access**: public | Param | Type | Description | | --- | --- | --- | | waypoint | <code>Waypoint</code> | The waypoint to search with | **Example** ```js const waypoint = control.currentMap.waypoints[0] const zone = getByWaypoint(waypoint) ``` <a name="ZoneCollection+getByMap"></a> ### zoneCollection.getByMap(map) ⇒ [<code>Array.&lt;Zone&gt;</code>](#Zone) - Returns Zone/s by a given map (or returns an empty array) **Kind**: instance method of [<code>ZoneCollection</code>](#ZoneCollection) **Returns**: [<code>Array.&lt;Zone&gt;</code>](#Zone) - - The desired Zone/s (or an empty array if map is invalid) **Access**: public | Param | Type | Description | | --- | --- | --- | | map | <code>Map</code> | The map on which we're searching | **Example** ```js const map = control.currentMap const zone = getByMap(map) ``` <a name="ZoneKit"></a> ## ZoneKit Kit for working with Jibestream Zones **Kind**: global class * [ZoneKit](#ZoneKit) * [new ZoneKit(core, control)](#new_ZoneKit_new) * [.getWaypointsInZone(zone)](#ZoneKit+getWaypointsInZone) ⇒ <code>Array.&lt;jmap.core.Waypoint&gt;</code> * [.getDestinationsInZone(zone)](#ZoneKit+getDestinationsInZone) ⇒ <code>Array.&lt;jmap.core.Destination&gt;</code> * [.getAmenitiesInZone(zone)](#ZoneKit+getAmenitiesInZone) ⇒ <code>Array.&lt;jmap.core.Amentity&gt;</code> * [.getBoundsOfZoneOnMap(zone, map)](#ZoneKit+getBoundsOfZoneOnMap) ⇒ <code>jmap.Bounds</code> * [.getPolygonOfZoneOnMap(zone, map)](#ZoneKit+getPolygonOfZoneOnMap) ⇒ <code>jmap.jungle.shape.Polygon</code> * [.drawPolygonOfZoneOnMap(zone, map, style)](#ZoneKit+drawPolygonOfZoneOnMap) ⇒ <code>Polygon</code> * [.getZones([cb])](#ZoneKit+getZones) ⇒ [<code>ZoneKit</code>](#ZoneKit) * [.getCentroidOfZoneOnMap(zone, map)](#ZoneKit+getCentroidOfZoneOnMap) ⇒ <code>Array.&lt;Number&gt;</code> * [.getClosestWaypointInZoneToPoint(zone, jMapPoint, [searchType])](#ZoneKit+getClosestWaypointInZoneToPoint) ⇒ <code>jmap.core.Waypoint</code> * [.highlightUnitsInZone(zone, style)](#ZoneKit+highlightUnitsInZone) ⇒ [<code>ZoneKit</code>](#ZoneKit) * [.watchMovingObjects(zonesExitedCallback, zonesEnteredCallback)](#ZoneKit+watchMovingObjects) ⇒ [<code>ZoneKit</code>](#ZoneKit) * [.unwatchMovingObjects()](#ZoneKit+unwatchMovingObjects) ⇒ [<code>ZoneKit</code>](#ZoneKit) <a name="new_ZoneKit_new"></a> ### new ZoneKit(core, control) Create a ZoneKit. | Param | Type | Description | | --- | --- | --- | | core | <code>jmap.core</code> | instantiated JCore | | control | <code>jmap.JController</code> | instantiated JController | <a name="ZoneKit+getWaypointsInZone"></a> ### zoneKit.getWaypointsInZone(zone) ⇒ <code>Array.&lt;jmap.core.Waypoint&gt;</code> - Returns all waypoints associated with a given Zone (or returns an empty array) **Kind**: instance method of [<code>ZoneKit</code>](#ZoneKit) **Returns**: <code>Array.&lt;jmap.core.Waypoint&gt;</code> - - The waypoints associated with a given zone (or an empty array) **Access**: public | Param | Type | Description | | --- | --- | --- | | zone | [<code>Zone</code>](#Zone) | The Zone we're using to search for waypoints | **Example** ```js const zone = zoneKit.zones.getAll()[0] const waypoints = zoneKit.getWaypointsInZone(zone) ``` <a name="ZoneKit+getDestinationsInZone"></a> ### zoneKit.getDestinationsInZone(zone) ⇒ <code>Array.&lt;jmap.core.Destination&gt;</code> - Returns all destinations associated with waypoints within an zone (or returns an empty array) **Kind**: instance method of [<code>ZoneKit</code>](#ZoneKit) **Returns**: <code>Array.&lt;jmap.core.Destination&gt;</code> - - The destinations associated with a given zone (or an empty array) **Access**: public | Param | Type | Description | | --- | --- | --- | | zone | [<code>Zone</code>](#Zone) | The Zone we're using to search for destinations | **Example** ```js const zone = zoneKit.zones.getAll()[0] const destinations = zoneKit.getDestinationsInZone(zone) ``` <a name="ZoneKit+getAmenitiesInZone"></a> ### zoneKit.getAmenitiesInZone(zone) ⇒ <code>Array.&lt;jmap.core.Amentity&gt;</code> - Returns all amenity instances associated with waypoints within an zone (or returns an empty array) **Kind**: instance method of [<code>ZoneKit</code>](#ZoneKit) **Returns**: <code>Array.&lt;jmap.core.Amentity&gt;</code> - - The amenities associated with a given zone (or an empty array) **Access**: public | Param | Type | Description | | --- | --- | --- | | zone | [<code>Zone</code>](#Zone) | The Zone we're using to search for destinations | **Example** ```js const zone = zoneKit.zones.getAll()[0] const amentities = zoneKit.getAmenitiesInZone(zone) ``` <a name="ZoneKit+getBoundsOfZoneOnMap"></a> ### zoneKit.getBoundsOfZoneOnMap(zone, map) ⇒ <code>jmap.Bounds</code> - For a given Zone, return the bounding box for the associated waypoints on the specified map If an invalid zone or map is given, null is returned **Kind**: instance method of [<code>ZoneKit</code>](#ZoneKit) **Returns**: <code>jmap.Bounds</code> - - A Bounds object **Access**: public | Param | Type | Description | | --- | --- | --- | | zone | [<code>Zone</code>](#Zone) | The Zone we're using to calculate bounding boxes | | map | <code>jmap.core.Map</code> | The map we'll use to calculate the bounding box | **Example** ```js const zone = zoneKit.zones.getAll()[0] const map = control.currentMap const bounds = zoneKit.getBoundsOfZone(zone, map) ``` <a name="ZoneKit+getPolygonOfZoneOnMap"></a> ### zoneKit.getPolygonOfZoneOnMap(zone, map) ⇒ <code>jmap.jungle.shape.Polygon</code> - Returns a polygon shape, based on the waypoints associated with the specified zone on the specified map. The zone must have three or more waypoints associated with it on the given map, otherwise null will be returned **Kind**: instance method of [<code>ZoneKit</code>](#ZoneKit) **Returns**: <code>jmap.jungle.shape.Polygon</code> - - A Polygon object **Access**: public | Param | Type | Description | | --- | --- | --- | | zone | [<code>Zone</code>](#Zone) | The Zone we're using to calculate polygons | | map | <code>jmap.core.Map</code> | The map we'll use to calculate the polygon | **Example** ```js const zone = zoneKit.zones.getAll()[0] const map = control.currentMap const polygon = zoneKit.getPolygonOfZone(zone, map) ``` <a name="ZoneKit+drawPolygonOfZoneOnMap"></a> ### zoneKit.drawPolygonOfZoneOnMap(zone, map, style) ⇒ <code>Polygon</code> - Given a specific Zone, draw a polygon the encompasses all of its waypoints on the specified map **Kind**: instance method of [<code>ZoneKit</code>](#ZoneKit) **Returns**: <code>Polygon</code> - - The polygon that was drawn **Access**: public | Param | Type | Description | | --- | --- | --- | | zone | [<code>Zone</code>](#Zone) | The Zone we wish to highlight using a polygon | | map | <code>jmap.core.Map</code> | The map we wish to draw the polygon on | | style | <code>jmap.Style</code> | The way in which the polygon should be styled. Default style uses zone.color | **Example** ```js const zone = zoneKit.zones.getAll()[0] const map = control.currentMap const polygon = zoneKit.drawPolygonOfZone(zone, map) ``` <a name="ZoneKit+getZones"></a> ### zoneKit.getZones([cb]) ⇒ [<code>ZoneKit</code>](#ZoneKit) - Returns all zones for the currently loaded building **Kind**: instance method of [<code>ZoneKit</code>](#ZoneKit) **Returns**: [<code>ZoneKit</code>](#ZoneKit) - - The current ZoneKit instance **Access**: public | Param | Type | Description | | --- | --- | --- | | [cb] | <code>function</code> | The callback function, which will run once the Zones have been retrieved. The Zones will be stored in this.zones | **Example** ```js const fn = (error, zones) => console.log(zones) zoneKit.getZones(fn) ``` <a name="ZoneKit+getCentroidOfZoneOnMap"></a> ### zoneKit.getCentroidOfZoneOnMap(zone, map) ⇒ <code>Array.&lt;Number&gt;</code> - Return the coordinates of the centroid of a given zone on the given map The zone must have three or more waypoints associated with it on the given map otherwise null will be returned **Kind**: instance method of [<code>ZoneKit</code>](#ZoneKit) **Returns**: <code>Array.&lt;Number&gt;</code> - - The centroid in the form of [x, y] **Access**: public | Param | Type | Description | | --- | --- | --- | | zone | [<code>Zone</code>](#Zone) | The zone we wish to find the centroid of | | map | <code>jmap.core.Map</code> | The map on which we'll use to find the centroid | **Example** ```js const zone = zoneKit.zones.getAll()[0] const map = control.currentMap const centroid = zoneKit.getCentroidOfZone(zone, map) ``` <a name="ZoneKit+getClosestWaypointInZoneToPoint"></a> ### zoneKit.getClosestWaypointInZoneToPoint(zone, jMapPoint, [searchType]) ⇒ <code>jmap.core.Waypoint</code> - Given a specific point on the a map, return the closest waypoint associated with the given Zone **Kind**: instance method of [<code>ZoneKit</code>](#ZoneKit) **Returns**: <code>jmap.core.Waypoint</code> - - The closest waypoint within the specified Zone to the provided point **Access**: public | Param | Type | Default | Description | | --- | --- | --- | --- | | zone | [<code>Zone</code>](#Zone) | | The zone we wish to search within | | jMapPoint | <code>jMapPoint</code> | | The point we wish to search with | | [searchType] | <code>String</code> | <code>&#x27;proximity&#x27;</code> | Either 'proximity' or 'grid' | **Example** ```js const jMapPoint = { x: 2750, y: 2750, mapId: control.currentMap.id } const zone = zoneKit.zones.getAll()[0] const waypoint = zoneKit.getClosestWaypointInZoneToPoint(zone, jMapPoint) ``` <a name="ZoneKit+highlightUnitsInZone"></a> ### zoneKit.highlightUnitsInZone(zone, style) ⇒ [<code>ZoneKit</code>](#ZoneKit) - Highlight all units associated to a specific zone using either the color specified in the CMS or the color override provided **Kind**: instance method of [<code>ZoneKit</code>](#ZoneKit) **Returns**: [<code>ZoneKit</code>](#ZoneKit) - - The current ZoneKit instance **Access**: public | Param | Type | Description | | --- | --- | --- | | zone | [<code>Zone</code>](#Zone) | The zone we wish to highlight | | style | <code>jmap.Style</code> | The way in which the unit will be styled | **Example** ```js const zone = zoneKit.zones.getAll()[0] const style = new jmap.Style({ fill: '#4a85e2' }) zoneKit.highlightUnitsInZone(zone, style) ``` <a name="ZoneKit+watchMovingObjects"></a> ### zoneKit.watchMovingObjects(zonesExitedCallback, zonesEnteredCallback) ⇒ [<code>ZoneKit</code>](#ZoneKit) - Subscribe to animation complete callback for moving objects and send back zones exited/entered **Kind**: instance method of [<code>ZoneKit</code>](#ZoneKit) **Returns**: [<code>ZoneKit</code>](#ZoneKit) - - The current ZoneKit instance **Access**: public | Param | Type | Description | | --- | --- | --- | | zonesExitedCallback | <code>function</code> | Callback for zones being exited | | zonesEnteredCallback | <code>function</code> | Callback for zones being entered | **Example** ```js function watchMovingObjCallback(zones) { } zoneKit.watchMovingObjects(watchMovingObjCallback, watchMovingObjCallback) ``` <a name="ZoneKit+unwatchMovingObjects"></a> ### zoneKit.unwatchMovingObjects() ⇒ [<code>ZoneKit</code>](#ZoneKit) - Unsubscribe to animation complete callback for moving objects **Kind**: instance method of [<code>ZoneKit</code>](#ZoneKit) **Returns**: [<code>ZoneKit</code>](#ZoneKit) - - The current ZoneKit instance **Access**: public **Example** ```js zonKit.unwatchMovingObjects() ```