source: binary-improvements/webserver_legacy/js/leaflet.control.reloadtiles.js@ 501

Last change on this file since 501 was 249, checked in by alloc, 9 years ago

Fixes: Web v8

File size: 3.4 KB
Line 
1L.Control.ReloadTiles = L.Control.extend({
2 options: {
3 position: 'bottomleft',
4 autoreload_enable: true,
5 autoreload_minInterval: 30,
6 autoreload_interval: 120,
7 autoreload_defaultOn: false,
8 layers: []
9 },
10
11 onAdd: function (map) {
12 var name = 'control-reloadtiles',
13 container = L.DomUtil.create('div', name + ' webmap-control');
14
15 var stop = L.DomEvent.stopPropagation;
16 L.DomEvent
17 .on (container, 'mousemove', stop)
18 .on (container, 'click', stop)
19 .on (container, 'mousedown', stop)
20 .on (container, 'dblclick', stop);
21
22 this._map = map;
23
24 this._reloadbutton = $("<a>")
25 .addClass (name+"-btn")
26 .text ("Reload tiles now")
27 .attr ("href", "#")
28 .attr ("title", "Reload tiles now")
29 .on ("click.action", null, this, this._reload);
30 $(container).append (this._reloadbutton);
31
32 if (this.options.autoreload_enable) {
33 $(container).append ("<br>");
34
35 this._autocheck = $("<input>")
36 .addClass (name + "-chk")
37 .attr ("type", "checkbox")
38 .attr ("name", "map_reloadtiles_autoreload")
39 .attr ("id", "map_reloadtiles_autoreload")
40 .attr ("value", "1")
41 .on ("change", null, this, this._selectreload);
42 if (this.options.autoreload_defaultOn) {
43 this._autocheck.attr ("checked", "checked");
44 this._timeout = window.setTimeout ($.proxy (this._reloadTilesEvent, this), this.options.autoreload_interval*1000);
45 }
46 $(container).append (this._autocheck);
47
48 var label1 = $("<label>")
49 .attr ("for", "map_reloadtiles_autoreload");
50 label1.append ("Reload every ");
51 $(container).append (label1);
52
53 this._reloadinterval = $("<input>")
54 .addClass (name + "-txt")
55 .attr ("name", "map_reloadtiles_autoreload_time")
56 .attr ("type", "text")
57 .attr ("size", "4")
58 .attr ("maxlength", "5")
59 .attr ("value", this.options.autoreload_interval)
60 .on ("input", null, this, this._verifyinterval);
61 $(container).append (this._reloadinterval);
62
63 var label2 = $("<label>")
64 .attr ("for", "map_reloadtiles_autoreload");
65 label2.append (" seconds");
66 $(container).append (label2);
67 }
68
69 return container;
70 },
71
72 onRemove: function (map) {
73 },
74
75 _selectreload: function (e) {
76 if (e.data._autocheck.prop ("checked")) {
77 e.data._timeout = window.setTimeout ($.proxy (e.data._reloadTilesEvent, e.data), e.data.options.autoreload_interval*1000);
78 } else {
79 window.clearTimeout (e.data._timeout);
80 }
81 },
82
83 _verifyinterval: function (e) {
84 var val = e.data._reloadinterval.val ();
85 if (/^[\d]+$/.test (val)) {
86 if (val >= e.data.options.autoreload_minInterval) {
87 e.data._reloadinterval.removeClass ("invalidinput");
88 e.data.options.autoreload_interval = val;
89 if (e.data._autocheck.prop ("checked")) {
90 window.clearTimeout (e.data._timeout);
91 e.data._timeout = window.setTimeout ($.proxy (e.data._reloadTilesEvent, e.data), e.data.options.autoreload_interval*1000);
92 }
93 } else {
94 e.data._reloadinterval.addClass ("invalidinput");
95 }
96 } else {
97 e.data._reloadinterval.addClass ("invalidinput");
98 }
99 },
100
101 _reload: function (e) {
102 var newTileTime = new Date().getTime();
103
104 for (var i = 0; i < e.data.options.layers.length; i++) {
105 e.data.options.layers [i].options.time = newTileTime;
106 e.data.options.layers [i].redraw ();
107 }
108 },
109
110 _reloadTilesEvent: function() {
111 var div = this._div;
112 this._reload ({data: this});
113 this._timeout = window.setTimeout ($.proxy (this._reloadTilesEvent, this), this.options.autoreload_interval*1000);
114 },
115
116});
117
Note: See TracBrowser for help on using the repository browser.