Skip to content

Commit 5866123

Browse files
author
huangjiahong
committed
添加基础模块,以提供往后实现
1 parent 99d1759 commit 5866123

File tree

9 files changed

+263
-82
lines changed

9 files changed

+263
-82
lines changed

android/src/main/java/com/imfunc/flutter_minemap/FMMMapController.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.imfunc.flutter_minemap.interfaces.MineMapInterface;
1212
import com.imfunc.flutter_minemap.unil.Config;
1313
import com.imfunc.flutter_minemap.unil.Constants;
14+
import com.imfunc.flutter_minemap.unil.conveter.FMMMapConveter;
1415
import com.minedata.minemap.MinemapAccountManager;
1516
import com.minedata.minemap.camera.CameraPosition;
1617
import com.minedata.minemap.geometry.LatLng;
@@ -39,13 +40,22 @@ public class FMMMapController implements MethodChannel.MethodCallHandler, Applic
3940

4041
private final MethodChannel mMethodChannel;
4142

42-
public FMMMapController(int id, Context context, BinaryMessenger binaryMessenger, @Nullable Map<String, Object> creationParams) {
43+
public FMMMapController(int id, Context context, BinaryMessenger binaryMessenger, Map<String, Object> creationParams) {
4344

4445
mContext = context;
4546

4647
this.application = ((Application) (context.getApplicationContext()));
4748
this.application.registerActivityLifecycleCallbacks(this);
4849

50+
mMethodChannel = new MethodChannel(binaryMessenger,
51+
Constants.VIEW_METHOD_CHANNEL_PREFIX + id);
52+
mMethodChannel.setMethodCallHandler(this);
53+
54+
initMap(creationParams);
55+
}
56+
57+
/// 初始化地图组件
58+
private void initMap(Map<String, Object> creationParams) {
4959
String accessToken = creationParams.get("accessToken").toString();
5060
String offlineAccessToken = creationParams.get("offlineAccessToken").toString();
5161
String solution = creationParams.get("solution").toString();
@@ -58,8 +68,21 @@ public FMMMapController(int id, Context context, BinaryMessenger binaryMessenger
5868

5969
mapView.addMapRenderCallback(new MapView.OnMapReadyListener() {
6070
@Override
61-
public void onMapReady(final MineMap mineMap) {
62-
FMMMapController.mineMap = mineMap;
71+
public void onMapReady(final MineMap oMineMap) {
72+
mineMap = oMineMap;
73+
74+
mineMap.setStyleUrl(Config.mBase);
75+
mineMap.setCameraPosition(
76+
new CameraPosition.Builder()
77+
// 设置相机指向的位置
78+
.target(new LatLng(38.913828, 116.405419))
79+
// 设置相机缩放等级
80+
.zoom(13)
81+
// 设置相机的俯视角度
82+
.tilt(0)
83+
// 摄像机指向的方向,从北部顺时针方向设置
84+
.bearing(0)
85+
.build());
6386
}
6487
});
6588

@@ -68,11 +91,6 @@ public void onMapReady(final MineMap mineMap) {
6891
if (mineMap != null) {
6992
uiSettings = mineMap.getUiSettings();
7093
}
71-
72-
mMethodChannel = new MethodChannel(binaryMessenger,
73-
Constants.VIEW_METHOD_CHANNEL_PREFIX + id);
74-
75-
mMethodChannel.setMethodCallHandler(this);
7694
}
7795

7896
public MapView getMapView() {
@@ -204,7 +222,7 @@ public void setCompassEnabled(Boolean enabled) {
204222
@Override
205223
public void setLogoEnabled(Boolean enabled) {
206224
if (mineMap != null && enabled != null) {
207-
uiSettings.setLogoEnabled(enabled);
225+
mineMap.getUiSettings().setLogoEnabled(enabled);
208226
}
209227
}
210228

android/src/main/java/com/imfunc/flutter_minemap/factory/MineViewFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,21 @@ private FMMMapController buildFMMMapController(Context context, int viewId, Map<
8484
if (args.containsKey("minZoomLevel") ) {
8585
Integer minZoomLevel = FMMMapConveter.toInt(args.get("minZoomLevel"));
8686
if (minZoomLevel != null) {
87-
builder.mapType(minZoomLevel);
87+
builder.minZoomLevel(minZoomLevel);
8888
}
8989
}
9090

9191
if (args.containsKey("tilt") ) {
9292
Integer tilt = FMMMapConveter.toInt(args.get("tilt"));
9393
if (tilt != null) {
94-
builder.mapType(tilt);
94+
builder.tilt(tilt);
9595
}
9696
}
9797

9898
if (args.containsKey("bearing") ) {
9999
Integer bearing = FMMMapConveter.toInt(args.get("bearing"));
100100
if (bearing != null) {
101-
builder.mapType(bearing);
101+
builder.bearing(bearing);
102102
}
103103
}
104104

example/lib/config/config.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Config {
2+
static String offlineAccessToken = '';
3+
static String accessToken = '';
4+
static String solution = '';
5+
}

example/lib/index_page.dart

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_minemap_example/view/base_map_page.dart';
3+
import 'package:flutter_minemap_example/view/map_style_page.dart';
4+
5+
class IndexPage extends StatefulWidget {
6+
const IndexPage({Key key}) : super(key: key);
7+
8+
@override
9+
_IndexPageState createState() => _IndexPageState();
10+
}
11+
12+
class _IndexPageState extends State<IndexPage> {
13+
List<BTNWidgetClass> _btnList = [];
14+
15+
@override
16+
void initState() {
17+
super.initState();
18+
_setBtnList();
19+
}
20+
21+
@override
22+
Widget build(BuildContext context) {
23+
return Scaffold(
24+
appBar: AppBar(
25+
title: const Text('Plugin example app'),
26+
),
27+
body: ListView.builder(
28+
itemCount: _btnList.length,
29+
itemBuilder: (BuildContext context, int i) {
30+
if (_btnList[i].title.isEmpty) {
31+
return Container(
32+
width: MediaQuery.of(context).size.width,
33+
height: 35,
34+
alignment: Alignment.centerLeft,
35+
padding: EdgeInsets.symmetric(horizontal: 20),
36+
decoration: BoxDecoration(color: Colors.amberAccent),
37+
child: Text(
38+
_btnList[i].subtitle,
39+
style: TextStyle(
40+
fontSize: 16,
41+
),
42+
),
43+
);
44+
} else {
45+
return _btnWidget(_btnList[i]);
46+
}
47+
},
48+
),
49+
);
50+
}
51+
52+
Widget _btnWidget(BTNWidgetClass d) {
53+
return ListTile(
54+
// contentPadding: EdgeInsets.symmetric(),
55+
onTap: d.func,
56+
title: Text(
57+
d.title,
58+
style: TextStyle(
59+
fontSize: 16,
60+
),
61+
),
62+
subtitle: Text(d.subtitle),
63+
);
64+
}
65+
66+
void _setBtnList() {
67+
_btnList = [
68+
BTNWidgetClass(
69+
'',
70+
'基础地图',
71+
() => Navigator.push(
72+
context,
73+
MaterialPageRoute(builder: (context) => BaseMapPage()),
74+
),
75+
),
76+
BTNWidgetClass('基础地图', '地图视角边界', () {}),
77+
BTNWidgetClass('边界', '地图视角边界', () {}),
78+
BTNWidgetClass('Fragment', '如何制作一个Fragment', () {}),
79+
BTNWidgetClass('', '交互事件', () {}),
80+
BTNWidgetClass('地图基础操作', '介绍地图的基础操作', () {}),
81+
BTNWidgetClass('UI控制功能', '介绍UI的基本操作和控件的显示隐藏操作', () {}),
82+
BTNWidgetClass(
83+
'地图样式设置',
84+
'介绍地图样式设置方法',
85+
() => Navigator.push(
86+
context,
87+
MaterialPageRoute(builder: (context) => MapStylePage()),
88+
),
89+
),
90+
BTNWidgetClass('视角移动', '介绍地图的两种移动视角的方式', () {}),
91+
BTNWidgetClass('坐标转换', '介绍坐标转换的方法', () {}),
92+
BTNWidgetClass('距离测量', '介绍测距测面积的方法', () {}),
93+
BTNWidgetClass('', '简单覆盖物', () {}),
94+
BTNWidgetClass('点', '往地图上添加简单点', () {}),
95+
BTNWidgetClass('Polygon', '往地图上添加多边形', () {}),
96+
BTNWidgetClass('', '复杂覆盖物', () {}),
97+
BTNWidgetClass('圆', '往地图上添加圆', () {}),
98+
BTNWidgetClass('点-marklayer', '往地图上添加复杂点', () {}),
99+
BTNWidgetClass('点-marklayer', '如何修改文字特殊效果', () {}),
100+
BTNWidgetClass('PolylineLayer', '往地图上添加线段层', () {}),
101+
BTNWidgetClass('三维建筑物', '如何往地图上添加3D建筑物', () {}),
102+
BTNWidgetClass('复杂多边形', '如何往地图上添加3D多边形', () {}),
103+
BTNWidgetClass('混合', '覆盖物的混合模式,看是否会有干扰', () {}),
104+
BTNWidgetClass('', '混合', () {}),
105+
BTNWidgetClass('混合航线图', '往地图上添加混合航线图层', () {}),
106+
BTNWidgetClass('混合wmts图像图', '往地图上添加混合wmts图像图层', () {}),
107+
BTNWidgetClass('', '拓展覆盖物', () {}),
108+
BTNWidgetClass('光晕圈', '往地图上添加光晕圈图层', () {}),
109+
BTNWidgetClass('大规模图标图', '往地图上添加大规模图标', () {}),
110+
BTNWidgetClass('热力图', '', () {}),
111+
BTNWidgetClass('柱状图', '往地图上添加柱状图层', () {}),
112+
BTNWidgetClass('点聚合图', '往地图上添加点聚合图层', () {}),
113+
BTNWidgetClass('波形圈', '往地图上添加波形圈图层', () {}),
114+
BTNWidgetClass('OD迁徙图', '往地图上添加OD迁徙图层', () {}),
115+
BTNWidgetClass('航线地图', '往地图上添加航线图层', () {}),
116+
BTNWidgetClass('wmts图像图', '往地图上添加混合wmts图像图层', () {}),
117+
BTNWidgetClass('导航线图', '往地图上添加导航线', () {}),
118+
BTNWidgetClass('水纹图', '水纹特效', () {}),
119+
BTNWidgetClass('大规模图标图', '往地图上添加大规模散点图层', () {}),
120+
BTNWidgetClass('点平滑移动', '往地图上添加点平滑移动图层', () {}),
121+
];
122+
}
123+
}
124+
125+
class BTNWidgetClass {
126+
final String title;
127+
final String subtitle;
128+
final Function func;
129+
130+
BTNWidgetClass(this.title, this.subtitle, this.func);
131+
}

example/lib/main.dart

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import 'package:flutter/material.dart';
2-
import 'dart:async';
3-
4-
import 'package:flutter/services.dart';
5-
import 'package:flutter_minemap/flutter_minemap.dart';
6-
import 'package:flutter_minemap_example/map_demo_page.dart';
2+
import 'package:flutter_minemap_example/index_page.dart';
73

84
void main() {
95
runApp(MyApp());
@@ -52,31 +48,3 @@ class _MyAppState extends State<MyApp> {
5248
}
5349
}
5450

55-
class IndexPage extends StatelessWidget {
56-
const IndexPage({Key key}) : super(key: key);
57-
58-
@override
59-
Widget build(BuildContext context) {
60-
return Scaffold(
61-
appBar: AppBar(
62-
title: const Text('Plugin example app'),
63-
),
64-
body: Center(
65-
child: Column(
66-
children: [
67-
TextButton(
68-
onPressed: () => Navigator.push(
69-
context,
70-
MaterialPageRoute(
71-
builder: (context) => MapDemoPage(),
72-
),
73-
),
74-
child: Text('跳转到地图'),
75-
),
76-
],
77-
),
78-
),
79-
);
80-
}
81-
}
82-

example/lib/map_demo_page.dart

Lines changed: 0 additions & 37 deletions
This file was deleted.

example/lib/map_type_page.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'package:flutter/material.dart';
2+
3+
class MapTypePage extends StatelessWidget {
4+
const MapTypePage({Key key}) : super(key: key);
5+
6+
@override
7+
Widget build(BuildContext context) {
8+
return Scaffold(
9+
appBar: AppBar(
10+
title: Text('地图类型'),
11+
),
12+
);
13+
}
14+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_minemap/flutter_minemap.dart';
3+
import 'package:flutter_minemap/minemap_view.dart';
4+
import 'package:flutter_minemap/models/fmm_map_models.dart';
5+
import 'package:flutter_minemap/models/fmm_types.dart';
6+
import 'package:flutter_minemap_example/config/config.dart';
7+
8+
class BaseMapPage extends StatelessWidget {
9+
const BaseMapPage({Key key}) : super(key: key);
10+
11+
@override
12+
Widget build(BuildContext context) {
13+
MineMapController _mineMapController;
14+
15+
return Scaffold(
16+
appBar: AppBar(
17+
title: Text('地图'),
18+
),
19+
body: Container(
20+
height: double.infinity,
21+
width: double.infinity,
22+
alignment: Alignment.center,
23+
child: MineMapView(
24+
mapOptions: FMMMapOptions(
25+
mapType: FMMMapType.Satellite,
26+
offlineAccessToken: Config.offlineAccessToken,
27+
accessToken: Config.accessToken,
28+
solution: Config.solution,
29+
center: FMMCoordinate(38.913828, 116.405419),
30+
logoEnabled: false,
31+
),
32+
onMineMapViewCreated: (MineMapController controller) {
33+
_mineMapController = controller;
34+
},
35+
),
36+
),
37+
);
38+
}
39+
}

0 commit comments

Comments
 (0)