提交 a0a2b526 authored 作者: 袁静春's avatar 袁静春

提交:修改通道和文件,适配poi;

上级 72db3daa
......@@ -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
......@@ -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';
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);
}
......
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
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.
......
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>();
}
......
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论