Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

leaflet-side-by-side.js 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. (function (global){
  3. var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null)
  4. require('./layout.css')
  5. require('./range.css')
  6. var mapWasDragEnabled
  7. // Leaflet v0.7 backwards compatibility
  8. function on (el, types, fn, context) {
  9. types.split(' ').forEach(function (type) {
  10. L.DomEvent.on(el, type, fn, context)
  11. })
  12. }
  13. // Leaflet v0.7 backwards compatibility
  14. function off (el, types, fn, context) {
  15. types.split(' ').forEach(function (type) {
  16. L.DomEvent.off(el, type, fn, context)
  17. })
  18. }
  19. function getRangeEvent (rangeInput) {
  20. return 'oninput' in rangeInput ? 'input' : 'change'
  21. }
  22. function cancelMapDrag () {
  23. mapWasDragEnabled = this._map.dragging.enabled()
  24. this._map.dragging.disable()
  25. }
  26. function uncancelMapDrag (e) {
  27. if (!mapWasDragEnabled) return
  28. this._refocusOnMap(e)
  29. this._map.dragging.enable()
  30. }
  31. function noop () {
  32. return
  33. }
  34. L.Control.SideBySide = L.Control.extend({
  35. initialize: function (leftLayers, rightLayers) {
  36. this._leftLayers = Array.isArray(leftLayers) ? leftLayers : [leftLayers]
  37. this._rightLayers = Array.isArray(rightLayers) ? rightLayers : [rightLayers]
  38. },
  39. getPosition: noop,
  40. setPosition: noop,
  41. includes: L.Mixin.Events,
  42. addTo: function (map) {
  43. this.remove()
  44. this._map = map
  45. var container = this._container = L.DomUtil.create('div', 'leaflet-sbs', map._controlContainer)
  46. this._divider = L.DomUtil.create('div', 'leaflet-sbs-divider', container)
  47. var range = this._range = L.DomUtil.create('input', 'leaflet-sbs-range', container)
  48. range.type = 'range'
  49. range.min = 0
  50. range.max = 1
  51. range.step = 'any'
  52. range.value = 0.5
  53. this._addEvents()
  54. this._updateLayers()
  55. this._updateClip()
  56. return this
  57. },
  58. remove: function () {
  59. if (!this._map) {
  60. return this
  61. }
  62. this._removeEvents()
  63. L.DomUtil.remove(this._container)
  64. this._map = null
  65. return this
  66. },
  67. _updateClip: function () {
  68. var map = this._map
  69. var rangeValue = this._range.value
  70. var nw = map.containerPointToLayerPoint([0, 0])
  71. var se = map.containerPointToLayerPoint(map.getSize())
  72. var offset = (0.5 - rangeValue) * 44
  73. var clipX = nw.x + (se.x - nw.x) * rangeValue + offset
  74. var dividerX = map.getSize().x * rangeValue + offset
  75. this._divider.style.left = dividerX + 'px'
  76. this.fire('dividermove', {x: dividerX})
  77. var clipLeft = 'rect(' + [nw.y, clipX, se.y, nw.x].join('px,') + 'px)'
  78. var clipRight = 'rect(' + [nw.y, se.x, se.y, clipX].join('px,') + 'px)'
  79. if (this._leftLayer) {
  80. this._leftLayer.getContainer().style.clip = clipLeft
  81. }
  82. if (this._rightLayer) {
  83. this._rightLayer.getContainer().style.clip = clipRight
  84. }
  85. },
  86. _updateLayers: function () {
  87. var prevLeft = this._leftLayer
  88. var prevRight = this._rightLayer
  89. this._leftLayer = this._rightLayer = null
  90. this._leftLayers.forEach(function (layer) {
  91. if (this._map.hasLayer(layer)) {
  92. this._leftLayer = layer
  93. }
  94. }, this)
  95. this._rightLayers.forEach(function (layer) {
  96. if (this._map.hasLayer(layer)) {
  97. this._rightLayer = layer
  98. }
  99. }, this)
  100. if (prevLeft !== this._leftLayer) {
  101. prevLeft && this.fire('leftlayerremove', {layer: prevLeft})
  102. this._leftLayer && this.fire('leftlayeradd', {layer: this._leftLayer})
  103. }
  104. if (prevRight !== this._rightLayer) {
  105. prevRight && this.fire('rightlayerremove', {layer: prevRight})
  106. this._rightLayer && this.fire('rightlayeradd', {layer: this._rightLayer})
  107. }
  108. this._updateClip()
  109. },
  110. _addEvents: function () {
  111. var range = this._range
  112. var map = this._map
  113. if (!map || !range) return
  114. map.on('move', this._updateClip, this)
  115. map.on('layeradd layerremove', this._updateLayers, this)
  116. on(range, getRangeEvent(range), this._updateClip, this)
  117. on(range, 'mousedown touchstart', cancelMapDrag, this)
  118. on(range, 'mouseup touchend', uncancelMapDrag, this)
  119. },
  120. _removeEvents: function () {
  121. var range = this._range
  122. var map = this._map
  123. if (range) {
  124. off(range, getRangeEvent(range), this._updateClip, this)
  125. off(range, 'mousedown touchstart', cancelMapDrag, this)
  126. off(range, 'mouseup touchend', uncancelMapDrag, this)
  127. }
  128. if (map) {
  129. map.off('layeradd layerremove', this._updateLayers, this)
  130. map.off('move', this._updateClip, this)
  131. }
  132. }
  133. })
  134. L.Control.sideBySide = function (leftLayers, rightLayers, options) {
  135. return new L.Control.SideBySide(leftLayers, rightLayers, options)
  136. }
  137. module.export = L.Control.sideBySide
  138. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  139. },{"./layout.css":2,"./range.css":4}],2:[function(require,module,exports){
  140. var css = ".leaflet-sbs-range {\n position: absolute;\n top: 50%;\n width: 100%;\n z-index: 999;\n}\n.leaflet-sbs-divider {\n position: absolute;\n top: 0;\n bottom: 0;\n left: 50%;\n margin-left: -2px;\n width: 4px;\n background-color: #fff;\n pointer-events: none;\n z-index: 999;\n}\n"; (require("./node_modules/cssify"))(css, undefined, '/Users/gregor/Dev/DdDev/leaflet-side-by-side/layout.css'); module.exports = css;
  141. },{"./node_modules/cssify":3}],3:[function(require,module,exports){
  142. function injectStyleTag(document, fileName, cb) {
  143. var style = document.getElementById(fileName);
  144. if (style) {
  145. cb(style);
  146. } else {
  147. var head = document.getElementsByTagName('head')[0];
  148. style = document.createElement('style');
  149. style.id = fileName;
  150. cb(style);
  151. head.appendChild(style);
  152. }
  153. return style;
  154. }
  155. module.exports = function (css, customDocument, fileName) {
  156. var doc = customDocument || document;
  157. if (doc.createStyleSheet) {
  158. var sheet = doc.createStyleSheet()
  159. sheet.cssText = css;
  160. return sheet.ownerNode;
  161. } else {
  162. return injectStyleTag(doc, fileName, function(style) {
  163. if (style.styleSheet) {
  164. style.styleSheet.cssText = css;
  165. } else {
  166. style.innerHTML = css;
  167. }
  168. });
  169. }
  170. };
  171. module.exports.byUrl = function(url) {
  172. if (document.createStyleSheet) {
  173. return document.createStyleSheet(url).ownerNode;
  174. } else {
  175. var head = document.getElementsByTagName('head')[0],
  176. link = document.createElement('link');
  177. link.rel = 'stylesheet';
  178. link.href = url;
  179. head.appendChild(link);
  180. return link;
  181. }
  182. };
  183. },{}],4:[function(require,module,exports){
  184. var css = ".leaflet-sbs-range {\n -webkit-appearance: none;\n display: inline-block!important;\n vertical-align: middle;\n height: 0;\n padding: 0;\n margin: 0;\n border: 0;\n background: rgba(0, 0, 0, 0.25);\n min-width: 100px;\n cursor: pointer;\n pointer-events: none;\n z-index: 999;\n}\n.leaflet-sbs-range::-ms-fill-upper {\n background: transparent;\n}\n.leaflet-sbs-range::-ms-fill-lower {\n background: rgba(255, 255, 255, 0.25);\n}\n/* Browser thingies */\n\n.leaflet-sbs-range::-moz-range-track {\n opacity: 0;\n}\n.leaflet-sbs-range::-ms-track {\n opacity: 0;\n}\n.leaflet-sbs-range::-ms-tooltip {\n display: none;\n}\n/* For whatever reason, these need to be defined\n * on their own so dont group them */\n\n.leaflet-sbs-range::-webkit-slider-thumb {\n -webkit-appearance: none;\n margin: 0;\n padding: 0;\n background: #fff;\n height: 40px;\n width: 40px;\n border-radius: 20px;\n cursor: ew-resize;\n pointer-events: auto;\n border: 1px solid #ddd;\n background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAMAAAC5zwKfAAAABlBMVEV9fX3///+Kct39AAAAAnRSTlP/AOW3MEoAAAA9SURBVFjD7dehDQAwDANBZ/+l2wmKoiqR7pHRcaeaCxAIBAL/g7k9JxAIBAKBQCAQCAQC14H+MhAIBE4CD3fOFvGVBzhZAAAAAElFTkSuQmCC\");\n background-position: 50% 50%;\n background-repeat: no-repeat;\n background-size: 40px 40px;\n}\n.leaflet-sbs-range::-ms-thumb {\n margin: 0;\n padding: 0;\n background: #fff;\n height: 40px;\n width: 40px;\n border-radius: 20px;\n cursor: ew-resize;\n pointer-events: auto;\n border: 1px solid #ddd;\n background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAMAAAC5zwKfAAAABlBMVEV9fX3///+Kct39AAAAAnRSTlP/AOW3MEoAAAA9SURBVFjD7dehDQAwDANBZ/+l2wmKoiqR7pHRcaeaCxAIBAL/g7k9JxAIBAKBQCAQCAQC14H+MhAIBE4CD3fOFvGVBzhZAAAAAElFTkSuQmCC\");\n background-position: 50% 50%;\n background-repeat: no-repeat;\n background-size: 40px 40px;\n}\n.leaflet-sbs-range::-moz-range-thumb {\n padding: 0;\n right: 0 ;\n background: #fff;\n height: 40px;\n width: 40px;\n border-radius: 20px;\n cursor: ew-resize;\n pointer-events: auto;\n border: 1px solid #ddd;\n background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAMAAAC5zwKfAAAABlBMVEV9fX3///+Kct39AAAAAnRSTlP/AOW3MEoAAAA9SURBVFjD7dehDQAwDANBZ/+l2wmKoiqR7pHRcaeaCxAIBAL/g7k9JxAIBAKBQCAQCAQC14H+MhAIBE4CD3fOFvGVBzhZAAAAAElFTkSuQmCC\");\n background-position: 50% 50%;\n background-repeat: no-repeat;\n background-size: 40px 40px;\n}\n.leaflet-sbs-range:disabled::-moz-range-thumb {\n cursor: default;\n}\n.leaflet-sbs-range:disabled::-ms-thumb {\n cursor: default;\n}\n.leaflet-sbs-range:disabled::-webkit-slider-thumb {\n cursor: default;\n}\n.leaflet-sbs-range:disabled {\n cursor: default;\n}\n.leaflet-sbs-range:focus {\n outline: none!important;\n}\n.leaflet-sbs-range::-moz-focus-outer {\n border: 0;\n}\n\n"; (require("./node_modules/cssify"))(css, undefined, '/Users/gregor/Dev/DdDev/leaflet-side-by-side/range.css'); module.exports = css;
  185. },{"./node_modules/cssify":3}]},{},[1]);