Skip to content

Commit

Permalink
Utility to get the visible boundary.
Browse files Browse the repository at this point in the history
  • Loading branch information
xclud committed Mar 16, 2023
1 parent ca0ff40 commit 09ff446
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 67 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.4.1]

* Utility to get the visible boundary.

## [1.4.0]

* Support Dart SDK 3.0.0.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-2022 Mahdi K. Fard
Copyright (c) 2020-2023 Mahdi K. Fard

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 1 addition & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
include: package:flutter_lints/flutter.yaml
analyzer:
exclude:
- 'lib/**/generated/**'
- "lib/**/generated/**"
language:
strict-raw-types: false
strong-mode:
implicit-casts: true
implicit-dynamic: false
errors:
always_declare_return_types: error
always_specify_types: error
Expand Down
6 changes: 6 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:example/pages/metro_lines_page.dart';
import 'package:example/pages/raster_map_page.dart';
import 'package:example/pages/vector_map_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

void main() => runApp(const MapApp());

Expand All @@ -17,6 +18,11 @@ class MapApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Map Examples',
supportedLocales: const [Locale('en')],
localizationsDelegates: const [
GlobalWidgetsLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
],
theme: ThemeData(
colorSchemeSeed: Colors.purple,
useMaterial3: true,
Expand Down
5 changes: 5 additions & 0 deletions example/lib/pages/custom_tile_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class CustomTilePageState extends State<CustomTilePage> {
body: MapLayout(
controller: controller,
builder: (context, transformer) {
final boundary = transformer.getBoundary();
final boundaryText =
'TopLeft: (${boundary.topLeft.latitude}, ${boundary.topLeft.longitude})\nBottomRight: (${boundary.bottomRight.latitude}, ${boundary.bottomRight.longitude})';

return GestureDetector(
behavior: HitTestBehavior.opaque,
onDoubleTapDown: (details) => _onDoubleTap(
Expand Down Expand Up @@ -100,6 +104,7 @@ class CustomTilePageState extends State<CustomTilePage> {
);
},
),
Positioned(bottom: 16, right: 16, child: Text(boundaryText)),
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import FlutterMacOS
import Foundation

import path_provider_macos
import path_provider_foundation
import sqflite

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
Expand Down
2 changes: 2 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ dependencies:
sdk: flutter
latlng: any
cached_network_image: ^3.2.0
flutter_localizations:
sdk: flutter
platform: ^3.1.0
map:
path: ../
Expand Down
21 changes: 13 additions & 8 deletions lib/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
/// * This package supports **caching** out of the box through [cached_network_image](https://pub.dev/packages/cached_network_image) and [flutter_cache_manager](https://pub.dev/packages/flutter_cache_manager) packages.
library map;

export 'src/map.dart';
export 'src/layout_builder.dart';
export 'src/map_layout.dart';
export 'src/transformer.dart' show MapTransformer;
export 'src/controller.dart';
export 'src/polyline.dart';
export 'src/layers/tile_layer.dart';
export 'src/layers/polyline_layer.dart';
import 'dart:math';

import 'package:latlng/latlng.dart';
import 'package:flutter/widgets.dart';

part 'src/map.dart';
part 'src/layout_builder.dart';
part 'src/map_layout.dart';
part 'src/transformer.dart';
part 'src/controller.dart';
part 'src/polyline.dart';
part 'src/layers/tile_layer.dart';
part 'src/layers/polyline_layer.dart';
3 changes: 1 addition & 2 deletions lib/src/controller.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/widgets.dart';
import 'package:latlng/latlng.dart';
part of map;

/// A controller to modify the [center] and [zoom] of the [MapLayout].
class MapController extends ChangeNotifier {
Expand Down
7 changes: 1 addition & 6 deletions lib/src/layers/polyline_layer.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import 'dart:math';

import 'package:flutter/widgets.dart';
import 'package:map/src/polyline.dart';
import 'package:map/src/transformer.dart';
import 'package:map/src/map_layout.dart';
part of map;

/// Draws a layer of polylines on the [MapLayout].
class PolylineLayer extends StatelessWidget {
Expand Down
8 changes: 1 addition & 7 deletions lib/src/layers/tile_layer.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import 'dart:math';

import 'package:flutter/widgets.dart';
import 'package:latlng/latlng.dart';
import 'package:map/src/controller.dart';
import 'package:map/src/layout_builder.dart';
import 'package:map/src/map_layout.dart';
part of map;

/// Raster or Vector data for a specific [z, x, y] coordinate.
///
Expand Down
6 changes: 2 additions & 4 deletions lib/src/layout_builder.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:flutter/widgets.dart';
import 'package:map/src/controller.dart';
import 'package:map/src/transformer.dart';
part of map;

/// Builds a widget tree that can depend on the parent widget's size and
/// providers a map coordinates transfom helper to its children.
Expand All @@ -18,7 +16,7 @@ class MapLayoutBuilder extends InheritedWidget {
key: key,
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final transformer = createMapTransformer(
final transformer = MapTransformer._internal(
controller: controller,
constraints: constraints,
tileSize: tileSize,
Expand Down
6 changes: 1 addition & 5 deletions lib/src/map.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:latlng/latlng.dart';
import 'package:map/src/controller.dart';
part of map;

/// Raster or Vector data for a specific [z, x, y] coordinate.
///
Expand Down
6 changes: 2 additions & 4 deletions lib/src/map_layout.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:flutter/widgets.dart';
import 'package:map/src/controller.dart';
import 'package:map/src/transformer.dart';
part of map;

/// Builds a widget tree that can depend on the parent widget's size and
/// providers a map coordinates transfom helper to its children.
Expand All @@ -17,7 +15,7 @@ class MapLayout extends InheritedWidget {
key: key,
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final transformer = createMapTransformer(
final transformer = MapTransformer._internal(
controller: controller,
constraints: constraints,
tileSize: tileSize,
Expand Down
4 changes: 1 addition & 3 deletions lib/src/polyline.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'dart:ui';

import 'package:latlng/latlng.dart';
part of map;

/// Defines a polyline to draw on the map.
class Polyline {
Expand Down
32 changes: 14 additions & 18 deletions lib/src/transformer.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import 'dart:math';

import 'package:flutter/widgets.dart';
import 'package:latlng/latlng.dart';
import 'package:map/src/controller.dart';
part of map;

/// Helps with converting map coordinates to XY coordinates and vice-versa.
class MapTransformer {
Expand All @@ -13,7 +9,7 @@ class MapTransformer {
}) : _centerX = constraints.biggest.width / 2.0,
_centerY = constraints.biggest.height / 2.0;

/// Map controller which is used in [MapLayoutBuilder].
/// Map controller which is used in [MapLayout].
final MapController controller;

/// The size of the tiles. This is usually equal to the size of the .png file taken from the server. E.g. 256 for a 256x256 pixels or 512 for a 512x512 pixels.
Expand Down Expand Up @@ -103,17 +99,17 @@ class MapTransformer {

return Rect.fromCenter(center: centerPixels, width: size, height: size);
}
}

/// For internal use.
MapTransformer createMapTransformer({
required MapController controller,
required BoxConstraints constraints,
required int tileSize,
}) {
return MapTransformer._internal(
controller: controller,
constraints: constraints,
tileSize: tileSize,
);
/// Gets the current visible boundary.
Boundary getBoundary() {
final biggest = Offset(
constraints.biggest.width,
constraints.biggest.height,
);

final topLeft = toLatLng(Offset.zero);
final bottomRight = toLatLng(biggest);

return Boundary(topLeft: topLeft, bottomRight: bottomRight);
}
}
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: map
description: Lightweight Map widget for flutter supporting different projections including EPSG4326/Mercator/WGS1984.
version: 1.4.0
description: Geographical Map widget for flutter supporting different projections including EPSG4326/Mercator/WGS1984.
version: 1.4.1
homepage: https://pwa.ir
repository: https://github.com/xclud/flutter_map

environment:
sdk: ">=2.12.0 <4.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
sdk: flutter
latlng: ^0.2.0
latlng: ^0.2.1

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 09ff446

Please sign in to comment.