-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayground5.html
More file actions
51 lines (32 loc) · 1 KB
/
playground5.html
File metadata and controls
51 lines (32 loc) · 1 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
<link rel="stylesheet" href="includes/leaflet.css" />
<script src="includes/leaflet.js"></script>
Please hit "+" one or two times to get it working
<div id="map" style="height: 600px;"></div>
<script>
// the .setView() appears to be mandatory
map = L.map('map').setView([37.8, -96], 4);
// create a custom layer whose tiles are generated by f()
custom = L.tileLayer("").addTo(map)
custom.getTileUrl = f
// Given some text, g() returns the data url of a PNG with that text
function g(text) {
// create a 256 x 256 pixel canvas
let canvas = document.createElement('canvas');
canvas.height = 256;
canvas.width = 256;
// print the given text
let ctx = canvas.getContext('2d');
ctx.fillStyle = '#000000';
ctx.fillText(text, 0, 10);
// return the PNG-fied URL
return canvas.toDataURL('image/png');
}
// calls g to return the PNG
function f(coords, done) {
fetch('shortsample.txt')
.then(response => response.text())
.then(result => res = g(result))
return res
}
</script>
</body>