mapbox-gl
Version:
A WebGL interactive maps library
2 lines (1 loc) • 2.46 kB
JavaScript
!function t(e,n,o){function i(r,u){if(!n[r]){if(!e[r]){var c="function"==typeof require&&require;if(!u&&c)return c(r,!0);if(s)return s(r,!0);var h=new Error("Cannot find module '"+r+"'");throw h.code="MODULE_NOT_FOUND",h}var d=n[r]={exports:{}};e[r][0].call(d.exports,function(t){var n=e[r][1][t];return i(n?n:t)},d,d.exports,t,e,n,o)}return n[r].exports}for(var s="function"==typeof require&&require,r=0;r<o.length;r++)i(o[r]);return i}({1:[function(t,e,n){"use strict";function o(t,e){mapboxgl.util.bindHandlers(this);var n=document.createElement("div");n.className="compare-swiper",n.addEventListener("mousedown",this._onDown),n.addEventListener("touchstart",this._onDown),this._container=document.createElement("div"),this._container.className="mapboxgl-compare",this._container.appendChild(n),t.getContainer().appendChild(this._container),this._clippedMap=e,this._bounds=e.getContainer().getBoundingClientRect(),this._setPosition(this._bounds.width/2),this._syncMaps(t,e),e.on("resize",function(){this._bounds=e.getContainer().getBoundingClientRect(),this._x&&this._setPosition(this._x)}.bind(this))}o.prototype={_copyPosition:function(t,e){e.jumpTo({center:t.getCenter(),zoom:t.getZoom(),bearing:t.getBearing(),pitch:t.getPitch()})},_syncMaps:function(t,e){function n(){e.off("move",o),i(t,e),e.on("move",o)}function o(){t.off("move",o),i(e,t),t.on("move",o)}var i=this._copyPosition;t.on("move",n),e.on("move",o)},_onDown:function(t){t.touches?(document.addEventListener("touchmove",this._onMove),document.addEventListener("touchend",this._onTouchEnd)):(document.addEventListener("mousemove",this._onMove),document.addEventListener("mouseup",this._onMouseUp))},_setPosition:function(t){var e="translate("+t+"px, 0)";this._container.style.transform=e,this._container.style.WebkitTransform=e,this._clippedMap.getContainer().style.clip="rect(0, 999em, "+this._bounds.height+"px,"+t+"px)",this._x=t},_onMove:function(t){this._setPosition(this._getX(t))},_onMouseUp:function(){document.removeEventListener("mousemove",this._onMove),document.removeEventListener("mouseup",this._onMouseUp)},_onTouchEnd:function(){document.removeEventListener("touchmove",this._onMove),document.removeEventListener("touchend",this._onTouchEnd)},_getX:function(t){t=t.touches?t.touches[0]:t;var e=t.clientX-this._bounds.left;return 0>e&&(e=0),e>this._bounds.width&&(e=this._bounds.width),e}},window.mapboxgl?mapboxgl.Compare=o:"undefined"!=typeof e&&(e.exports=o)},{}]},{},[1]);