@jibestream-dev/jmap-zone-kit
Version:
Kit for the Jibestream SDK to utilize Zones plotted in the CMS
1 lines • 10.9 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["jmap-zone-kit"]=e():t["jmap-zone-kit"]=e()}(this,function(){return function(t){function e(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,o){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:o})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=4)}([function(t,e,n){"use strict";var o,r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};o=function(){return this}();try{o=o||Function("return this")()||(0,eval)("this")}catch(t){"object"===("undefined"==typeof window?"undefined":r(window))&&(o=window)}t.exports=o},function(t,e,n){"use strict";(function(e){function o(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var i=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),u=n(3),a=function(){function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(r(this,t),n instanceof e.jmap.core.JCore==!1)throw new Error("ZoneKit uses JCore as its first argument.");if(o instanceof e.jmap.JController==!1)throw new Error("ZoneKit uses JController as its second argument.");this._core=n,this._control=o,this._activeVenue=o.activeVenue,this.zones=new u,this.getBoundsOfZoneOnMap=this.getBoundsOfZoneOnMap,this.watchedMovingObjects=new Map}return i(t,[{key:"_getUrl",value:function(){return"/venue/"+this._activeVenue.id+"/zone/full"}},{key:"_isJMapPoint",value:function(t){return"number"==typeof t.x&&"number"==typeof t.y&&"number"==typeof t.mapId&&this._activeVenue.maps.getById(t.mapId)}},{key:"_getPointsFromZoneAndMap",value:function(t,e){if(this.zones.isZone(t)&&e&&e.constructor===jmap.core.Map){return this.getWaypointsInZone(t).reduce(function(t,n){return n.mapId===e.id&&t.push(n.coordinates),t},[])}return[]}},{key:"_getParsedMapView",value:function(t){var e=this._control.stage.getMapViewById(t.id);return e||(this._control.parseMap(t),e=this._control.stage.getMapViewById(t.id)||this._control.stage.currentMapView),e}},{key:"getWaypointsInZone",value:function(t){var e=this;if(this.zones.isZone(t)){return t.getLocations().reduce(function(t,n){var r=e._activeVenue.maps.getById(n.mapId);return r?t.concat.apply(t,o(n.waypointIds.map(function(t){return r.waypoints.getById(t)}))):t},[])}return[]}},{key:"getDestinationsInZone",value:function(t){if(this.zones.isZone(t)){var e=this.getWaypointsInZone(t),n=this._activeVenue.destinations;return e.reduce(function(t,e){var o=n.getByWaypoint(e),r=o.reduce(function(e,n){return-1===t.indexOf(n)&&e.push(n),e},[]);return t.concat(r)},[])}return[]}},{key:"getAmenitiesInZone",value:function(t){if(this.zones.isZone(t)){var e=this.getWaypointsInZone(t),n=this._activeVenue.amenities;return e.reduce(function(t,e){var o=n.getByWaypoint(e),r=o.reduce(function(e,n){return-1===t.indexOf(n)&&e.push(n),e},[]);return t.concat(r)},[])}return[]}},{key:"getBoundsOfZoneOnMap",value:function(t,e){var n=this._getPointsFromZoneAndMap(t,e);return n.length>=2?new jmap.Bounds(this._control.jungle.util.getBoundingBoxFromPoints(n)):null}},{key:"getPolygonOfZoneOnMap",value:function(e,n){var o=this._getPointsFromZoneAndMap(e,n);if(o.length>=3){var r=t._createConvexHull(o);r.push(r[0]);var i=new this._control.jungle.shape.Polygon({points:r});return i.meta.zone=e,i}return null}},{key:"drawPolygonOfZoneOnMap",value:function(t,e,n){var o=n||new jmap.Style({fill:t.color||"#000000"}),r=this.getPolygonOfZoneOnMap(t,e);if(r&&"Polygon"===r.baseTypeName){if(o&&o.constructor===jmap.Style){var i=o.hexidecimal();Object.keys(i).forEach(function(t){"number"==typeof i[t]&&(r[t]=i[t])})}return this._getParsedMapView(e).guaranteeMapLayer("Zones").addShape(r),this._control.pauseRender||this._control.renderCurrentMapView(),r}return null}},{key:"getZones",value:function(t){var e=this,n=this._getUrl();return this._core.get(n,function(n,o){e._responseData=o;var r=o.zones&&o.zones.items?o.zones.items:[];e.zones=new u,e.zones.createBatch(r),t(n,e.zones)}),this}},{key:"getCentroidOfZoneOnMap",value:function(e,n){if(this._getPointsFromZoneAndMap(e,n).length>=3){var o=this.getPolygonOfZoneOnMap(e,n);if(o){var r=6*t._getAreaOfPolygon(o);return o.points.reduce(function(t,e,n,o){var r=o[n-1>-1?n-1:o.length-1],i=e[0]*r[1]-r[0]*e[1],u=(e[0]+r[0])*i,a=(e[1]+r[1])*i;return[t[0]+u,t[1]+a]},[0,0]).map(function(t){return Math.abs(t/r)})}}return null}},{key:"getClosestWaypointInZoneToPoint",value:function(t,e){var n=this,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"proximity";if(this._isJMapPoint(e)){var r=this.getWaypointsInZone(t),i=r.filter(function(t){return t.mapId===e.mapId}),u=[e.x,e.y];if(i.length){if("proximity"===o){var a=1/0;return i.reduce(function(t,e){var o=n._control.jungle.util.distanceBetweenPoints;return o(u,e)<a?(a=o(u,e),e):t})}if("grid"===o){var c=this._activeVenue.getClosestWaypointToCoordinate(u,i);return this._activeVenue.getClosestWaypointInArrayToWaypoint(c,r)}}}return null}},{key:"highlightUnitsInZone",value:function(t,e){var n=this;if(e&&e.constructor===jmap.Style){var o=this.getWaypointsInZone(t),r=o.map(function(t){return n._control.getUnitFromWaypoint(t)}).filter(function(t){return t});this._control.styleShapes(r,e)}return this}},{key:"watchMovingObjects",value:function(t,n){var o=this;return"function"!=typeof t||"function"!=typeof n?(console.warn("watchMovingObjects :: requires a function callback"),this):(this.watchMovingObjectsHandler=function(e){var r=o.watchedMovingObjects.get(e)||[],i=o.zones.getByMap(e.map).reduce(function(t,n){var r=o.getPolygonOfZoneOnMap(n,e.map);return r&&r.containsPoint(e.position)?t.concat(n):t},[]);if(r){var u=r.filter(function(t){return-1===i.indexOf(t)});0!==u.length&&t(e,u)}if(i){var a=i.filter(function(t){return-1===r.indexOf(t)});0!==a.length&&n(e,a)}o.watchedMovingObjects.set(e,i)},e.jmap&&e.jmap.dispatcher.subscribe("MOVING_OBJECT_ANIMATION_COMPLETE",this.watchMovingObjectsHandler),this)}},{key:"unwatchMovingObjects",value:function(){return e.jmap&&this.watchMovingObjectsHandler&&e.jmap.dispatcher.unsubscribe("MOVING_OBJECT_ANIMATION_COMPLETE",this.watchMovingObjectsHandler),this}}],[{key:"_getAreaOfPolygon",value:function(t){if("Polygon"===t.baseTypeName&&t.points){var e=t.points.reduce(function(t,e,n,o){var r=o[n-1>-1?n-1:o.length-1];return t+e[0]*r[1]-e[1]*r[0]},0);return Math.abs(e/2)}return null}},{key:"_createConvexHull",value:function(e){if(Array.isArray(e)){e.sort(function(t,e){return t[0]===e[0]?t[1]-e[1]:t[0]-e[0]});var n=function(t){return t[t.length-2]},o=function(t){return t[t.length-1]},r=function(e){var r=[];return e.forEach(function(e){for(;r.length>=2&&t.cross(n(r),o(r),e)<=0;)r.pop();r.push(e)}),r.pop(),r},i=r(e),u=r(e.reverse());return i.concat(u)}return null}},{key:"cross",value:function(t,e,n){return(t[0]-n[0])*(e[1]-n[1])-(t[1]-n[1])*(e[0]-n[0])}}]),t}();t.exports=a}).call(e,n(0))},function(t,e,n){"use strict";(function(e){function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var i=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),u=function(t){function e(){return n(this,e),o(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return r(e,t),i(e,[{key:"getLocations",value:function(){return Array.isArray(this._.locations)?this._.locations:[]}},{key:"name",get:function(){return this.get("name",null)},set:function(t){this.set("name",t,String)}},{key:"description",get:function(){return this.get("description",null)},set:function(t){this.set("description",t,String)}},{key:"color",get:function(){return this.get("color",null)},set:function(t){this.set("color",t,String)}}]),e}(e.jmap.core.BaseModel);t.exports=u}).call(e,n(0))},function(t,e,n){"use strict";(function(e){function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var u=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),a=n(2),c=function(t){function e(){return o(this,e),r(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,a))}return i(e,t),u(e,[{key:"isZone",value:function(t){return this.isCollectionItemType(t)}},{key:"getByName",value:function(t){return this.filter(function(e){return e.name.toLowerCase()===t.toLowerCase()})}},{key:"getByWaypoint",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.filter(function(e){return e.getLocations().find(function(e){return e.waypointIds.indexOf(t.id)>-1})})}},{key:"getByMap",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.filter(function(e){return e.getLocations().find(function(e){return e.mapId===t.id})})}}]),e}(e.jmap.core.BaseCollection);t.exports=c}).call(e,n(0))},function(t,e,n){"use strict";(function(e){var o=n(1);e.ZoneKit=o,t.exports=o}).call(e,n(0))}])});