Files
rog_app/lib/widgets/map_widget.dart

199 lines
10 KiB
Dart
Raw Normal View History

2022-05-18 19:09:26 +05:30
import 'dart:async';
2022-03-14 12:28:57 +05:30
import 'package:flutter/material.dart';
import 'package:flutter_map/plugin_api.dart';
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
2022-04-17 11:45:21 +05:30
import 'package:flutter_map_marker_cluster/flutter_map_marker_cluster.dart';
2022-03-14 12:28:57 +05:30
import 'package:geojson/geojson.dart';
import 'package:get/get.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:latlong2/latlong.dart';
2022-05-12 02:17:08 +05:30
import 'package:rogapp/pages/index/index_controller.dart';
2022-03-14 12:28:57 +05:30
import 'package:rogapp/widgets/base_layer_widget.dart';
2022-06-27 12:15:54 +05:30
import 'package:rogapp/widgets/bottom_sheet_new.dart';
2022-03-14 12:28:57 +05:30
import 'package:rogapp/widgets/bottom_sheet_widget.dart';
2022-04-17 11:45:21 +05:30
class MapWidget extends StatelessWidget {
2022-03-14 12:28:57 +05:30
2022-04-17 11:45:21 +05:30
final IndexController indexController = Get.find<IndexController>();
2022-03-30 16:19:18 +05:30
2022-04-17 11:45:21 +05:30
MapWidget({ Key? key}) : super(key: key);
2022-03-14 12:28:57 +05:30
2022-05-18 19:09:26 +05:30
StreamSubscription? subscription;
2022-03-14 12:28:57 +05:30
@override
Widget build(BuildContext context) {
final PopupController _popupController = PopupController();
2022-04-17 11:45:21 +05:30
return Stack(
2022-03-14 12:28:57 +05:30
children: [
2022-04-17 11:45:21 +05:30
Obx(() =>
2022-05-18 19:09:26 +05:30
indexController.is_loading == true ? Padding(
padding: const EdgeInsets.only(top: 60.0),
child: CircularProgressIndicator(),
):
2022-04-17 11:45:21 +05:30
FlutterMap(
//mapController: mapController,
2022-03-24 14:20:04 +05:30
options: MapOptions(
2022-05-18 19:09:26 +05:30
onMapCreated: (c){
indexController.mapController = c;
indexController.mapController!.onReady.then((_) {
subscription = indexController.mapController!.mapEventStream.listen((MapEvent mapEvent) {
if (mapEvent is MapEventMoveStart) {
//print(DateTime.now().toString() + ' [MapEventMoveStart] START');
// do something
}
if (mapEvent is MapEventMoveEnd) {
//print(DateTime.now().toString() + ' [MapEventMoveStart] END');
indexController.loadLocationsBound();
}
});
});
},
2022-03-30 16:19:18 +05:30
//center: LatLng(37.15319600454702, 139.58765950528198),
2022-04-17 11:45:21 +05:30
bounds: indexController.currentBound.length > 0 ? indexController.currentBound[0]: LatLngBounds.fromPoints([LatLng(35.03999881162295, 136.40587119778962), LatLng(36.642756778706904, 137.95226720406063)]),
zoom: 1,
2022-03-24 14:20:04 +05:30
maxZoom: 20,
2022-04-18 15:22:08 +05:30
interactiveFlags: InteractiveFlag.pinchZoom | InteractiveFlag.drag,
2022-03-24 14:20:04 +05:30
plugins: [
MarkerClusterPlugin(),
],
2022-05-18 19:09:26 +05:30
onPositionChanged: (MapPosition pos, isvalue){
// LatLng c1 = pos.center?? LatLng(0, 0);
// Timer(Duration(milliseconds:800), () {
// print(pos.bounds!.center);
// print("Yeah, this line is printed after 3 second");
// LatLng c2 = pos.center?? LatLng(0, 0);
// if(c1.latitude != 0 && c1.latitude == c2.latitude){
// print("------ calling ----");
// //indexController.loadLocationsBound();
// }
// });
//
},
2022-03-24 14:20:04 +05:30
onTap: (_, __) =>
_popupController
.hideAllPopups(), // Hide popup when the map is tapped.
2022-03-14 12:28:57 +05:30
),
2022-05-18 19:09:26 +05:30
layers: [
// MarkerLayerOptions(
// markers: indexController.locations[0].collection.map((i) {
// print("i si ${i.properties!['location_id']}");
// GeoJsonMultiPoint p = i.geometry as GeoJsonMultiPoint;
// print("lat is ${p.geoSerie!.geoPoints[0].latitude} and lon is ${p.geoSerie!.geoPoints[0].longitude}");
// return Marker(
// anchorPos: AnchorPos.align(AnchorAlign.center),
// height: 70.0,
// width: 70.0,
// point: LatLng(p.geoSerie!.geoPoints[0].latitude, p.geoSerie!.geoPoints[0].longitude),
// builder: (ctx) =>
// IconButton(
// icon: const Icon(Icons.pin_drop),
// tooltip: 'Increase volume by 10',
// onPressed: () {
// GeoJsonFeature? fs = indexController.getFeatureForLatLong(p.geoSerie!.geoPoints[0].latitude, p.geoSerie!.geoPoints[0].longitude);
// print(fs);
// if(fs != null){
// if(indexController.currentFeature.length > 0) {
// indexController.currentFeature.clear();
// }
// indexController.currentFeature.add(fs);
// indexController.getAction();
// showModalBottomSheet(context: context, isScrollControlled: true,
// builder:((context) => BottomSheetWidget())
// );
// }
// },
// ),
// );
// }).toList(),
// ),
],
2022-03-24 14:20:04 +05:30
children: [
BaseLayer(),
LocationMarkerLayerWidget(),
2022-05-18 19:09:26 +05:30
2022-04-17 11:45:21 +05:30
indexController.locations.length > 0 ?
2022-03-24 14:20:04 +05:30
MarkerClusterLayerWidget(
options: MarkerClusterLayerOptions(
2022-05-18 19:09:26 +05:30
spiderfyCircleRadius: 0,
2022-03-24 14:20:04 +05:30
spiderfySpiralDistanceMultiplier: 2,
circleSpiralSwitchover: 12,
2022-05-18 19:09:26 +05:30
maxClusterRadius: 0,
2022-03-24 14:20:04 +05:30
rotate: true,
onMarkerTap: (marker){
2022-04-17 11:45:21 +05:30
GeoJsonFeature? fs = indexController.getFeatureForLatLong(marker.point.latitude, marker.point.longitude);
2022-03-24 14:20:04 +05:30
print(fs);
if(fs != null){
2022-04-17 11:45:21 +05:30
if(indexController.currentFeature.length > 0) {
indexController.currentFeature.clear();
2022-03-24 14:20:04 +05:30
}
2022-04-17 11:45:21 +05:30
indexController.currentFeature.add(fs);
2022-05-12 02:17:08 +05:30
indexController.getAction();
2022-03-24 14:20:04 +05:30
2022-06-27 12:15:54 +05:30
showModalBottomSheet(
context: context,
isScrollControlled: true,
isDismissible: true,
builder:((context) => BottomSheetNew())
//builder:((context) => BottomSheetWidget())
2022-03-24 14:20:04 +05:30
);
}
2022-03-30 16:19:18 +05:30
2022-03-24 14:20:04 +05:30
},
size: Size(40, 40),
anchor: AnchorPos.align(AnchorAlign.center),
fitBoundsOptions: const FitBoundsOptions(
padding: EdgeInsets.all(50),
2022-03-30 16:19:18 +05:30
maxZoom: 265,
2022-03-14 12:28:57 +05:30
),
2022-04-17 11:45:21 +05:30
markers:indexController.locations[0].collection.map((i) {
2022-04-18 15:22:08 +05:30
print("i si ${i.properties!['location_id']}");
2022-03-24 14:20:04 +05:30
GeoJsonMultiPoint p = i.geometry as GeoJsonMultiPoint;
2022-04-18 15:22:08 +05:30
print("lat is ${p.geoSerie!.geoPoints[0].latitude} and lon is ${p.geoSerie!.geoPoints[0].longitude}");
2022-03-24 14:20:04 +05:30
return Marker(
anchorPos: AnchorPos.align(AnchorAlign.center),
2022-06-29 18:25:19 +05:30
height: 22.0,
width: 22.0,
2022-03-24 14:20:04 +05:30
point: LatLng(p.geoSerie!.geoPoints[0].latitude, p.geoSerie!.geoPoints[0].longitude),
builder: (ctx) => Icon(Icons.pin_drop),
2022-05-24 20:43:41 +05:30
// builder: (ctx) => i.properties!["category"] != null ?
// ImageIcon(
// AssetImage("assets/images/${i.properties!["category"]}.png"),
// color: Color(0xFF3A5A98),
2022-06-29 18:25:19 +05:30
// size:12.0,
2022-05-24 20:43:41 +05:30
// )
// : Icon(Icons.pin_drop),
2022-03-24 14:20:04 +05:30
);
}).toList(),
builder: (context, markers) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.blue),
child: Center(
child: Text(
markers.length.toString(),
style: TextStyle(color: Colors.white),
),
),
);
},
2022-03-14 12:28:57 +05:30
),
2022-03-24 14:20:04 +05:30
): Container(height:0,width: 0),
],
)
2022-04-17 11:45:21 +05:30
)
2022-03-14 12:28:57 +05:30
],
2022-04-17 11:45:21 +05:30
);
2022-03-14 12:28:57 +05:30
}
2022-04-17 11:45:21 +05:30
}