2010-09-27 22:02:00 +08:00
|
|
|
L.ImageOverlay = L.Class.extend({
|
|
|
|
includes: L.Mixin.Events,
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2011-12-09 22:51:31 +08:00
|
|
|
initialize: function (/*String*/ url, /*LatLngBounds*/ bounds) {
|
2010-09-27 22:02:00 +08:00
|
|
|
this._url = url;
|
|
|
|
this._bounds = bounds;
|
|
|
|
},
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2011-12-09 22:51:31 +08:00
|
|
|
onAdd: function (map) {
|
2010-09-27 22:02:00 +08:00
|
|
|
this._map = map;
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2011-05-20 16:26:40 +08:00
|
|
|
if (!this._image) {
|
|
|
|
this._initImage();
|
|
|
|
}
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2011-05-20 16:26:40 +08:00
|
|
|
map.getPanes().overlayPane.appendChild(this._image);
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2011-05-20 16:26:40 +08:00
|
|
|
map.on('viewreset', this._reset, this);
|
|
|
|
this._reset();
|
|
|
|
},
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2011-12-09 22:51:31 +08:00
|
|
|
onRemove: function (map) {
|
2011-05-20 16:26:40 +08:00
|
|
|
map.getPanes().overlayPane.removeChild(this._image);
|
|
|
|
map.off('viewreset', this._reset, this);
|
|
|
|
},
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2011-12-09 22:51:31 +08:00
|
|
|
_initImage: function () {
|
2011-01-13 18:17:50 +08:00
|
|
|
this._image = L.DomUtil.create('img', 'leaflet-image-layer');
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2010-09-27 22:02:00 +08:00
|
|
|
this._image.style.visibility = 'hidden';
|
|
|
|
//TODO opacity option
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2011-03-22 23:58:35 +08:00
|
|
|
//TODO createImage util method to remove duplication
|
2010-09-27 22:02:00 +08:00
|
|
|
L.Util.extend(this._image, {
|
|
|
|
galleryimg: 'no',
|
|
|
|
onselectstart: L.Util.falseFn,
|
|
|
|
onmousemove: L.Util.falseFn,
|
|
|
|
onload: this._onImageLoad,
|
|
|
|
src: this._url
|
|
|
|
});
|
|
|
|
},
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2011-12-09 22:51:31 +08:00
|
|
|
_reset: function () {
|
2010-09-27 22:02:00 +08:00
|
|
|
var topLeft = this._map.latLngToLayerPoint(this._bounds.getNorthWest()),
|
|
|
|
bottomRight = this._map.latLngToLayerPoint(this._bounds.getSouthEast()),
|
|
|
|
size = bottomRight.subtract(topLeft);
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2010-09-27 22:02:00 +08:00
|
|
|
L.DomUtil.setPosition(this._image, topLeft);
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2010-09-27 22:02:00 +08:00
|
|
|
this._image.style.width = size.x + 'px';
|
|
|
|
this._image.style.height = size.y + 'px';
|
|
|
|
},
|
2011-12-09 22:35:15 +08:00
|
|
|
|
2011-12-09 22:51:31 +08:00
|
|
|
_onImageLoad: function () {
|
2010-09-27 22:02:00 +08:00
|
|
|
this.style.visibility = '';
|
|
|
|
//TODO fire layerload
|
|
|
|
}
|
2011-12-09 22:35:15 +08:00
|
|
|
});
|