/* * 🍂class ImageOverlay.Rotated * 🍂inherits ImageOverlay * https://github.com/IvanSanchez/Leaflet.ImageOverlay.Rotated * Like `ImageOverlay`, but rotates and skews the image. This is done by using * *three* control points instead of *two*. * * @example * * ``` * var topleft = L.latLng(40.52256691873593, -3.7743186950683594), * topright = L.latLng(40.5210255066156, -3.7734764814376835), * bottomleft = L.latLng(40.52180437272552, -3.7768453359603886); * * var overlay = L.imageOverlay.rotated("./palacio.jpg", topleft, topright, bottomleft, { * opacity: 0.4, * interactive: true, * attribution: "© Instituto Geográfico Nacional de España" * }); * ``` * */ L.ImageOverlay.Rotated = L.ImageOverlay.extend({ initialize: function (image, topleft, topright, bottomleft, options) { if (typeof(image) === 'string') { this._url = image; } else { // Assume that the first parameter is an instance of HTMLImage or HTMLCanvas this._rawImage = image; } this._topLeft = L.latLng(topleft); this._topRight = L.latLng(topright); this._bottomLeft = L.latLng(bottomleft); L.setOptions(this, options); }, onAdd: function (map) { if (!this._image) { this._initImage(); if (this.options.opacity < 1) { this._updateOpacity(); } } if (this.options.interactive) { L.DomUtil.addClass(this._rawImage, 'leaflet-interactive'); this.addInteractiveTarget(this._rawImage); } map.on('zoomend resetview', this._reset, this); this.getPane().appendChild(this._image); this._reset(); }, onRemove: function(map) { map.off('zoomend resetview', this._reset, this); L.ImageOverlay.prototype.onRemove.call(this, map); }, _initImage: function () { var img = this._rawImage; if (this._url) { img = L.DomUtil.create('img'); img.style.display = 'none'; // Hide while the first transform (zero or one frames) is being done if (this.options.crossOrigin) { img.crossOrigin = ''; } img.src = this._url; this._rawImage = img; } L.DomUtil.addClass(img, 'leaflet-image-layer'); // this._image is reused by some of the methods of the parent class and // must keep the name, even if it is counter-intuitive. var div = this._image = L.DomUtil.create('div', 'leaflet-image-layer ' + (this._zoomAnimated ? 'leaflet-zoom-animated' : '')); this._updateZIndex(); // apply z-index style setting to the div (if defined) div.appendChild(img); div.onselectstart = L.Util.falseFn; div.onmousemove = L.Util.falseFn; img.onload = function(){ this._reset(); img.style.display = 'block'; this.fire('load'); }.bind(this); img.alt = this.options.alt; }, _reset: function () { var div = this._image; if (!this._map) { return; } // Project control points to container-pixel coordinates var pxTopLeft = this._map.latLngToLayerPoint(this._topLeft); var pxTopRight = this._map.latLngToLayerPoint(this._topRight); var pxBottomLeft = this._map.latLngToLayerPoint(this._bottomLeft); // Infer coordinate of bottom right var pxBottomRight = pxTopRight.subtract(pxTopLeft).add(pxBottomLeft); // pxBounds is mostly for positioning the