Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.00 KB | None | 0 0
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.L || (g.L = {})).NonTiledLayer = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  2. (function (global){
  3. /*
  4. * L.NonTiledLayer.WMS is used for putting WMS non tiled layers on the map.
  5. */
  6. "use strict";
  7.  
  8. var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null);
  9.  
  10. L.NonTiledLayer.WMS = L.NonTiledLayer.extend({
  11.  
  12. defaultWmsParams: {
  13. service: 'WMS',
  14. request: 'GetMap',
  15. version: '1.1.1',
  16. layers: '',
  17. styles: '',
  18. format: 'image/jpeg',
  19. transparent: false
  20. },
  21.  
  22. options: {
  23. crs: null,
  24. },
  25.  
  26. initialize: function (url, options) { // (String, Object)
  27. this._wmsUrl = url;
  28.  
  29. var wmsParams = L.extend({}, this.defaultWmsParams);
  30.  
  31. // all keys that are not NonTiledLayer options go to WMS params
  32. for (var i in options) {
  33. if (!L.NonTiledLayer.prototype.options.hasOwnProperty(i) &&
  34. !(L.Layer && L.Layer.prototype.options.hasOwnProperty(i))) {
  35. wmsParams[i] = options[i];
  36. }
  37. }
  38.  
  39. this.wmsParams = wmsParams;
  40.  
  41. L.setOptions(this, options);
  42. },
  43.  
  44. onAdd: function (map) {
  45.  
  46. this._crs = this.options.crs || map.options.crs;
  47. this._wmsVersion = parseFloat(this.wmsParams.version);
  48.  
  49. var projectionKey = this._wmsVersion >= 1.3 ? 'crs' : 'srs';
  50. this.wmsParams[projectionKey] = this._crs.code;
  51.  
  52. L.NonTiledLayer.prototype.onAdd.call(this, map);
  53. },
  54.  
  55. getImageUrl: function (bounds, width, height) {
  56. var wmsParams = this.wmsParams;
  57. wmsParams.width = width;
  58. wmsParams.height = height;
  59.  
  60. var nw = this._crs.project(bounds.getNorthWest());
  61. var se = this._crs.project(bounds.getSouthEast());
  62.  
  63. var url = this._wmsUrl;
  64.  
  65. var bbox = bbox = (this._wmsVersion >= 1.3 && this._crs === L.CRS.EPSG4326 ?
  66. [se.y, nw.x, nw.y, se.x] :
  67. [nw.x, se.y, se.x, nw.y]).join(',');
  68.  
  69. return url +
  70. L.Util.getParamString(this.wmsParams, url, true) +
  71. (true ? '&BBOX=' : '&bbox=') + bbox;
  72. },
  73.  
  74. setParams: function (params, noRedraw) {
  75.  
  76. L.extend(this.wmsParams, params);
  77.  
  78. if (!noRedraw) {
  79. this.redraw();
  80. }
  81.  
  82. return this;
  83. }
  84. });
  85.  
  86. L.nonTiledLayer.wms = function (url, options) {
  87. return new L.NonTiledLayer.WMS(url, options);
  88. };
  89.  
  90. module.exports = L.NonTiledLayer.WMS;
  91.  
  92. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  93. },{}],2:[function(require,module,exports){
  94. (function (global){
  95. /*
  96. * L.NonTiledLayer is an addon for leaflet which renders dynamic image overlays
  97. */
  98. "use strict";
  99.  
  100. var L = (typeof window !== "undefined" ? window['L'] : typeof global !== "undefined" ? global['L'] : null);
  101.  
  102. L.NonTiledLayer = (L.Layer || L.Class).extend({
  103. includes: L.Evented || L.Mixin.Events,
  104.  
  105. emptyImageUrl: 'data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==', //1px transparent GIF
  106.  
  107. options: {
  108. attribution: '',
  109. opacity: 1.0,
  110. zIndex: undefined,
  111. minZoom: 0,
  112. maxZoom: 18,
  113. pointerEvents: null,
  114. errorImageUrl: 'data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==', //1px transparent GIF
  115. bounds: L.latLngBounds([-85.05, -180], [85.05, 180]),
  116. useCanvas: undefined,
  117. detectRetina: false
  118. },
  119.  
  120. key: '',
  121.  
  122. // override this method in the inherited class
  123. //getImageUrl: function (bounds, width, height) {},
  124. //getImageUrlAsync: function (bounds, width, height, f) {},
  125.  
  126. initialize: function (options) {
  127. L.setOptions(this, options);
  128. },
  129.  
  130. onAdd: function (map) {
  131. this._map = map;
  132.  
  133. // don't animate on browsers without hardware-accelerated transitions or old Android/Opera
  134. if (typeof this._zoomAnimated == 'undefined') // Leaflet 0.7
  135. this._zoomAnimated = L.DomUtil.TRANSITION && L.Browser.any3d && !L.Browser.mobileOpera && this._map.options.zoomAnimation;
  136.  
  137. if (L.version < '1.0') this._map.on(this.getEvents(), this);
  138. if (!this._div) {
  139. this._div = L.DomUtil.create('div', 'leaflet-image-layer');
  140. if (this.options.pointerEvents) {
  141. this._div.style['pointer-events'] = this.options.pointerEvents;
  142. }
  143. if (typeof this.options.zIndex !== 'undefined') {
  144. this._div.style.zIndex = this.options.zIndex;
  145. }
  146. if (typeof this.options.opacity !== 'undefined') {
  147. this._div.style.opacity = this.options.opacity;
  148. }
  149. }
  150.  
  151. this.getPane().appendChild(this._div);
  152.  
  153. var canvasSupported = !!window.HTMLCanvasElement;
  154. if (typeof this.options.useCanvas === 'undefined') {
  155. this._useCanvas = canvasSupported;
  156. } else {
  157. this._useCanvas = this.options.useCanvas;
  158. }
  159.  
  160. if (this._useCanvas) {
  161. this._bufferCanvas = this._initCanvas();
  162. this._currentCanvas = this._initCanvas();
  163. }
  164. else {
  165. this._bufferImage = this._initImage();
  166. this._currentImage = this._initImage();
  167. }
  168.  
  169. this._update();
  170. },
  171.  
  172. getPane: function () {
  173. if (L.Layer) {
  174. return L.Layer.prototype.getPane.call(this);
  175. }
  176. if (this.options.pane) {
  177. this._pane = this.options.pane;
  178. }
  179. else {
  180. this._pane = this._map.getPanes().overlayPane;
  181. }
  182. return this._pane;
  183. },
  184.  
  185. onRemove: function (map) {
  186. if (L.version < '1.0') this._map.off(this.getEvents(), this);
  187.  
  188. this.getPane().removeChild(this._div);
  189.  
  190. if (this._useCanvas) {
  191. this._div.removeChild(this._bufferCanvas);
  192. this._div.removeChild(this._currentCanvas);
  193. }
  194. else {
  195. this._div.removeChild(this._bufferImage);
  196. this._div.removeChild(this._currentImage);
  197. }
  198. },
  199.  
  200. addTo: function (map) {
  201. map.addLayer(this);
  202. return this;
  203. },
  204.  
  205. _setZoom: function () {
  206. if (this._useCanvas) {
  207. if (this._currentCanvas._bounds)
  208. this._resetImageScale(this._currentCanvas, true);
  209. if (this._bufferCanvas._bounds)
  210. this._resetImageScale(this._bufferCanvas);
  211. }
  212. else {
  213. if (this._currentImage._bounds)
  214. this._resetImageScale(this._currentImage, true);
  215. if (this._bufferImage._bounds)
  216. this._resetImageScale(this._bufferImage);
  217. }
  218. },
  219.  
  220. getEvents: function () {
  221. var events = {
  222. moveend: this._update
  223. };
  224.  
  225. if (this._zoomAnimated) {
  226. events.zoomanim = this._animateZoom;
  227. }
  228.  
  229. // fix: no zoomanim for pinch with Leaflet 1.0!
  230. if(L.version >= '1.0') {
  231. events.zoom = this._setZoom;
  232. }
  233.  
  234. return events;
  235. },
  236.  
  237. getElement: function () {
  238. return this._div;
  239. },
  240.  
  241. setOpacity: function (opacity) {
  242. this.options.opacity = opacity;
  243. if (this._div) {
  244. L.DomUtil.setOpacity(this._div, this.options.opacity);
  245. }
  246. return this;
  247. },
  248.  
  249. setZIndex: function (zIndex) {
  250. if (zIndex) {
  251. this.options.zIndex = zIndex;
  252. if (this._div) {
  253. this._div.style.zIndex = zIndex;
  254. }
  255. }
  256. return this;
  257. },
  258.  
  259. // TODO remove bringToFront/bringToBack duplication from TileLayer/Path
  260. bringToFront: function () {
  261. if (this._div) {
  262. this.getPane().appendChild(this._div);
  263. }
  264. return this;
  265. },
  266.  
  267. bringToBack: function () {
  268. if (this._div) {
  269. this.getPane().insertBefore(this._div, this.getPane().firstChild);
  270. }
  271. return this;
  272. },
  273.  
  274. getAttribution: function () {
  275. return this.options.attribution;
  276. },
  277.  
  278. _initCanvas: function () {
  279. var _canvas = L.DomUtil.create('canvas', 'leaflet-image-layer');
  280.  
  281. this._div.appendChild(_canvas);
  282. _canvas._image = new Image();
  283. this._ctx = _canvas.getContext('2d');
  284.  
  285. if (this._map.options.zoomAnimation && L.Browser.any3d) {
  286. L.DomUtil.addClass(_canvas, 'leaflet-zoom-animated');
  287. } else {
  288. L.DomUtil.addClass(_canvas, 'leaflet-zoom-hide');
  289. }
  290.  
  291. L.extend(_canvas._image, {
  292. onload: L.bind(this._onImageLoad, this),
  293. onerror: L.bind(this._onImageError, this)
  294. });
  295.  
  296. return _canvas;
  297. },
  298.  
  299. _initImage: function () {
  300. var _image = L.DomUtil.create('img', 'leaflet-image-layer');
  301.  
  302. this._div.appendChild(_image);
  303.  
  304. if (this._map.options.zoomAnimation && L.Browser.any3d) {
  305. L.DomUtil.addClass(_image, 'leaflet-zoom-animated');
  306. } else {
  307. L.DomUtil.addClass(_image, 'leaflet-zoom-hide');
  308. }
  309.  
  310.  
  311. //TODO createImage util method to remove duplication
  312. L.extend(_image, {
  313. galleryimg: 'no',
  314. onselectstart: L.Util.falseFn,
  315. onmousemove: L.Util.falseFn,
  316. onload: L.bind(this._onImageLoad, this),
  317. onerror: L.bind(this._onImageError, this)
  318. });
  319.  
  320. return _image;
  321. },
  322.  
  323. redraw: function () {
  324. if (this._map) {
  325. this._update();
  326. }
  327. return this;
  328. },
  329.  
  330. _animateZoom: function (e) {
  331. if (this._useCanvas) {
  332. if (this._currentCanvas._bounds)
  333. this._animateImage(this._currentCanvas, e);
  334. if (this._bufferCanvas._bounds)
  335. this._animateImage(this._bufferCanvas, e);
  336. }
  337. else {
  338. if (this._currentImage._bounds)
  339. this._animateImage(this._currentImage, e);
  340. if (this._bufferImage._bounds)
  341. this._animateImage(this._bufferImage, e);
  342. }
  343. },
  344.  
  345. _animateImage: function (image, e) {
  346. if (typeof L.DomUtil.setTransform === 'undefined') { // Leaflet 0.7
  347. var map = this._map,
  348. scale = image._scale * map.getZoomScale(e.zoom),
  349. nw = image._bounds.getNorthWest(),
  350. se = image._bounds.getSouthEast(),
  351.  
  352. topLeft = map._latLngToNewLayerPoint(nw, e.zoom, e.center),
  353. size = map._latLngToNewLayerPoint(se, e.zoom, e.center)._subtract(topLeft),
  354. origin = topLeft._add(size._multiplyBy((1 / 2) * (1 - 1 / scale)));
  355.  
  356. image.style[L.DomUtil.TRANSFORM] =
  357. L.DomUtil.getTranslateString(origin) + ' scale(' + scale + ') ';
  358. } else {
  359. var map = this._map,
  360. scale = image._scale * image._sscale * map.getZoomScale(e.zoom),
  361. nw = image._bounds.getNorthWest(),
  362. se = image._bounds.getSouthEast(),
  363.  
  364. topLeft = map._latLngToNewLayerPoint(nw, e.zoom, e.center);
  365.  
  366. L.DomUtil.setTransform(image, topLeft, scale);
  367. }
  368.  
  369. image._lastScale = scale;
  370. },
  371.  
  372. _resetImageScale: function (image, resetTransform) {
  373. var bounds = new L.Bounds(
  374. this._map.latLngToLayerPoint(image._bounds.getNorthWest()),
  375. this._map.latLngToLayerPoint(image._bounds.getSouthEast())),
  376. orgSize = image._orgBounds.getSize().y,
  377. scaledSize = bounds.getSize().y;
  378.  
  379. var scale = scaledSize / orgSize;
  380. image._sscale = scale;
  381.  
  382. L.DomUtil.setTransform(image, bounds.min, scale);
  383. },
  384.  
  385. _resetImage: function (image) {
  386. var bounds = new L.Bounds(
  387. this._map.latLngToLayerPoint(image._bounds.getNorthWest()),
  388. this._map.latLngToLayerPoint(image._bounds.getSouthEast())),
  389. size = bounds.getSize();
  390.  
  391. L.DomUtil.setPosition(image, bounds.min);
  392.  
  393. image._orgBounds = bounds;
  394. image._sscale = 1;
  395.  
  396. if (this._useCanvas) {
  397. image.width = size.x;
  398. image.height = size.y;
  399.  
  400. } else {
  401. image.style.width = size.x + 'px';
  402. image.style.height = size.y + 'px';
  403. }
  404. },
  405.  
  406. _getClippedBounds: function () {
  407. var wgsBounds = this._map.getBounds();
  408.  
  409. // truncate bounds to valid wgs bounds
  410. var mSouth = wgsBounds.getSouth();
  411. var mNorth = wgsBounds.getNorth();
  412. var mWest = wgsBounds.getWest();
  413. var mEast = wgsBounds.getEast();
  414.  
  415. var lSouth = this.options.bounds.getSouth();
  416. var lNorth = this.options.bounds.getNorth();
  417. var lWest = this.options.bounds.getWest();
  418. var lEast = this.options.bounds.getEast();
  419.  
  420. //mWest = (mWest + 180) % 360 - 180;
  421. if (mSouth < lSouth) mSouth = lSouth;
  422. if (mNorth > lNorth) mNorth = lNorth;
  423. if (mWest < lWest) mWest = lWest;
  424. if (mEast > lEast) mEast = lEast;
  425.  
  426. var world1 = new L.LatLng(mNorth, mWest);
  427. var world2 = new L.LatLng(mSouth, mEast);
  428.  
  429. return new L.LatLngBounds(world1, world2);
  430. },
  431.  
  432. _getImageScale: function () {
  433. return this.options.detectRetina && L.Browser.retina ? 2 : 1;
  434. },
  435.  
  436. _update: function () {
  437. var bounds = this._getClippedBounds();
  438.  
  439. // re-project to corresponding pixel bounds
  440. var pix1 = this._map.latLngToContainerPoint(bounds.getNorthWest());
  441. var pix2 = this._map.latLngToContainerPoint(bounds.getSouthEast());
  442.  
  443. // get pixel size
  444. var width = pix2.x - pix1.x;
  445. var height = pix2.y - pix1.y;
  446.  
  447. var i;
  448. if (this._useCanvas) {
  449. // set scales for zoom animation
  450. this._bufferCanvas._scale = this._bufferCanvas._lastScale;
  451. this._currentCanvas._scale = this._currentCanvas._lastScale = 1;
  452. this._bufferCanvas._sscale = 1;
  453.  
  454. this._currentCanvas._bounds = bounds;
  455.  
  456. this._resetImage(this._currentCanvas);
  457.  
  458. i = this._currentCanvas._image;
  459.  
  460. L.DomUtil.setOpacity(i, 0);
  461. } else {
  462. // set scales for zoom animation
  463. this._bufferImage._scale = this._bufferImage._lastScale;
  464. this._currentImage._scale = this._currentImage._lastScale = 1;
  465. this._bufferImage._sscale = 1;
  466.  
  467. this._currentImage._bounds = bounds;
  468.  
  469. this._resetImage(this._currentImage);
  470.  
  471. i = this._currentImage;
  472.  
  473. L.DomUtil.setOpacity(i, 0);
  474. }
  475.  
  476. if (this._map.getZoom() < this.options.minZoom ||
  477. this._map.getZoom() > this.options.maxZoom ||
  478. width < 32 || height < 32) {
  479. this._div.style.visibility = 'hidden';
  480. i.src = this.emptyImageUrl;
  481. this.key = i.key = '<empty>';
  482. i.tag = null;
  483. return;
  484. }
  485.  
  486. // fire loading event
  487. this.fire('loading');
  488.  
  489. width = width * this._getImageScale();
  490. height = height * this._getImageScale();
  491.  
  492. // create a key identifying the current request
  493. this.key = '' + bounds.getNorthWest() + ', ' + bounds.getSouthEast() + ', ' + width + ', ' + height;
  494.  
  495. if (this.getImageUrl) {
  496. i.src = this.getImageUrl(bounds, width, height);
  497. i.key = this.key;
  498. }
  499. else {
  500. this.getImageUrlAsync(bounds, width, height, this.key, function (key, url, tag) {
  501. i.key = key;
  502. i.src = url;
  503. i.tag = tag;
  504. });
  505. }
  506. },
  507. _onImageError: function (e) {
  508. this.fire('error', e);
  509. L.DomUtil.addClass(e.target, 'invalid');
  510. if (e.target.src !== this.options.errorImageUrl) { // prevent error loop if error image is not valid
  511. e.target.src = this.options.errorImageUrl;
  512. }
  513. },
  514. _onImageLoad: function (e) {
  515. if (e.target.src !== this.options.errorImageUrl) {
  516. L.DomUtil.removeClass(e.target, 'invalid');
  517. if (!e.target.key || e.target.key !== this.key) { // obsolete / outdated image
  518. return;
  519. }
  520. }
  521. this._onImageDone(e);
  522.  
  523. this.fire('load', e);
  524. },
  525. _onImageDone: function (e) {
  526. if (this._useCanvas) {
  527. this._renderCanvas(e);
  528. } else {
  529. L.DomUtil.setOpacity(this._currentImage, 1);
  530. L.DomUtil.setOpacity(this._bufferImage, 0);
  531.  
  532. if (this._addInteraction && this._currentImage.tag)
  533. this._addInteraction(this._currentImage.tag);
  534.  
  535. var tmp = this._bufferImage;
  536. this._bufferImage = this._currentImage;
  537. this._currentImage = tmp;
  538. }
  539.  
  540. if(e.target.key !== '<empty>')
  541. this._div.style.visibility = 'visible';
  542. },
  543. _renderCanvas: function (e) {
  544. var ctx = this._currentCanvas.getContext('2d');
  545.  
  546. ctx.drawImage(this._currentCanvas._image, 0, 0,
  547. this._currentCanvas.width, this._currentCanvas.height);
  548.  
  549. L.DomUtil.setOpacity(this._currentCanvas, 1);
  550. L.DomUtil.setOpacity(this._bufferCanvas, 0);
  551.  
  552. if (this._addInteraction && this._currentCanvas._image.tag)
  553. this._addInteraction(this._currentCanvas._image.tag);
  554.  
  555. var tmp = this._bufferCanvas;
  556. this._bufferCanvas = this._currentCanvas;
  557. this._currentCanvas = tmp;
  558. }
  559.  
  560. });
  561.  
  562. L.nonTiledLayer = function () {
  563. return new L.NonTiledLayer();
  564. };
  565.  
  566. module.exports = L.NonTiledLayer;
  567.  
  568. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  569. },{}]},{},[2,1])(2)
  570. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement