-
Notifications
You must be signed in to change notification settings - Fork 203
Expand file tree
/
Copy pathLeaflet.Renderer.Canvas.Tile.js
More file actions
100 lines (77 loc) · 2.43 KB
/
Leaflet.Renderer.Canvas.Tile.js
File metadata and controls
100 lines (77 loc) · 2.43 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
L.Canvas.Tile = L.Canvas.extend({
initialize: function (tileCoord, tileSize, options) {
L.Canvas.prototype.initialize.call(this, options);
this._tileCoord = tileCoord;
this._size = tileSize;
this._initContainer();
this._container.setAttribute('width', this._size.x);
this._container.setAttribute('height', this._size.y);
this._layers = {};
this._drawnLayers = {};
this._drawing = true;
if (options.interactive) {
// By default, Leaflet tiles do not have pointer events
this._container.style.pointerEvents = 'auto';
}
},
getCoord: function() {
return this._tileCoord;
},
getContainer: function() {
return this._container;
},
getOffset: function() {
return this._tileCoord.scaleBy(this._size).subtract(this._map.getPixelOrigin());
},
onAdd: L.Util.falseFn,
addTo: function(map) {
this._map = map;
},
removeFrom: function (map) {
delete this._map;
},
_onClick: function (e) {
var point = this._map.mouseEventToLayerPoint(e).subtract(this.getOffset()), layer, clickedLayer;
for (var id in this._layers) {
layer = this._layers[id];
if (layer.options.interactive && layer._containsPoint(point) && !this._map._draggableMoved(layer)) {
clickedLayer = layer;
}
}
if (clickedLayer) {
// For Leaflet versions < 1.1.0, use _fakeStop.
var fakeStop = L.DomEvent._fakeStop || L.DomEvent.fakeStop;
fakeStop(e);
this._fireEvent([clickedLayer], e);
}
},
_onMouseMove: function (e) {
if (!this._map || this._map.dragging.moving() || this._map._animatingZoom) { return; }
var point = this._map.mouseEventToLayerPoint(e).subtract(this.getOffset());
this._handleMouseHover(e, point);
},
/// TODO: Modify _initPath to include an extra parameter, a group name
/// to order symbolizers by z-index
_updateIcon: function (layer) {
if (!this._drawing) { return; }
var icon = layer.options.icon,
options = icon.options,
size = L.point(options.iconSize),
anchor = options.iconAnchor ||
size && size.divideBy(2, true),
p = layer._point.subtract(anchor),
ctx = this._ctx,
img = layer._getImage();
if (img.complete) {
ctx.drawImage(img, p.x, p.y, size.x, size.y);
} else {
L.DomEvent.on(img, 'load', function() {
ctx.drawImage(img, p.x, p.y, size.x, size.y);
});
}
this._drawnLayers[layer._leaflet_id] = layer;
}
});
L.canvas.tile = function(tileCoord, tileSize, opts){
return new L.Canvas.Tile(tileCoord, tileSize, opts);
}