UNPKG

ooomap-geolocation

Version:

ooomap geolocation plugin

2 lines (1 loc) 2.06 kB
var t,e;t=this,e=function(t){"use strict";var e=function(t,e){e={};var n={};return t.setEventState=function(t,e){n[t]=e},t.getEventState=function(t){return!1!==n[t]},t._tmpEventMode=!1,Object.defineProperties(t,{tmpEventMode:{get:function(){return t._tmpEventMode},set:function(e){t._tmpEventMode=e,e||t.tmpEvents&&(t.tmpEvents.forEach((function(t){return t()})),t.tmpEvents.length=0,delete t.tmpEvents)}}}),t.on=function(n,o){var i=[].concat(n);function c(){i.forEach((function(e){t.off(e,o)}))}return i.forEach((function(t){(e[t]=e[t]||[]).push(o)})),t.tmpEventMode&&(t.tmpEvents||(t.tmpEvents=[]),t.tmpEvents.push(c)),c},t.clearHandlers=function(t){t?(e[t]={},delete n[t]):(e={},n={})},t.once=function(e,n){function o(){n.apply(t.off(e,o),arguments)}return o.h=n,t.on(e,o)},t.off=function(o,i){for(var c=e[o],r=0;i&&c&&c[r];r++)c[r]!=i&&c[r].h!=i||c.splice(r--,1);return i||(delete e[o],delete n[o]),t},t.emit=function(o){var i=arguments;if(!1===n[o])return t;t.__events||(t.__events={}),t.__events[o]=o;for(var c=e[o],r=0;c&&c[r];)c[r++].apply(t,c.slice.call(i,1));return t},t},n=navigator.geolocation,o=function(t,n){t&&(this.config=Object.assign({enableHighAccuracy:!0},n),this.om=t,this._id,this.pause=!1,e(this))};o.prototype.start=function(){var t=this;if(n&&(this.map||(this.map=this.om.Map.getInstance()),this.map)){var e=this.map.config.center;e&&(this.pause=!1,n.clearWatch(this._id),this._id=n.watchPosition((function(n){if(!t.pause){var o=n.coords.longitude,i=n.coords.latitude,c=t.om.utils.coordTransform.lngLatToMercator(o,i),r={x:c.x-e.x,y:c.y-e.y};t.emit("position",r,c,{lng:o,lat:i})}}),(function(t){}),{enableHighAccuracy:this.config.enableHighAccuracy}))}},o.prototype.stop=function(){n.clearWatch(this._id),this.pause=!0},t.GeoLocation=o,Object.defineProperty(t,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).om=(t="undefined"!=typeof globalThis?globalThis:t||self).om||{});