hyzp_ybqx-Commit137:已经实现android版通过资产添加百度地图标识图标,并通过BMFText添加文本标识;IOS版则通过自定义 flutter_bmfmap_1.0.2 插件加载外部存储中的.png带文本的标识图标
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bmfbase/BaiduMap/bmfmap_base.dart';
|
import 'package:flutter_bmfbase/BaiduMap/bmfmap_base.dart';
|
||||||
import 'package:flutter_bmfmap/BaiduMap/bmfmap_map.dart';
|
import 'package:flutter_bmfmap/BaiduMap/bmfmap_map.dart';
|
||||||
@@ -41,13 +43,17 @@ Future getListBMFMarker({List listDwinfo}) async {
|
|||||||
|
|
||||||
int len = listDwinfo.length;
|
int len = listDwinfo.length;
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
BMFMarker marker = BMFMarker(
|
BMFMarker marker;
|
||||||
|
if (Platform.isIOS) {
|
||||||
|
marker = BMFMarker(
|
||||||
position: getBMFCoordinate(listDwinfo[i]["dwzb"]),
|
position: getBMFCoordinate(listDwinfo[i]["dwzb"]),
|
||||||
// title: '${listDwinfo[i]["id"].toString()}、${listDwinfo[i]["dwmc"]}',
|
// title: '${listDwinfo[i]["id"].toString()}、${listDwinfo[i]["dwmc"]}',
|
||||||
title: '${(i + 1).toString()}、${listDwinfo[i]["dwmc"]}',
|
title: '${(i + 1).toString()}、${listDwinfo[i]["dwmc"]}',
|
||||||
subtitle: 'test',
|
subtitle: 'test',
|
||||||
// identifier: '${listDwinfo[i]["id"].toString()}、${listDwinfo[i]["dwmc"]}',
|
// identifier: '${listDwinfo[i]["id"].toString()}、${listDwinfo[i]["dwmc"]}',
|
||||||
identifier: '${(i + 1).toString()}、${listDwinfo[i]["dwmc"]}',
|
identifier: '${(i + 1).toString()}、${listDwinfo[i]["dwmc"]}',
|
||||||
|
|
||||||
|
// android版使用
|
||||||
// icon: 'assets/images/location.png',
|
// icon: 'assets/images/location.png',
|
||||||
|
|
||||||
// 为IOS在百度地图中显示文本图标
|
// 为IOS在百度地图中显示文本图标
|
||||||
@@ -64,6 +70,35 @@ Future getListBMFMarker({List listDwinfo}) async {
|
|||||||
//标记中心偏移
|
//标记中心偏移
|
||||||
enabled: enable,
|
enabled: enable,
|
||||||
draggable: dragable);
|
draggable: dragable);
|
||||||
|
} else if (Platform.isAndroid) {
|
||||||
|
marker = BMFMarker(
|
||||||
|
position: getBMFCoordinate(listDwinfo[i]["dwzb"]),
|
||||||
|
// title: '${listDwinfo[i]["id"].toString()}、${listDwinfo[i]["dwmc"]}',
|
||||||
|
title: '${(i + 1).toString()}、${listDwinfo[i]["dwmc"]}',
|
||||||
|
subtitle: 'test',
|
||||||
|
// identifier: '${listDwinfo[i]["id"].toString()}、${listDwinfo[i]["dwmc"]}',
|
||||||
|
identifier: '${(i + 1).toString()}、${listDwinfo[i]["dwmc"]}',
|
||||||
|
|
||||||
|
// android版使用
|
||||||
|
icon: 'assets/images/location.png',
|
||||||
|
|
||||||
|
// 为IOS在百度地图中显示文本图标
|
||||||
|
// icon: "$g_myIconPathPre/${g_myIconPre}${i + 1}.png",
|
||||||
|
// icon: '/data/user/0/com.example.hyzp_yibin_bmfmap/app_flutter/myIcons/myIcon01.png',
|
||||||
|
|
||||||
|
/// 默认情况下, annotation view的中心位于annotation的坐标位置,
|
||||||
|
/// 可以设置centerOffset改变view的位置,正的偏移使view朝右下方移动,负的朝左上方,单位是像素
|
||||||
|
/// 目前Android只支持Y轴设置偏移量对应SDK的 yOffset(int yOffset) 方法
|
||||||
|
/// 添加标记 BMFMarker 百度官方有 centerOffset 偏移参数,
|
||||||
|
/// 文本标签 BMFText 官方没有 centerOffset 偏移参数,我取消了 BMFMarker 的偏移。你看这样行吗?
|
||||||
|
/// 按公司要求,为更准确定位,取消 BMFMarker 的偏移
|
||||||
|
centerOffset: BMFPoint(0, 0),
|
||||||
|
//标记中心偏移
|
||||||
|
enabled: enable,
|
||||||
|
draggable: dragable);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 百度地图的脑残设计,用Flutter添加多个BMFMarker时,必须在添加BMFMarker时自己保存ID,
|
// 百度地图的脑残设计,用Flutter添加多个BMFMarker时,必须在添加BMFMarker时自己保存ID,
|
||||||
// 否则响应点击时无法确定用户点击的是哪个定位标注
|
// 否则响应点击时无法确定用户点击的是哪个定位标注
|
||||||
// 代码不会自动返回,也没有任何文档说明,是花了一天时间搜索网络无果,是自己翻江倒海摸索出来的
|
// 代码不会自动返回,也没有任何文档说明,是花了一天时间搜索网络无果,是自己翻江倒海摸索出来的
|
||||||
@@ -72,34 +107,36 @@ Future getListBMFMarker({List listDwinfo}) async {
|
|||||||
g_map_BMFMarkerID_dwIndex[marker.getId()] = i;
|
g_map_BMFMarkerID_dwIndex[marker.getId()] = i;
|
||||||
g_listBMFMarker.add(marker);
|
g_listBMFMarker.add(marker);
|
||||||
|
|
||||||
// android专有
|
// android版专有
|
||||||
// g_listBMFText.add(BMFText(
|
if (Platform.isAndroid) {
|
||||||
// // text: '${listDwinfo[i]["id"].toString()}、${listDwinfo[i]["dwmc"]}',
|
g_listBMFText.add(BMFText(
|
||||||
// text: '${(i + 1).toString()}、${listDwinfo[i]["dwmc"]}',
|
// text: '${listDwinfo[i]["id"].toString()}、${listDwinfo[i]["dwmc"]}',
|
||||||
// //纬度偏移-上下 off_latitude, 经度偏移-左右 off_longitude
|
text: '${(i + 1).toString()}、${listDwinfo[i]["dwmc"]}',
|
||||||
// //已经在zoomLevel = 15时调整好定位标记与文本标记的相对位置
|
//纬度偏移-上下 off_latitude, 经度偏移-左右 off_longitude
|
||||||
// // ,当地图缩放时,会发生位置变化,必须使用 Provider 或者 EventBus 进行跟踪更新
|
//已经在zoomLevel = 15时调整好定位标记与文本标记的相对位置
|
||||||
//
|
// ,当地图缩放时,会发生位置变化,必须使用 Provider 或者 EventBus 进行跟踪更新
|
||||||
// //https://time.geekbang.org/column/article/131890
|
|
||||||
// //老师,provider、eventBus的用途有啥区别吗,都可以做状态的通知
|
//https://time.geekbang.org/column/article/131890
|
||||||
// // 作者回复: Provider 主要是用来做数据读写共享;event_bus主要是用来做数据状态通知、实现组件间单向数据传递。
|
//老师,provider、eventBus的用途有啥区别吗,都可以做状态的通知
|
||||||
// //如果我们的应用足够简单,数据流动的方向和顺序是清晰的,我们只需要将数据映射成视图就可以了。
|
// 作者回复: Provider 主要是用来做数据读写共享;event_bus主要是用来做数据状态通知、实现组件间单向数据传递。
|
||||||
// // 作为声明式的框架,Flutter 可以自动处理数据到渲染的全过程,通常并不需要 Provider 状态管理。
|
//如果我们的应用足够简单,数据流动的方向和顺序是清晰的,我们只需要将数据映射成视图就可以了。
|
||||||
// // position: getBMFCoordinate(listDwinfo[i]["dwzb"],
|
// 作为声明式的框架,Flutter 可以自动处理数据到渲染的全过程,通常并不需要 Provider 状态管理。
|
||||||
// // off_latitude: -0.0002 * g_zoomLevel * _scale,
|
// position: getBMFCoordinate(listDwinfo[i]["dwzb"],
|
||||||
// // off_longitude: -0.00009 * g_zoomLevel * _scale),
|
// off_latitude: -0.0002 * g_zoomLevel * _scale,
|
||||||
// position: getBMFCoordinate(listDwinfo[i]["dwzb"]),
|
// off_longitude: -0.00009 * g_zoomLevel * _scale),
|
||||||
// //自己控制off_latitude、off_longitude效果不好
|
position: getBMFCoordinate(listDwinfo[i]["dwzb"]),
|
||||||
// bgColor: Colors.yellow,
|
//自己控制off_latitude、off_longitude效果不好
|
||||||
// fontColor: Colors.black,
|
bgColor: Colors.yellow,
|
||||||
// fontSize: 35,
|
fontColor: Colors.black,
|
||||||
// // typeFace:
|
fontSize: 35,
|
||||||
// // BMFTypeFace(familyName: BMFFamilyName.sMonospace, textStype: BMFTextStyle.BOLD_ITALIC),
|
// typeFace:
|
||||||
// typeFace: BMFTypeFace(familyName: BMFFamilyName.sMonospace, textStype: BMFTextStyle.BOLD),
|
// BMFTypeFace(familyName: BMFFamilyName.sMonospace, textStype: BMFTextStyle.BOLD_ITALIC),
|
||||||
// alignY: BMFVerticalAlign.ALIGN_TOP,
|
typeFace: BMFTypeFace(familyName: BMFFamilyName.sMonospace, textStype: BMFTextStyle.BOLD),
|
||||||
// alignX: BMFHorizontalAlign.ALIGN_LEFT,
|
alignY: BMFVerticalAlign.ALIGN_TOP,
|
||||||
// rotate: 0.0,
|
alignX: BMFHorizontalAlign.ALIGN_LEFT,
|
||||||
// zIndex: 99));
|
rotate: 0.0,
|
||||||
|
zIndex: 99));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'dart:io';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
@@ -694,6 +695,8 @@ Future getAllSumCll(String field, List listStatis) async {
|
|||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// 百度地图初始化
|
// 百度地图初始化
|
||||||
Future bmfInit() async {
|
Future bmfInit() async {
|
||||||
|
// 只有IOS版才需要
|
||||||
|
if (Platform.isIOS) {
|
||||||
g_myIconPathPre = await createDir(g_myIconDir);
|
g_myIconPathPre = await createDir(g_myIconDir);
|
||||||
print("g_myIconPathPre = $g_myIconPathPre");
|
print("g_myIconPathPre = $g_myIconPathPre");
|
||||||
// g_myIconPathPre = /data/user/0/com.example.hyzp_yibin_bmfmap/app_flutter/myIcons
|
// g_myIconPathPre = /data/user/0/com.example.hyzp_yibin_bmfmap/app_flutter/myIcons
|
||||||
@@ -709,6 +712,7 @@ Future bmfInit() async {
|
|||||||
// runApp(MyApp());
|
// runApp(MyApp());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (Platform.isAndroid) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user