Web UI for ARGUS server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
5.4 KiB

5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * 🍂class ImageOverlay.Rotated
  3. * 🍂inherits ImageOverlay
  4. * https://github.com/IvanSanchez/Leaflet.ImageOverlay.Rotated
  5. * Like `ImageOverlay`, but rotates and skews the image. This is done by using
  6. * *three* control points instead of *two*.
  7. *
  8. * @example
  9. *
  10. * ```
  11. * var topleft = L.latLng(40.52256691873593, -3.7743186950683594),
  12. * topright = L.latLng(40.5210255066156, -3.7734764814376835),
  13. * bottomleft = L.latLng(40.52180437272552, -3.7768453359603886);
  14. *
  15. * var overlay = L.imageOverlay.rotated("./palacio.jpg", topleft, topright, bottomleft, {
  16. * opacity: 0.4,
  17. * interactive: true,
  18. * attribution: "&copy; <a href='http://www.ign.es'>Instituto Geográfico Nacional de España</a>"
  19. * });
  20. * ```
  21. *
  22. */
  23. L.ImageOverlay.Rotated = L.ImageOverlay.extend({
  24. initialize: function (image, topleft, topright, bottomleft, options) {
  25. if (typeof(image) === 'string') {
  26. this._url = image;
  27. } else {
  28. // Assume that the first parameter is an instance of HTMLImage or HTMLCanvas
  29. this._rawImage = image;
  30. }
  31. this._topLeft = L.latLng(topleft);
  32. this._topRight = L.latLng(topright);
  33. this._bottomLeft = L.latLng(bottomleft);
  34. L.setOptions(this, options);
  35. },
  36. onAdd: function (map) {
  37. if (!this._image) {
  38. this._initImage();
  39. if (this.options.opacity < 1) {
  40. this._updateOpacity();
  41. }
  42. }
  43. if (this.options.interactive) {
  44. L.DomUtil.addClass(this._rawImage, 'leaflet-interactive');
  45. this.addInteractiveTarget(this._rawImage);
  46. }
  47. map.on('zoomend resetview', this._reset, this);
  48. this.getPane().appendChild(this._image);
  49. this._reset();
  50. },
  51. onRemove: function(map) {
  52. map.off('zoomend resetview', this._reset, this);
  53. L.ImageOverlay.prototype.onRemove.call(this, map);
  54. },
  55. _initImage: function () {
  56. var img = this._rawImage;
  57. if (this._url) {
  58. img = L.DomUtil.create('img');
  59. img.style.display = 'none'; // Hide while the first transform (zero or one frames) is being done
  60. if (this.options.crossOrigin) {
  61. img.crossOrigin = '';
  62. }
  63. img.src = this._url;
  64. this._rawImage = img;
  65. }
  66. L.DomUtil.addClass(img, 'leaflet-image-layer');
  67. // this._image is reused by some of the methods of the parent class and
  68. // must keep the name, even if it is counter-intuitive.
  69. var div = this._image = L.DomUtil.create('div',
  70. 'leaflet-image-layer ' + (this._zoomAnimated ? 'leaflet-zoom-animated' : ''));
  71. this._updateZIndex(); // apply z-index style setting to the div (if defined)
  72. div.appendChild(img);
  73. div.onselectstart = L.Util.falseFn;
  74. div.onmousemove = L.Util.falseFn;
  75. img.onload = function(){
  76. this._reset();
  77. img.style.display = 'block';
  78. this.fire('load');
  79. }.bind(this);
  80. img.alt = this.options.alt;
  81. },
  82. _reset: function () {
  83. var div = this._image;
  84. if (!this._map) {
  85. return;
  86. }
  87. // Project control points to container-pixel coordinates
  88. var pxTopLeft = this._map.latLngToLayerPoint(this._topLeft);
  89. var pxTopRight = this._map.latLngToLayerPoint(this._topRight);
  90. var pxBottomLeft = this._map.latLngToLayerPoint(this._bottomLeft);
  91. // Infer coordinate of bottom right
  92. var pxBottomRight = pxTopRight.subtract(pxTopLeft).add(pxBottomLeft);
  93. // pxBounds is mostly for positioning the <div> container
  94. var pxBounds = L.bounds([pxTopLeft, pxTopRight, pxBottomLeft, pxBottomRight]);
  95. var size = pxBounds.getSize();
  96. var pxTopLeftInDiv = pxTopLeft.subtract(pxBounds.min);
  97. // LatLngBounds are needed for (zoom) animations
  98. this._bounds = L.latLngBounds( this._map.layerPointToLatLng(pxBounds.min),
  99. this._map.layerPointToLatLng(pxBounds.max) );
  100. L.DomUtil.setPosition(div, pxBounds.min);
  101. div.style.width = size.x + 'px';
  102. div.style.height = size.y + 'px';
  103. var imgW = this._rawImage.width;
  104. var imgH = this._rawImage.height;
  105. if (!imgW || !imgH) {
  106. return; // Probably because the image hasn't loaded yet.
  107. }
  108. // Sides of the control-point box, in pixels
  109. // These are the main ingredient for the transformation matrix.
  110. var vectorX = pxTopRight.subtract(pxTopLeft);
  111. var vectorY = pxBottomLeft.subtract(pxTopLeft);
  112. this._rawImage.style.transformOrigin = '0 0';
  113. // The transformation is an affine matrix that switches
  114. // coordinates around in just the right way. This is the result
  115. // of calculating the skew/rotation/scale matrices and simplyfing
  116. // everything.
  117. this._rawImage.style.transform = "matrix(" +
  118. (vectorX.x/imgW) + ', ' + (vectorX.y/imgW) + ', ' +
  119. (vectorY.x/imgH) + ', ' + (vectorY.y/imgH) + ', ' +
  120. pxTopLeftInDiv.x + ', ' + pxTopLeftInDiv.y + ')';
  121. },
  122. reposition: function(topleft, topright, bottomleft) {
  123. this._topLeft = L.latLng(topleft);
  124. this._topRight = L.latLng(topright);
  125. this._bottomLeft = L.latLng(bottomleft);
  126. this._reset();
  127. },
  128. setUrl: function (url) {
  129. this._url = url;
  130. if (this._rawImage) {
  131. this._rawImage.src = url;
  132. }
  133. return this;
  134. }
  135. });
  136. /* 🍂factory imageOverlay.rotated(imageUrl: String|HTMLImageElement|HTMLCanvasElement, topleft: LatLng, topright: LatLng, bottomleft: LatLng, options?: ImageOverlay options)
  137. * Instantiates a rotated/skewed image overlay, given the image URL and
  138. * the `LatLng`s of three of its corners.
  139. *
  140. * Alternatively to specifying the URL of the image, an existing instance of `HTMLImageElement`
  141. * or `HTMLCanvasElement` can be used.
  142. */
  143. L.imageOverlay.rotated = function(imgSrc, topleft, topright, bottomleft, options) {
  144. return new L.ImageOverlay.Rotated(imgSrc, topleft, topright, bottomleft, options);
  145. };