From c5ba5b0456a711d157e317f220e9c739226e7f50 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Tue, 10 Jan 2012 01:54:37 +0100 Subject: Installed leaflet in extlib --- extlib/leaflet/src/layer/ImageOverlay.js | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 extlib/leaflet/src/layer/ImageOverlay.js (limited to 'extlib/leaflet/src/layer/ImageOverlay.js') diff --git a/extlib/leaflet/src/layer/ImageOverlay.js b/extlib/leaflet/src/layer/ImageOverlay.js new file mode 100644 index 00000000..4551b2e3 --- /dev/null +++ b/extlib/leaflet/src/layer/ImageOverlay.js @@ -0,0 +1,58 @@ +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; + + if (!this._image) { + this._initImage(); + } + + map.getPanes().overlayPane.appendChild(this._image); + + map.on('viewreset', this._reset, this); + this._reset(); + }, + + onRemove: function(map) { + map.getPanes().overlayPane.removeChild(this._image); + map.off('viewreset', this._reset, this); + }, + + _initImage: function() { + this._image = L.DomUtil.create('img', 'leaflet-image-layer'); + + this._image.style.visibility = 'hidden'; + //TODO opacity option + + //TODO createImage util method to remove duplication + L.Util.extend(this._image, { + galleryimg: 'no', + onselectstart: L.Util.falseFn, + onmousemove: L.Util.falseFn, + onload: this._onImageLoad, + src: this._url + }); + }, + + _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 -- cgit v1.2.3