Leaflet/src/layer/ImageOverlay.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2010-09-27 22:02:00 +08:00
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 = L.DomUtil.create('img', 'leaflet-image-layer');
2010-09-27 22:02:00 +08:00
this._image.style.visibility = 'hidden';
//TODO opacity option
L.Util.extend(this._image, {
galleryimg: 'no',
onselectstart: L.Util.falseFn,
onmousemove: L.Util.falseFn,
onload: this._onImageLoad,
src: this._url
});
2010-09-27 22:02:00 +08:00
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
}
});