Skip to content

Commit

Permalink
refactor: example app plugins (#1744)
Browse files Browse the repository at this point in the history
  • Loading branch information
josxha authored Dec 2, 2023
1 parent c0829b4 commit ad8318b
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 42 deletions.
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import 'package:flutter_map_example/pages/map_inside_listview.dart';
import 'package:flutter_map_example/pages/markers.dart';
import 'package:flutter_map_example/pages/moving_markers.dart';
import 'package:flutter_map_example/pages/overlay_image.dart';
import 'package:flutter_map_example/pages/plugin_scalebar.dart';
import 'package:flutter_map_example/pages/plugin_zoombuttons.dart';
import 'package:flutter_map_example/pages/polygon.dart';
import 'package:flutter_map_example/pages/polyline.dart';
import 'package:flutter_map_example/pages/reset_tile_layer.dart';
Expand All @@ -28,8 +30,6 @@ import 'package:flutter_map_example/pages/stateful_markers.dart';
import 'package:flutter_map_example/pages/tile_builder.dart';
import 'package:flutter_map_example/pages/tile_loading_error_handle.dart';
import 'package:flutter_map_example/pages/wms_tile_layer.dart';
import 'package:flutter_map_example/plugins/plugin_scalebar.dart';
import 'package:flutter_map_example/plugins/plugin_zoombuttons.dart';
import 'package:url_strategy/url_strategy.dart';

void main() {
Expand Down
2 changes: 1 addition & 1 deletion example/lib/pages/map_inside_listview.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_example/misc/tile_providers.dart';
import 'package:flutter_map_example/plugins/zoombuttons_plugin_option.dart';
import 'package:flutter_map_example/plugins/zoombuttons_plugin.dart';
import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart';
import 'package:latlong2/latlong.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_example/misc/tile_providers.dart';
import 'package:flutter_map_example/pages/scale_layer_plugin_option.dart';
import 'package:flutter_map_example/plugins/scale_layer_plugin_option.dart';
import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart';
import 'package:latlong2/latlong.dart';

Expand All @@ -23,13 +23,11 @@ class PluginScaleBar extends StatelessWidget {
),
children: [
openStreetMapTileLayer,
ScaleLayerWidget(
options: ScaleLayerPluginOption(
lineColor: Colors.black,
lineWidth: 3,
textStyle: const TextStyle(color: Colors.black, fontSize: 14),
padding: const EdgeInsets.all(10),
),
const FlutterMapScaleLayer(
lineColor: Colors.black,
lineWidth: 3,
textStyle: TextStyle(color: Colors.black, fontSize: 14),
padding: EdgeInsets.all(10),
),
],
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_example/misc/tile_providers.dart';
import 'package:flutter_map_example/plugins/zoombuttons_plugin_option.dart';
import 'package:flutter_map_example/plugins/zoombuttons_plugin.dart';
import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart';
import 'package:latlong2/latlong.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,9 @@ import 'dart:ui' as ui;

import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_example/pages/scalebar_utils.dart';
import 'package:flutter_map_example/plugins/scalebar_utils.dart';

class ScaleLayerPluginOption {
TextStyle? textStyle;
Color lineColor;
double lineWidth;
final EdgeInsets? padding;

ScaleLayerPluginOption({
this.textStyle,
this.lineColor = Colors.white,
this.lineWidth = 2,
this.padding,
});
}

class ScaleLayerWidget extends StatelessWidget {
final ScaleLayerPluginOption options;
class FlutterMapScaleLayer extends StatelessWidget {
static const scale = <int>[
25000000,
15000000,
Expand All @@ -46,18 +31,27 @@ class ScaleLayerWidget extends StatelessWidget {
10,
5
];
final TextStyle? textStyle;
final Color lineColor;
final double lineWidth;
final EdgeInsets? padding;

const ScaleLayerWidget({super.key, required this.options});
const FlutterMapScaleLayer({
super.key,
this.textStyle,
this.lineColor = Colors.white,
this.lineWidth = 2,
this.padding,
});

@override
Widget build(BuildContext context) {
final map = MapCamera.of(context);
final zoom = map.zoom;
final distance = scale[max(0, min(20, zoom.round() + 2))].toDouble();
final center = map.center;
final start = map.project(center);
final camera = MapCamera.of(context);
final distance = scale[max(0, min(20, camera.zoom.round() + 2))].toDouble();
final center = camera.center;
final start = camera.project(center);
final targetPoint = calculateEndingGlobalCoordinates(center, 90, distance);
final end = map.project(targetPoint);
final end = camera.project(targetPoint);
final displayDistance = distance > 999
? '${(distance / 1000).toStringAsFixed(0)} km'
: '${distance.toStringAsFixed(0)} m';
Expand All @@ -69,10 +63,10 @@ class ScaleLayerWidget extends StatelessWidget {
painter: ScalePainter(
width,
displayDistance,
lineColor: options.lineColor,
lineWidth: options.lineWidth,
padding: options.padding,
textStyle: options.textStyle,
lineColor: lineColor,
lineWidth: lineWidth,
padding: padding,
textStyle: textStyle,
),
);
},
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions example/lib/widgets/drawer/menu_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import 'package:flutter_map_example/pages/map_inside_listview.dart';
import 'package:flutter_map_example/pages/markers.dart';
import 'package:flutter_map_example/pages/moving_markers.dart';
import 'package:flutter_map_example/pages/overlay_image.dart';
import 'package:flutter_map_example/pages/plugin_scalebar.dart';
import 'package:flutter_map_example/pages/plugin_zoombuttons.dart';
import 'package:flutter_map_example/pages/polygon.dart';
import 'package:flutter_map_example/pages/polyline.dart';
import 'package:flutter_map_example/pages/reset_tile_layer.dart';
Expand All @@ -28,8 +30,6 @@ import 'package:flutter_map_example/pages/stateful_markers.dart';
import 'package:flutter_map_example/pages/tile_builder.dart';
import 'package:flutter_map_example/pages/tile_loading_error_handle.dart';
import 'package:flutter_map_example/pages/wms_tile_layer.dart';
import 'package:flutter_map_example/plugins/plugin_scalebar.dart';
import 'package:flutter_map_example/plugins/plugin_zoombuttons.dart';
import 'package:flutter_map_example/widgets/drawer/menu_item.dart';

class MenuDrawer extends StatelessWidget {
Expand Down

0 comments on commit ad8318b

Please sign in to comment.