-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTileLayer.WMS.Canvas2D.js
35 lines (27 loc) · 977 Bytes
/
TileLayer.WMS.Canvas2D.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(function() {
var L = window.L;
L.TileLayer.WMS.Canvas2D = L.TileLayer.WMS.extend({
createTile: function(coords, done) {
var tileUrl = this.getTileUrl(coords);
// create canvas
var canvas = L.DomUtil.create('canvas', 'leaflet-tile');
// setup tile width and height according to the options
var size = this.getTileSize();
canvas.width = size.x;
canvas.height = size.y;
// get the canvas context and draw image on it
var context = canvas.getContext('2d');
var img = new Image();
img.src = tileUrl;
img.onload = function() {
context.drawImage(img, 0, 0);
};
L.DomEvent.on(img, 'load', L.Util.bind(this._tileOnLoad, this, done, img));
L.DomEvent.on(img, 'error', L.Util.bind(this._tileOnError, this, done, img));
return canvas;
}
});
L.tileLayer.wms.canvas2D = function (url, options) {
return new L.TileLayer.WMS.Canvas2D(url, options);
};
})();