Skip to content

Commit

Permalink
Changed type of tileSize to integer throughout
Browse files Browse the repository at this point in the history
Minor documentation improvements
  • Loading branch information
JaffaKetchup committed Aug 5, 2024
1 parent 74110db commit 3234219
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/src/layer/tile_layer/tile_bounds/tile_bounds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:meta/meta.dart';
abstract class TileBounds {
/// Reference to the coordinate reference system.
final Crs crs;
final double _tileSize;
final int _tileSize;
final LatLngBounds? _latLngBounds;

/// Constructor that creates an instance of a subclass of [TileBounds]:
Expand All @@ -18,7 +18,7 @@ abstract class TileBounds {
/// [WrappedTileBounds] if the CRS is wrapped.
factory TileBounds({
required Crs crs,
required double tileSize,
required int tileSize,
LatLngBounds? latLngBounds,
}) {
if (crs.infinite && latLngBounds == null) {
Expand All @@ -43,7 +43,7 @@ abstract class TileBounds {
/// parameters.
bool shouldReplace(
Crs crs,
double tileSize,
int tileSize,
LatLngBounds? latLngBounds,
) =>
crs != this.crs || tileSize != _tileSize || latLngBounds != _latLngBounds;
Expand Down
15 changes: 9 additions & 6 deletions lib/src/layer/tile_layer/tile_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ class TileLayer extends StatefulWidget {
/// If not `null`, then tiles will pull's WMS protocol requests
final WMSTileLayerOptions? wmsOptions;

/// Size for the tile.
/// Default is 256
late final double tileSize;
/// Size in pixels of each tile image
///
/// Should be a positive power of 2.
///
/// If increasing past 256(px) (default), adjust [zoomOffset] as necessary,
/// for example 512px: -1.
late final int tileSize;

/// The minimum zoom level down to which this layer will be displayed
/// (inclusive)
Expand Down Expand Up @@ -216,7 +220,7 @@ class TileLayer extends StatefulWidget {
super.key,
this.urlTemplate,
this.fallbackUrl,
double tileSize = 256,
int tileSize = 256,
double minZoom = 0,
double maxZoom = double.infinity,
int minNativeZoom = 0,
Expand Down Expand Up @@ -319,8 +323,7 @@ class TileLayer extends StatefulWidget {
this.zoomOffset = useSimulatedRetina
? (zoomReverse ? zoomOffset - 1.0 : zoomOffset + 1.0)
: zoomOffset;
this.tileSize =
useSimulatedRetina ? (tileSize / 2.0).floorToDouble() : tileSize;
this.tileSize = useSimulatedRetina ? (tileSize / 2).floor() : tileSize;
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ abstract class TileProvider {
/// When creating a specialized [TileProvider], prefer overriding URL
/// generation related methods in the following order:
///
/// 1. [populateTemplatePlaceholders]
/// 2. [generateReplacementMap]
/// 1. [TileLayer.additionalOptions] (or [generateReplacementMap] for more
/// advanced usage)
/// 2. [populateTemplatePlaceholders]
/// 3. [getTileUrl] and/or [getTileFallbackUrl]
///
/// Note to implementors: it is not safe to assume that at least one of
Expand All @@ -224,7 +225,7 @@ abstract class TileProvider {
populateTemplatePlaceholders(
options.wmsOptions?.getUrl(
coordinates,
options.tileSize.toInt(),
options.tileSize,
options.resolvedRetinaMode == RetinaMode.simulation,
) ??
options.urlTemplate ??
Expand Down
2 changes: 1 addition & 1 deletion lib/src/layer/tile_layer/tile_range.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DiscreteTileRange extends TileRange {
/// Calculate a [DiscreteTileRange] by using the pixel bounds.
factory DiscreteTileRange.fromPixelBounds({
required int zoom,
required double tileSize,
required int tileSize,
required Bounds<double> pixelBounds,
}) {
final Bounds<int> bounds;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/layer/tile_layer/tile_range_calculator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:meta/meta.dart';
@immutable
class TileRangeCalculator {
/// The tile size in pixels.
final double tileSize;
final int tileSize;

/// Create a new [TileRangeCalculator] instance.
const TileRangeCalculator({required this.tileSize});
Expand Down
4 changes: 2 additions & 2 deletions lib/src/layer/tile_layer/tile_scale_calculator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TileScaleCalculator {
final Crs crs;

/// The size in pixel of tiles.
final double tileSize;
final int tileSize;

double? _cachedCurrentZoom;
final Map<int, double> _cache = {};
Expand All @@ -18,7 +18,7 @@ class TileScaleCalculator {
});

/// Returns true to indicate that the TileSizeCache should get replaced.
bool shouldReplace(Crs crs, double tileSize) =>
bool shouldReplace(Crs crs, int tileSize) =>
this.crs != crs || this.tileSize != tileSize;

/// Clears the cache if the zoom level does not match the current cached one
Expand Down

0 comments on commit 3234219

Please sign in to comment.