|
| 1 | +/*globals L */ |
| 2 | + |
| 3 | +/* |
| 4 | + * L.ImageOverlay is used to overlay images over the map (to specific geographical bounds). |
| 5 | + */ |
| 6 | +L.ImageOverlay.Canvas = L.ImageOverlay.extend({ |
| 7 | + includes: L.Mixin.Events, |
| 8 | + |
| 9 | + options: { |
| 10 | + opacity: 1 |
| 11 | + }, |
| 12 | + |
| 13 | + initialize: function (bounds, options) { // (LatLngBounds, Object) |
| 14 | + this._bounds = L.latLngBounds(bounds); |
| 15 | + |
| 16 | + L.Util.setOptions(this, options); |
| 17 | + }, |
| 18 | + |
| 19 | + _initImage: function () { |
| 20 | + var topLeft = this._map.latLngToLayerPoint(this._bounds.getNorthWest()), |
| 21 | + size = this._map.latLngToLayerPoint(this._bounds.getSouthEast())._subtract(topLeft); |
| 22 | + |
| 23 | + this._image = this.canvas = L.DomUtil.create('canvas', 'leaflet-image-layer'); |
| 24 | + this._image.width = size.x; |
| 25 | + this._image.height = size.y; |
| 26 | + |
| 27 | + if (this._map.options.zoomAnimation && L.Browser.any3d) { |
| 28 | + L.DomUtil.addClass(this._image, 'leaflet-zoom-animated'); |
| 29 | + } else { |
| 30 | + L.DomUtil.addClass(this._image, 'leaflet-zoom-hide'); |
| 31 | + } |
| 32 | + |
| 33 | + this._updateOpacity(); |
| 34 | + |
| 35 | + //TODO createImage util method to remove duplication |
| 36 | + L.Util.extend(this._image, { |
| 37 | + galleryimg: 'no', |
| 38 | + onselectstart: L.Util.falseFn, |
| 39 | + onmousemove: L.Util.falseFn, |
| 40 | + onload: L.Util.bind(this._onImageLoad, this) |
| 41 | + }); |
| 42 | + }, |
| 43 | + |
| 44 | + _reset: function () { |
| 45 | + var image = this._image, |
| 46 | + topLeft = this._map.latLngToLayerPoint(this._bounds.getNorthWest()), |
| 47 | + size = this._map.latLngToLayerPoint(this._bounds.getSouthEast())._subtract(topLeft); |
| 48 | + |
| 49 | + L.DomUtil.setPosition(image, topLeft); |
| 50 | + |
| 51 | + image.style.width = size.x + 'px'; |
| 52 | + image.style.height = size.y + 'px'; |
| 53 | + }, |
| 54 | + |
| 55 | + _onImageLoad: function () { |
| 56 | + this.fire('load'); |
| 57 | + } |
| 58 | +}); |
| 59 | + |
| 60 | +L.imageOverlay.canvas = function (bounds, options) { |
| 61 | + return new L.ImageOverlay.Canvas(bounds, options); |
| 62 | +}; |
0 commit comments