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

Last change on this file since 372 was 315, checked in by alloc, 7 years ago

Fixes

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