8 lines
3.1 KiB
JavaScript
8 lines
3.1 KiB
JavaScript
|
/*!
|
||
|
* Copyright (c) 2016 Mapbox
|
||
|
* mapbox-gl-compare.
|
||
|
* github: https://github.com/mapbox/mapbox-gl-compare
|
||
|
* license: ISC
|
||
|
*/
|
||
|
!function t(e,n,o){function i(r,u){if(!n[r]){if(!e[r]){var h="function"==typeof require&&require;if(!u&&h)return h(r,!0);if(s)return s(r,!0);var c=new Error("Cannot find module '"+r+"'");throw c.code="MODULE_NOT_FOUND",c}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,n){this.options=n?n:{},this._onDown=this._onDown.bind(this),this._onMove=this._onMove.bind(this),this._onMouseUp=this._onMouseUp.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._swiper=document.createElement("div"),this._swiper.className="compare-swiper",this._container=document.createElement("div"),this._container.className="mapboxgl-compare",this._container.appendChild(this._swiper),t.getContainer().appendChild(this._container),this._clippedMap=e,this._bounds=e.getContainer().getBoundingClientRect(),this._setPosition(this._bounds.width/2),i(t,e),e.on("resize",function(){this._bounds=e.getContainer().getBoundingClientRect(),this._x&&this._setPosition(this._x)}.bind(this)),this.options&&this.options.mousemove&&(t.getContainer().addEventListener("mousemove",this._onMove),e.getContainer().addEventListener("mousemove",this._onMove)),this._swiper.addEventListener("mousedown",this._onDown),this._swiper.addEventListener("touchstart",this._onDown)}var i=t("mapbox-gl-sync-move");o.prototype={_setPointerEvents:function(t){this._container.style.pointerEvents=t,this._swiper.style.pointerEvents=t},_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.options&&this.options.mousemove&&this._setPointerEvents(t.touches?"auto":"none"),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)},{"mapbox-gl-sync-move":2}],2:[function(t,e,n){function o(t,e){e.jumpTo({center:t.getCenter(),zoom:t.getZoom(),bearing:t.getBearing(),pitch:t.getPitch()})}function i(t,e){function n(){t.on("move",s),e.on("move",r)}function i(){t.off("move",s),e.off("move",r)}function s(){i(),o(t,e),n()}function r(){i(),o(e,t),n()}n()}e.exports=i},{}]},{},[1]);
|