tileToQuadKey method
Returns the quad key (as specified by Microsoft) for tile
.
See also: https://docs.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system
Implementation
String tileToQuadKey(Scalable2i tile) {
// tile x and y
final tx = tile.x;
final int ty;
// handle origin variations
switch (origin) {
case CanvasOrigin.topLeft:
ty = tile.y;
break;
case CanvasOrigin.bottomLeft:
final size = matrixSize(tile.zoom);
ty = (size - 1) - tile.y;
break;
}
// calculuate the quad key
final str = StringBuffer();
for (var zoom = tile.zoom; zoom > 0; zoom--) {
var key = 0;
final mask = 1 << (zoom - 1);
if ((tx & mask) != 0) {
key++;
}
if ((ty & mask) != 0) {
key += 2;
}
// writes '0', '1', '2' or '3'
str.writeCharCode(48 + key);
}
return str.toString();
}