Skip to content

Commit

Permalink
添加设置中心点
Browse files Browse the repository at this point in the history
  • Loading branch information
huangjiahong committed Sep 9, 2021
1 parent bb9a703 commit b3f765c
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static class ViewType {
*/
public static class FMMMapStateMethodId {
public static final String sMapSetStyleMethod = "flutter_minemap/map/setStyleJson";
public static final String sMapSetCenterMethod = "flutter_minemap/map/setCenter";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void dispatchMethodHandler(Context context, MethodCall call,
/// 对不同类型的操作进行分治管理
switch (methodId) {
case Constants.FMMMapStateMethodId.sMapSetStyleMethod:
case Constants.FMMMapStateMethodId.sMapSetCenterMethod:
mMapHandler = mMapHandlerHashMap.get(Constants.MMapHandlerType.MAP_STATE);
break;
case Constants.FMMClusterLayerMethodId.sMapAddClusterLayerMethod:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@

import com.imfunc.flutter_minemap.FMMMapController;
import com.imfunc.flutter_minemap.unil.Constants;
import com.imfunc.flutter_minemap.unil.conveter.FMMMapConveter;
import com.minedata.minemap.geometry.LatLng;
import com.minedata.minemap.map.MineMap;

import java.util.Map;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

public class MapStateHandler extends MMapHandler {
private static final String TAG = MapStateHandler.class.getSimpleName();
private MineMap mineMap;




public MapStateHandler(FMMMapController mMapController) {
super(mMapController);
Expand All @@ -35,13 +38,27 @@ public void handlerMethodCallResult(Context context, MethodCall call, MethodChan
case Constants.FMMMapStateMethodId.sMapSetStyleMethod:
setMapType(call, result);
break;
case Constants.FMMMapStateMethodId.sMapSetCenterMethod:
setCenter(call, result);
break;
default:
break;
}
}

/**
* @param call
* @param result
*/
private void setCenter(MethodCall call, MethodChannel.Result result) {
LatLng center = FMMMapConveter.mapToLatlng((Map<String, Object>) call.arguments);
mMapController.setCenter(center);
result.success(true);
}

/**
* 设置地图样式
*
* @param call
* @param result
*/
Expand All @@ -50,7 +67,7 @@ private void setMapType(MethodCall call,
Integer mapType = call.arguments();

mMapController.setMapType(mapType);

result.success(true);
}
}
71 changes: 65 additions & 6 deletions example/lib/view/base_map_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,35 @@ import 'package:flutter_minemap/models/fmm_map_models.dart';
import 'package:flutter_minemap/models/fmm_types.dart';
import 'package:flutter_minemap_example/config/config.dart';

class BaseMapPage extends StatelessWidget {
class BaseMapPage extends StatefulWidget {
const BaseMapPage({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
MineMapController _mineMapController;
_BaseMapPageState createState() => _BaseMapPageState();
}

class _BaseMapPageState extends State<BaseMapPage> {
MineMapController _mineMapController;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('地图'),
),
body: Container(
height: double.infinity,
width: double.infinity,
body: Column(
children: [
_mapWidget(),
_makeWidget(context),
],
),
);
}

Widget _mapWidget() {
return Expanded(
child: Container(
width: MediaQuery.of(context).size.width,
alignment: Alignment.center,
child: MineMapView(
mapOptions: FMMMapOptions(
Expand All @@ -36,4 +51,48 @@ class BaseMapPage extends StatelessWidget {
),
);
}

Widget _makeWidget(BuildContext context) {
final List<CustomButtonModel> _btnL = [
CustomButtonModel(
'北京',
() => _mineMapController
.setMapCenter(FMMCoordinate(39.914687, 116.403613))),
CustomButtonModel(
'上海',
() => _mineMapController
.setMapCenter(FMMCoordinate(31.233706, 121.477091))),
CustomButtonModel(
'济南',
() => _mineMapController
.setMapCenter(FMMCoordinate(36.656786, 117.122375))),
CustomButtonModel(
'珠海',
() => _mineMapController
.setMapCenter(FMMCoordinate(22.26827, 113.573358))),
];

List<Widget> _l = [];

for (CustomButtonModel e in _btnL) {
_l.add(TextButton(
onPressed: e.func,
child: Text(e.name),
));
}

return Container(
width: MediaQuery.of(context).size.width,
child: Wrap(
children: _l,
),
);
}
}

class CustomButtonModel {
final String name;
final Function func;

CustomButtonModel(this.name, this.func);
}
17 changes: 17 additions & 0 deletions lib/mimemap_controler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:flutter_minemap/models/overlays/cluster_layer_model.dart';
import 'package:flutter_minemap/private/fmm_method_channel_handler.dart';
import 'package:flutter_minemap/private/fmm_method_id.dart';

import 'models/fmm_map_models.dart';

class MineMapController {
MethodChannel _mapChannel;

Expand Down Expand Up @@ -36,6 +38,21 @@ class MineMapController {
return result;
}

/// 设置中心点
Future<bool> setMapCenter(FMMCoordinate coordinate) async {
if (_mapChannel == null) {
return false;
}
bool result = false;
try {
result = (await _mapChannel.invokeMethod(
FMMMapStateMethodId.kMapSetCenterMethod, coordinate.toMap())) as bool;
} on PlatformException catch (e) {
print(e.toString());
}
return result;
}

/// 添加聚合点图层
Future<bool> addClusterLayer(ClusterLayerModel params) async {
print(params);
Expand Down

0 comments on commit b3f765c

Please sign in to comment.