From 488046bde9f619d815e83e6516bb5bc896f2446f Mon Sep 17 00:00:00 2001 From: mourner Date: Mon, 27 Sep 2010 17:02:00 +0300 Subject: [PATCH] ImageOverlay --- src/layer/ImageOverlay.js | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/layer/ImageOverlay.js diff --git a/src/layer/ImageOverlay.js b/src/layer/ImageOverlay.js new file mode 100644 index 00000000..6cdfacda --- /dev/null +++ b/src/layer/ImageOverlay.js @@ -0,0 +1,47 @@ +L.ImageOverlay = L.Class.extend({ + includes: L.Mixin.Events, + + initialize: function(/*String*/ url, /*LatLngBounds*/ bounds) { + this._url = url; + this._bounds = bounds; + }, + + onAdd: function(map) { + this._map = map; + + this._image = document.createElement('img'); + + this._image.style.visibility = 'hidden'; + this._image.style.position = 'absolute'; + //TODO opacity option + + L.Util.extend(this._image, { + className: 'leaflet-image-layer', + galleryimg: 'no', + onselectstart: L.Util.falseFn, + onmousemove: L.Util.falseFn, + onload: this._onImageLoad, + src: this._url + }); + this._map.getPanes().overlayPane.appendChild(this._image); + + this._map.on('viewreset', this._reset, this); + this._reset(); + }, + + _reset: function() { + var topLeft = this._map.latLngToLayerPoint(this._bounds.getNorthWest()), + bottomRight = this._map.latLngToLayerPoint(this._bounds.getSouthEast()), + size = bottomRight.subtract(topLeft); + + L.DomUtil.setPosition(this._image, topLeft); + + this._image.style.width = size.x + 'px'; + this._image.style.height = size.y + 'px'; + }, + + _onImageLoad: function() { + this.style.visibility = ''; + //TODO fire layerload + } +}); \ No newline at end of file