Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dart2.0 fix for issue#6 #23

Merged
merged 1 commit into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions flutter_map/lib/src/core/bounds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Bounds<T extends num> {

const Bounds._(this.min, this.max);

Bounds extend(Point<T> point) {
Bounds<T> extend(Point<T> point) {
Point<T> newMin;
Point<T> newMax;
if (this.min == null && this.max == null) {
Expand All @@ -30,8 +30,8 @@ class Bounds<T extends num> {
return new Bounds._(newMin, newMax);
}

Point getCenter() {
return new Point(
Point<double> getCenter() {
return new Point<double>(
(min.x + max.x) / 2,
(min.y + max.y) / 2,
);
Expand Down
6 changes: 3 additions & 3 deletions flutter_map/lib/src/core/point.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class Point<T extends num> extends math.Point<T> {
}

Point<T> floor() {
return new Point(x.floor(), y.floor());
return new Point<T>(x.floor(), y.floor());
}

Point<T> unscaleBy(Point point) {
return new Point(x / point.x, y / point.y);
Point<T> unscaleBy(Point<T> point) {
return new Point<T>(x / point.x, y / point.y);
}

Point<T> operator +(math.Point<T> other) {
Expand Down
12 changes: 6 additions & 6 deletions flutter_map/lib/src/geo/crs/crs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ abstract class Crs {
try {
var projectedPoint = this.projection.project(latlng);
var scale = this.scale(zoom);
return transformation.transform(projectedPoint, scale);
return transformation.transform(projectedPoint, scale.toDouble());
} catch (e) {
return new Point(0.0, 0.0);
}
}

LatLng pointToLatLng(Point point, double zoom) {
var scale = this.scale(zoom);
var untransformedPoint = this.transformation.untransform(point, scale);
var untransformedPoint = this.transformation.untransform(point, scale.toDouble());
try {
return projection.unproject(untransformedPoint);
} catch (e) {
return null;
}
}

double scale(double zoom) {
num scale(double zoom) {
return 256 * math.pow(2, zoom);
}

Expand All @@ -42,8 +42,8 @@ abstract class Crs {

var b = projection.bounds;
var s = this.scale(zoom);
var min = this.transformation.transform(b.min, s);
var max = this.transformation.transform(b.max, s);
var min = this.transformation.transform(b.min, s.toDouble());
var max = this.transformation.transform(b.max, s.toDouble());
return new Bounds(min, max);
}

Expand Down Expand Up @@ -117,7 +117,7 @@ class Transformation {
final num d;
const Transformation(this.a, this.b, this.c, this.d);

Point transform(Point<double> point, double scale) {
Point transform(Point<num> point, double scale) {
if (scale == null) {
scale = 1.0;
}
Expand Down
2 changes: 1 addition & 1 deletion flutter_map/lib/src/gestures/gestures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ abstract class MapGestureMixin extends State<FlutterMap>
}

Offset _pointToOffset(Point point) {
return new Offset(point.x, point.y);
return new Offset(point.x.toDouble(), point.y.toDouble());
}
}
4 changes: 2 additions & 2 deletions flutter_map/lib/src/layer/marker_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class MarkerLayer extends StatelessWidget {
new Positioned(
width: markerOpt.width,
height: markerOpt.height,
left: pos.x - markerOpt.width / 2,
top: pos.y - markerOpt.height / 2,
left: (pos.x - markerOpt.width / 2).toDouble(),
top: (pos.y - markerOpt.height / 2).toDouble(),
child: markerOpt.builder(context),
),
);
Expand Down
4 changes: 2 additions & 2 deletions flutter_map/lib/src/layer/polyline_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class PolylineLayer extends StatelessWidget {
var pos = map.project(point);
pos = pos.multiplyBy(map.getZoomScale(map.zoom, map.zoom)) -
map.getPixelOrigin();
polylineOpt.offsets.add(new Offset(pos.x, pos.y));
polylineOpt.offsets.add(new Offset(pos.x.toDouble(), pos.y.toDouble()));
if (i > 0 && i < polylineOpt.points.length) {
polylineOpt.offsets.add(new Offset(pos.x, pos.y));
polylineOpt.offsets.add(new Offset(pos.x.toDouble(), pos.y.toDouble()));
}
i++;
}
Expand Down
26 changes: 13 additions & 13 deletions flutter_map/lib/src/layer/tile_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class _TileLayerState extends State<TileLayer> {
'z': coords.z.round().toString(),
's': _getSubdomain(coords)
};
var allOpts = new Map.from(data)..addAll(this.options.additionalOptions);
Map<String,String> allOpts = new Map.from(data)..addAll(this.options.additionalOptions);
return util.template(this.options.urlTemplate, allOpts);
}

Expand Down Expand Up @@ -164,7 +164,7 @@ class _TileLayerState extends State<TileLayer> {
_tiles[key].current = false;
}

_resetGrid() {
void _resetGrid() {
var map = this.map;
var crs = map.options.crs;
var tileSize = this.getTileSize();
Expand Down Expand Up @@ -217,7 +217,7 @@ class _TileLayerState extends State<TileLayer> {
Widget build(BuildContext context) {
var pixelBounds = _getTiledPixelBounds(map.center);
var tileRange = _pxBoundsToTileRange(pixelBounds);
var tileCenter = tileRange.getCenter();
Point<double> tileCenter = tileRange.getCenter();
var queue = <Coords>[];

// mark tiles as out of view...
Expand Down Expand Up @@ -259,8 +259,8 @@ class _TileLayerState extends State<TileLayer> {
tilesToRender.add(tile);
}
tilesToRender.sort((aTile, bTile) {
var a = aTile.coords;
var b = bTile.coords;
Coords<double> a = aTile.coords;
Coords<double> b = bTile.coords;
// a = 13, b = 12, b is less than a, the result should be positive.
if (a.z != b.z) {
return (b.z - a.z).toInt();
Expand All @@ -285,7 +285,7 @@ class _TileLayerState extends State<TileLayer> {
var mapZoom = map.zoom;
var scale = map.getZoomScale(mapZoom, this._tileZoom);
var pixelCenter = map.project(center, this._tileZoom).floor();
var halfSize = map.size / (scale * 2);
Point<num> halfSize = map.size / (scale * 2);
return new Bounds(pixelCenter - halfSize, pixelCenter + halfSize);
}

Expand Down Expand Up @@ -325,10 +325,10 @@ class _TileLayerState extends State<TileLayer> {
var blankImageBytes = new Uint8List(0);

return new Positioned(
left: pos.x,
top: pos.y,
width: width,
height: height,
left: pos.x.toDouble(),
top: pos.y.toDouble(),
width: width.toDouble(),
height: height.toDouble(),
child: new Container(
child: new FadeInImage(
fadeInDuration: const Duration(milliseconds: 100),
Expand All @@ -342,7 +342,7 @@ class _TileLayerState extends State<TileLayer> {
);
}

_wrapCoords(Coords coords) {
Coords _wrapCoords(Coords coords) {
var newCoords = new Coords(
_wrapX != null
? util.wrapNum(coords.x.toDouble(), _wrapX)
Expand All @@ -351,7 +351,7 @@ class _TileLayerState extends State<TileLayer> {
? util.wrapNum(coords.y.toDouble(), _wrapY)
: coords.y.toDouble(),
);
newCoords.z = coords.z;
newCoords.z = coords.z.toDouble();
return newCoords;
}

Expand Down Expand Up @@ -388,7 +388,7 @@ class Coords<T extends num> extends Point<T> {
T z;
Coords(T x, T y) : super(x, y);
String toString() => 'Coords($x, $y, $z)';
bool operator ==(other) {
bool operator ==(dynamic other) {
if (other is Coords) {
return this.x == other.x && this.y == other.y && this.z == other.z;
}
Expand Down
4 changes: 2 additions & 2 deletions flutter_map/lib/src/map/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MapState {
move(options.center, zoom);
}

void move(LatLng center, double zoom, [data]) {
void move(LatLng center, double zoom, [dynamic data]) {
if (zoom == null) {
zoom = this.zoom;
}
Expand Down Expand Up @@ -121,7 +121,7 @@ class MapState {
}

Point getNewPixelOrigin(LatLng center, [double zoom]) {
var viewHalf = this.size / 2;
var viewHalf = this.size / 2.0;
return (this.project(center, zoom) - viewHalf).round();
}
}