getUrl method

String getUrl(
  1. TileCoordinates coords,
  2. int tileDimension,
  3. bool retinaMode
)

Build the URL for a tile

Implementation

String getUrl(TileCoordinates coords, int tileDimension, bool retinaMode) {
  final nwPoint = coords * tileDimension;
  final sePoint = nwPoint + Point<int>(tileDimension, tileDimension);
  final nwCoords =
      crs.offsetToLatLng(nwPoint.toOffset(), coords.z.toDouble());
  final seCoords =
      crs.offsetToLatLng(sePoint.toOffset(), coords.z.toDouble());
  final nw = crs.projection.project(nwCoords);
  final se = crs.projection.project(seCoords);
  final bounds = Rect.fromPoints(nw, se);
  final bbox = (_versionNumber >= 1.3 && crs is Epsg4326)
      ? [bounds.min.dy, bounds.min.dx, bounds.max.dy, bounds.max.dx]
      : [bounds.min.dx, bounds.min.dy, bounds.max.dx, bounds.max.dy];

  final buffer = StringBuffer(_encodedBaseUrl);
  buffer.write('&width=${retinaMode ? tileDimension * 2 : tileDimension}');
  buffer.write('&height=${retinaMode ? tileDimension * 2 : tileDimension}');
  buffer.write('&bbox=${bbox.join(',')}');
  return buffer.toString();
}