source: binary-improvements/webserver/js/leaflet.regionlayer.js@ 295

Last change on this file since 295 was 244, checked in by alloc, 9 years ago

Fixes intermediate state

File size: 1.8 KB
RevLine 
[244]1function GetRegionLayer (mapinfo) {
2 var FormatRegionFileName = function(latlng) {
3 return "r." + latlng.lat + "." + latlng.lng + ".7rg";
4 }
5
6 var regionLayer = L.tileLayer.canvas({
7 maxZoom: mapinfo.maxzoom + 1,
8 minZoom: 0,
9 maxNativeZoom: mapinfo.maxzoom + 1,
10 tileSize: mapinfo.tilesize,
11 continuousWorld: true
12 });
13
14 regionLayer.drawTile = function(canvas, tilePoint, zoom) {
15 var blockWorldSize = mapinfo.tilesize * Math.pow(2, mapinfo.maxzoom - zoom);
16 var tileLeft = tilePoint.x * blockWorldSize;
17 var tileBottom = (-1-tilePoint.y) * blockWorldSize;
18 var blockPos = L.latLng(tileLeft, tileBottom);
19
20 var ctx = canvas.getContext('2d');
21
22 ctx.strokeStyle = "lightblue";
23 ctx.fillStyle = "lightblue";
24 ctx.lineWidth = 1;
25 ctx.font="14px Arial";
26
27 var lineCount = blockWorldSize / mapinfo.regionsize;
28 if (lineCount >= 1) {
29 var pos = 0;
30 while (pos < mapinfo.tilesize) {
31 // Vertical
32 ctx.beginPath();
33 ctx.moveTo(pos, 0);
34 ctx.lineTo(pos, mapinfo.tilesize);
35 ctx.stroke();
36
37 // Horizontal
38 ctx.beginPath();
39 ctx.moveTo(0, pos);
40 ctx.lineTo(mapinfo.tilesize, pos);
41 ctx.stroke();
42
43 pos += mapinfo.tilesize / lineCount;
44 }
45 ctx.fillText(FormatRegionFileName(CoordToRegion(blockPos)), 4, mapinfo.tilesize-5);
46 } else {
47 if ((tileLeft % mapinfo.regionsize) == 0) {
48 // Vertical
49 ctx.beginPath();
50 ctx.moveTo(0, 0);
51 ctx.lineTo(0, mapinfo.tilesize);
52 ctx.stroke();
53 }
54 if ((tileBottom % mapinfo.regionsize) == 0) {
55 // Horizontal
56 ctx.beginPath();
57 ctx.moveTo(0, mapinfo.tilesize);
58 ctx.lineTo(mapinfo.tilesize, mapinfo.tilesize);
59 ctx.stroke();
60 }
61 if ((tileLeft % mapinfo.regionsize) == 0 && (tileBottom % mapinfo.regionsize) == 0) {
62 ctx.fillText(FormatRegionFileName(CoordToRegion(blockPos)), 4, mapinfo.tilesize-5);
63 }
64 }
65
66 }
67
68 return regionLayer;
69}
70
Note: See TracBrowser for help on using the repository browser.