Leaflet gridlayer with bounds and sequential number starting at 1

Viewed 18

I use this snippet to create a grid for a fixed area with bounds: Show fixed 100 m x 100 m grid on lowest zoom level

For example, my grid has 9 fields. I would like to number them from 1 to 9 or A1, A2, A3, B1, B2, ... But i don't know how to start.

Any suggestions how to solve this?

1 Answers

I have found a solution:

I define the bounds with two clicks on the map. I assume that you click on the upper left corner first. Then I remember the first tileNumber and subtract the tile number with these numbers.

My onclick handler:

...
const fractionalTileNumber = latLngToTileNumber(e.latlng);
const tileNumber = new TileNumber(Math.floor(fractionalTileNumber.x), Math.floor(fractionalTileNumber.y));
...
...
const tileX = tile.x - self.options.tileNumber.x    ;
const tileY = tile.y - self.options.tileNumber.y;
ctx.fillText(alphabet[tileX] + String(tileY), xMinPixel + 10, yMinPixel + 20, xMaxPixel - xMinPixel);
...
``
Related