Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
amap_flutter_map
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
amap_flutter_map
Commits
a0a2b526
提交
a0a2b526
authored
12月 02, 2022
作者:
袁静春
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
提交:修改通道和文件,适配poi;
上级
72db3daa
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
149 行增加
和
15 行删除
+149
-15
AMapFlutterMapPlugin.m
ios/Classes/AMapFlutterMapPlugin.m
+25
-0
amap_flutter_map.dart
lib/amap_flutter_map.dart
+2
-0
amap_controller.dart
lib/src/amap_controller.dart
+1
-3
amap_poisearch_controller.dart
lib/src/amap_poisearch_controller.dart
+38
-0
amap_flutter_platform.dart
lib/src/core/amap_flutter_platform.dart
+8
-0
method_channel_amap_flutter_map.dart
lib/src/core/method_channel_amap_flutter_map.dart
+9
-12
method_channel_amap_flutter_search.dart
lib/src/core/method_channel_amap_flutter_search.dart
+66
-0
没有找到文件。
ios/Classes/AMapFlutterMapPlugin.m
浏览文件 @
a0a2b526
...
...
@@ -13,6 +13,31 @@
withId
:
@"com.amap.flutter.map"
gestureRecognizersBlockingPolicy
:
FlutterPlatformViewGestureRecognizersBlockingPolicyWaitUntilTouchesEnded
];
//注册 - MethodChannel
FlutterMethodChannel
*
channel
=
[
FlutterMethodChannel
methodChannelWithName
:
@"amap_flutter_map_search"
binaryMessenger
:[
registrar
messenger
]];
AMapFlutterMapPlugin
*
instance
=
[[
AMapFlutterMapPlugin
alloc
]
init
];
[
registrar
addMethodCallDelegate
:
instance
channel
:
channel
];
}
// 使用[MethodChannel]与Native代码通信的[AMapFlutterPlatform]的实现。
-
(
void
)
handleMethodCall
:
(
FlutterMethodCall
*
)
call
result
:
(
FlutterResult
)
result
{
NSLog
(
@"--- AMapFlutterMapPlugin ---: call method -> %@"
,
call
.
method
);
NSDictionary
*
arguments
=
call
.
arguments
;
__weak
AMapFlutterMapPlugin
*
weakSelf
=
self
;
if
([
@"camera#searchPOI#keywords"
isEqualToString
:
call
.
method
])
{
@try
{
if
([
arguments
.
allKeys
containsObject
:
@"keywords"
])
{
NSString
*
keywords
=
arguments
[
@"keywords"
];
NSLog
(
@"keywords:%@"
,
keywords
);
}
result
(
nil
);
}
@catch
(
FlutterError
*
e
)
{
result
(
e
);
}
}
}
@end
lib/amap_flutter_map.dart
浏览文件 @
a0a2b526
...
...
@@ -8,6 +8,7 @@ import 'package:amap_flutter_base/amap_flutter_base.dart';
import
'package:amap_flutter_map/src/core/amap_flutter_platform.dart'
;
import
'package:amap_flutter_map/src/core/map_event.dart'
;
import
'package:amap_flutter_map/src/core/method_channel_amap_flutter_map.dart'
;
import
'package:amap_flutter_map/src/core/method_channel_amap_flutter_search.dart'
;
import
'package:amap_flutter_map/src/types/types.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/gestures.dart'
;
...
...
@@ -18,3 +19,4 @@ export 'package:amap_flutter_map/src/types/types.dart';
part
'src/amap_controller.dart'
;
part
'src/amap_widget.dart'
;
part
'src/amap_poisearch_controller.dart'
;
lib/src/amap_controller.dart
浏览文件 @
a0a2b526
part of
amap_flutter_map
;
final
MethodChannelAMapFlutterMap
_methodChannel
=
AMapFlutterPlatform
.
instance
as
MethodChannelAMapFlutterMap
;
final
MethodChannelAMapFlutterMap
_methodChannel
=
AMapFlutterPlatform
.
instance
as
MethodChannelAMapFlutterMap
;
/// 地图通信中心
class
AMapController
{
...
...
@@ -151,7 +150,6 @@ class AMapController {
}
//地图可视区域
Future
<
dynamic
>
getVisibleRegion
()
{
return
_methodChannel
.
getVisibleRegion
(
mapId:
mapId
);
}
...
...
lib/src/amap_poisearch_controller.dart
0 → 100644
浏览文件 @
a0a2b526
part of
amap_flutter_map
;
final
MethodChannelAMapFlutterSearch
_searchMethodChannel
=
AMapFlutterPlatform
.
instance
as
MethodChannelAMapFlutterSearch
;
class
AMapPoiSearchController
{
/// 单例
static
AMapPoiSearchController
instance
=
AMapPoiSearchController
.
_
();
AMapPoiSearchController
.
_
()
{
initPoiSearch
();
}
/// 初始化方法
initPoiSearch
()
async
{
await
_searchMethodChannel
.
init
(
888
);
}
void
disponse
()
{
_searchMethodChannel
.
dispose
(
id:
888
);
}
@visibleForTesting
MethodChannel
get
channel
{
return
_searchMethodChannel
.
searchChannel
();
}
/// poi 搜索
Future
<
void
>
keywordsSearch
(
String
keyWord
)
{
return
_searchMethodChannel
.
keywordsSearch
(
keyWord
);
}
/// 周边搜索
Future
<
void
>
aroundSearch
(
double
latitude
,
double
longitude
)
{
return
_searchMethodChannel
.
aroundSearch
(
latitude
,
longitude
);
}
}
\ No newline at end of file
lib/src/core/amap_flutter_platform.dart
浏览文件 @
a0a2b526
import
'package:amap_flutter_map/src/core/method_channel_amap_flutter_map.dart'
;
import
'package:amap_flutter_map/src/core/method_channel_amap_flutter_search.dart'
;
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/gestures.dart'
;
...
...
@@ -10,17 +11,24 @@ abstract class AMapFlutterPlatform extends PlatformInterface {
static
final
Object
_token
=
Object
();
AMapFlutterPlatform
()
:
super
(
token:
_token
);
static
AMapFlutterPlatform
_instance
=
MethodChannelAMapFlutterMap
();
static
AMapFlutterPlatform
_poiInstance
=
MethodChannelAMapFlutterSearch
();
/// The default instance of [AMapFlutterPlatform] to use.
///
/// Defaults to [MethodChannelAMapFlutterMap].
static
AMapFlutterPlatform
get
instance
=>
_instance
;
static
AMapFlutterPlatform
get
poiInstance
=>
_poiInstance
;
static
set
instance
(
AMapFlutterPlatform
instance
)
{
PlatformInterface
.
verifyToken
(
instance
,
_token
);
_instance
=
instance
;
}
static
set
poiInstance
(
AMapFlutterPlatform
instance
)
{
PlatformInterface
.
verifyToken
(
instance
,
_token
);
_poiInstance
=
instance
;
}
/// /// Initializes the platform interface with [id].
///
/// This method is called when the plugin is first initialized.
...
...
lib/src/core/method_channel_amap_flutter_map.dart
浏览文件 @
a0a2b526
import
'dart:async'
;
import
'dart:typed_data'
;
import
'package:amap_flutter_base/amap_flutter_base.dart'
;
import
'package:amap_flutter_map/src/core/amap_flutter_platform.dart'
;
import
'package:amap_flutter_map/src/types/input_tips_result.dart'
;
...
...
@@ -12,13 +11,13 @@ import 'package:flutter/foundation.dart';
import
'package:flutter/gestures.dart'
;
import
'package:flutter/services.dart'
;
import
'package:stream_transform/stream_transform.dart'
;
import
'map_event.dart'
;
const
VIEW_TYPE
=
'com.amap.flutter.map'
;
/// 使用[MethodChannel]与Native代码通信的[AMapFlutterPlatform]的实现。
class
MethodChannelAMapFlutterMap
implements
AMapFlutterPlatform
{
final
Map
<
int
,
MethodChannel
>
_channels
=
{};
MethodChannel
channel
(
int
mapId
)
{
...
...
@@ -116,39 +115,37 @@ class MethodChannelAMapFlutterMap implements AMapFlutterPlatform {
}
// handleMethodCall的`broadcast`
final
StreamController
<
MapEvent
>
_mapEventStreamController
=
StreamController
<
MapEvent
>.
broadcast
();
final
StreamController
<
MapEvent
>
_mapEventStreamController
=
StreamController
<
MapEvent
>.
broadcast
();
// 根据mapid返回相应的event.
Stream
<
MapEvent
>
_events
(
int
mapId
)
=>
_mapEventStreamController
.
stream
.
where
((
event
)
=>
event
.
mapId
==
mapId
);
Stream
<
MapEvent
>
_events
(
int
mapId
)
=>
_mapEventStreamController
.
stream
.
where
((
event
)
=>
event
.
mapId
==
mapId
);
//定位回调
//
定位回调
Stream
<
LocationChangedEvent
>
onLocationChanged
({
required
int
mapId
})
{
return
_events
(
mapId
).
whereType
<
LocationChangedEvent
>();
}
//Camera 移动回调
//
Camera 移动回调
Stream
<
CameraPositionMoveEvent
>
onCameraMove
({
required
int
mapId
})
{
return
_events
(
mapId
).
whereType
<
CameraPositionMoveEvent
>();
}
//
/
Camera 移动结束回调
//
Camera 移动结束回调
Stream
<
CameraPositionMoveEndEvent
>
onCameraMoveEnd
({
required
int
mapId
})
{
return
_events
(
mapId
).
whereType
<
CameraPositionMoveEndEvent
>();
}
//
/
Camera 搜索POI回调
//
Camera 搜索POI回调
Stream
<
MapSearchPOIEvent
>
mapSearchPOI
({
required
int
mapId
})
{
return
_events
(
mapId
).
whereType
<
MapSearchPOIEvent
>();
}
//
/
Camera 搜索inputtips回调
//
Camera 搜索inputtips回调
Stream
<
MapSearchInputTipsEvent
>
mapSearchInputTips
({
required
int
mapId
})
{
return
_events
(
mapId
).
whereType
<
MapSearchInputTipsEvent
>();
}
//
/
Camera 搜索regeocode回调
//
Camera 搜索regeocode回调
Stream
<
MapSearchRegeocodeEvent
>
mapSearchRegeocode
({
required
int
mapId
})
{
return
_events
(
mapId
).
whereType
<
MapSearchRegeocodeEvent
>();
}
...
...
lib/src/core/method_channel_amap_flutter_search.dart
0 → 100644
浏览文件 @
a0a2b526
import
'package:flutter/services.dart'
;
import
'package:flutter/src/foundation/basic_types.dart'
;
import
'package:flutter/src/gestures/recognizer.dart'
;
import
'package:flutter/src/widgets/framework.dart'
;
import
'amap_flutter_platform.dart'
;
/// 使用[MethodChannel]与Native代码通信的[AMapFlutterPlatform]的实现。
class
MethodChannelAMapFlutterSearch
implements
AMapFlutterPlatform
{
late
final
MethodChannel
?
_channel
;
MethodChannel
searchChannel
()
{
return
_channel
!;
}
@override
Future
<
void
>
init
(
int
mapId
)
{
MethodChannel
?
channel
=
_channel
;
if
(
channel
==
null
)
{
channel
=
MethodChannel
(
'amap_flutter_map_search'
);
channel
.
setMethodCallHandler
((
call
)
=>
_handleMethodCall
(
call
));
_channel
=
channel
;
}
return
channel
.
invokeMethod
<
void
>(
'map#waitForMap'
);
}
Future
<
dynamic
>
_handleMethodCall
(
MethodCall
call
)
async
{
switch
(
call
.
method
)
{
case
'map#onPoiTouched'
:
try
{
}
catch
(
e
)
{
print
(
'map#onPoiTouched error===>'
+
e
.
toString
());
}
break
;
}
}
// 关键字搜索
Future
<
void
>
keywordsSearch
(
String
keywords
)
{
return
searchChannel
().
invokeMethod
<
dynamic
>(
'camera#searchPOI#keywords'
,
<
String
,
dynamic
>{
'keywords'
:
keywords
,
});
}
// 周边搜索
Future
<
void
>
aroundSearch
(
double
latitude
,
double
longitude
)
{
return
searchChannel
().
invokeMethod
<
dynamic
>(
'camera#searchPOI#around'
,
<
String
,
dynamic
>{
'latitude'
:
latitude
,
'longitude'
:
longitude
,
});
}
/// 重写的方法
@override
Widget
buildView
(
Map
<
String
,
dynamic
>
creationParams
,
Set
<
Factory
<
OneSequenceGestureRecognizer
>>
gestureRecognizers
,
PlatformViewCreatedCallback
onPlatformViewCreated
)
{
throw
UnimplementedError
();
}
@override
void
dispose
({
required
int
id
})
{
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论