hyzp_ybqx-Commit135:为了支持ios版在百度地图中显示文本图标,已经替换使用my_flutter_bmfmap-1.0.2插件,安卓版编译运行正常
@ -1 +1 @@
|
||||
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":20220426,"versionName":"1.4.28","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
|
||||
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":20220502,"versionName":"1.4.29","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
|
||||
@ -0,0 +1,13 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Flutter",
|
||||
"request": "launch",
|
||||
"type": "dart"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
## 1.0.0
|
||||
|
||||
* TODO: Describe initial release.
|
||||
|
||||
## 1.0.1
|
||||
提升版本号
|
||||
|
||||
## 1.0.2
|
||||
解决了与其它Flutter插件冲突的问题
|
||||
@ -0,0 +1,13 @@
|
||||
Copyright (C) 2020 Baidu, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@ -0,0 +1,14 @@
|
||||
# flutter_bmfmap
|
||||
|
||||
A new Flutter plugin for BaiDuMap.
|
||||
|
||||
## Getting Started
|
||||
|
||||
This project is a starting point for a Flutter
|
||||
[plug-in package](https://flutter.dev/developing-packages/),
|
||||
a specialized package that includes platform-specific implementation code for
|
||||
Android and/or iOS.
|
||||
|
||||
For help getting started with Flutter, view our
|
||||
[online documentation](https://flutter.dev/docs), which offers tutorials,
|
||||
samples, guidance on mobile development, and a full API reference.
|
||||
@ -0,0 +1,27 @@
|
||||
# include: package:pedantic/analysis_options.1.9.0.yaml
|
||||
|
||||
analyzer:
|
||||
errors:
|
||||
unused_import: warning
|
||||
unused_shown_name: warning
|
||||
exclude:
|
||||
- 'doc/**'
|
||||
- 'lib/src/third_party/pkg/**'
|
||||
- 'lib/templates/*.html'
|
||||
- 'pub.dartlang.org/**'
|
||||
- 'testing/**'
|
||||
- 'testing/test_package_flutter_plugin/**'
|
||||
- 'testing/test_package_export_error/**'
|
||||
linter:
|
||||
rules:
|
||||
# - always_declare_return_types
|
||||
- annotate_overrides
|
||||
- avoid_init_to_null
|
||||
- directives_ordering
|
||||
- no_adjacent_strings_in_list
|
||||
- package_api_docs
|
||||
- prefer_final_fields
|
||||
- prefer_generic_function_type_aliases
|
||||
- slash_for_doc_comments
|
||||
- unawaited_futures
|
||||
# - unnecessary_brace_in_string_interps
|
||||
@ -0,0 +1,8 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
@ -0,0 +1,46 @@
|
||||
group 'com.baidu.flutter_bmfmap'
|
||||
version '1.0'
|
||||
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
}
|
||||
lintOptions {
|
||||
disable 'InvalidPackage'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(includes: ['*.jar'], dir: 'libs')
|
||||
implementation rootProject.findProject(":flutter_bmfbase")
|
||||
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
org.gradle.jvmargs=-Xmx1536M
|
||||
android.enableR8=true
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
||||
@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
|
||||
@ -0,0 +1 @@
|
||||
rootProject.name = 'flutter_bmfmap'
|
||||
@ -0,0 +1,3 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.baidu.flutter_bmfmap">
|
||||
</manifest>
|
||||
@ -0,0 +1,38 @@
|
||||
package com.baidu.flutter_bmfmap;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.baidu.mapapi.map.MapView;
|
||||
|
||||
import io.flutter.plugin.common.BinaryMessenger;
|
||||
import io.flutter.plugin.common.EventChannel;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
public class BMFEventHandler<ViewType> implements EventChannel.StreamHandler {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private ViewType mMapView;
|
||||
|
||||
private BinaryMessenger mMessager;
|
||||
|
||||
private MethodChannel mMethodChannel;
|
||||
private EventChannel mEventChannel;
|
||||
|
||||
public BMFEventHandler(Context context, ViewType mapView, MethodChannel methodChannel, EventChannel eventChannel){
|
||||
mContext = context;
|
||||
mMapView = mapView;
|
||||
mMethodChannel = methodChannel;
|
||||
mEventChannel = eventChannel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListen(Object arguments, EventChannel.EventSink events) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(Object arguments) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package com.baidu.flutter_bmfmap;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.baidu.flutter_bmfmap.map.FlutterCommonMapView;
|
||||
|
||||
import io.flutter.plugin.common.EventChannel;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
public class BMFHandlerHelper <ViewType>{
|
||||
|
||||
private MethodChannel mMethodChannel;
|
||||
|
||||
private BMFMethodHandler mBMFMethodHandler;
|
||||
|
||||
private EventChannel mEventChannel;
|
||||
|
||||
private BMFEventHandler mBMFEventHandler;
|
||||
|
||||
public BMFHandlerHelper(Context context
|
||||
, FlutterCommonMapView mapView
|
||||
, MethodChannel methodChannel
|
||||
, EventChannel eventChannel){
|
||||
init(context, mapView, methodChannel, eventChannel);
|
||||
}
|
||||
|
||||
private void init(Context context, FlutterCommonMapView mapView, MethodChannel methodChannel, EventChannel eventChannel){
|
||||
mMethodChannel = methodChannel;
|
||||
mBMFMethodHandler = new BMFMethodHandler(context, mapView, methodChannel, eventChannel);
|
||||
mMethodChannel.setMethodCallHandler(mBMFMethodHandler);
|
||||
|
||||
mEventChannel = eventChannel;
|
||||
mBMFEventHandler = new BMFEventHandler(context, mapView, methodChannel, eventChannel);
|
||||
mEventChannel.setStreamHandler(mBMFEventHandler);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
package com.baidu.flutter_bmfmap;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.baidu.flutter_bmfmap.map.mapHandler.BMapHandlerFactory;
|
||||
import com.baidu.flutter_bmfmap.map.FlutterCommonMapView;
|
||||
import com.baidu.flutter_bmfmap.map.overlayHandler.OverlayHandlerFactory;
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
|
||||
import io.flutter.plugin.common.EventChannel;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
public class BMFMethodHandler implements MethodChannel.MethodCallHandler {
|
||||
private static final String TAG = "BMFMethodHandler";
|
||||
|
||||
private Context mContext;
|
||||
private FlutterCommonMapView mMapView;
|
||||
private final BaiduMap mBaiduMap;
|
||||
private MethodChannel mMethodChannel;
|
||||
private EventChannel mEventChannel;
|
||||
|
||||
public BMFMethodHandler(Context context
|
||||
,FlutterCommonMapView mapView
|
||||
,MethodChannel methodChannel
|
||||
,EventChannel eventChannel){
|
||||
mContext = context;
|
||||
mMapView = mapView;
|
||||
mBaiduMap = mapView.getBaiduMap();
|
||||
mMethodChannel = methodChannel;
|
||||
mEventChannel = eventChannel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG,"onMethodCall enter");
|
||||
}
|
||||
|
||||
if(null == call || null == result){
|
||||
Log.d(TAG,"null == call || null == result");
|
||||
return;
|
||||
}
|
||||
|
||||
if (null == mMapView || null == mBaiduMap) {
|
||||
Log.d(TAG,"mMapView == call || mBaiduMap == result");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean ret = OverlayHandlerFactory.getInstance(mBaiduMap).dispatchMethodHandler(call,
|
||||
result);
|
||||
|
||||
if (!ret) {
|
||||
BMapHandlerFactory.getInstance(mMapView).dispatchMethodHandler(mContext,call,
|
||||
result, mMethodChannel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,127 @@
|
||||
package com.baidu.flutter_bmfmap;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.baidu.flutter_bmfmap.map.OfflineHandler;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants;
|
||||
|
||||
import io.flutter.embedding.engine.plugins.FlutterPlugin;
|
||||
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
|
||||
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
|
||||
import io.flutter.plugin.common.BinaryMessenger;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
||||
import io.flutter.plugin.common.MethodChannel.Result;
|
||||
import io.flutter.plugin.common.PluginRegistry.Registrar;
|
||||
import io.flutter.plugin.platform.PlatformViewRegistry;
|
||||
|
||||
/** FlutterBmfmapPlugin */
|
||||
public class FlutterBmfmapPlugin implements FlutterPlugin, ActivityAware, MethodCallHandler {
|
||||
private static final String TAG = FlutterBmfmapPlugin.class.getSimpleName();
|
||||
|
||||
private OfflineHandler mOfflineHandler;
|
||||
private PlatformViewRegistry mPlatformViewRegistry;
|
||||
private BinaryMessenger mMessenger;
|
||||
|
||||
@Override
|
||||
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
|
||||
if(null == flutterPluginBinding){
|
||||
return;
|
||||
}
|
||||
|
||||
mMessenger = flutterPluginBinding.getBinaryMessenger();
|
||||
if (null == mMessenger) {
|
||||
return;
|
||||
}
|
||||
|
||||
mOfflineHandler = new OfflineHandler();
|
||||
mOfflineHandler.init(mMessenger);
|
||||
|
||||
mPlatformViewRegistry = flutterPluginBinding.getPlatformViewRegistry();
|
||||
}
|
||||
|
||||
// This static function is optional and equivalent to onAttachedToEngine. It supports the old
|
||||
// pre-Flutter-1.12 Android projects. You are encouraged to continue supporting
|
||||
// plugin registration via this function while apps migrate to use the new Android APIs
|
||||
// post-flutter-1.12 via https://flutter.dev/go/android-project-migration.
|
||||
//
|
||||
// It is encouraged to share logic between onAttachedToEngine and registerWith to keep
|
||||
// them functionally equivalent. Only one of onAttachedToEngine or registerWith will be called
|
||||
// depending on the user's project. onAttachedToEngine or registerWith must both be defined
|
||||
// in the same class.
|
||||
public static void registerWith(Registrar registrar) {
|
||||
OfflineHandler offlineHandler = new OfflineHandler();
|
||||
offlineHandler.init(registrar.messenger());
|
||||
|
||||
registrar.platformViewRegistry().registerViewFactory(
|
||||
Constants.ViewType.sMapView,
|
||||
new MapViewFactory(registrar.activity()
|
||||
, registrar.messenger()
|
||||
, Constants.ViewType.sMapView));
|
||||
|
||||
registrar.platformViewRegistry().registerViewFactory(
|
||||
Constants.ViewType.sTextureMapView,
|
||||
new TextureMapViewFactory(registrar.activity()
|
||||
, registrar.messenger()
|
||||
, Constants.ViewType.sTextureMapView));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
|
||||
if (call.method.equals("getPlatformVersion")) {
|
||||
result.success("Android " + android.os.Build.VERSION.RELEASE);
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
|
||||
if(null == binding){
|
||||
return;
|
||||
}
|
||||
|
||||
BinaryMessenger binaryMessenger = binding.getBinaryMessenger();
|
||||
if(null == binaryMessenger){
|
||||
return;
|
||||
}
|
||||
|
||||
mOfflineHandler.unInit(binding.getBinaryMessenger());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToActivity(ActivityPluginBinding binding) {
|
||||
if(null == binding || null == mPlatformViewRegistry || null == mMessenger){
|
||||
return;
|
||||
}
|
||||
|
||||
mPlatformViewRegistry.registerViewFactory(
|
||||
Constants.ViewType.sMapView,
|
||||
new MapViewFactory(binding.getActivity()
|
||||
, mMessenger
|
||||
, Constants.ViewType.sMapView));
|
||||
|
||||
mPlatformViewRegistry.registerViewFactory(
|
||||
Constants.ViewType.sTextureMapView,
|
||||
new TextureMapViewFactory(binding.getActivity()
|
||||
, mMessenger
|
||||
, Constants.ViewType.sTextureMapView));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromActivityForConfigChanges() {
|
||||
Log.d(TAG, "onDetachedFromActivityForConfigChanges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding) {
|
||||
Log.d(TAG, "onReattachedToActivityForConfigChanges");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromActivity() {
|
||||
Log.d(TAG, "onDetachedFromActivity");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package com.baidu.flutter_bmfmap;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import io.flutter.plugin.common.BinaryMessenger;
|
||||
import io.flutter.plugin.common.StandardMessageCodec;
|
||||
import io.flutter.plugin.platform.PlatformView;
|
||||
import io.flutter.plugin.platform.PlatformViewFactory;
|
||||
|
||||
import com.baidu.flutter_bmfmap.map.FlutterMapView;
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
|
||||
public class MapViewFactory extends PlatformViewFactory {
|
||||
|
||||
private static final String TAG = "ViewFactory";
|
||||
private BinaryMessenger mMessenger;
|
||||
private Context mContext;
|
||||
private String mViewType;
|
||||
/**
|
||||
* @param messenger the codec used to decode the args parameter of {@link #create}.
|
||||
*/
|
||||
public MapViewFactory(Context context, BinaryMessenger messenger, String viewType) {
|
||||
super(StandardMessageCodec.INSTANCE);
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "ViewFactory");
|
||||
}
|
||||
mContext = context;
|
||||
mMessenger = messenger;
|
||||
mViewType = viewType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformView create(Context context, int viewId, Object args) {
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "create");
|
||||
}
|
||||
return new FlutterMapView(mContext, mMessenger, viewId, args, mViewType);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package com.baidu.flutter_bmfmap;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.baidu.flutter_bmfmap.map.FlutterMapView;
|
||||
import com.baidu.flutter_bmfmap.map.FlutterTextureMapView;
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
|
||||
import io.flutter.plugin.common.BinaryMessenger;
|
||||
import io.flutter.plugin.common.MessageCodec;
|
||||
import io.flutter.plugin.common.StandardMessageCodec;
|
||||
import io.flutter.plugin.platform.PlatformView;
|
||||
import io.flutter.plugin.platform.PlatformViewFactory;
|
||||
|
||||
public class TextureMapViewFactory extends PlatformViewFactory {
|
||||
|
||||
private static final String TAG = "ViewFactory";
|
||||
private BinaryMessenger mMessenger;
|
||||
private Context mContext;
|
||||
private String mViewType;
|
||||
/**
|
||||
* @param messenger the codec used to decode the args parameter of {@link #create}.
|
||||
*/
|
||||
public TextureMapViewFactory(Context context, BinaryMessenger messenger, String viewType) {
|
||||
super(StandardMessageCodec.INSTANCE);
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "ViewFactory");
|
||||
}
|
||||
mContext = context;
|
||||
mMessenger = messenger;
|
||||
mViewType = viewType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformView create(Context context, int viewId, Object args) {
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "create");
|
||||
}
|
||||
return new FlutterTextureMapView(mContext, mMessenger, viewId, args, mViewType);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package com.baidu.flutter_bmfmap.map;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class FlutterBaseMapView {
|
||||
|
||||
protected String mViewType;
|
||||
|
||||
protected boolean mResume = false;
|
||||
|
||||
protected int mGetViewCount = 0;
|
||||
|
||||
protected abstract void init(int viewId, Object args);
|
||||
|
||||
protected abstract void initMapView(Object args, FlutterCommonMapView flutterCommonMapView);
|
||||
|
||||
protected void initMapStatus(Map<String, Object> mapOptionsMap,
|
||||
FlutterCommonMapView flutterCommonMapView) {
|
||||
if (null == mapOptionsMap) {
|
||||
return;
|
||||
}
|
||||
|
||||
MapStateUpdateImp.getInstance()
|
||||
.setCommView(flutterCommonMapView)
|
||||
.updateMapState(mapOptionsMap);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
package com.baidu.flutter_bmfmap.map;
|
||||
|
||||
import com.baidu.flutter_bmfmap.utils.Constants;
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
import com.baidu.mapapi.map.MapView;
|
||||
import com.baidu.mapapi.map.TextureMapView;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class FlutterCommonMapView{
|
||||
protected String mViewType;
|
||||
public String getViewType(){
|
||||
return mViewType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setmViewType(String viewType){
|
||||
mViewType = viewType;
|
||||
}
|
||||
|
||||
abstract public MapView getMapView();
|
||||
abstract public TextureMapView getTextureMapView();
|
||||
|
||||
public BaiduMap getBaiduMap(){
|
||||
BaiduMap baiduMap = null;
|
||||
switch (mViewType){
|
||||
case Constants.ViewType.sMapView:
|
||||
baiduMap = getBaiduMapFromMapView();
|
||||
break;
|
||||
case Constants.ViewType.sTextureMapView:
|
||||
baiduMap = getBaiduMapFromTextureMapView();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return baiduMap;
|
||||
}
|
||||
|
||||
private BaiduMap getBaiduMapFromMapView(){
|
||||
MapView mapView = this.getMapView();
|
||||
if(null == mapView){
|
||||
return null;
|
||||
}
|
||||
|
||||
return mapView.getMap();
|
||||
}
|
||||
|
||||
private BaiduMap getBaiduMapFromTextureMapView(){
|
||||
TextureMapView textureMapView = this.getTextureMapView();
|
||||
if(null == textureMapView){
|
||||
return null;
|
||||
}
|
||||
|
||||
return textureMapView.getMap();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,170 @@
|
||||
package com.baidu.flutter_bmfmap.map;
|
||||
|
||||
import static com.baidu.flutter_bmfmap.utils.Constants.MAX_GET_VIEW_CNT_BY_FLUTTER_RESIZE;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.baidu.flutter_bmfmap.BMFHandlerHelper;
|
||||
import com.baidu.flutter_bmfmap.map.mapHandler.BMapHandlerFactory;
|
||||
import com.baidu.flutter_bmfmap.map.overlayHandler.OverlayHandlerFactory;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants;
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
import com.baidu.mapapi.map.MapView;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import io.flutter.plugin.common.BinaryMessenger;
|
||||
import io.flutter.plugin.common.EventChannel;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import io.flutter.plugin.platform.PlatformView;
|
||||
|
||||
public class FlutterMapView extends FlutterBaseMapView implements PlatformView {
|
||||
|
||||
private static final String TAG = "FlutterMapView";
|
||||
|
||||
private MapView mMapView;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private BinaryMessenger mMessager;
|
||||
|
||||
private BMFHandlerHelper mBMFHandlerHelper;
|
||||
|
||||
private MethodChannel mMethodChannel;
|
||||
|
||||
private EventChannel mEventChannel;
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (Constants.sConfigChangedAction.equals(action) && !mResume) {
|
||||
mResume = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public FlutterMapView(Context context,
|
||||
BinaryMessenger messenger,
|
||||
int viewId,
|
||||
Object args,
|
||||
String viewType) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "FlutterMapView");
|
||||
}
|
||||
mContext = context;
|
||||
mMessager = messenger;
|
||||
mViewType = viewType;
|
||||
init(viewId, args);
|
||||
}
|
||||
|
||||
protected void init(int viewId, Object args) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "init");
|
||||
}
|
||||
|
||||
mMapView = new MapView(mContext);
|
||||
FlutterCommonMapView mapViewWrapper = new MapViewWrapper(this, mViewType);
|
||||
initMapView(args, mapViewWrapper);
|
||||
|
||||
mMethodChannel = new MethodChannel(mMessager,
|
||||
Constants.VIEW_METHOD_CHANNEL_PREFIX + (char) (viewId + 97));
|
||||
|
||||
mEventChannel = new EventChannel(mMessager,
|
||||
Constants.VIEW_EVENT_CHANNEL_PREFIX + (char) (viewId + 97));
|
||||
|
||||
mBMFHandlerHelper =
|
||||
new BMFHandlerHelper(mContext, mapViewWrapper, mMethodChannel, mEventChannel);
|
||||
|
||||
new MapListener(new MapViewWrapper(this, mViewType), mMethodChannel);
|
||||
|
||||
IntentFilter intentFilter = new IntentFilter(Constants.sConfigChangedAction);
|
||||
LocalBroadcastManager.getInstance(mContext).registerReceiver(mReceiver, intentFilter);
|
||||
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "init success");
|
||||
}
|
||||
}
|
||||
|
||||
protected void initMapView(Object args, FlutterCommonMapView flutterCommonMapView) {
|
||||
if (null == mContext) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> mapOptionsMap = (Map<String, Object>) args;
|
||||
if (null == mapOptionsMap) {
|
||||
return;
|
||||
}
|
||||
|
||||
initMapStatus(mapOptionsMap, flutterCommonMapView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView() {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "getView");
|
||||
}
|
||||
|
||||
if (mResume) {
|
||||
mGetViewCount++;
|
||||
}
|
||||
|
||||
if (mGetViewCount >= MAX_GET_VIEW_CNT_BY_FLUTTER_RESIZE - 1) {
|
||||
mMapView.onResume();
|
||||
mResume = false;
|
||||
mGetViewCount = 0;
|
||||
}
|
||||
|
||||
return mMapView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFlutterViewAttached(@NonNull View flutterView) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "onFlutterViewAttached");
|
||||
}
|
||||
if (null != mMapView) {
|
||||
mMapView.onResume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFlutterViewDetached() {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "onFlutterViewDetached");
|
||||
}
|
||||
if (null != mMapView) {
|
||||
mMapView.onPause();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "dispose");
|
||||
}
|
||||
|
||||
LocalBroadcastManager.getInstance(mContext).unregisterReceiver(mReceiver);
|
||||
|
||||
BMapHandlerFactory.getInstance(null).clean();
|
||||
OverlayHandlerFactory.getInstance(null).clean();
|
||||
|
||||
if (null != mMapView) {
|
||||
mMapView.onDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
public void setResumeState(boolean resume) {
|
||||
mResume = true;
|
||||
}
|
||||
|
||||
public MapView getMapView() {
|
||||
return mMapView;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,152 @@
|
||||
package com.baidu.flutter_bmfmap.map;
|
||||
|
||||
import static com.baidu.flutter_bmfmap.utils.Constants.MAX_GET_VIEW_CNT_BY_FLUTTER_RESIZE;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.baidu.flutter_bmfmap.BMFHandlerHelper;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants;
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
import com.baidu.mapapi.map.TextureMapView;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import io.flutter.plugin.common.BinaryMessenger;
|
||||
import io.flutter.plugin.common.EventChannel;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import io.flutter.plugin.platform.PlatformView;
|
||||
|
||||
public class FlutterTextureMapView extends FlutterBaseMapView implements PlatformView {
|
||||
|
||||
private static final String TAG = "FlutterMapView";
|
||||
|
||||
private TextureMapView mTextureMapView;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private BinaryMessenger mMessager;
|
||||
|
||||
private BMFHandlerHelper mBMFHandlerHelper;
|
||||
|
||||
private MethodChannel mMethodChannel;
|
||||
|
||||
private EventChannel mEventChannel;
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (Constants.sConfigChangedAction.equals(action) && !mResume) {
|
||||
mResume = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public FlutterTextureMapView(Context context,
|
||||
BinaryMessenger messenger,
|
||||
int viewId,
|
||||
Object args,
|
||||
String viewType) {
|
||||
Log.d(TAG, "FlutterMapView");
|
||||
mContext = context;
|
||||
mMessager = messenger;
|
||||
mViewType = viewType;
|
||||
init(viewId, args);
|
||||
}
|
||||
|
||||
protected void init(int viewId, Object args) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "init");
|
||||
}
|
||||
|
||||
mTextureMapView = new TextureMapView(mContext);
|
||||
FlutterCommonMapView flutterCommonMapView =
|
||||
new TextureMapViewWrapper(mTextureMapView, mViewType);
|
||||
initMapView(args, flutterCommonMapView);
|
||||
|
||||
mMethodChannel = new MethodChannel(mMessager,
|
||||
Constants.VIEW_METHOD_CHANNEL_PREFIX + (char) (viewId + 97));
|
||||
|
||||
mEventChannel = new EventChannel(mMessager,
|
||||
Constants.VIEW_EVENT_CHANNEL_PREFIX + (char) (viewId + 97));
|
||||
|
||||
mBMFHandlerHelper =
|
||||
new BMFHandlerHelper(mContext, flutterCommonMapView, mMethodChannel, mEventChannel);
|
||||
|
||||
new MapListener(new TextureMapViewWrapper(mTextureMapView, mViewType), mMethodChannel);
|
||||
|
||||
IntentFilter intentFilter = new IntentFilter(Constants.sConfigChangedAction);
|
||||
LocalBroadcastManager.getInstance(mContext).registerReceiver(mReceiver, intentFilter);
|
||||
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "init success");
|
||||
}
|
||||
}
|
||||
|
||||
protected void initMapView(Object args, FlutterCommonMapView flutterCommonMapView) {
|
||||
if (null == mContext) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> mapOptionsMap = (Map<String, Object>) args;
|
||||
if (null == mapOptionsMap) {
|
||||
return;
|
||||
}
|
||||
|
||||
initMapStatus(mapOptionsMap, flutterCommonMapView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView() {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "getView");
|
||||
}
|
||||
|
||||
if (mResume) {
|
||||
mGetViewCount++;
|
||||
}
|
||||
|
||||
if (mGetViewCount >= MAX_GET_VIEW_CNT_BY_FLUTTER_RESIZE - 1) {
|
||||
mTextureMapView.onResume();
|
||||
mResume = false;
|
||||
mGetViewCount = 0;
|
||||
}
|
||||
|
||||
return mTextureMapView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFlutterViewAttached(@NonNull View flutterView) {
|
||||
if (null != mTextureMapView) {
|
||||
mTextureMapView.onResume();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFlutterViewDetached() {
|
||||
if (null != mTextureMapView) {
|
||||
mTextureMapView.onPause();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "dispose");
|
||||
}
|
||||
|
||||
LocalBroadcastManager.getInstance(mContext).unregisterReceiver(mReceiver);
|
||||
|
||||
if (null != mTextureMapView) {
|
||||
mTextureMapView.onDestroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,696 @@
|
||||
package com.baidu.flutter_bmfmap.map;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.baidu.flutter_bmfmap.utils.Constants;
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
import android.os.Message;
|
||||
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
import com.baidu.mapapi.map.MapBaseIndoorMapInfo;
|
||||
import com.baidu.mapapi.map.MapPoi;
|
||||
import com.baidu.mapapi.map.MapStatus;
|
||||
import com.baidu.mapapi.map.Marker;
|
||||
import com.baidu.mapapi.map.Polyline;
|
||||
import com.baidu.mapapi.model.LatLng;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import android.os.Handler;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import com.baidu.flutter_bmfmap.utils.ThreadPoolUtil;
|
||||
import com.baidu.mapapi.model.LatLngBounds;
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MapListener implements BaiduMap.OnMapClickListener ,BaiduMap.OnMapLoadedCallback,
|
||||
BaiduMap.OnMapStatusChangeListener ,BaiduMap.OnMapRenderCallback,BaiduMap.OnMapDrawFrameCallback,
|
||||
BaiduMap.OnBaseIndoorMapListener ,BaiduMap.OnMarkerClickListener,BaiduMap.OnPolylineClickListener,
|
||||
BaiduMap.OnMapDoubleClickListener,BaiduMap.OnMapLongClickListener,BaiduMap.OnMarkerDragListener,
|
||||
BaiduMap.OnMapRenderValidDataListener,BaiduMap.OnMyLocationClickListener {
|
||||
|
||||
private static final int DRAW_FRAME_MESSAGE = 0;
|
||||
private static final String TAG = "MapListener";
|
||||
private BaiduMap mBaiduMap;
|
||||
private MethodChannel mMethodChannel;
|
||||
private int mReason;
|
||||
private HashMap<String, HashMap> mStatusMap;
|
||||
|
||||
private final Handler mHandler = new Handler(){
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
if (msg.what == DRAW_FRAME_MESSAGE) {
|
||||
if (null != mStatusMap){
|
||||
mMethodChannel.invokeMethod(
|
||||
Constants.MethodProtocol.MapStateProtocol.sMapOnDrawMapFrameCallback,mStatusMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public MapListener(FlutterCommonMapView mapView, MethodChannel methodChannel) {
|
||||
this.mMethodChannel = methodChannel;
|
||||
|
||||
if (null == mapView) {
|
||||
return;
|
||||
}
|
||||
mBaiduMap = mapView.getBaiduMap();
|
||||
initListener();
|
||||
}
|
||||
|
||||
private void initListener() {
|
||||
if (null == mBaiduMap) {
|
||||
return;
|
||||
}
|
||||
mBaiduMap.setOnMapClickListener(this);
|
||||
mBaiduMap.setOnMapLoadedCallback(this);
|
||||
mBaiduMap.setOnMapStatusChangeListener(this);
|
||||
mBaiduMap.setOnMapDrawFrameCallback(this);
|
||||
mBaiduMap.setOnMapRenderCallbadk(this);
|
||||
mBaiduMap.setOnBaseIndoorMapListener(this);
|
||||
mBaiduMap.setOnMarkerClickListener(this);
|
||||
mBaiduMap.setOnPolylineClickListener(this);
|
||||
mBaiduMap.setOnMapDoubleClickListener(this);
|
||||
mBaiduMap.setOnMapLongClickListener(this);
|
||||
mBaiduMap.setOnMarkerDragListener(this);
|
||||
mBaiduMap.setOnMapRenderValidDataListener(this);
|
||||
mBaiduMap.setOnMyLocationClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapClick(LatLng latLng) {
|
||||
if (null == latLng || mMethodChannel == null) {
|
||||
return;
|
||||
}
|
||||
HashMap<String, HashMap> coordinateMap = new HashMap<>();
|
||||
HashMap<String, Double> coord = new HashMap<>();
|
||||
coord.put("latitude",latLng.latitude);
|
||||
coord.put("longitude",latLng.longitude);
|
||||
coordinateMap.put("coord",coord);
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.MapStateProtocol.sMapOnClickedMapBlankCallback,coordinateMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapPoiClick(MapPoi mapPoi) {
|
||||
if (null == mapPoi || mMethodChannel == null) {
|
||||
return;
|
||||
}
|
||||
HashMap<String, Double> pt = new HashMap<>();
|
||||
LatLng position = mapPoi.getPosition();
|
||||
if (null != position) {
|
||||
pt.put("latitude",mapPoi.getPosition().latitude);
|
||||
pt.put("longitude",mapPoi.getPosition().longitude);
|
||||
}
|
||||
HashMap<String, HashMap> poiMap = new HashMap<>();
|
||||
HashMap poi = new HashMap();
|
||||
poi.put("text",mapPoi.getName());
|
||||
poi.put("uid",mapPoi.getUid());
|
||||
poi.put("pt",pt);
|
||||
poiMap.put("poi",poi);
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.MapStateProtocol.sMapOnClickedMapPoiCallback,poiMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapLoaded() {
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.MapStateProtocol.sMapDidLoadCallback,"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapStatusChangeStart(MapStatus mapStatus) {
|
||||
if (null == mapStatus || mMethodChannel == null) {
|
||||
return;
|
||||
}
|
||||
HashMap<String, Double> targetScreenMap = new HashMap<>();
|
||||
Point targetScreen = mapStatus.targetScreen;
|
||||
if (null == targetScreen) {
|
||||
return;
|
||||
}
|
||||
targetScreenMap.put("x", (double) targetScreen.x);
|
||||
targetScreenMap.put("y", (double) targetScreen.y);
|
||||
HashMap<String, Double> targetMap = new HashMap<>();
|
||||
LatLng latLng = mapStatus.target;
|
||||
if (null == latLng){
|
||||
return;
|
||||
}
|
||||
targetMap.put("latitude", latLng.latitude);
|
||||
targetMap.put("longitude", latLng.longitude);
|
||||
|
||||
LatLngBounds bound = mapStatus.bound;
|
||||
if (null == bound) {
|
||||
return;
|
||||
}
|
||||
HashMap latLngBoundMap = latLngBounds(bound);
|
||||
if (null == latLngBoundMap) {
|
||||
return;
|
||||
}
|
||||
HashMap statusMap = new HashMap<>();
|
||||
HashMap status = new HashMap();
|
||||
status.put("fLevel",((double)mapStatus.zoom));
|
||||
double rotate = mapStatus.rotate;
|
||||
if (rotate > 180) {
|
||||
rotate = rotate - 360;
|
||||
}
|
||||
status.put("fRotation", rotate);
|
||||
status.put("fOverlooking",((double) mapStatus.overlook));
|
||||
status.put("targetScreenPt",targetScreenMap);
|
||||
status.put("targetGeoPt",targetMap);
|
||||
status.put("visibleMapBounds",latLngBoundMap);
|
||||
statusMap.put("mapStatus",status);
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.MapStateProtocol.sMapRegionWillChangeCallback,statusMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapStatusChangeStart(MapStatus mapStatus, int reason) {
|
||||
if (null == mapStatus || mMethodChannel == null) {
|
||||
return;
|
||||
}
|
||||
mReason = reason;
|
||||
HashMap<String, Double> targetScreenMap = new HashMap<>();
|
||||
Point targetScreen = mapStatus.targetScreen;
|
||||
if (null == targetScreen) {
|
||||
return;
|
||||
}
|
||||
targetScreenMap.put("x", (double) targetScreen.x);
|
||||
targetScreenMap.put("y", (double) targetScreen.y);
|
||||
HashMap<String, Double> targetMap = new HashMap<>();
|
||||
LatLng latLng = mapStatus.target;
|
||||
if (null == latLng){
|
||||
return;
|
||||
}
|
||||
targetMap.put("latitude", latLng.latitude);
|
||||
targetMap.put("longitude", latLng.longitude);
|
||||
|
||||
LatLngBounds bound = mapStatus.bound;
|
||||
if (null == bound) {
|
||||
return;
|
||||
}
|
||||
HashMap latLngBoundMap = latLngBounds(bound);
|
||||
if (null == latLngBoundMap) {
|
||||
return;
|
||||
}
|
||||
HashMap statusMap = new HashMap<>();
|
||||
HashMap status = new HashMap();
|
||||
status.put("fLevel",((double)mapStatus.zoom));
|
||||
double rotate = mapStatus.rotate;
|
||||
if (rotate > 180) {
|
||||
rotate = rotate - 360;
|
||||
}
|
||||
status.put("fRotation", rotate);
|
||||
status.put("fOverlooking",((double) mapStatus.overlook));
|
||||
status.put("targetScreenPt",targetScreenMap);
|
||||
status.put("targetGeoPt",targetMap);
|
||||
status.put("visibleMapBounds",latLngBoundMap);
|
||||
statusMap.put("mapStatus",status);
|
||||
statusMap.put("reason",mReason);
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.MapStateProtocol.
|
||||
sMapRegionWillChangeWithReasonCallback,statusMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapStatusChange(MapStatus mapStatus) {
|
||||
if (null == mapStatus || mMethodChannel == null) {
|
||||
return;
|
||||
}
|
||||
HashMap<String, Double> targetScreenMap = new HashMap<>();
|
||||
Point targetScreen = mapStatus.targetScreen;
|
||||
if (null == targetScreen) {
|
||||
return;
|
||||
}
|
||||
targetScreenMap.put("x", (double) targetScreen.x);
|
||||
targetScreenMap.put("y", (double) targetScreen.y);
|
||||
HashMap<String, Double> targetMap = new HashMap<>();
|
||||
LatLng latLng = mapStatus.target;
|
||||
if (null == latLng){
|
||||
return;
|
||||
}
|
||||
targetMap.put("latitude", latLng.latitude);
|
||||
targetMap.put("longitude", latLng.longitude);
|
||||
|
||||
LatLngBounds bound = mapStatus.bound;
|
||||
if (null == bound) {
|
||||
return;
|
||||
}
|
||||
HashMap latLngBoundMap = latLngBounds(bound);
|
||||
if (null == latLngBoundMap) {
|
||||
return;
|
||||
}
|
||||
HashMap statusMap = new HashMap<>();
|
||||
HashMap status = new HashMap();
|
||||
status.put("fLevel",((double)mapStatus.zoom));
|
||||
double rotate = mapStatus.rotate;
|
||||
if (rotate > 180) {
|
||||
rotate = rotate - 360;
|
||||
}
|
||||
status.put("fRotation", rotate);
|
||||
status.put("fOverlooking",((double) mapStatus.overlook));
|
||||
status.put("targetScreenPt",targetScreenMap);
|
||||
status.put("targetGeoPt",targetMap);
|
||||
status.put("visibleMapBounds",latLngBoundMap);
|
||||
statusMap.put("mapStatus",status);
|
||||
|
||||
mMethodChannel.invokeMethod(
|
||||
Constants.MethodProtocol.MapStateProtocol.sMapRegionDidChangeCallback,statusMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapStatusChangeFinish(MapStatus mapStatus) {
|
||||
if (null == mapStatus || mMethodChannel == null) {
|
||||
return;
|
||||
}
|
||||
HashMap<String, Double> targetScreenMap = new HashMap<>();
|
||||
Point targetScreen = mapStatus.targetScreen;
|
||||
if (null == targetScreen) {
|
||||
return;
|
||||
}
|
||||
targetScreenMap.put("x", (double) targetScreen.x);
|
||||
targetScreenMap.put("y", (double) targetScreen.y);
|
||||
HashMap<String, Double> targetMap = new HashMap<>();
|
||||
LatLng latLng = mapStatus.target;
|
||||
if (null == latLng){
|
||||
return;
|
||||
}
|
||||
targetMap.put("latitude", latLng.latitude);
|
||||
targetMap.put("longitude", latLng.longitude);
|
||||
|
||||
LatLngBounds bound = mapStatus.bound;
|
||||
if (null == bound) {
|
||||
return;
|
||||
}
|
||||
HashMap latLngBoundMap = latLngBounds(bound);
|
||||
if (null == latLngBoundMap) {
|
||||
return;
|
||||
}
|
||||
HashMap statusMap = new HashMap<>();
|
||||
HashMap status = new HashMap();
|
||||
status.put("fLevel",((double)mapStatus.zoom));
|
||||
double rotate = mapStatus.rotate;
|
||||
if (rotate > 180) {
|
||||
rotate = rotate - 360;
|
||||
}
|
||||
status.put("fRotation", rotate);
|
||||
status.put("fOverlooking",((double) mapStatus.overlook));
|
||||
status.put("targetScreenPt",targetScreenMap);
|
||||
status.put("targetGeoPt",targetMap);
|
||||
status.put("visibleMapBounds",latLngBoundMap);
|
||||
statusMap.put("mapStatus",status);
|
||||
statusMap.put("reason",mReason);
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.MapStateProtocol.sMapRegionDidChangeWithReasonCallback,statusMap);
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.MapStateProtocol.sMapStatusDidChangedCallback,"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapRenderFinished() {
|
||||
HashMap hashMap = new HashMap();
|
||||
hashMap.put("success",true);
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.MapStateProtocol.sMapDidFinishRenderCallback,hashMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapDrawFrame(GL10 gl10, MapStatus mapStatus) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapDrawFrame(MapStatus mapStatus) {
|
||||
if (null == mapStatus || mMethodChannel == null) {
|
||||
return;
|
||||
}
|
||||
HashMap<String, Double> targetScreenMap = new HashMap<>();
|
||||
Point targetScreen = mapStatus.targetScreen;
|
||||
if (null == targetScreen) {
|
||||
return;
|
||||
}
|
||||
targetScreenMap.put("x", (double) targetScreen.x);
|
||||
targetScreenMap.put("y", (double) targetScreen.y);
|
||||
HashMap<String, Double> targetMap = new HashMap<>();
|
||||
LatLng latLng = mapStatus.target;
|
||||
if (null == latLng){
|
||||
return;
|
||||
}
|
||||
targetMap.put("latitude", latLng.latitude);
|
||||
targetMap.put("longitude", latLng.longitude);
|
||||
|
||||
LatLngBounds bound = mapStatus.bound;
|
||||
if (null == bound) {
|
||||
return;
|
||||
}
|
||||
|
||||
HashMap latLngBoundMap = latLngBounds(bound);
|
||||
if (null == latLngBoundMap) {
|
||||
return;
|
||||
}
|
||||
mStatusMap = new HashMap<>();
|
||||
HashMap status = new HashMap();
|
||||
status.put("fLevel",((double)mapStatus.zoom));
|
||||
double rotate = mapStatus.rotate;
|
||||
if (rotate > 180) {
|
||||
rotate = rotate - 360;
|
||||
}
|
||||
status.put("fRotation", rotate);
|
||||
status.put("fOverlooking",((double) mapStatus.overlook));
|
||||
status.put("targetScreenPt",targetScreenMap);
|
||||
status.put("targetGeoPt",targetMap);
|
||||
status.put("visibleMapBounds",latLngBoundMap);
|
||||
mStatusMap.put("mapStatus",status);
|
||||
|
||||
ThreadPoolUtil.getInstance().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Message msg = Message.obtain();
|
||||
msg.arg1 = DRAW_FRAME_MESSAGE;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBaseIndoorMapMode(boolean isIndoorMap, MapBaseIndoorMapInfo mapBaseIndoorMapInfo) {
|
||||
if (mMethodChannel == null) {
|
||||
return;
|
||||
}
|
||||
HashMap indoorHashMap = new HashMap();
|
||||
indoorHashMap.put("flag",isIndoorMap);
|
||||
HashMap indoorMap = new HashMap();
|
||||
if (isIndoorMap) {
|
||||
if (null == mapBaseIndoorMapInfo) {
|
||||
return;
|
||||
}
|
||||
String curFloor = mapBaseIndoorMapInfo.getCurFloor();
|
||||
String id = mapBaseIndoorMapInfo.getID();
|
||||
ArrayList<String> floors = mapBaseIndoorMapInfo.getFloors();
|
||||
indoorMap.put("strFloor", curFloor);
|
||||
indoorMap.put("strID", id);
|
||||
indoorMap.put("listStrFloors", floors);
|
||||
}
|
||||
indoorHashMap.put("info",indoorMap);
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.MapStateProtocol.sMapInOrOutBaseIndoorMapCallback
|
||||
,indoorHashMap);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onMarkerClick(Marker marker) {
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "onMarkerClick");
|
||||
}
|
||||
if(null == mMethodChannel){
|
||||
return false;
|
||||
}
|
||||
|
||||
Bundle bundle = marker.getExtraInfo();
|
||||
if(null == bundle){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "bundle is null");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
String id = bundle.getString("id");
|
||||
if(TextUtils.isEmpty(id)){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "marker id is null ");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Map<String, Object> clickMap = new HashMap<>();
|
||||
clickMap.put("id", id);
|
||||
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.MarkerProtocol.sMapClickedmarkedMethod, clickMap);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPolylineClick(Polyline polyline) {
|
||||
|
||||
Log.d("polyline", "polyline click");
|
||||
|
||||
HashMap hashMap = polylineClick(polyline);
|
||||
HashMap<String, Object> polyLineMap = new HashMap<>();
|
||||
polyLineMap.put("polyline", hashMap);
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.PolylineProtocol.sMapOnClickedOverlayCallback, polyLineMap);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private HashMap polylineClick(Polyline polyline) {
|
||||
if (null == polyline) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Bundle bundle = polyline.getExtraInfo();
|
||||
String id = bundle.getString("id");
|
||||
|
||||
HashMap polylineMap = new HashMap();
|
||||
|
||||
List<LatLng> points = polyline.getPoints();
|
||||
List<Object> latlngLists = new ArrayList<>();
|
||||
if (null != points){
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
HashMap<String, Double> latlngHashMap = new HashMap<>();
|
||||
latlngHashMap.put("latitude",points.get(i).latitude);
|
||||
latlngHashMap.put("longitude",points.get(i).longitude);
|
||||
latlngLists.add(latlngHashMap);
|
||||
}
|
||||
}
|
||||
polylineMap.put("id", id);
|
||||
polylineMap.put("coordinates",latlngLists);
|
||||
|
||||
ArrayList<String> colorList = new ArrayList<>();
|
||||
int[] colors = polyline.getColorList();
|
||||
if(null != colors){
|
||||
for(int i = 0; i < colors.length; i++){
|
||||
colorList.add(Integer.toHexString(colors[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
polylineMap.put("colors", colorList);
|
||||
|
||||
polylineMap.put("color", polyline.getColor());
|
||||
polylineMap.put("lineDashType", polyline.getDottedLineType());
|
||||
polylineMap.put("lineCapType", 0);
|
||||
polylineMap.put("lineJoinType", 0);
|
||||
polylineMap.put("width", polyline.getWidth());
|
||||
polylineMap.put("zIndex", polyline.getZIndex());
|
||||
|
||||
return polylineMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapDoubleClick(LatLng latLng) {
|
||||
if (null == latLng || mMethodChannel == null) {
|
||||
return;
|
||||
}
|
||||
HashMap<String, HashMap> coordinateMap = new HashMap<>();
|
||||
HashMap<String, Double> coord = new HashMap<>();
|
||||
coord.put("latitude",latLng.latitude);
|
||||
coord.put("longitude",latLng.longitude);
|
||||
coordinateMap.put("coord",coord);
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.MapStateProtocol.sMapOnDoubleClickCallback,coordinateMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapLongClick(LatLng latLng) {
|
||||
if (null == latLng || mMethodChannel == null) {
|
||||
return;
|
||||
}
|
||||
HashMap<String, HashMap> coordinateMap = new HashMap<>();
|
||||
HashMap<String, Double> coord = new HashMap<>();
|
||||
coord.put("latitude",latLng.latitude);
|
||||
coord.put("longitude",latLng.longitude);
|
||||
coordinateMap.put("coord",coord);
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.MapStateProtocol.sMapOnLongClickCallback,coordinateMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkerDrag(Marker marker) {
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "onMarkerDrag");
|
||||
}
|
||||
if(null == mMethodChannel){
|
||||
return;
|
||||
}
|
||||
|
||||
Bundle bundle = marker.getExtraInfo();
|
||||
if(null == bundle){
|
||||
return;
|
||||
}
|
||||
|
||||
String id = bundle.getString("id");
|
||||
|
||||
if(null == mMethodChannel){
|
||||
return;
|
||||
}
|
||||
|
||||
if(TextUtils.isEmpty(id)){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "id is null");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(TextUtils.isEmpty(id)){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "id is null");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Map<String, Object> dragMap = new HashMap<>();
|
||||
dragMap.put("id", id);
|
||||
Map<String, Object> extraInfoMap = new HashMap<>();
|
||||
extraInfoMap.put("state", Constants.MethodProtocol.MarkerProtocol.MarkerDragState.sDragging);
|
||||
dragMap.put("extra", extraInfoMap);
|
||||
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.MarkerProtocol.sMapDragMarkerMethod, dragMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkerDragEnd(Marker marker) {
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "onMarkerDrag");
|
||||
}
|
||||
if(null == mMethodChannel){
|
||||
return;
|
||||
}
|
||||
|
||||
Bundle bundle = marker.getExtraInfo();
|
||||
if(null == bundle){
|
||||
return;
|
||||
}
|
||||
|
||||
String id = bundle.getString("id");
|
||||
|
||||
if(null == mMethodChannel){
|
||||
return;
|
||||
}
|
||||
|
||||
if(TextUtils.isEmpty(id)){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "id is null");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
LatLng center = marker.getPosition();
|
||||
if(null == center){
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> dragMap = new HashMap<>();
|
||||
dragMap.put("id", id);
|
||||
|
||||
Map<String, Double> centerMap = new HashMap<>();
|
||||
centerMap.put("latitude", center.latitude);
|
||||
centerMap.put("longitude", center.longitude);
|
||||
|
||||
Map<String, Object> extraInfoMap = new HashMap<>();
|
||||
extraInfoMap.put("center", centerMap);
|
||||
extraInfoMap.put("state", Constants.MethodProtocol.MarkerProtocol.MarkerDragState.sDragEnd);
|
||||
dragMap.put("extra", extraInfoMap);
|
||||
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.MarkerProtocol.sMapDragMarkerMethod, dragMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkerDragStart(Marker marker) {
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "onMarkerDrag");
|
||||
}
|
||||
|
||||
Bundle bundle = marker.getExtraInfo();
|
||||
if(null == bundle){
|
||||
return;
|
||||
}
|
||||
|
||||
String id = bundle.getString("id");
|
||||
|
||||
if(null == mMethodChannel){
|
||||
return;
|
||||
}
|
||||
|
||||
if(TextUtils.isEmpty(id)){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "id is null");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
LatLng center = marker.getPosition();
|
||||
if(null == center){
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> dragMap = new HashMap<>();
|
||||
dragMap.put("id", id);
|
||||
|
||||
Map<String, Double> centerMap = new HashMap<>();
|
||||
centerMap.put("latitude", center.latitude);
|
||||
centerMap.put("longitude", center.longitude);
|
||||
|
||||
Map<String, Object> extraInfoMap = new HashMap<>();
|
||||
extraInfoMap.put("center", centerMap);
|
||||
extraInfoMap.put("state", Constants.MethodProtocol.MarkerProtocol.MarkerDragState.sDragStart);
|
||||
dragMap.put("extra", extraInfoMap);
|
||||
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.MarkerProtocol.sMapDragMarkerMethod, dragMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapRenderValidData(boolean isValid, int errorCode, String errorMessage) {
|
||||
HashMap hashMap = new HashMap();
|
||||
hashMap.put("isValid",isValid);
|
||||
hashMap.put("errorCode",errorCode);
|
||||
hashMap.put("errorMessage",errorMessage);
|
||||
mMethodChannel.invokeMethod(Constants.MethodProtocol.MapStateProtocol.sMapRenderValidDataCallback,hashMap);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onMyLocationClick() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private HashMap latLngBounds(LatLngBounds latLngBounds) {
|
||||
if (null == latLngBounds) {
|
||||
return null;
|
||||
}
|
||||
// 该地理范围东北坐标
|
||||
LatLng northeast = latLngBounds.northeast;
|
||||
// 该地理范围西南坐标
|
||||
LatLng southwest = latLngBounds.southwest;
|
||||
|
||||
HashMap boundsMap = new HashMap();
|
||||
HashMap northeastMap = new HashMap<String,Double>();
|
||||
if (null == northeast){
|
||||
return null;
|
||||
}
|
||||
northeastMap.put("latitude", northeast.latitude);
|
||||
northeastMap.put("longitude",northeast.longitude);
|
||||
HashMap southwestMap = new HashMap<String,Double>();
|
||||
if (null == southwest) {
|
||||
return null;
|
||||
}
|
||||
southwestMap.put("latitude",southwest.latitude);
|
||||
southwestMap.put("longitude", southwest.longitude);
|
||||
boundsMap.put("northeast",northeastMap);
|
||||
boundsMap.put("southwest",southwestMap);
|
||||
return boundsMap;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
package com.baidu.flutter_bmfmap.map;
|
||||
|
||||
import com.baidu.mapapi.map.MapView;
|
||||
import com.baidu.mapapi.map.TextureMapView;
|
||||
|
||||
public class MapViewWrapper extends FlutterCommonMapView {
|
||||
FlutterMapView mFlutterMapView;
|
||||
|
||||
public MapViewWrapper(FlutterMapView mapView, String viewType) {
|
||||
mFlutterMapView = mapView;
|
||||
mViewType = viewType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapView getMapView() {
|
||||
return mFlutterMapView.getMapView();
|
||||
}
|
||||
|
||||
public FlutterMapView getFlutterMapView() {
|
||||
return mFlutterMapView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureMapView getTextureMapView() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.baidu.flutter_bmfmap.map;
|
||||
|
||||
import com.baidu.mapapi.map.MapView;
|
||||
import com.baidu.mapapi.map.TextureMapView;
|
||||
|
||||
class TextureMapViewWrapper extends FlutterCommonMapView {
|
||||
|
||||
private TextureMapView mTextureMapView;
|
||||
|
||||
public TextureMapViewWrapper(TextureMapView textureMapView, String viewType){
|
||||
mTextureMapView = textureMapView;
|
||||
mViewType = viewType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapView getMapView() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureMapView getTextureMapView() {
|
||||
return mTextureMapView;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.baidu.flutter_bmfmap.map.mapHandler;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.baidu.flutter_bmfmap.map.FlutterCommonMapView;
|
||||
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
public abstract class BMapHandler{
|
||||
protected FlutterCommonMapView mMapView;
|
||||
|
||||
public BMapHandler(FlutterCommonMapView mapView){
|
||||
this.mMapView = mapView;
|
||||
}
|
||||
|
||||
public abstract void handlerMethodCallResult(Context context,MethodCall call, MethodChannel.Result result);
|
||||
|
||||
public void updateMapView(FlutterCommonMapView mapView){
|
||||
mMapView = mapView;
|
||||
}
|
||||
|
||||
public void clean(){}
|
||||
}
|
||||
@ -0,0 +1,200 @@
|
||||
package com.baidu.flutter_bmfmap.map.mapHandler;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.baidu.flutter_bmfmap.map.FlutterCommonMapView;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.CustomMapProtocol;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.MapStateProtocol;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.HeatMapProtocol;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.TileMapProtocol;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.MarkerProtocol;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.InfoWindowProtocol;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.ProjectionMethodId;
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
|
||||
public class BMapHandlerFactory{
|
||||
|
||||
private static volatile BMapHandlerFactory sInstance;
|
||||
private HashMap<Integer, BMapHandler> mMapHandlerHashMap;
|
||||
|
||||
public static BMapHandlerFactory getInstance(FlutterCommonMapView mapView) {
|
||||
|
||||
if (null == sInstance) {
|
||||
synchronized (BMapHandlerFactory.class) {
|
||||
if (null == sInstance) {
|
||||
sInstance = new BMapHandlerFactory(mapView);
|
||||
} else {
|
||||
sInstance.updateMapView(mapView);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sInstance.updateMapView(mapView);
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private void updateMapView(FlutterCommonMapView mapView) {
|
||||
if (null == mapView) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(null == mMapHandlerHashMap || mMapHandlerHashMap.isEmpty()){
|
||||
init(mapView);
|
||||
}
|
||||
|
||||
Iterator it = mMapHandlerHashMap.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<Integer, BMapHandler> entry = (Map.Entry<Integer, BMapHandler>) it.next();
|
||||
BMapHandler bMapHandler = entry.getValue();
|
||||
if (null != bMapHandler) {
|
||||
bMapHandler.updateMapView(mapView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BMapHandlerFactory(FlutterCommonMapView mapView) {
|
||||
init(mapView);
|
||||
}
|
||||
|
||||
private void init(FlutterCommonMapView mapView) {
|
||||
if (null == mapView) {
|
||||
return;
|
||||
}
|
||||
|
||||
mMapHandlerHashMap = new HashMap<>();
|
||||
|
||||
mMapHandlerHashMap.put(Constants.BMapHandlerType.CUSTOM_MAP,new CustomMapHandler(mapView));
|
||||
mMapHandlerHashMap.put(Constants.BMapHandlerType.MAP_STATE,new MapStateHandler(mapView));
|
||||
mMapHandlerHashMap.put(Constants.BMapHandlerType.INDOOR_MAP, new IndoorMapHandler(mapView));
|
||||
mMapHandlerHashMap.put(Constants.BMapHandlerType.MAP_UPDATE, new MapUpdateHandler(mapView));
|
||||
mMapHandlerHashMap.put(Constants.BMapHandlerType.HEAT_MAP, new HeatMapHandler(mapView));
|
||||
mMapHandlerHashMap.put(Constants.BMapHandlerType.TILE_MAP, new TileMapHandler(mapView));
|
||||
mMapHandlerHashMap.put(Constants.BMapHandlerType.INFOWINDOW_HANDLER, new InfoWindowHandler(mapView));
|
||||
mMapHandlerHashMap.put(Constants.BMapHandlerType.MARKER_HANDLER, new MarkerHandler(mapView));
|
||||
mMapHandlerHashMap.put(Constants.BMapHandlerType.LOCATION_LAYER, new LocationLayerHandler(mapView));
|
||||
mMapHandlerHashMap.put(Constants.BMapHandlerType.PROJECTION, new ProjectionHandler(mapView));
|
||||
}
|
||||
|
||||
public boolean dispatchMethodHandler(Context context, MethodCall call, MethodChannel.Result result,
|
||||
MethodChannel methodChannel) {
|
||||
if (null == call) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String methodId = call.method;
|
||||
if(Env.DEBUG){
|
||||
Log.d("BMapHandlerFactory", "dispatchMethodHandler: " + methodId);
|
||||
}
|
||||
BMapHandler bMapHandler = null;
|
||||
switch (methodId) {
|
||||
case CustomMapProtocol.sMapSetCustomMapStyleEnableMethod:
|
||||
case CustomMapProtocol.sMapSetCustomMapStylePathMethod:
|
||||
case CustomMapProtocol.sMapSetCustomMapStyleWithOptionMethod:
|
||||
bMapHandler = mMapHandlerHashMap.get(Constants.BMapHandlerType.CUSTOM_MAP);
|
||||
break;
|
||||
case Constants.MethodProtocol.IndoorMapProtocol.sShowBaseIndoorMapMethod:
|
||||
case Constants.MethodProtocol.IndoorMapProtocol.sShowBaseIndoorMapPoiMethod:
|
||||
case Constants.MethodProtocol.IndoorMapProtocol.sSwitchBaseIndoorMapFloorMethod:
|
||||
case Constants.MethodProtocol.IndoorMapProtocol.sGetFocusedBaseIndoorMapInfoMethod:
|
||||
bMapHandler = mMapHandlerHashMap.get(Constants.BMapHandlerType.INDOOR_MAP);
|
||||
break;
|
||||
case MapStateProtocol.sMapUpdateMethod:
|
||||
case MapStateProtocol.sMapSetVisibleMapBoundsMethod:
|
||||
case MapStateProtocol.sMapSetVisibleMapBoundsWithPaddingMethod:
|
||||
case MapStateProtocol.sMapSetCompassImageMethod:
|
||||
case MapStateProtocol.sMapSetCustomTrafficColorMethod:
|
||||
case MapStateProtocol.sMapTakeSnapshotMethod:
|
||||
case MapStateProtocol.sMapTakeSnapshotWithRectMethod:
|
||||
case MapStateProtocol.sMapDidUpdateWidget:
|
||||
case MapStateProtocol.sMapReassemble:
|
||||
bMapHandler = mMapHandlerHashMap.get(Constants.BMapHandlerType.MAP_STATE);
|
||||
break;
|
||||
case MapStateProtocol.sMapZoomInMethod:
|
||||
case MapStateProtocol.sMapZoomOutMethod:
|
||||
case MapStateProtocol.sMapSetCenterCoordinateMethod:
|
||||
case MapStateProtocol.sMapSetCenterZoomMethod:
|
||||
case MapStateProtocol.sMapSetMapStatusMethod:
|
||||
case MapStateProtocol.sMapSetScrollByMethod:
|
||||
case MapStateProtocol.sMapSetZoomByMethod:
|
||||
case MapStateProtocol.sMapSetZoomPointByMethod:
|
||||
case MapStateProtocol.sMapSetZoomToMethod:
|
||||
case MapStateProtocol.sMapGetMapStatusMethod:
|
||||
bMapHandler = mMapHandlerHashMap.get(Constants.BMapHandlerType.MAP_UPDATE);
|
||||
break;
|
||||
case HeatMapProtocol.sMapAddHeatMapMethod:
|
||||
case HeatMapProtocol.sMapRemoveHeatMapMethod:
|
||||
case HeatMapProtocol.sShowHeatMapMethod:
|
||||
bMapHandler = mMapHandlerHashMap.get(Constants.BMapHandlerType.HEAT_MAP);
|
||||
break;
|
||||
case TileMapProtocol.sAddTileMapMethod:
|
||||
case TileMapProtocol.sRemoveTileMapMethod:
|
||||
bMapHandler = mMapHandlerHashMap.get(Constants.BMapHandlerType.TILE_MAP);
|
||||
break;
|
||||
case MarkerProtocol.sMapAddMarkerMethod:
|
||||
case MarkerProtocol.sMapAddMarkersMethod:
|
||||
case MarkerProtocol.sMapRemoveMarkerMethod:
|
||||
case MarkerProtocol.sMapRemoveMarkersMethod:
|
||||
case MarkerProtocol.sMapDidSelectMarkerMethod:
|
||||
case MarkerProtocol.sMapDidDeselectMarkerMethod:
|
||||
case MarkerProtocol.sMapCleanAllMarkersMethod:
|
||||
case MarkerProtocol.sMapUpdateMarkerMemberMethod:
|
||||
bMapHandler = mMapHandlerHashMap.get(Constants.BMapHandlerType.MARKER_HANDLER);
|
||||
break;
|
||||
case InfoWindowProtocol.sAddInfoWindowMapMethod:
|
||||
case InfoWindowProtocol.sRemoveInfoWindowMapMethod:
|
||||
case InfoWindowProtocol.sAddInfoWindowsMapMethod:
|
||||
bMapHandler = mMapHandlerHashMap.get(Constants.BMapHandlerType.INFOWINDOW_HANDLER);
|
||||
break;
|
||||
case Constants.LocationLayerMethodId.sMapShowUserLocationMethod:
|
||||
case Constants.LocationLayerMethodId.sMapUpdateLocationDataMethod:
|
||||
case Constants.LocationLayerMethodId.sMapUserTrackingModeMethod:
|
||||
case Constants.LocationLayerMethodId.sMapUpdateLocationDisplayParamMethod:
|
||||
bMapHandler = mMapHandlerHashMap.get(Constants.BMapHandlerType.LOCATION_LAYER);
|
||||
break;
|
||||
case ProjectionMethodId.sFromScreenLocation:
|
||||
case ProjectionMethodId.sToScreenLocation:
|
||||
bMapHandler = mMapHandlerHashMap.get(Constants.BMapHandlerType.PROJECTION);
|
||||
break;
|
||||
default:
|
||||
if(methodId.startsWith("flutter_bmfmap/map/get")){
|
||||
bMapHandler = mMapHandlerHashMap.get(Constants.BMapHandlerType.MAP_UPDATE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (null == bMapHandler) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bMapHandler.handlerMethodCallResult(context,call, result);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clean(){
|
||||
if (null == mMapHandlerHashMap || mMapHandlerHashMap.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
BMapHandler bMapHandler = null;
|
||||
Iterator iterator = mMapHandlerHashMap.values().iterator();
|
||||
while (iterator.hasNext()){
|
||||
bMapHandler = (BMapHandler) iterator.next();
|
||||
if(null == bMapHandler){
|
||||
continue;
|
||||
}
|
||||
|
||||
bMapHandler.clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,437 @@
|
||||
package com.baidu.flutter_bmfmap.map.mapHandler;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.baidu.flutter_bmfmap.map.FlutterCommonMapView;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants;
|
||||
import com.baidu.mapapi.map.CustomMapStyleCallBack;
|
||||
import com.baidu.mapapi.map.MapCustomStyleOptions;
|
||||
import com.baidu.mapapi.map.MapView;
|
||||
import com.baidu.mapapi.map.TextureMapView;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import io.flutter.view.FlutterMain;
|
||||
|
||||
public class CustomMapHandler extends BMapHandler {
|
||||
|
||||
private MapViewCustomMapHandler mMapViewCustomMapHandler;
|
||||
private TextureMapViewCustomMapHandler mTextureMapViewCustomMapHandler;
|
||||
|
||||
public CustomMapHandler(FlutterCommonMapView mapView) {
|
||||
super(mapView);
|
||||
mMapViewCustomMapHandler = new MapViewCustomMapHandler(mMapView);
|
||||
mTextureMapViewCustomMapHandler = new TextureMapViewCustomMapHandler(mMapView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMapView(FlutterCommonMapView mapView){
|
||||
mMapView = mapView;
|
||||
mMapViewCustomMapHandler.updateMapView(mapView);
|
||||
mTextureMapViewCustomMapHandler.updateMapView(mapView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerMethodCallResult(Context context,MethodCall call, MethodChannel.Result result) {
|
||||
switch (mMapView.getViewType()){
|
||||
case Constants.ViewType.sMapView:
|
||||
mMapViewCustomMapHandler.handlerMethodCallResult(context, call, result);
|
||||
break;
|
||||
case Constants.ViewType.sTextureMapView:
|
||||
mTextureMapViewCustomMapHandler.handlerMethodCallResult(context, call, result);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
class MapViewCustomMapHandler extends BMapHandler {
|
||||
|
||||
private MapView mRealMapView;
|
||||
|
||||
public MapViewCustomMapHandler(FlutterCommonMapView mapView) {
|
||||
super(mapView);
|
||||
mRealMapView = mMapView.getMapView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMapView(FlutterCommonMapView mapView){
|
||||
mMapView = mapView;
|
||||
if(null != mMapView){
|
||||
mRealMapView = mMapView.getMapView();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerMethodCallResult(Context context, MethodCall call, MethodChannel.Result result) {
|
||||
if (null == call) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
String methodId = call.method;
|
||||
if (TextUtils.isEmpty(methodId)) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (methodId) {
|
||||
case Constants.MethodProtocol.CustomMapProtocol.sMapSetCustomMapStyleEnableMethod:
|
||||
setCustomMapStyleEnable(call, result);
|
||||
break;
|
||||
case Constants.MethodProtocol.CustomMapProtocol.sMapSetCustomMapStylePathMethod:
|
||||
setCustomMapStylePath(context,call,result);
|
||||
break;
|
||||
case Constants.MethodProtocol.CustomMapProtocol.sMapSetCustomMapStyleWithOptionMethod:
|
||||
setMapCustomStyle(call,result);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 个性化地图开关
|
||||
*/
|
||||
private void setCustomMapStyleEnable(MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mMapView) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
if (!argument.containsKey("enable")) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
boolean enable = (boolean) argument.get("enable");
|
||||
mRealMapView.setMapCustomStyleEnable(enable);
|
||||
result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置个性化地图样式文件的路径
|
||||
*/
|
||||
private void setCustomMapStylePath(Context context, MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mMapView || context == null) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!argument.containsKey("path") || !argument.containsKey("mode")) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
String path = (String) argument.get("path");
|
||||
if (path.isEmpty()) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
String customStyleFilePath = getCustomStyleFilePath(context, path);
|
||||
if(TextUtils.isEmpty(customStyleFilePath)){
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
mRealMapView.setMapCustomStylePath(customStyleFilePath);
|
||||
result.success(true);
|
||||
}
|
||||
|
||||
private String getCustomStyleFilePath(Context context, String customStyleFilePath) {
|
||||
if (customStyleFilePath.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
FileOutputStream outputStream = null;
|
||||
InputStream inputStream = null;
|
||||
String parentPath = null;
|
||||
String customStyleFileName = null;
|
||||
try {
|
||||
customStyleFileName = FlutterMain.getLookupKeyForAsset(customStyleFilePath);
|
||||
inputStream = context.getAssets().open(customStyleFileName);
|
||||
byte[] buffer = new byte[inputStream.available()];
|
||||
inputStream.read(buffer);
|
||||
|
||||
parentPath = context.getCacheDir().getAbsolutePath();
|
||||
String substr = customStyleFileName.substring(0, customStyleFileName.lastIndexOf("/"));
|
||||
File customStyleFile = new File(parentPath + "/" + customStyleFileName);
|
||||
if (customStyleFile.exists()) {
|
||||
customStyleFile.delete();
|
||||
}
|
||||
File dirFile = new File(parentPath + "/" + substr);
|
||||
if (!dirFile.exists()) {
|
||||
dirFile.mkdirs();
|
||||
}
|
||||
customStyleFile.createNewFile();
|
||||
outputStream = new FileOutputStream(customStyleFile);
|
||||
outputStream.write(buffer);
|
||||
} catch (IOException e) {
|
||||
Log.e("TAG", "Copy file failed", e);
|
||||
} finally {
|
||||
try {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
if (outputStream != null) {
|
||||
outputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e("TAG", "Close stream failed", e);
|
||||
}
|
||||
}
|
||||
return parentPath + "/" + customStyleFileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在线个性化样式加载状态回调接口
|
||||
*/
|
||||
private void setMapCustomStyle(MethodCall call, final MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mMapView) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
if (!argument.containsKey("customMapStyleOption")) {
|
||||
return;
|
||||
}
|
||||
Map<String, Object> customMapStyleOption = (Map<String, Object>) argument.get("customMapStyleOption");
|
||||
if (!customMapStyleOption.containsKey("customMapStyleID")
|
||||
|| !customMapStyleOption.containsKey("customMapStyleFilePath")) {
|
||||
return;
|
||||
}
|
||||
|
||||
String customMapStyleID = (String) customMapStyleOption.get("customMapStyleID");
|
||||
String customMapStyleFilePath = (String) customMapStyleOption.get("customMapStyleFilePath");
|
||||
if (customMapStyleID.isEmpty() && customMapStyleFilePath.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
MapCustomStyleOptions mapCustomStyleOptions = new MapCustomStyleOptions();
|
||||
mapCustomStyleOptions.customStyleId(customMapStyleID);
|
||||
mapCustomStyleOptions.localCustomStylePath(customMapStyleFilePath);
|
||||
final HashMap<String, String> reslutMap = new HashMap<>();
|
||||
mRealMapView.setMapCustomStyle(mapCustomStyleOptions, new CustomMapStyleCallBack() {
|
||||
@Override
|
||||
public boolean onPreLoadLastCustomMapStyle(String path) {
|
||||
reslutMap.put("preloadPath", path);
|
||||
result.success(reslutMap);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCustomMapStyleLoadSuccess(boolean b, String path) {
|
||||
// TODO: 2020-03-05 回调的 boolean 类型没有返回之后补齐
|
||||
reslutMap.put("successPath", path);
|
||||
result.success(reslutMap);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCustomMapStyleLoadFailed(int status, String message, String path) {
|
||||
String sStatus = String.valueOf(status);
|
||||
reslutMap.put("errorCode", sStatus);
|
||||
reslutMap.put("successPath", path);
|
||||
result.success(reslutMap);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class TextureMapViewCustomMapHandler extends BMapHandler {
|
||||
|
||||
private TextureMapView mTextureMapView;
|
||||
|
||||
public TextureMapViewCustomMapHandler(FlutterCommonMapView mapView) {
|
||||
super(mapView);
|
||||
mTextureMapView = mMapView.getTextureMapView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMapView(FlutterCommonMapView mapView){
|
||||
mMapView = mapView;
|
||||
if(null != mMapView){
|
||||
mTextureMapView = mMapView.getTextureMapView();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerMethodCallResult(Context context, MethodCall call, MethodChannel.Result result) {
|
||||
if (null == call) {
|
||||
return;
|
||||
}
|
||||
|
||||
String methodId = call.method;
|
||||
if (TextUtils.isEmpty(methodId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (methodId) {
|
||||
case Constants.MethodProtocol.CustomMapProtocol.sMapSetCustomMapStyleEnableMethod:
|
||||
setCustomMapStyleEnable(call, result);
|
||||
break;
|
||||
case Constants.MethodProtocol.CustomMapProtocol.sMapSetCustomMapStylePathMethod:
|
||||
setCustomMapStylePath(context,call,result);
|
||||
break;
|
||||
case Constants.MethodProtocol.CustomMapProtocol.sMapSetCustomMapStyleWithOptionMethod:
|
||||
setMapCustomStyle(context, call,result);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 个性化地图开关
|
||||
*/
|
||||
private void setCustomMapStyleEnable(MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mMapView) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
if (!argument.containsKey("enable")) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
boolean enable = (boolean) argument.get("enable");
|
||||
mTextureMapView.setMapCustomStyleEnable(enable);
|
||||
result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置个性化地图样式文件的路径
|
||||
*/
|
||||
private void setCustomMapStylePath(Context context, MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mMapView || context == null) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!argument.containsKey("path") || !argument.containsKey("mode")) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
String path = (String) argument.get("path");
|
||||
if (path.isEmpty()) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
String customStyleFilePath = getCustomStyleFilePath(context, path);
|
||||
mTextureMapView.setMapCustomStylePath(customStyleFilePath);
|
||||
result.success(true);
|
||||
}
|
||||
|
||||
private String getCustomStyleFilePath(Context context, String customStyleFilePath) {
|
||||
if (customStyleFilePath.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
FileOutputStream outputStream = null;
|
||||
InputStream inputStream = null;
|
||||
String parentPath = null;
|
||||
String customStyleFileName = null;
|
||||
try {
|
||||
customStyleFileName = FlutterMain.getLookupKeyForAsset(customStyleFilePath);
|
||||
inputStream = context.getAssets().open(customStyleFileName);
|
||||
byte[] buffer = new byte[inputStream.available()];
|
||||
inputStream.read(buffer);
|
||||
|
||||
parentPath = context.getCacheDir().getAbsolutePath();
|
||||
String substr = customStyleFileName.substring(0, customStyleFileName.lastIndexOf("/"));
|
||||
File customStyleFile = new File(parentPath + "/" + customStyleFileName);
|
||||
if (customStyleFile.exists()) {
|
||||
customStyleFile.delete();
|
||||
}
|
||||
File dirFile = new File(parentPath + "/" + substr);
|
||||
if (!dirFile.exists()) {
|
||||
dirFile.mkdirs();
|
||||
}
|
||||
customStyleFile.createNewFile();
|
||||
outputStream = new FileOutputStream(customStyleFile);
|
||||
outputStream.write(buffer);
|
||||
} catch (IOException e) {
|
||||
Log.e("TAG", "Copy file failed", e);
|
||||
} finally {
|
||||
try {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
if (outputStream != null) {
|
||||
outputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e("TAG", "Close stream failed", e);
|
||||
}
|
||||
}
|
||||
return parentPath + "/" + customStyleFileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在线个性化样式加载状态回调接口
|
||||
*/
|
||||
private void setMapCustomStyle(Context context, MethodCall call,
|
||||
final MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mMapView) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
if (!argument.containsKey("customMapStyleOption")) {
|
||||
return;
|
||||
}
|
||||
Map<String, Object> customMapStyleOption = (Map<String, Object>) argument.get("customMapStyleOption");
|
||||
if (!customMapStyleOption.containsKey("customMapStyleID")
|
||||
|| !customMapStyleOption.containsKey("customMapStyleFilePath")) {
|
||||
return;
|
||||
}
|
||||
|
||||
String customMapStyleID = (String) customMapStyleOption.get("customMapStyleID");
|
||||
String customMapStyleFilePath = (String) customMapStyleOption.get("customMapStyleFilePath");
|
||||
customMapStyleFilePath = getCustomStyleFilePath(context, customMapStyleFilePath);
|
||||
if (customMapStyleID.isEmpty() && customMapStyleFilePath.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
MapCustomStyleOptions mapCustomStyleOptions = new MapCustomStyleOptions();
|
||||
mapCustomStyleOptions.customStyleId(customMapStyleID);
|
||||
mapCustomStyleOptions.localCustomStylePath(customMapStyleFilePath);
|
||||
final HashMap<String, String> reslutMap = new HashMap<>();
|
||||
mTextureMapView.setMapCustomStyle(mapCustomStyleOptions, new CustomMapStyleCallBack() {
|
||||
@Override
|
||||
public boolean onPreLoadLastCustomMapStyle(String path) {
|
||||
reslutMap.put("preloadPath", path);
|
||||
result.success(reslutMap);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCustomMapStyleLoadSuccess(boolean b, String path) {
|
||||
// TODO: 2020-03-05 回调的 boolean 类型没有返回之后补齐
|
||||
reslutMap.put("successPath", path);
|
||||
result.success(reslutMap);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCustomMapStyleLoadFailed(int status, String message, String path) {
|
||||
String sStatus = String.valueOf(status);
|
||||
reslutMap.put("errorCode", sStatus);
|
||||
reslutMap.put("successPath", path);
|
||||
result.success(reslutMap);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,270 @@
|
||||
package com.baidu.flutter_bmfmap.map.mapHandler;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.baidu.flutter_bmfmap.map.FlutterCommonMapView;
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
import com.baidu.flutter_bmfmap.utils.converter.FlutterDataConveter;
|
||||
import com.baidu.flutter_bmfmap.utils.converter.TypeConverter;
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
import com.baidu.mapapi.map.Gradient;
|
||||
import com.baidu.mapapi.map.HeatMap;
|
||||
import com.baidu.mapapi.map.WeightedLatLng;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Iterator;
|
||||
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.HeatMapProtocol;
|
||||
|
||||
class HeatMapHandler extends BMapHandler {
|
||||
private static final String TAG = "HeapMapHandler";
|
||||
|
||||
HeatMap mHeatMap = null;
|
||||
|
||||
public HeatMapHandler(FlutterCommonMapView mapView) {
|
||||
super(mapView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerMethodCallResult(Context context,MethodCall call, MethodChannel.Result result) {
|
||||
if (null == call) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
String methodId = call.method;
|
||||
if (TextUtils.isEmpty(methodId)) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean ret = false;
|
||||
switch (methodId) {
|
||||
case HeatMapProtocol.sMapAddHeatMapMethod:
|
||||
ret = addHeapMap(context, call);
|
||||
break;
|
||||
case HeatMapProtocol.sMapRemoveHeatMapMethod:
|
||||
ret = switchHeatMap(context, call);
|
||||
break;
|
||||
case HeatMapProtocol.sShowHeatMapMethod:
|
||||
ret = isShowBaiduHeatMap(call);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.success(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否显示百度热力图
|
||||
*/
|
||||
public boolean isShowBaiduHeatMap(MethodCall call) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (argument == null || !argument.containsKey("show")) {
|
||||
return false;
|
||||
}
|
||||
Boolean show = (Boolean) argument.get("show");
|
||||
if (null == show) {
|
||||
return false;
|
||||
}
|
||||
if (null == mMapView) {
|
||||
return false;
|
||||
}
|
||||
BaiduMap baiduMap = mMapView.getBaiduMap();
|
||||
baiduMap.setBaiduHeatMapEnabled(show);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean addHeapMap(Context context,MethodCall call){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "addHeapMap enter");
|
||||
}
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if(null == argument){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "argument is null");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Object heatMapObj = argument.get("heatMap");
|
||||
if(null == heatMapObj){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "null == heatMapObj");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Map<String, Object> heatMapMap = (Map<String, Object>)heatMapObj;
|
||||
if(null == heatMapMap){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "null == heatMapMap");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!heatMapMap.containsKey("data")
|
||||
|| !heatMapMap.containsKey("radius")
|
||||
|| !heatMapMap.containsKey("opacity")
|
||||
|| !heatMapMap.containsKey("gradient")) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "argument does not contain"+ argument.toString());
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
HeatMap.Builder builder = new HeatMap.Builder();
|
||||
|
||||
List<WeightedLatLng> weightedLatLngList = getData(heatMapMap);
|
||||
if(null == weightedLatLngList){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "null == weightedLatLngList");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
builder.weightedData(weightedLatLngList);
|
||||
|
||||
Object gradientObj = heatMapMap.get("gradient");
|
||||
if(null == gradientObj){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "null == gradientObj");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Map<String, Object> gradientMap = (Map<String, Object>)gradientObj;
|
||||
if(null == gradientMap){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "null == gradientMap");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Gradient gradient = getGradient(gradientMap);
|
||||
builder.gradient(gradient);
|
||||
|
||||
Double opacity = new TypeConverter<Double>().getValue(heatMapMap, "opacity");
|
||||
if(null == opacity){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "null == opacity");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
builder.opacity(opacity);
|
||||
|
||||
Integer radius = new TypeConverter<Integer>().getValue(heatMapMap, "radius");
|
||||
if(null == radius) {
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "null == radius");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
builder.radius(radius);
|
||||
|
||||
mHeatMap = builder.build();
|
||||
|
||||
if(null == mHeatMap){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "null == mHeatMap");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
BaiduMap baiduMap = mMapView.getBaiduMap();
|
||||
if(null == baiduMap){
|
||||
return false;
|
||||
}
|
||||
|
||||
baiduMap.addHeatMap(mHeatMap);
|
||||
return true;
|
||||
}
|
||||
|
||||
private List<WeightedLatLng> getData(Map<String, Object> heatMapMap){
|
||||
List<WeightedLatLng> weightedLatLngList = null;
|
||||
Object dataObj = heatMapMap.get("data");
|
||||
if(null == dataObj){
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Map<String, Object> > dataList = (List<Map<String, Object> >)dataObj;
|
||||
if(null == dataList){
|
||||
return null;
|
||||
}
|
||||
|
||||
weightedLatLngList = FlutterDataConveter.mapToWeightedLatLngList(dataList);
|
||||
|
||||
return weightedLatLngList;
|
||||
}
|
||||
|
||||
private Gradient getGradient(Map<String, Object> heatMapMap){
|
||||
if(!heatMapMap.containsKey("colors") || !heatMapMap.containsKey("startPoints")){
|
||||
return null;
|
||||
}
|
||||
|
||||
Object colorsObj = heatMapMap.get("colors");
|
||||
Object startPointsObj = heatMapMap.get("startPoints");
|
||||
if(null == colorsObj || null == startPointsObj){
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> colorsList = (List<String>)colorsObj;
|
||||
List<Double> startPointsList = (List<Double>)startPointsObj;
|
||||
if(null == colorsList || null == startPointsList){
|
||||
return null;
|
||||
}
|
||||
|
||||
int[] intColors = new int[colorsList.size()];
|
||||
Iterator<String> itr = colorsList.iterator();
|
||||
int i = 0;
|
||||
while (itr.hasNext()){
|
||||
String colorStr = itr.next();
|
||||
int color = FlutterDataConveter.strColorToInteger(colorStr);
|
||||
intColors[i++] = color;
|
||||
}
|
||||
|
||||
float[] startPoints = new float[startPointsList.size()];
|
||||
Iterator<Double> startPointsItr = startPointsList.iterator();
|
||||
i = 0;
|
||||
while (startPointsItr.hasNext()){
|
||||
startPoints[i++] = startPointsItr.next().floatValue();
|
||||
}
|
||||
|
||||
Gradient gradient = new Gradient(intColors, startPoints);
|
||||
return gradient;
|
||||
}
|
||||
|
||||
public boolean switchHeatMap(Context context,MethodCall call){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "switchHeatMap enter");
|
||||
}
|
||||
|
||||
if(null == mHeatMap){
|
||||
return false;
|
||||
}
|
||||
|
||||
BaiduMap baiduMap = mMapView.getBaiduMap();
|
||||
if(null == baiduMap){
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "baiduMap is null");
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
mHeatMap.removeHeatMap();
|
||||
mHeatMap = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,195 @@
|
||||
package com.baidu.flutter_bmfmap.map.mapHandler;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.baidu.flutter_bmfmap.map.FlutterCommonMapView;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants;
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
import com.baidu.mapapi.map.MapBaseIndoorMapInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
|
||||
public class IndoorMapHandler extends BMapHandler {
|
||||
|
||||
private static final String TAG = "IndoorMapHandler";
|
||||
|
||||
private BaiduMap mBaiduMap;
|
||||
|
||||
public IndoorMapHandler(FlutterCommonMapView mapView) {
|
||||
super(mapView);
|
||||
if(null != mapView){
|
||||
mBaiduMap = mapView.getBaiduMap();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMapView(FlutterCommonMapView mapView) {
|
||||
super.updateMapView(mapView);
|
||||
if(null != mapView){
|
||||
mBaiduMap = mapView.getBaiduMap();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerMethodCallResult(Context context, MethodCall call, MethodChannel.Result result) {
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "handlerMethodCallResult enter");
|
||||
}
|
||||
if (null == call) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
String methodId = call.method;
|
||||
if (TextUtils.isEmpty(methodId)) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
switch (methodId) {
|
||||
case Constants.MethodProtocol.IndoorMapProtocol.sShowBaseIndoorMapMethod:
|
||||
setIndoorMap(call, result);
|
||||
break;
|
||||
case Constants.MethodProtocol.IndoorMapProtocol.sShowBaseIndoorMapPoiMethod:
|
||||
setIndoorMapPoi(call, result);
|
||||
break;
|
||||
case Constants.MethodProtocol.IndoorMapProtocol.sSwitchBaseIndoorMapFloorMethod:
|
||||
switchIndoorMapFloor(call, result);
|
||||
break;
|
||||
case Constants.MethodProtocol.IndoorMapProtocol.sGetFocusedBaseIndoorMapInfoMethod:
|
||||
getFocusedBaseIndoorMapInfo(call, result);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 室内图开关
|
||||
*/
|
||||
private void setIndoorMap(MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mBaiduMap) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
if (!argument.containsKey("show")) {
|
||||
result.success(false);
|
||||
}
|
||||
boolean showIndoorMap = (boolean) argument.get("show");
|
||||
mBaiduMap.setIndoorEnable(showIndoorMap);
|
||||
BMFMapStatus.getsInstance().setBaseIndoorEnable(showIndoorMap);
|
||||
result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 室内图poi开关
|
||||
*/
|
||||
private void setIndoorMapPoi(MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mMapView) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if(null == mBaiduMap){
|
||||
return;
|
||||
}
|
||||
|
||||
if (!argument.containsKey("showIndoorPoi")) {
|
||||
result.success(false);
|
||||
}
|
||||
boolean showIndoorPoi = (boolean) argument.get("showIndoorPoi");
|
||||
mBaiduMap.showMapIndoorPoi(showIndoorPoi);
|
||||
BMFMapStatus.getsInstance().setIndoorMapPoiEnable(showIndoorPoi);
|
||||
result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 室内图楼层切换
|
||||
*/
|
||||
private void switchIndoorMapFloor(MethodCall call, MethodChannel.Result result) {
|
||||
HashMap<String, Integer> errorMap = new HashMap<>();
|
||||
int switchIndoorFloorSuccess = Constants.SwitchIndoorFloorError.FAILED;
|
||||
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mBaiduMap) {
|
||||
errorMap.put("result", switchIndoorFloorSuccess);
|
||||
result.success(errorMap);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!argument.containsKey("floorId") || !argument.containsKey("indoorId")) {
|
||||
errorMap.put("result", switchIndoorFloorSuccess);
|
||||
result.success(errorMap);
|
||||
return;
|
||||
}
|
||||
String floorId = (String) argument.get("floorId");
|
||||
String indoorId = (String) argument.get("indoorId");
|
||||
if (floorId.isEmpty() || indoorId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
MapBaseIndoorMapInfo.SwitchFloorError switchFloorError = mBaiduMap.switchBaseIndoorMapFloor(floorId, indoorId);
|
||||
switch (switchFloorError) {
|
||||
case SWITCH_OK:
|
||||
switchIndoorFloorSuccess = Constants.SwitchIndoorFloorError.SUCCESS;
|
||||
break;
|
||||
case SWITCH_ERROR:
|
||||
switchIndoorFloorSuccess = Constants.SwitchIndoorFloorError.FAILED;
|
||||
break;
|
||||
case FOCUSED_ID_ERROR:
|
||||
switchIndoorFloorSuccess = Constants.SwitchIndoorFloorError.NOT_FOCUSED;
|
||||
break;
|
||||
case FLOOR_OVERLFLOW:
|
||||
switchIndoorFloorSuccess = Constants.SwitchIndoorFloorError.NOT_EXIST;
|
||||
break;
|
||||
case FLOOR_INFO_ERROR:
|
||||
switchIndoorFloorSuccess = Constants.SwitchIndoorFloorError.SWICH_FLOOR_INFO_ERROR;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
errorMap.put("result", switchIndoorFloorSuccess);
|
||||
result.success(errorMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前聚焦的室内图信息
|
||||
*/
|
||||
private void getFocusedBaseIndoorMapInfo(MethodCall call, MethodChannel.Result result) {
|
||||
if (null == mBaiduMap) {
|
||||
return;
|
||||
}
|
||||
MapBaseIndoorMapInfo focusedBaseIndoorMapInfo = mBaiduMap.getFocusedBaseIndoorMapInfo();
|
||||
BMFBaseIndoorMapInfo bmfBaseIndoorMapInfo = new BMFBaseIndoorMapInfo();
|
||||
if (null != focusedBaseIndoorMapInfo) {
|
||||
bmfBaseIndoorMapInfo.strFloor = focusedBaseIndoorMapInfo.getCurFloor();
|
||||
bmfBaseIndoorMapInfo.strID = focusedBaseIndoorMapInfo.getID();
|
||||
bmfBaseIndoorMapInfo.listStrFloors = focusedBaseIndoorMapInfo.getFloors();
|
||||
}
|
||||
|
||||
HashMap<String, Object> stringObjectHashMap = new HashMap<>();
|
||||
stringObjectHashMap.put("listStrFloors", bmfBaseIndoorMapInfo.listStrFloors);
|
||||
stringObjectHashMap.put("strFloor", bmfBaseIndoorMapInfo.strFloor);
|
||||
stringObjectHashMap.put("strID", bmfBaseIndoorMapInfo.strID);
|
||||
result.success(stringObjectHashMap);
|
||||
}
|
||||
|
||||
|
||||
class BMFBaseIndoorMapInfo {
|
||||
private String strID = "";
|
||||
private String strFloor = "";
|
||||
private ArrayList<String> listStrFloors;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,306 @@
|
||||
package com.baidu.flutter_bmfmap.map.mapHandler;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.baidu.flutter_bmfmap.map.mapHandler.BMapHandler;
|
||||
import com.baidu.flutter_bmfmap.map.FlutterCommonMapView;
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
import com.baidu.flutter_bmfmap.utils.converter.FlutterDataConveter;
|
||||
import com.baidu.flutter_bmfmap.utils.converter.TypeConverter;
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.InfoWindowProtocol;
|
||||
import com.baidu.mapapi.map.BitmapDescriptor;
|
||||
import com.baidu.mapapi.map.BitmapDescriptorFactory;
|
||||
import com.baidu.mapapi.map.InfoWindow;
|
||||
import com.baidu.mapapi.model.LatLng;
|
||||
|
||||
public class InfoWindowHandler extends BMapHandler{
|
||||
|
||||
private static final String TAG = "InfoWindowHandler";
|
||||
|
||||
private HashMap<String, InfoWindow> mInfoWindows;
|
||||
private HashMap<String, BitmapDescriptor> mBitmapMap = new HashMap<>();
|
||||
private MethodChannel mMethodChannel;
|
||||
private BaiduMap mBaiduMap;
|
||||
|
||||
public InfoWindowHandler(FlutterCommonMapView mapView){
|
||||
super(mapView);
|
||||
if(null != mMapView){
|
||||
mBaiduMap = mMapView.getBaiduMap();
|
||||
}
|
||||
mInfoWindows = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMapView(FlutterCommonMapView mapView){
|
||||
mMapView = mapView;
|
||||
if(null != mMapView){
|
||||
mBaiduMap = mMapView.getBaiduMap();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerMethodCallResult(Context context, MethodCall call, MethodChannel.Result result) {
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "handlerMethodCallResult enter");
|
||||
}
|
||||
if(null == mBaiduMap){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "mBaidumap is null");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
String methodId = call.method;
|
||||
|
||||
switch (methodId){
|
||||
case InfoWindowProtocol.sAddInfoWindowMapMethod:
|
||||
addInfoWindow(call, result);
|
||||
break;
|
||||
case InfoWindowProtocol.sAddInfoWindowsMapMethod:
|
||||
addInfoWindows(call,result);
|
||||
break;
|
||||
case InfoWindowProtocol.sRemoveInfoWindowMapMethod:
|
||||
removeInfoWindow(call, result);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加单个infoWindow
|
||||
* @param call
|
||||
* @param result
|
||||
*/
|
||||
private void addInfoWindow(MethodCall call, MethodChannel.Result result){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "addInfoWindow enter");
|
||||
}
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if(null == argument){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "argument is null");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
addOneInfoWindowImp(argument);
|
||||
}
|
||||
|
||||
/**
|
||||
* 具体添加一个infowindow
|
||||
* @param infoWindowMap
|
||||
*/
|
||||
private void addOneInfoWindowImp(Map<String, Object> infoWindowMap){
|
||||
|
||||
AbstractMap.SimpleEntry<String,InfoWindow> infoWindowEntry = MaptoInfoWindowEntry(infoWindowMap);
|
||||
|
||||
if(null == infoWindowEntry){
|
||||
return;
|
||||
}
|
||||
|
||||
mInfoWindows.put(infoWindowEntry.getKey(), infoWindowEntry.getValue());
|
||||
mBaiduMap.showInfoWindow(infoWindowEntry.getValue());
|
||||
}
|
||||
|
||||
private AbstractMap.SimpleEntry<String, InfoWindow> MaptoInfoWindowEntry(Map<String, Object> infoWindowMap){
|
||||
if(null == infoWindowMap){
|
||||
return null;
|
||||
}
|
||||
if(!infoWindowMap.containsKey("id")){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "argument does not contain");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
final String id = new TypeConverter<String>().getValue(infoWindowMap, "id");
|
||||
if(TextUtils.isEmpty(id)){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "TextUtils.isEmpty(id)");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if(mInfoWindows.containsKey(id)){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "infowindow already added");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String image = new TypeConverter<String>().getValue(infoWindowMap, "image");
|
||||
if(TextUtils.isEmpty(image)){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "TextUtils.isEmpty(image)");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Map<String, Object> latLngMap = new TypeConverter<Map<String, Object>>().getValue(infoWindowMap, "coordinate");
|
||||
LatLng latLng = FlutterDataConveter.mapToLatlng(latLngMap);
|
||||
if(null == latLng){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "null == latLng");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Double yOffSet = new TypeConverter<Double>().getValue(infoWindowMap, "yOffset");
|
||||
if(null == yOffSet){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "null == yOffSet");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Boolean isAddWithBitmapDescriptor = new TypeConverter<Boolean>().getValue(infoWindowMap, "isAddWithBitmapDescriptor");
|
||||
if(null == isAddWithBitmapDescriptor){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "null == isAddWithBitmapDescriptor");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
BitmapDescriptor bitmap = BitmapDescriptorFactory.fromAsset("flutter_assets/" + image);
|
||||
if(null == bitmap){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "null == bitmap");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
mBitmapMap.put(id, bitmap);
|
||||
|
||||
InfoWindow infoWindow = new InfoWindow(bitmap, latLng, yOffSet.intValue(), new InfoWindow.OnInfoWindowClickListener(){
|
||||
|
||||
@Override
|
||||
public void onInfoWindowClick() {
|
||||
if(null == mMethodChannel){
|
||||
return;
|
||||
}
|
||||
Map<String, Object> infoWindowMap = new HashMap<>();
|
||||
|
||||
infoWindowMap.put("id", id);
|
||||
|
||||
mMethodChannel.invokeMethod(InfoWindowProtocol.sMapDidClickedInfoWindowMethod, infoWindowMap);
|
||||
}
|
||||
} );
|
||||
|
||||
return new AbstractMap.SimpleEntry<String, InfoWindow>(id, infoWindow);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量添加infowindow
|
||||
* @param call
|
||||
* @param result
|
||||
*/
|
||||
private void addInfoWindows(MethodCall call, MethodChannel.Result result) {
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "addInfoWindows enter");
|
||||
}
|
||||
List<Object> arguments = (List<Object>)call.arguments;
|
||||
if(null == arguments){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "arguments is null");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
List<InfoWindow> infoWindowList = new ArrayList<>();
|
||||
Iterator itr = arguments.iterator();
|
||||
while (itr.hasNext()){
|
||||
Map<String, Object> infoWindowMap = (Map<String, Object> )itr.next();
|
||||
if(null == infoWindowMap){
|
||||
continue;
|
||||
}
|
||||
|
||||
AbstractMap.SimpleEntry<String,InfoWindow> infoWindowEntry = MaptoInfoWindowEntry(infoWindowMap);
|
||||
if(null == infoWindowEntry){
|
||||
continue;
|
||||
}
|
||||
|
||||
infoWindowList.add(infoWindowEntry.getValue());
|
||||
mInfoWindows.put(infoWindowEntry.getKey(), infoWindowEntry.getValue());
|
||||
}
|
||||
|
||||
if(infoWindowList.size() > 0){
|
||||
mBaiduMap.showInfoWindows(infoWindowList);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeInfoWindow(MethodCall call, MethodChannel.Result result){
|
||||
if(null == mBaiduMap){
|
||||
return;
|
||||
}
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if(null == argument){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "argument is null");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String id = new TypeConverter<String>().getValue(argument, "id");
|
||||
if(TextUtils.isEmpty(id)){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "TextUtils.isEmpty(id)");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
InfoWindow infoWindow = mInfoWindows.get(id);
|
||||
if(null == infoWindow){
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "null == infoWindow");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(Env.DEBUG){
|
||||
Log.d(TAG, "removeInfoWindow success");
|
||||
}
|
||||
mBaiduMap.hideInfoWindow(infoWindow);
|
||||
|
||||
mInfoWindows.remove(id);
|
||||
|
||||
BitmapDescriptor bitmapDescriptor = mBitmapMap.get(id);
|
||||
if(null != bitmapDescriptor){
|
||||
bitmapDescriptor.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clean(){
|
||||
super.clean();
|
||||
Iterator iterator = mBitmapMap.values().iterator();
|
||||
BitmapDescriptor bitmapDescriptor;
|
||||
while (iterator.hasNext()){
|
||||
bitmapDescriptor = (BitmapDescriptor)iterator.next();
|
||||
if(null != bitmapDescriptor){
|
||||
bitmapDescriptor.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
if(null != mInfoWindows) {
|
||||
mInfoWindows.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,330 @@
|
||||
package com.baidu.flutter_bmfmap.map.mapHandler;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.baidu.flutter_bmfmap.map.FlutterCommonMapView;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants;
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
import com.baidu.mapapi.map.BitmapDescriptor;
|
||||
import com.baidu.mapapi.map.BitmapDescriptorFactory;
|
||||
import com.baidu.mapapi.map.MyLocationConfiguration;
|
||||
import com.baidu.mapapi.map.MyLocationData;
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
|
||||
public class LocationLayerHandler extends BMapHandler {
|
||||
private BaiduMap mBaiduMap;
|
||||
|
||||
public LocationLayerHandler(FlutterCommonMapView mapView) {
|
||||
super(mapView);
|
||||
if (null != mapView) {
|
||||
mBaiduMap = mapView.getBaiduMap();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMapView(FlutterCommonMapView mapView) {
|
||||
super.updateMapView(mapView);
|
||||
if (null != mapView) {
|
||||
mBaiduMap = mapView.getBaiduMap();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerMethodCallResult(Context context, MethodCall call, MethodChannel.Result result) {
|
||||
if (null == call) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
String methodId = call.method;
|
||||
if (TextUtils.isEmpty(methodId)) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
switch (methodId) {
|
||||
case Constants.LocationLayerMethodId.sMapShowUserLocationMethod:
|
||||
setLocationEnabled(call, result);
|
||||
break;
|
||||
|
||||
case Constants.LocationLayerMethodId.sMapUpdateLocationDataMethod:
|
||||
setUpdateLocationData(call, result);
|
||||
break;
|
||||
|
||||
case Constants.LocationLayerMethodId.sMapUserTrackingModeMethod:
|
||||
setLoctype(call, result);
|
||||
|
||||
break;
|
||||
case Constants.LocationLayerMethodId.sMapUpdateLocationDisplayParamMethod:
|
||||
setCustomLocation(call, result);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义定位图层
|
||||
*/
|
||||
private void setCustomLocation(MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mBaiduMap) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
if (!argument.containsKey("userlocationDisplayParam")) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> locationDisplayParam = (Map<String, Object>) argument.get("userlocationDisplayParam");
|
||||
|
||||
if (null == locationDisplayParam) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!locationDisplayParam.containsKey("userTrackingMode")
|
||||
|| !locationDisplayParam.containsKey("enableDirection")
|
||||
|| !locationDisplayParam.containsKey("accuracyCircleStrokeColor")
|
||||
|| !locationDisplayParam.containsKey("accuracyCircleFillColor")
|
||||
|| !locationDisplayParam.containsKey("locationViewImage")
|
||||
|| !locationDisplayParam.containsKey("locationViewHierarchy")) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Integer userTrackingMode = (Integer) locationDisplayParam.get("userTrackingMode");
|
||||
Boolean enableDirection = (Boolean) locationDisplayParam.get("enableDirection");
|
||||
String locationViewImage = (String) locationDisplayParam.get("locationViewImage");
|
||||
String accuracyCircleStrokeColor = (String) locationDisplayParam.get("accuracyCircleStrokeColor");
|
||||
String accuracyCircleFillColor = (String) locationDisplayParam.get("accuracyCircleFillColor");
|
||||
|
||||
|
||||
BitmapDescriptor bitmap = null;
|
||||
if (!TextUtils.isEmpty(locationViewImage)) {
|
||||
bitmap = BitmapDescriptorFactory.fromAsset("flutter_assets/" + locationViewImage);
|
||||
}
|
||||
|
||||
int strokeColor = 0;
|
||||
String color = "#";
|
||||
if (!TextUtils.isEmpty(accuracyCircleStrokeColor)) {
|
||||
strokeColor = Color.parseColor(color.concat(accuracyCircleStrokeColor));
|
||||
}
|
||||
|
||||
int fillColor = 0;
|
||||
if (!TextUtils.isEmpty(accuracyCircleFillColor)) {
|
||||
fillColor = Color.parseColor(color.concat(accuracyCircleFillColor));
|
||||
}
|
||||
|
||||
if (null != userTrackingMode && null != enableDirection && null != bitmap
|
||||
&& strokeColor != 0 && fillColor != 0) {
|
||||
switch (userTrackingMode) {
|
||||
case Env.LocationMode.NORMAL:
|
||||
case Env.LocationMode.MODEHEADING:
|
||||
mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(
|
||||
MyLocationConfiguration.LocationMode.NORMAL, enableDirection,
|
||||
bitmap,fillColor,strokeColor));
|
||||
break;
|
||||
case Env.LocationMode.FOLLOWING:
|
||||
mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(
|
||||
MyLocationConfiguration.LocationMode.FOLLOWING, enableDirection,
|
||||
bitmap,fillColor,strokeColor));
|
||||
break;
|
||||
case Env.LocationMode.COMPASS:
|
||||
mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(
|
||||
MyLocationConfiguration.LocationMode.COMPASS, enableDirection,
|
||||
bitmap,fillColor,strokeColor));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (null != userTrackingMode && null != enableDirection && strokeColor != 0 && fillColor != 0) {
|
||||
switch (userTrackingMode) {
|
||||
case Env.LocationMode.NORMAL:
|
||||
case Env.LocationMode.MODEHEADING:
|
||||
mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(
|
||||
MyLocationConfiguration.LocationMode.NORMAL, enableDirection,
|
||||
null,fillColor,strokeColor));
|
||||
break;
|
||||
case Env.LocationMode.FOLLOWING:
|
||||
mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(
|
||||
MyLocationConfiguration.LocationMode.FOLLOWING, enableDirection,
|
||||
null,fillColor,strokeColor));
|
||||
break;
|
||||
case Env.LocationMode.COMPASS:
|
||||
mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(
|
||||
MyLocationConfiguration.LocationMode.COMPASS, enableDirection,
|
||||
null,fillColor,strokeColor));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置定位模式
|
||||
*/
|
||||
private void setLoctype(MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mBaiduMap) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!argument.containsKey("userTrackingMode")
|
||||
|| !argument.containsKey("enableDirection")
|
||||
|| !argument.containsKey("customMarker")) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
Integer userTrackingMode = (Integer) argument.get("userTrackingMode");
|
||||
Boolean enableDirection = (Boolean) argument.get("enableDirection");
|
||||
String customMarker = (String) argument.get("customMarker");
|
||||
|
||||
BitmapDescriptor bitmap = BitmapDescriptorFactory.fromAsset("flutter_assets/" + customMarker);
|
||||
if (null != userTrackingMode && null != enableDirection && null != bitmap) {
|
||||
switch (userTrackingMode) {
|
||||
case Env.LocationMode.NORMAL:
|
||||
case Env.LocationMode.MODEHEADING:
|
||||
mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(
|
||||
MyLocationConfiguration.LocationMode.NORMAL, enableDirection, bitmap));
|
||||
break;
|
||||
case Env.LocationMode.FOLLOWING:
|
||||
mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(
|
||||
MyLocationConfiguration.LocationMode.FOLLOWING, enableDirection, bitmap));
|
||||
break;
|
||||
case Env.LocationMode.COMPASS:
|
||||
mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(
|
||||
MyLocationConfiguration.LocationMode.COMPASS, enableDirection, bitmap));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
result.success(true);
|
||||
} else if (null != userTrackingMode && null != enableDirection) {
|
||||
switch (userTrackingMode) {
|
||||
case Env.LocationMode.NORMAL:
|
||||
case Env.LocationMode.MODEHEADING:
|
||||
mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(
|
||||
MyLocationConfiguration.LocationMode.NORMAL, enableDirection, null));
|
||||
break;
|
||||
case Env.LocationMode.FOLLOWING:
|
||||
mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(
|
||||
MyLocationConfiguration.LocationMode.FOLLOWING, enableDirection, null));
|
||||
break;
|
||||
case Env.LocationMode.COMPASS:
|
||||
mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(
|
||||
MyLocationConfiguration.LocationMode.COMPASS, enableDirection, null));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
result.success(true);
|
||||
}
|
||||
result.success(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 定位数据
|
||||
*/
|
||||
private void setUpdateLocationData(MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
MyLocationData.Builder builder = new MyLocationData.Builder();
|
||||
if (null == argument || null == mBaiduMap) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
if (!argument.containsKey("userLocation")) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String,Object> userLocation = (Map<String, Object>) argument.get("userLocation");
|
||||
if (null == userLocation) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
if (!userLocation.containsKey("location")) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String,Object> location = (Map<String, Object>) userLocation.get("location");
|
||||
if (null == location) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
if (!location.containsKey("coordinate") || !location.containsKey("course")
|
||||
|| !location.containsKey("speed") || !location.containsKey("accuracy")
|
||||
|| !location.containsKey("satellitesNum")) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
Map<String,Double> coordinate = (Map<String, Double>) location.get("coordinate");
|
||||
if (null != coordinate) {
|
||||
if (coordinate.containsKey("latitude") && coordinate.containsKey("longitude")) {
|
||||
Double latitude = coordinate.get("latitude");
|
||||
Double longitude = coordinate.get("longitude");
|
||||
if (null != latitude && null != longitude) {
|
||||
builder.latitude(latitude);
|
||||
builder.longitude(longitude);
|
||||
}
|
||||
}
|
||||
}
|
||||
Double course = (Double) location.get("course");
|
||||
if (null != course) {
|
||||
builder.accuracy(course.floatValue());
|
||||
}
|
||||
|
||||
Double speed = (Double) location.get("speed");
|
||||
if (null != speed) {
|
||||
builder.speed(speed.floatValue());
|
||||
}
|
||||
|
||||
Double accuracy = (Double) location.get("accuracy");
|
||||
if (null != accuracy) {
|
||||
builder.speed(accuracy.floatValue());
|
||||
}
|
||||
|
||||
Integer satellitesNum = (Integer) location.get("satellitesNum");
|
||||
if (null != satellitesNum) {
|
||||
builder.satellitesNum(satellitesNum);
|
||||
}
|
||||
|
||||
mBaiduMap.setMyLocationData(builder.build());
|
||||
result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启定位图层
|
||||
*/
|
||||
private void setLocationEnabled(MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mBaiduMap) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!argument.containsKey("show")) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Boolean show = (Boolean) argument.get("show");
|
||||
if (null == show) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
mBaiduMap.setMyLocationEnabled(show);
|
||||
result.success(true);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,409 @@
|
||||
package com.baidu.flutter_bmfmap.map.mapHandler;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baidu.flutter_bmfmap.map.FlutterCommonMapView;
|
||||
import com.baidu.flutter_bmfmap.map.FlutterMapView;
|
||||
import com.baidu.flutter_bmfmap.map.MapStateUpdateImp;
|
||||
import com.baidu.flutter_bmfmap.map.MapViewWrapper;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants;
|
||||
import com.baidu.flutter_bmfmap.utils.converter.FlutterDataConveter;
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
import com.baidu.mapapi.map.BitmapDescriptor;
|
||||
import com.baidu.mapapi.map.BitmapDescriptorFactory;
|
||||
import com.baidu.mapapi.map.MapStatus;
|
||||
import com.baidu.mapapi.map.MapStatusUpdate;
|
||||
import com.baidu.mapapi.map.MapStatusUpdateFactory;
|
||||
import com.baidu.mapapi.map.MapView;
|
||||
import com.baidu.mapapi.map.TextureMapView;
|
||||
import com.baidu.mapapi.map.WinRound;
|
||||
import com.baidu.mapapi.model.LatLng;
|
||||
import com.baidu.mapapi.model.LatLngBounds;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Rect;
|
||||
import android.text.TextUtils;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
public class MapStateHandler extends BMapHandler {
|
||||
private static final String TAG = MapStateHandler.class.getSimpleName();
|
||||
private BaiduMap mBaiduMap;
|
||||
|
||||
private String mViewType;
|
||||
|
||||
public MapStateHandler(FlutterCommonMapView mapView) {
|
||||
super(mapView);
|
||||
mViewType = mapView.getViewType();
|
||||
mBaiduMap = mapView.getBaiduMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMapView(FlutterCommonMapView mapView) {
|
||||
super.updateMapView(mapView);
|
||||
if (null != mapView) {
|
||||
mBaiduMap = mapView.getBaiduMap();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlerMethodCallResult(Context context, MethodCall call,
|
||||
MethodChannel.Result result) {
|
||||
if (null == call) {
|
||||
return;
|
||||
}
|
||||
String methodId = call.method;
|
||||
if (TextUtils.isEmpty(methodId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (methodId) {
|
||||
case Constants.MethodProtocol.MapStateProtocol.sMapUpdateMethod:
|
||||
setMapUpdate(call, result);
|
||||
break;
|
||||
case Constants.MethodProtocol.MapStateProtocol.sMapTakeSnapshotMethod:
|
||||
mapSnapshot(result);
|
||||
break;
|
||||
case Constants.MethodProtocol.MapStateProtocol.sMapTakeSnapshotWithRectMethod:
|
||||
snapShotRect(call, result);
|
||||
break;
|
||||
case Constants.MethodProtocol.MapStateProtocol.sMapSetCompassImageMethod:
|
||||
setCompassImage(call, result);
|
||||
break;
|
||||
case Constants.MethodProtocol.MapStateProtocol.sMapSetCustomTrafficColorMethod:
|
||||
setCustomTrafficColor(call, result);
|
||||
break;
|
||||
case Constants.MethodProtocol.MapStateProtocol.sMapSetVisibleMapBoundsMethod:
|
||||
setNewCoordinateBounds(call, result);
|
||||
break;
|
||||
case Constants.MethodProtocol.MapStateProtocol.sMapSetVisibleMapBoundsWithPaddingMethod:
|
||||
setVisibleMapBoundsWithPaddingMethod(call, result);
|
||||
break;
|
||||
case Constants.MethodProtocol.MapStateProtocol.sMapDidUpdateWidget:
|
||||
case Constants.MethodProtocol.MapStateProtocol.sMapReassemble:
|
||||
resumeMap();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义路况颜色
|
||||
*/
|
||||
private void setCustomTrafficColor(MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mBaiduMap) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
if (!argument.containsKey("smooth") || !argument.containsKey("slow")
|
||||
|| !argument.containsKey("congestion") || !argument
|
||||
.containsKey("severeCongestion")) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
String smooth = (String) argument.get("smooth");
|
||||
String slow = (String) argument.get("slow");
|
||||
String congestion = (String) argument.get("congestion");
|
||||
String severeCongestion = (String) argument.get("severeCongestion");
|
||||
if (smooth == null || slow == null || congestion == null || severeCongestion == null) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
String color = "#";
|
||||
String severeCongestionColor = color.concat(severeCongestion);
|
||||
String congestionColor = color.concat(congestion);
|
||||
String slowColor = color.concat(slow);
|
||||
String smoothColor = color.concat(smooth);
|
||||
|
||||
mBaiduMap.setCustomTrafficColor(severeCongestionColor, congestionColor, slowColor,
|
||||
smoothColor);
|
||||
result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置罗盘图片
|
||||
*/
|
||||
private void setCompassImage(MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mBaiduMap) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!argument.containsKey("imagePath")) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
String imagePath = (String) argument.get("imagePath");
|
||||
if (imagePath == null) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
BitmapDescriptor bitmapDescriptor =
|
||||
BitmapDescriptorFactory.fromAsset("flutter_assets/" + imagePath);
|
||||
Bitmap bitmap = bitmapDescriptor.getBitmap();
|
||||
mBaiduMap.setCompassIcon(bitmap);
|
||||
result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 选取区域截图
|
||||
*/
|
||||
private void snapShotRect(MethodCall call, final MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mBaiduMap) {
|
||||
result.success(null);
|
||||
return;
|
||||
}
|
||||
if (!argument.containsKey("rect")) {
|
||||
result.success(null);
|
||||
return;
|
||||
}
|
||||
Map<String, Object> rect = (Map<String, Object>) argument.get("rect");
|
||||
|
||||
WinRound winRound = FlutterDataConveter.BMFRectToWinRound(rect);
|
||||
if (null == winRound) {
|
||||
result.success(null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (winRound.left > winRound.right || winRound.top > winRound.bottom) {
|
||||
result.success(null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (winRound.right - winRound.left > getMapViewWidth()
|
||||
|| winRound.bottom - winRound.top > getMapViewHeight()) {
|
||||
result.success(null);
|
||||
return;
|
||||
}
|
||||
|
||||
// 矩形区域保证left <= right top <= bottom 否则截屏失败
|
||||
Rect recta = new Rect(winRound.left, winRound.top, winRound.right, winRound.bottom);
|
||||
mBaiduMap.snapshotScope(recta, new BaiduMap.SnapshotReadyCallback() {
|
||||
@Override
|
||||
public void onSnapshotReady(Bitmap bitmap) {
|
||||
if (null == bitmap) {
|
||||
result.success(null);
|
||||
return;
|
||||
}
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
|
||||
result.success(byteArrayOutputStream.toByteArray());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private int getMapViewWidth() {
|
||||
int width = 0;
|
||||
switch (mViewType) {
|
||||
case Constants.ViewType.sMapView:
|
||||
MapView mapView = mMapView.getMapView();
|
||||
width = null != mapView ? mapView.getWidth() : 0;
|
||||
break;
|
||||
case Constants.ViewType.sTextureMapView:
|
||||
TextureMapView textureMapView = mMapView.getTextureMapView();
|
||||
width = null != textureMapView ? textureMapView.getWidth() : 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
private int getMapViewHeight() {
|
||||
int height = 0;
|
||||
switch (mViewType) {
|
||||
case Constants.ViewType.sMapView:
|
||||
MapView mapView = mMapView.getMapView();
|
||||
height = null != mapView ? mapView.getHeight() : 0;
|
||||
break;
|
||||
case Constants.ViewType.sTextureMapView:
|
||||
TextureMapView textureMapView = mMapView.getTextureMapView();
|
||||
height = null != textureMapView ? textureMapView.getHeight() : 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* 截图 全部地图展示区域
|
||||
*/
|
||||
private void mapSnapshot(final MethodChannel.Result result) {
|
||||
if (null == mBaiduMap) {
|
||||
result.success(null);
|
||||
return;
|
||||
}
|
||||
mBaiduMap.snapshot(new BaiduMap.SnapshotReadyCallback() {
|
||||
@Override
|
||||
public void onSnapshotReady(Bitmap bitmap) {
|
||||
if (null == bitmap) {
|
||||
result.success(null);
|
||||
return;
|
||||
}
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
|
||||
result.success(byteArrayOutputStream.toByteArray());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新地图
|
||||
*/
|
||||
private void setMapUpdate(MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mBaiduMap) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean ret = MapStateUpdateImp.getInstance()
|
||||
.setCommView(mMapView)
|
||||
.updateMapState(argument);
|
||||
|
||||
result.success(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置显示在屏幕中的地图地理范围
|
||||
*/
|
||||
private void setNewCoordinateBounds(MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mBaiduMap) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!argument.containsKey("visibleMapBounds")) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> visibleMapBounds =
|
||||
(Map<String, Object>) argument.get("visibleMapBounds");
|
||||
if (null == visibleMapBounds) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
LatLngBounds latLngBounds = visibleMapBoundsImp(visibleMapBounds);
|
||||
if (null == latLngBounds) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLngBounds(latLngBounds));
|
||||
result.success(true);
|
||||
}
|
||||
|
||||
private LatLngBounds visibleMapBoundsImp(Map<String, Object> visibleMapBounds) {
|
||||
if (!visibleMapBounds.containsKey("northeast") || !visibleMapBounds
|
||||
.containsKey("southwest")) {
|
||||
return null;
|
||||
}
|
||||
HashMap<String, Double> northeast =
|
||||
(HashMap<String, Double>) visibleMapBounds.get("northeast");
|
||||
HashMap<String, Double> southwest =
|
||||
(HashMap<String, Double>) visibleMapBounds.get("southwest");
|
||||
if (null == northeast || null == southwest) {
|
||||
return null;
|
||||
}
|
||||
if (!northeast.containsKey("latitude") || !northeast.containsKey("longitude")
|
||||
|| !southwest.containsKey("latitude") || !southwest.containsKey("longitude")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Double northeastLatitude = northeast.get("latitude");
|
||||
Double northeastLongitude = northeast.get("longitude");
|
||||
Double southwestLatitude = southwest.get("latitude");
|
||||
Double southwestLongitude = southwest.get("longitude");
|
||||
|
||||
if (null == northeastLatitude || null == northeastLongitude
|
||||
|| null == southwestLatitude || null == southwestLongitude) {
|
||||
return null;
|
||||
}
|
||||
|
||||
LatLng northeastLatLng = new LatLng(northeastLatitude, northeastLongitude);
|
||||
LatLng southwestLatLng = new LatLng(southwestLatitude, southwestLongitude);
|
||||
LatLngBounds.Builder builder = new LatLngBounds.Builder();
|
||||
builder.include(northeastLatLng);
|
||||
builder.include(southwestLatLng);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据Padding设置地理范围的合适缩放级别
|
||||
*/
|
||||
private void setVisibleMapBoundsWithPaddingMethod(MethodCall call,
|
||||
MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument || null == mBaiduMap) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!argument.containsKey("visibleMapBounds") || !argument.containsKey("insets")) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> visibleMapBounds =
|
||||
(Map<String, Object>) argument.get("visibleMapBounds");
|
||||
Map<String, Double> insets = (Map<String, Double>) argument.get("insets");
|
||||
if (null == visibleMapBounds || null == insets) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
LatLngBounds latLngBounds = visibleMapBoundsImp(visibleMapBounds);
|
||||
if (null == latLngBounds) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!insets.containsKey("left") || !insets.containsKey("top")
|
||||
|| !insets.containsKey("right") || !insets.containsKey("bottom")) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
Double left = insets.get("left");
|
||||
Double top = insets.get("top");
|
||||
Double right = insets.get("right");
|
||||
Double bottom = insets.get("bottom");
|
||||
|
||||
if (null == left || null == top || null == right || null == bottom) {
|
||||
result.success(false);
|
||||
return;
|
||||
}
|
||||
MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newLatLngBounds(latLngBounds,
|
||||
left.intValue(), top.intValue(), right.intValue(), bottom.intValue());
|
||||
mBaiduMap.setMapStatus(mapStatusUpdate);
|
||||
result.success(true);
|
||||
}
|
||||
|
||||
private void updateMap() {
|
||||
MapStatus.Builder builder = new MapStatus.Builder();
|
||||
MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(builder.build());
|
||||
mBaiduMap.setMapStatus(mapStatusUpdate);
|
||||
}
|
||||
|
||||
private void resumeMap() {
|
||||
MapViewWrapper mapViewWrapper = (MapViewWrapper) mMapView;
|
||||
FlutterMapView flutterMapView = mapViewWrapper.getFlutterMapView();
|
||||
flutterMapView.setResumeState(true);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,102 @@
|
||||
package com.baidu.flutter_bmfmap.map.overlayHandler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
import com.baidu.flutter_bmfmap.utils.converter.FlutterDataConveter;
|
||||
import com.baidu.mapapi.map.ArcOptions;
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
import com.baidu.mapapi.map.Overlay;
|
||||
import com.baidu.mapapi.model.LatLng;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
public class ArcLineHandler extends OverlayHandler {
|
||||
private static final String TAG = "ArcLineHandler";
|
||||
|
||||
public ArcLineHandler(BaiduMap baiduMap) {
|
||||
super(baiduMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Overlay> handlerMethodCall(MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!argument.containsKey("id")
|
||||
|| !argument.containsKey("coordinates")) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "argument does not contain");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
ArcOptions arcOptions = new ArcOptions();
|
||||
|
||||
final String id = (String) argument.get("id");
|
||||
if (TextUtils.isEmpty(id)) {
|
||||
return null;
|
||||
}
|
||||
List<Map<String, Object>> coordinates =
|
||||
(List<Map<String, Object>>) argument.get("coordinates");
|
||||
|
||||
if (coordinates.size() < 3) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "atlngs.size() < 3");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
LatLng latLngStart = FlutterDataConveter.mapToLatlng(coordinates.get(0));
|
||||
LatLng latLngMiddle = FlutterDataConveter.mapToLatlng(coordinates.get(1));
|
||||
LatLng latLngEnd = FlutterDataConveter.mapToLatlng(coordinates.get(2));
|
||||
|
||||
if (null == latLngStart
|
||||
|| null == latLngMiddle
|
||||
|| null == latLngEnd) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "null == latLngStart\n" +
|
||||
" || null == latLngMiddle\n" +
|
||||
" || null == latLngEnd");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
arcOptions.points(latLngStart, latLngMiddle, latLngEnd);
|
||||
|
||||
if (argument.containsKey("width")) {
|
||||
int width = (Integer) argument.get("width");
|
||||
arcOptions.width(width);
|
||||
}
|
||||
|
||||
if (argument.containsKey("color")) {
|
||||
String strokeColorStr = (String) argument.get("color");
|
||||
int strokeColor = FlutterDataConveter.strColorToInteger(strokeColorStr);
|
||||
arcOptions.color(strokeColor);
|
||||
}
|
||||
|
||||
if (argument.containsKey("zIndex")) {
|
||||
int zIndex = (Integer) argument.get("zIndex");
|
||||
arcOptions.zIndex(zIndex);
|
||||
}
|
||||
|
||||
if (argument.containsKey("visible")) {
|
||||
boolean visible = (Boolean) argument.get("visible");
|
||||
arcOptions.visible(visible);
|
||||
}
|
||||
|
||||
final Overlay overlay = mBaiduMap.addOverlay(arcOptions);
|
||||
return new HashMap<String, Overlay>() {
|
||||
{
|
||||
put(id, overlay);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,130 @@
|
||||
package com.baidu.flutter_bmfmap.map.overlayHandler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
import com.baidu.flutter_bmfmap.utils.converter.FlutterDataConveter;
|
||||
import com.baidu.flutter_bmfmap.utils.converter.TypeConverter;
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
import com.baidu.mapapi.map.CircleDottedStrokeType;
|
||||
import com.baidu.mapapi.map.CircleOptions;
|
||||
import com.baidu.mapapi.map.Overlay;
|
||||
import com.baidu.mapapi.map.Stroke;
|
||||
import com.baidu.mapapi.model.LatLng;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
public class CircleHandler extends OverlayHandler {
|
||||
|
||||
private static final String TAG = "CircleHandler";
|
||||
|
||||
public CircleHandler(BaiduMap baiduMap) {
|
||||
super(baiduMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Overlay> handlerMethodCall(MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "argument is null");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!argument.containsKey("id")
|
||||
|| !argument.containsKey("center")
|
||||
|| !argument.containsKey("radius")) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "argument does not contain");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
CircleOptions circleOptions = new CircleOptions();
|
||||
|
||||
final String id = new TypeConverter<String>().getValue(argument, "id");
|
||||
if (TextUtils.isEmpty(id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, Object> centerMap = (Map<String, Object>) argument.get("center");
|
||||
LatLng center = FlutterDataConveter.mapToLatlng(centerMap);
|
||||
if (null != center) {
|
||||
circleOptions.center(center);
|
||||
}
|
||||
|
||||
double radius = (Double) argument.get("radius");
|
||||
circleOptions.radius((int) radius);
|
||||
|
||||
|
||||
if (argument.containsKey("width") && argument.containsKey("strokeColor")) {
|
||||
int width = (Integer) argument.get("width");
|
||||
String strokeColorStr = (String) argument.get("strokeColor");
|
||||
if (!TextUtils.isEmpty(strokeColorStr)) {
|
||||
int strokeColor = FlutterDataConveter.strColorToInteger(strokeColorStr);
|
||||
Stroke stroke = new Stroke(width, strokeColor);
|
||||
circleOptions.stroke(stroke);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (argument.containsKey("fillColor")) {
|
||||
String fillColorStr = (String) argument.get("fillColor");
|
||||
int fillColor = FlutterDataConveter.strColorToInteger(fillColorStr);
|
||||
circleOptions.fillColor(fillColor);
|
||||
}
|
||||
|
||||
if (argument.containsKey("zIndex")) {
|
||||
int zIndex = (Integer) argument.get("zIndex");
|
||||
circleOptions.zIndex(zIndex);
|
||||
}
|
||||
|
||||
if (argument.containsKey("visible")) {
|
||||
boolean visible = (Boolean) argument.get("visible");
|
||||
circleOptions.visible(visible);
|
||||
}
|
||||
|
||||
setLineDashType(argument, circleOptions);
|
||||
|
||||
final Overlay overlay = mBaiduMap.addOverlay(circleOptions);
|
||||
return new HashMap<String, Overlay>() {
|
||||
{
|
||||
put(id, overlay);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void setLineDashType(Map<String, Object> circleOptionsMap,
|
||||
CircleOptions circleOptions) {
|
||||
if (null == circleOptionsMap || null == circleOptions) {
|
||||
return;
|
||||
}
|
||||
|
||||
Integer lineDashType =
|
||||
new TypeConverter<Integer>().getValue(circleOptionsMap, "lineDashType");
|
||||
if (null == lineDashType) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (lineDashType) {
|
||||
case OverlayCommon.LineDashType.sLineDashTypeNone:
|
||||
circleOptions.dottedStroke(false);
|
||||
break;
|
||||
case OverlayCommon.LineDashType.sLineDashTypeSquare:
|
||||
circleOptions.dottedStroke(true);
|
||||
circleOptions.dottedStrokeType(CircleDottedStrokeType.DOTTED_LINE_SQUARE);
|
||||
break;
|
||||
case OverlayCommon.LineDashType.sLineDashTypeDot:
|
||||
circleOptions.dottedStroke(true);
|
||||
circleOptions.dottedStrokeType(CircleDottedStrokeType.DOTTED_LINE_CIRCLE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,99 @@
|
||||
package com.baidu.flutter_bmfmap.map.overlayHandler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
import com.baidu.flutter_bmfmap.utils.converter.FlutterDataConveter;
|
||||
import com.baidu.flutter_bmfmap.utils.converter.TypeConverter;
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
import com.baidu.mapapi.map.DotOptions;
|
||||
import com.baidu.mapapi.map.Overlay;
|
||||
import com.baidu.mapapi.model.LatLng;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
public class DotHandler extends OverlayHandler {
|
||||
|
||||
public static final String TAG = "DotHandler";
|
||||
|
||||
public DotHandler(BaiduMap baiduMap) {
|
||||
super(baiduMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Overlay> handlerMethodCall(MethodCall call, MethodChannel.Result result) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "argument is null");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!argument.containsKey("id")) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "argument does not contain" + argument.toString());
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
final String id = new TypeConverter<String>().getValue(argument, "id");
|
||||
if (TextUtils.isEmpty(id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
DotOptions dotOptions = new DotOptions();
|
||||
|
||||
Map<String, Object> centerMap =
|
||||
new TypeConverter<Map<String, Object>>().getValue(argument, "center");
|
||||
LatLng center = FlutterDataConveter.mapToLatlng(centerMap);
|
||||
if (null == center) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "center is null");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
dotOptions.center(center);
|
||||
|
||||
Double radius = new TypeConverter<Double>().getValue(argument, "radius");
|
||||
if (null == radius) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "radius is null");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
dotOptions.radius(radius.intValue());
|
||||
|
||||
String colorStr = new TypeConverter<String>().getValue(argument, "color");
|
||||
if (TextUtils.isEmpty(colorStr)) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "colorStr is null");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
int color = FlutterDataConveter.strColorToInteger(colorStr);
|
||||
dotOptions.color(color);
|
||||
|
||||
Integer zIndex = new TypeConverter<Integer>().getValue(argument, "zIndex");
|
||||
if (null != zIndex) {
|
||||
dotOptions.zIndex(zIndex);
|
||||
}
|
||||
|
||||
Boolean visible = new TypeConverter<Boolean>().getValue(argument, "visible");
|
||||
if (null != visible) {
|
||||
dotOptions.visible(visible);
|
||||
}
|
||||
|
||||
final Overlay overlay = mBaiduMap.addOverlay(dotOptions);
|
||||
return new HashMap<String, Overlay>() {
|
||||
{
|
||||
put(id, overlay);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,177 @@
|
||||
package com.baidu.flutter_bmfmap.map.overlayHandler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
import com.baidu.flutter_bmfmap.utils.converter.FlutterDataConveter;
|
||||
import com.baidu.flutter_bmfmap.utils.converter.TypeConverter;
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
import com.baidu.mapapi.map.BitmapDescriptor;
|
||||
import com.baidu.mapapi.map.BitmapDescriptorFactory;
|
||||
import com.baidu.mapapi.map.GroundOverlay;
|
||||
import com.baidu.mapapi.map.GroundOverlayOptions;
|
||||
import com.baidu.mapapi.map.Overlay;
|
||||
import com.baidu.mapapi.model.LatLng;
|
||||
import com.baidu.mapapi.model.LatLngBounds;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
class GroundHandler extends OverlayHandler {
|
||||
|
||||
private static final String TAG = "GroundHandler";
|
||||
|
||||
private HashMap<String, BitmapDescriptor> mBitmapMap = new HashMap<>();
|
||||
|
||||
public GroundHandler(BaiduMap baiduMap) {
|
||||
super(baiduMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Overlay> handlerMethodCall(MethodCall call, MethodChannel.Result result) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "handlerMethodCall enter");
|
||||
}
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "argument is null");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!argument.containsKey("id")) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "argument does not contain" + argument.toString());
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
final String id = new TypeConverter<String>().getValue(argument, "id");
|
||||
if (TextUtils.isEmpty(id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
GroundOverlayOptions groundOverlayOptions = new GroundOverlayOptions();
|
||||
|
||||
setGroundOptions(id, argument, groundOverlayOptions);
|
||||
|
||||
final Overlay overlay = mBaiduMap.addOverlay(groundOverlayOptions);
|
||||
|
||||
return new HashMap<String, Overlay>() {
|
||||
{
|
||||
put(id, overlay);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void setGroundOptions(String id, Map<String, Object> groundOptionsMap,
|
||||
GroundOverlayOptions groundOverlayOptions) {
|
||||
if (null == groundOptionsMap) {
|
||||
return;
|
||||
}
|
||||
|
||||
String image = new TypeConverter<String>().getValue(groundOptionsMap, "image");
|
||||
if (!TextUtils.isEmpty(image)) {
|
||||
BitmapDescriptor bitmap = BitmapDescriptorFactory.fromAsset("flutter_assets/" + image);
|
||||
if (null != bitmap) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "image");
|
||||
|
||||
}
|
||||
groundOverlayOptions.image(bitmap);
|
||||
mBitmapMap.put(id, bitmap);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Double anchorX = new TypeConverter<Double>().getValue(groundOptionsMap, "anchorX");
|
||||
Double anchorY = new TypeConverter<Double>().getValue(groundOptionsMap, "anchorY");
|
||||
if (null != anchorX && null != anchorY) {
|
||||
groundOverlayOptions.anchor(anchorX.floatValue(), anchorY.floatValue());
|
||||
}
|
||||
|
||||
Map<String, Object> centerMap =
|
||||
new TypeConverter<Map<String, Object>>().getValue(groundOptionsMap, "position");
|
||||
if (null != centerMap) {
|
||||
LatLng center = FlutterDataConveter.mapToLatlng(centerMap);
|
||||
if (null != center) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "position");
|
||||
|
||||
}
|
||||
groundOverlayOptions.position(center);
|
||||
}
|
||||
}
|
||||
|
||||
Double width = new TypeConverter<Double>().getValue(groundOptionsMap, "width");
|
||||
Double height = new TypeConverter<Double>().getValue(groundOptionsMap, "height");
|
||||
if(null != width && null != height){
|
||||
groundOverlayOptions.dimensions(width.intValue(), height.intValue());
|
||||
}
|
||||
|
||||
Map<String, Object> boundsMap =
|
||||
new TypeConverter<Map<String, Object>>().getValue(groundOptionsMap, "bounds");
|
||||
LatLngBounds latLngBounds = FlutterDataConveter.mapToLatlngBounds(boundsMap);
|
||||
if (null != latLngBounds) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "bounds");
|
||||
|
||||
}
|
||||
groundOverlayOptions.positionFromBounds(latLngBounds);
|
||||
}
|
||||
|
||||
Double transparency =
|
||||
new TypeConverter<Double>().getValue(groundOptionsMap, "transparency");
|
||||
if (null != transparency) {
|
||||
groundOverlayOptions.transparency(transparency.floatValue());
|
||||
}
|
||||
|
||||
Integer zIndex = new TypeConverter<Integer>().getValue(groundOptionsMap, "zIndex");
|
||||
if (null != zIndex) {
|
||||
groundOverlayOptions.zIndex(zIndex);
|
||||
}
|
||||
|
||||
Boolean visible = new TypeConverter<Boolean>().getValue(groundOptionsMap, "visible");
|
||||
if (null != visible) {
|
||||
groundOverlayOptions.visible(visible);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void clean(){
|
||||
super.clean();
|
||||
Iterator iterator = mBitmapMap.values().iterator();
|
||||
BitmapDescriptor bitmapDescriptor;
|
||||
while (iterator.hasNext()){
|
||||
bitmapDescriptor = (BitmapDescriptor)iterator.next();
|
||||
if(null != bitmapDescriptor){
|
||||
bitmapDescriptor.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
mBitmapMap.clear();
|
||||
}
|
||||
|
||||
public void clean(String id) {
|
||||
if (TextUtils.isEmpty(id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BitmapDescriptor bitmapDescriptor = mBitmapMap.get(id);
|
||||
if (null != bitmapDescriptor) {
|
||||
bitmapDescriptor.recycle();
|
||||
}
|
||||
|
||||
mBitmapMap.remove(id);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package com.baidu.flutter_bmfmap.map.overlayHandler;
|
||||
|
||||
public class OverlayCommon{
|
||||
|
||||
public static class LineDashType{
|
||||
/**
|
||||
* 实折线
|
||||
*/
|
||||
public static final int sLineDashTypeNone = 0;
|
||||
|
||||
/**
|
||||
* 方块样式
|
||||
*/
|
||||
public static final int sLineDashTypeSquare = 1;
|
||||
|
||||
/**
|
||||
* 圆点样式
|
||||
*/
|
||||
public static final int sLineDashTypeDot = 2;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package com.baidu.flutter_bmfmap.map.overlayHandler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
import com.baidu.mapapi.map.Overlay;
|
||||
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
public abstract class OverlayHandler {
|
||||
protected BaiduMap mBaiduMap;
|
||||
|
||||
protected Overlay mCurrentOverlay;
|
||||
|
||||
public OverlayHandler(BaiduMap baiduMap) {
|
||||
this.mBaiduMap = baiduMap;
|
||||
}
|
||||
|
||||
public abstract Map<String, Overlay> handlerMethodCall(MethodCall call,
|
||||
MethodChannel.Result result);
|
||||
|
||||
public void updateBaiduMap(BaiduMap baiduMap) {
|
||||
mBaiduMap = baiduMap;
|
||||
}
|
||||
|
||||
public void setCurrentOverlay(Overlay overlay){
|
||||
mCurrentOverlay = overlay;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理所有
|
||||
*/
|
||||
public void clean(){}
|
||||
|
||||
/**
|
||||
* 清理指定id的overlay
|
||||
* @param id
|
||||
*/
|
||||
public void clean(String id) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,235 @@
|
||||
package com.baidu.flutter_bmfmap.map.overlayHandler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.ArclineProtocol;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.CirclelineProtocol;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.DotProtocol;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.GroundProtocol;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.OverlayProtocol;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.PolygonProtocol;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.PolylineProtocol;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.TextProtocol;
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.OverlayHandlerType;
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
import com.baidu.mapapi.map.Arc;
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
import com.baidu.mapapi.map.Circle;
|
||||
import com.baidu.mapapi.map.Dot;
|
||||
import com.baidu.mapapi.map.GroundOverlay;
|
||||
import com.baidu.mapapi.map.Overlay;
|
||||
import com.baidu.mapapi.map.Polygon;
|
||||
import com.baidu.mapapi.map.Polyline;
|
||||
import com.baidu.mapapi.map.Text;
|
||||
|
||||
import android.util.Log;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
public class OverlayHandlerFactory {
|
||||
private static final String TAG = "OverlayHandlerFactory";
|
||||
|
||||
private static volatile OverlayHandlerFactory sInstance;
|
||||
|
||||
private HashMap<Integer, OverlayHandler> overlayHandlerHashMap;
|
||||
|
||||
private OverlayManagerHandler mOverlayManagerHandler;
|
||||
|
||||
private OverlayHandlerFactory(BaiduMap baiduMap) {
|
||||
init(baiduMap);
|
||||
}
|
||||
|
||||
public static OverlayHandlerFactory getInstance(BaiduMap baiduMap) {
|
||||
|
||||
if (null == sInstance) {
|
||||
synchronized(OverlayHandlerFactory.class) {
|
||||
if (null == sInstance) {
|
||||
sInstance = new OverlayHandlerFactory(baiduMap);
|
||||
} else {
|
||||
sInstance.updateBaiduMap(baiduMap);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sInstance.updateBaiduMap(baiduMap);
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private void updateBaiduMap(BaiduMap baiduMap) {
|
||||
if (null == baiduMap) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(null == overlayHandlerHashMap || overlayHandlerHashMap.isEmpty()){
|
||||
init(baiduMap);
|
||||
}
|
||||
|
||||
Iterator it = overlayHandlerHashMap.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<Integer, OverlayHandler> entry =
|
||||
(Map.Entry<Integer, OverlayHandler>) it.next();
|
||||
OverlayHandler overlayHandler = entry.getValue();
|
||||
if (null != overlayHandler) {
|
||||
overlayHandler.updateBaiduMap(baiduMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void init(BaiduMap baiduMap) {
|
||||
if (null == baiduMap) {
|
||||
return;
|
||||
}
|
||||
|
||||
mOverlayManagerHandler = new OverlayManagerHandler(baiduMap);
|
||||
overlayHandlerHashMap = new HashMap<>();
|
||||
overlayHandlerHashMap.put(OverlayHandlerType.CIRCLE_HANDLER, new CircleHandler(baiduMap));
|
||||
overlayHandlerHashMap.put(OverlayHandlerType.DOT_HANDLER, new DotHandler(baiduMap));
|
||||
overlayHandlerHashMap.put(OverlayHandlerType.POLYGON_HANDLER, new PolygonHandler(baiduMap));
|
||||
overlayHandlerHashMap
|
||||
.put(OverlayHandlerType.POLYLINE_HANDLER, new PolylineHandler(baiduMap));
|
||||
overlayHandlerHashMap.put(OverlayHandlerType.TEXT_HANDLER, new TextHandler(baiduMap));
|
||||
overlayHandlerHashMap.put(OverlayHandlerType.ARCLINE_HANDLER, new ArcLineHandler(baiduMap));
|
||||
overlayHandlerHashMap.put(OverlayHandlerType.CIRCLE_HANDLER, new CircleHandler(baiduMap));
|
||||
overlayHandlerHashMap.put(OverlayHandlerType.GROUND_HANDLER, new GroundHandler(baiduMap));
|
||||
}
|
||||
|
||||
public boolean dispatchMethodHandler(MethodCall call, MethodChannel.Result result) {
|
||||
if (null == call) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "dispatchMethodHandler: null == call");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
String methodId = call.method;
|
||||
Log.d(TAG, "dispatchMethodHandler: " + methodId);
|
||||
OverlayHandler overlayHandler = null;
|
||||
Overlay overlay;
|
||||
int handlerType = -1;
|
||||
switch (methodId) {
|
||||
case ArclineProtocol.sMapAddArclinelineMethod:
|
||||
overlayHandler = overlayHandlerHashMap.get(OverlayHandlerType.ARCLINE_HANDLER);
|
||||
break;
|
||||
case PolygonProtocol.sMapAddPolygonMethod:
|
||||
overlayHandler = overlayHandlerHashMap.get(OverlayHandlerType.POLYGON_HANDLER);
|
||||
break;
|
||||
case CirclelineProtocol.sMapAddCirclelineMethod:
|
||||
overlayHandler = overlayHandlerHashMap.get(OverlayHandlerType.CIRCLE_HANDLER);
|
||||
break;
|
||||
case PolylineProtocol.sMapAddPolylineMethod:
|
||||
overlayHandler = overlayHandlerHashMap.get(OverlayHandlerType.POLYLINE_HANDLER);
|
||||
break;
|
||||
case DotProtocol.sMapAddDotMethod:
|
||||
overlayHandler = overlayHandlerHashMap.get(OverlayHandlerType.DOT_HANDLER);
|
||||
break;
|
||||
case TextProtocol.sMapAddTextMethod:
|
||||
overlayHandler = overlayHandlerHashMap.get(OverlayHandlerType.TEXT_HANDLER);
|
||||
break;
|
||||
case GroundProtocol.sMapAddGroundMethod:
|
||||
overlayHandler = overlayHandlerHashMap.get(OverlayHandlerType.GROUND_HANDLER);
|
||||
break;
|
||||
case OverlayProtocol.sMapRemoveOverlayMethod:
|
||||
OverlayHandler specOverlayHandler = getCurrentOverlayHandler(call);
|
||||
mOverlayManagerHandler.setCurrentOverlayHandler(specOverlayHandler);
|
||||
overlayHandler = mOverlayManagerHandler;
|
||||
break;
|
||||
case PolylineProtocol.sMapUpdatePolylineMemberMethod:
|
||||
overlayHandler = getCurrentOverlayHandler(call);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (null == overlayHandler) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Map<String, Overlay> overlayMap = overlayHandler.handlerMethodCall(call, result);
|
||||
|
||||
if (null == overlayMap) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mOverlayManagerHandler.addOverlay(overlayMap);
|
||||
return true;
|
||||
}
|
||||
|
||||
private Overlay getCurrentOverlay(MethodCall call) {
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "argument is null");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!argument.containsKey("id")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String id = (String) argument.get("id");
|
||||
|
||||
return mOverlayManagerHandler.getOverlay(id);
|
||||
}
|
||||
|
||||
private int getHandlerType(Overlay overlay) {
|
||||
int handlerType = -1;
|
||||
if (overlay instanceof Polyline) {
|
||||
handlerType = OverlayHandlerType.POLYLINE_HANDLER;
|
||||
} else if (overlay instanceof Polygon) {
|
||||
handlerType = OverlayHandlerType.POLYGON_HANDLER;
|
||||
} else if (overlay instanceof Arc) {
|
||||
handlerType = OverlayHandlerType.ARCLINE_HANDLER;
|
||||
} else if (overlay instanceof Circle) {
|
||||
handlerType = OverlayHandlerType.CIRCLE_HANDLER;
|
||||
} else if (overlay instanceof Dot) {
|
||||
handlerType = OverlayHandlerType.DOT_HANDLER;
|
||||
} else if (overlay instanceof GroundOverlay) {
|
||||
handlerType = OverlayHandlerType.GROUND_HANDLER;
|
||||
} else if (overlay instanceof Text) {
|
||||
handlerType = OverlayHandlerType.TEXT_HANDLER;
|
||||
}
|
||||
|
||||
return handlerType;
|
||||
}
|
||||
|
||||
public void clean(){
|
||||
if(null == overlayHandlerHashMap || overlayHandlerHashMap.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
OverlayHandler overlayHandler= null;
|
||||
Iterator iterator = overlayHandlerHashMap.values().iterator();
|
||||
while (iterator.hasNext()){
|
||||
overlayHandler = (OverlayHandler) iterator.next();
|
||||
if(null == overlayHandler){
|
||||
continue;
|
||||
}
|
||||
|
||||
overlayHandler.clean();
|
||||
}
|
||||
}
|
||||
|
||||
private OverlayHandler getCurrentOverlayHandler(MethodCall call) {
|
||||
if (null == call) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Overlay overlay = getCurrentOverlay(call);
|
||||
if (null == overlay) {
|
||||
return null;
|
||||
}
|
||||
int handlerType = getHandlerType(overlay);
|
||||
OverlayHandler overlayHandler = overlayHandlerHashMap.get(handlerType);
|
||||
if( null != overlayHandler) {
|
||||
overlayHandler.setCurrentOverlay(overlay);
|
||||
}
|
||||
|
||||
return overlayHandler;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,103 @@
|
||||
package com.baidu.flutter_bmfmap.map.overlayHandler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baidu.flutter_bmfmap.utils.Constants.MethodProtocol.OverlayProtocol;
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
import com.baidu.flutter_bmfmap.utils.converter.TypeConverter;
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
import com.baidu.mapapi.map.Overlay;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
public class OverlayManagerHandler extends OverlayHandler {
|
||||
private static final String TAG = "OverlayManagerHandler";
|
||||
|
||||
private HashMap<String, Overlay> mOverlayMap = new HashMap<>();
|
||||
|
||||
private OverlayHandler mCurrentOverlayHandler;
|
||||
|
||||
public OverlayManagerHandler(BaiduMap baiduMap) {
|
||||
super(baiduMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Overlay> handlerMethodCall(MethodCall call, MethodChannel.Result result) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "handlerMethodCall enter");
|
||||
//result.success(false);
|
||||
}
|
||||
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "argument is null");
|
||||
}
|
||||
result.success(false);
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean ret = false;
|
||||
String methodId = call.method;
|
||||
switch (methodId) {
|
||||
case OverlayProtocol.sMapRemoveOverlayMethod:
|
||||
ret = removeOverlay(argument);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.success(ret);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addOverlay(Map<String, Overlay> overlayMap) {
|
||||
mOverlayMap.putAll(overlayMap);
|
||||
}
|
||||
|
||||
public Overlay getOverlay(String id) {
|
||||
return mOverlayMap.get(id);
|
||||
}
|
||||
|
||||
public void setCurrentOverlayHandler(OverlayHandler overlayHandler) {
|
||||
mCurrentOverlayHandler = overlayHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除overlay
|
||||
*
|
||||
* @param argument
|
||||
* @return
|
||||
*/
|
||||
private boolean removeOverlay(Map<String, Object> argument) {
|
||||
String id = new TypeConverter<String>().getValue(argument, "id");
|
||||
if (TextUtils.isEmpty(id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Overlay overlay = mOverlayMap.get(id);
|
||||
if (null == overlay) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "not found overlay with id:" + id);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
overlay.remove();
|
||||
mOverlayMap.remove(id);
|
||||
if(null != mCurrentOverlayHandler) {
|
||||
mCurrentOverlayHandler.clean(id);
|
||||
mCurrentOverlayHandler = null;
|
||||
}
|
||||
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "remove Overlay success");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,117 @@
|
||||
package com.baidu.flutter_bmfmap.map.overlayHandler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
import com.baidu.flutter_bmfmap.utils.converter.FlutterDataConveter;
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
import com.baidu.mapapi.map.Overlay;
|
||||
import com.baidu.mapapi.map.PolygonOptions;
|
||||
import com.baidu.mapapi.map.Stroke;
|
||||
import com.baidu.mapapi.model.LatLng;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
public class PolygonHandler extends OverlayHandler {
|
||||
private static final String TAG = "PolygonHandler";
|
||||
|
||||
public PolygonHandler(BaiduMap baiduMap) {
|
||||
super(baiduMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Overlay> handlerMethodCall(MethodCall call, MethodChannel.Result result) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "handlerMethodCall enter0");
|
||||
}
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "argument is null");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!argument.containsKey("id")
|
||||
|| !argument.containsKey("coordinates")) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "argument does not contain");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
final String id = (String) argument.get("id");
|
||||
if (TextUtils.isEmpty(id)) {
|
||||
return null;
|
||||
}
|
||||
List<Map<String, Double>> coordinates =
|
||||
(List<Map<String, Double>>) argument.get("coordinates");
|
||||
|
||||
if (coordinates.size() < 1) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "coordinates.size() < 1");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
PolygonOptions polygonOptions = new PolygonOptions();
|
||||
|
||||
List<LatLng> coordinatesList = FlutterDataConveter.mapToLatlngs(coordinates);
|
||||
if (null == coordinatesList) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "coordinatesList is null");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
polygonOptions.points(coordinatesList);
|
||||
|
||||
if (argument.containsKey("width") && argument
|
||||
.containsKey("strokeColor")) {
|
||||
int width = (Integer) argument.get("width");
|
||||
String strokeColorStr = (String) argument.get("strokeColor");
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "strokeColorStr:" + strokeColorStr);
|
||||
}
|
||||
if (!TextUtils.isEmpty(strokeColorStr)) {
|
||||
int strokeColor = FlutterDataConveter.strColorToInteger(strokeColorStr);
|
||||
Stroke stroke = new Stroke(width, strokeColor);
|
||||
polygonOptions.stroke(stroke);
|
||||
}
|
||||
}
|
||||
|
||||
if (argument.containsKey("fillColor")) {
|
||||
String fillColorStr = (String) argument.get("fillColor");
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "fillColorStr:" + fillColorStr);
|
||||
}
|
||||
if (!TextUtils.isEmpty(fillColorStr)) {
|
||||
int fillColor = FlutterDataConveter.strColorToInteger(fillColorStr);
|
||||
polygonOptions.fillColor(fillColor);
|
||||
}
|
||||
}
|
||||
|
||||
if (argument.containsKey("zIndex")) {
|
||||
int zIndex = (Integer) argument.get("zIndex");
|
||||
polygonOptions.zIndex(zIndex);
|
||||
}
|
||||
|
||||
if (argument.containsKey("visible")) {
|
||||
boolean visible = (Boolean) argument.get("visible");
|
||||
polygonOptions.visible(visible);
|
||||
}
|
||||
|
||||
final Overlay overlay = mBaiduMap.addOverlay(polygonOptions);
|
||||
|
||||
return new HashMap<String, Overlay>() {
|
||||
{
|
||||
put(id, overlay);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,137 @@
|
||||
package com.baidu.flutter_bmfmap.map.overlayHandler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baidu.flutter_bmfmap.utils.Env;
|
||||
import com.baidu.flutter_bmfmap.utils.converter.FlutterDataConveter;
|
||||
import com.baidu.flutter_bmfmap.utils.converter.TypeConverter;
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
import com.baidu.mapapi.map.Overlay;
|
||||
import com.baidu.mapapi.map.TextOptions;
|
||||
import com.baidu.mapapi.model.LatLng;
|
||||
|
||||
import android.graphics.Typeface;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
public class TextHandler extends OverlayHandler {
|
||||
private static final String TAG = "TextHandler";
|
||||
|
||||
public TextHandler(BaiduMap baiduMap) {
|
||||
super(baiduMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Overlay> handlerMethodCall(MethodCall call, MethodChannel.Result result) {
|
||||
|
||||
Map<String, Object> argument = call.arguments();
|
||||
if (null == argument) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "argument is null");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!argument.containsKey("id")
|
||||
|| !argument.containsKey("text")
|
||||
|| !argument.containsKey("position")) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "argument does not contain" + argument.toString());
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
final String id = new TypeConverter<String>().getValue(argument, "id");
|
||||
if (TextUtils.isEmpty(id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TextOptions textOptions = new TextOptions();
|
||||
|
||||
Object posObj = (argument.get("position"));
|
||||
if (null != posObj) {
|
||||
Map<String, Object> posMap = (Map<String, Object>) posObj;
|
||||
LatLng pos = FlutterDataConveter.mapToLatlng(posMap);
|
||||
if (null != pos) {
|
||||
if (Env.DEBUG) {
|
||||
Log.d(TAG, "pos");
|
||||
}
|
||||
textOptions.position(pos);
|
||||
}
|
||||
}
|
||||
|
||||
String text = new TypeConverter<String>().getValue(argument, "text");
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
return null;
|
||||
}
|
||||
textOptions.text(text);
|
||||
|
||||
setTextOptions(argument, textOptions);
|
||||
|
||||
final Overlay overlay = mBaiduMap.addOverlay(textOptions);
|
||||
return new HashMap<String, Overlay>() {
|
||||
{
|
||||
put(id, overlay);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void setTextOptions(Map<String, Object> textOptionsMap, TextOptions textOptions) {
|
||||
if (null == textOptionsMap || null == textOptions) {
|
||||
return;
|
||||
}
|
||||
|
||||
String bgColorStr = new TypeConverter<String>().getValue(textOptionsMap, "bgColor");
|
||||
if (!TextUtils.isEmpty(bgColorStr)) {
|
||||
int bgColor = FlutterDataConveter.strColorToInteger(bgColorStr);
|
||||
textOptions.bgColor(bgColor);
|
||||
}
|
||||
|
||||
String fongColorStr = new TypeConverter<String>().getValue(textOptionsMap, "fontColor");
|
||||
if (!TextUtils.isEmpty(fongColorStr)) {
|
||||
int fontColor = FlutterDataConveter.strColorToInteger(fongColorStr);
|
||||
textOptions.fontColor(fontColor);
|
||||
}
|
||||
|
||||
Integer fontSize = new TypeConverter<Integer>().getValue(textOptionsMap, "fontSize");
|
||||
if (null != fontSize) {
|
||||
textOptions.fontSize(fontSize);
|
||||
}
|
||||
|
||||
Integer alignx = new TypeConverter<Integer>().getValue(textOptionsMap, "alignX");
|
||||
Integer aligny = new TypeConverter<Integer>().getValue(textOptionsMap, "alignY");
|
||||
if (null != alignx && null != aligny) {
|
||||
textOptions.align(alignx, aligny);
|
||||
}
|
||||
|
||||
Double roate = new TypeConverter<Double>().getValue(textOptionsMap, "rotate");
|
||||
if (null != roate) {
|
||||
textOptions.rotate(roate.floatValue());
|
||||
}
|
||||
|
||||
Integer zIndex = new TypeConverter<Integer>().getValue(textOptionsMap, "zIndex");
|
||||
if (null != zIndex) {
|
||||
textOptions.zIndex(zIndex);
|
||||
}
|
||||
|
||||
Boolean visible = new TypeConverter<Boolean>().getValue(textOptionsMap, "visible");
|
||||
if (null != visible) {
|
||||
textOptions.visible(visible);
|
||||
}
|
||||
|
||||
Map<String, Object> typeFaceMap =
|
||||
new TypeConverter<Map<String, Object>>().getValue(textOptionsMap, "typeFace");
|
||||
if (null != typeFaceMap) {
|
||||
String familyName = new TypeConverter<String>().getValue(typeFaceMap, "familyName");
|
||||
Integer textStype = new TypeConverter<Integer>().getValue(typeFaceMap, "textStype");
|
||||
if (!TextUtils.isEmpty(familyName) && textStype >= 0 && textStype <= 4) {
|
||||
Typeface typeface = Typeface.create(familyName, textStype);
|
||||
textOptions.typeface(typeface);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package com.baidu.flutter_bmfmap.utils;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 用于安全的关闭closeable对象
|
||||
*/
|
||||
public class IOStreamUtils{
|
||||
public static void closeSilently(Closeable o){
|
||||
if(null == o){
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
o.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||
public static void closeSilently(AutoCloseable o){
|
||||
if(null == o){
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
o.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
package com.baidu.flutter_bmfmap.utils;
|
||||
|
||||
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class ThreadPoolUtil {
|
||||
private ThreadFactory mThreadFactory = new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = new Thread(r,"mapThread"+mAtomicInteger.getAndIncrement());
|
||||
return t;
|
||||
}
|
||||
};
|
||||
|
||||
private AtomicInteger mAtomicInteger = new AtomicInteger(0);
|
||||
|
||||
private final int CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
private final int MAX_POLL_SIZE = CORE_POOL_SIZE*2;
|
||||
|
||||
private final int KEEP_ALIVE = 3; //空线程alive时间
|
||||
|
||||
private ExecutorService mExecutorService;
|
||||
|
||||
private ScheduledExecutorService mScheduleExecutorService;
|
||||
|
||||
private static volatile ThreadPoolUtil sInstance;
|
||||
|
||||
public static ThreadPoolUtil getInstance(){
|
||||
if(null == sInstance){
|
||||
synchronized (ThreadPoolUtil.class){
|
||||
if(null == sInstance){
|
||||
sInstance = new ThreadPoolUtil();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public ThreadPoolUtil(){
|
||||
mExecutorService = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POLL_SIZE, KEEP_ALIVE,
|
||||
TimeUnit.SECONDS,
|
||||
new ArrayBlockingQueue<Runnable>(1000),
|
||||
mThreadFactory, new ThreadPoolExecutor.DiscardOldestPolicy());
|
||||
|
||||
mScheduleExecutorService = new ScheduledThreadPoolExecutor(CORE_POOL_SIZE, mThreadFactory);
|
||||
}
|
||||
|
||||
public void execute(Runnable runnable){
|
||||
if(null == mExecutorService){
|
||||
return;
|
||||
}
|
||||
|
||||
mExecutorService.execute(runnable);
|
||||
}
|
||||
|
||||
public ScheduledFuture execute(Runnable runnable, int delayTime){
|
||||
if(null == mScheduleExecutorService){
|
||||
return null;
|
||||
}
|
||||
|
||||
return mScheduleExecutorService.schedule(runnable, delayTime, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="#FFFFFF" />
|
||||
<corners android:radius="3dip"/>
|
||||
<stroke
|
||||
android:width="1dip"
|
||||
android:color="#0000FF" />
|
||||
</shape>
|
||||
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="#FFFFFF" />
|
||||
<corners android:radius="3dip"/>
|
||||
<stroke
|
||||
android:width="1dip"
|
||||
android:color="#728ea3" />
|
||||
</shape>
|
||||
|
After Width: | Height: | Size: 4.7 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Modify this file to customize your launch splash screen -->
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@android:color/white" />
|
||||
|
||||
<!-- You can insert your own image assets here -->
|
||||
<!-- <item>
|
||||
<bitmap
|
||||
android:gravity="center"
|
||||
android:src="@mipmap/launch_image" />
|
||||
</item> -->
|
||||
</layer-list>
|
||||
|
After Width: | Height: | Size: 3.2 KiB |
@ -0,0 +1,23 @@
|
||||
# This file is used by dartdoc when generating API documentation for Flutter.
|
||||
dartdoc:
|
||||
include: ['bmfmap_map']
|
||||
|
||||
# linkToSource:
|
||||
# root: '.'
|
||||
# uriTemplate:
|
||||
showUndocumentedCategories: true
|
||||
ignore:
|
||||
- ambiguous-doc-reference
|
||||
errors:
|
||||
- unresolved-doc-reference
|
||||
warnings:
|
||||
- tool-error
|
||||
# Before you can run dartdoc, the snippets tool needs to have a snapshot built.
|
||||
# The dev/tools/dartdoc.dart script does this automatically.
|
||||
tools:
|
||||
snippet:
|
||||
command: ["dev/snippets/lib/main.dart", "--type=application"]
|
||||
description: "Creates application sample code documentation output from embedded documentation samples."
|
||||
sample:
|
||||
command: ["dev/snippets/lib/main.dart", "--type=sample"]
|
||||
description: "Creates sample code documentation output from embedded documentation samples."
|
||||
@ -0,0 +1,30 @@
|
||||
//
|
||||
// BMFFileManager.h
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zbj on 2020/2/12.
|
||||
//
|
||||
|
||||
#import <Flutter/Flutter.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface BMFFileManager : NSObject
|
||||
|
||||
/// registar
|
||||
@property (nonatomic, strong) NSObject<FlutterPluginRegistrar> *registar;
|
||||
|
||||
/// BMFFileManagerCenter
|
||||
+ (instancetype)defaultCenter;
|
||||
|
||||
/// 获取flutter端图片资源路径
|
||||
- (NSString *)pathForFlutterImageName:(NSString *)imageName;
|
||||
|
||||
/// 获取flutter端文件资源路径
|
||||
- (NSString *)pathForFlutterFileName:(NSString *)fileName;
|
||||
|
||||
/// 获取flutter端瓦片图路径
|
||||
- (NSString *)pathForFlutterTileResources:(NSString *)tileName;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -0,0 +1,39 @@
|
||||
//
|
||||
// BMFFileManager.m
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zbj on 2020/2/12.
|
||||
//
|
||||
|
||||
#import "BMFFileManager.h"
|
||||
|
||||
@implementation BMFFileManager
|
||||
|
||||
static BMFFileManager *_instance = nil;
|
||||
+ (instancetype)defaultCenter{
|
||||
if (!_instance) {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_instance = [[BMFFileManager alloc] init];
|
||||
});
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
/// 获取flutter端图片资源路径
|
||||
- (NSString *)pathForFlutterImageName:(NSString *)imageName{
|
||||
if (!_registar) return nil;
|
||||
return [[NSBundle mainBundle] pathForResource:[_registar lookupKeyForAsset:imageName] ofType:nil];
|
||||
}
|
||||
/// 获取flutter端文件资源路径
|
||||
- (NSString *)pathForFlutterFileName:(NSString *)fileName{
|
||||
if (!_registar) return nil;
|
||||
return [[NSBundle mainBundle] pathForResource:[_registar lookupKeyForAsset:fileName] ofType:nil];
|
||||
}
|
||||
|
||||
/// 获取flutter端瓦片图路径
|
||||
- (NSString *)pathForFlutterTileResources:(NSString *)tileName{
|
||||
if (!_registar) return nil;
|
||||
// 指定resoures/bmflocaltileimage/目录下存放瓦片图资源
|
||||
return [[NSBundle mainBundle] pathForResource:[_registar lookupKeyForAsset:[NSString stringWithFormat:@"resoures/bmflocaltileimage/%@", tileName]] ofType:nil];
|
||||
}
|
||||
@end
|
||||
@ -0,0 +1,7 @@
|
||||
#import <Flutter/Flutter.h>
|
||||
|
||||
@interface FlutterBmfmapPlugin : NSObject <FlutterPlugin>
|
||||
|
||||
//@property (nonatomic, strong) FlutterMethodChannel *channel;
|
||||
|
||||
@end
|
||||
@ -0,0 +1,30 @@
|
||||
#import "FlutterBmfmapPlugin.h"
|
||||
#import <BaiduMapAPI_Base/BMKBaseComponent.h>
|
||||
#import <BaiduMapAPI_Map/BMKMapComponent.h>
|
||||
#import "BMFMapViewController.h"
|
||||
#import "BMFFileManager.h"
|
||||
#import "BMFOfflineMapManager.h"
|
||||
|
||||
|
||||
|
||||
static NSString *kBMFMapIdentifier = @"flutter_bmfmap/map/BMKMapView";
|
||||
@interface FlutterBmfmapPlugin()<BMKGeneralDelegate>
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation FlutterBmfmapPlugin
|
||||
/// 注册
|
||||
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
|
||||
// 初始化BMFFileManagerCenter
|
||||
[BMFFileManager defaultCenter].registar = registrar;
|
||||
|
||||
// mapView
|
||||
[registrar registerViewFactory:[[FlutterMapViewFactory alloc] initWithMessenger:registrar.messenger] withId:kBMFMapIdentifier];
|
||||
|
||||
// 离线地图
|
||||
[BMFOfflineMapManager registerWithRegistrar:registrar];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@ -0,0 +1,44 @@
|
||||
//
|
||||
// BMFAnnotationHandles.h
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zhangbaojin on 2020/2/11.
|
||||
//
|
||||
|
||||
#import "BMFMapViewHandle.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface BMFAnnotationHandles : NSObject
|
||||
/// BMFAnnotationHandler管理中心
|
||||
+ (instancetype)defalutCenter;
|
||||
|
||||
- (NSDictionary<NSString *, NSString *> *)annotationHandles;
|
||||
@end
|
||||
#pragma mark - marker
|
||||
|
||||
@interface BMFAddAnnotation : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFAddAnnotations : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFRemoveAnnotation : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFRemoveAnnotations : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFCleanAllAnnotations : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFUpdateAnnotation : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -0,0 +1,280 @@
|
||||
//
|
||||
// BMFAnnotationHandles.m
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zhangbaojin on 2020/2/11.
|
||||
//
|
||||
|
||||
#import "BMFAnnotationHandles.h"
|
||||
#import "BMFMapView.h"
|
||||
#import "NSObject+BMFVerify.h"
|
||||
#import "BMFAnnotationMethodConst.h"
|
||||
#import "BMFFileManager.h"
|
||||
#import "UIColor+BMFString.h"
|
||||
#import "BMFAnnotation.h"
|
||||
#import "BMFMapModels.h"
|
||||
|
||||
@interface BMFAnnotationHandles ()
|
||||
{
|
||||
NSDictionary *_handles;
|
||||
}
|
||||
@end
|
||||
@implementation BMFAnnotationHandles
|
||||
|
||||
static BMFAnnotationHandles *_instance = nil;
|
||||
+ (instancetype)defalutCenter{
|
||||
if (!_instance) {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_instance = [[BMFAnnotationHandles alloc] init];
|
||||
});
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, NSString *> *)annotationHandles{
|
||||
if (!_handles) {
|
||||
_handles = @{
|
||||
kBMFMapAddMarkerMethod: NSStringFromClass([BMFAddAnnotation class]),
|
||||
kBMFMapAddMarkersMethod: NSStringFromClass([BMFAddAnnotations class]),
|
||||
kBMFMapRemoveMarkerMethod: NSStringFromClass([BMFRemoveAnnotation class]),
|
||||
kBMFMapRemoveMarkersMethod: NSStringFromClass([BMFRemoveAnnotations class]),
|
||||
kBMFMapCleanAllMarkersMethod: NSStringFromClass([BMFCleanAllAnnotations class]),
|
||||
kBMFMapUpdateMarkerMemberMethod: NSStringFromClass([BMFUpdateAnnotation class])
|
||||
};
|
||||
}
|
||||
return _handles;
|
||||
}
|
||||
@end
|
||||
|
||||
#pragma mark - marker
|
||||
|
||||
@implementation BMFAddAnnotation
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
BMKPointAnnotation *annotation = [BMKPointAnnotation annotationWith:call.arguments];
|
||||
if (annotation) {
|
||||
[_mapView addAnnotation:annotation];
|
||||
result(@YES);
|
||||
} else {
|
||||
result(@NO);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFAddAnnotations
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
|
||||
NSMutableArray *annotations = @[].mutableCopy;
|
||||
for (NSDictionary *dic in (NSArray *)call.arguments) {
|
||||
BMKPointAnnotation *an = [BMKPointAnnotation annotationWith:dic];
|
||||
[annotations addObject:an];
|
||||
}
|
||||
[_mapView addAnnotations:annotations];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation BMFRemoveAnnotation
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments || ![call.arguments safeObjectForKey:@"id"]) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
NSString *ID = [call.arguments safeObjectForKey:@"id"];
|
||||
__weak __typeof__(_mapView) weakMapView = _mapView;
|
||||
[_mapView.annotations enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
if ([ID isEqualToString:((BMKPointAnnotation *) obj).Id]) {
|
||||
[weakMapView removeAnnotation:obj];
|
||||
result(@YES);
|
||||
*stop = YES;
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation BMFRemoveAnnotations
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
|
||||
__block NSMutableArray <BMKPointAnnotation*> *annotations = @[].mutableCopy;
|
||||
for (NSDictionary *dic in (NSArray *)call.arguments) {
|
||||
[_mapView.annotations enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
if ([[dic safeObjectForKey:@"id"] isEqualToString:((BMKPointAnnotation *) obj).Id]) {
|
||||
[annotations addObject:obj];
|
||||
*stop = YES;
|
||||
}
|
||||
}];
|
||||
}
|
||||
[_mapView removeAnnotations:annotations];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFCleanAllAnnotations
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
[_mapView removeAnnotations:_mapView.annotations];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFUpdateAnnotation
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments || ![call.arguments safeObjectForKey:@"id"]) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
NSString *ID = [call.arguments safeObjectForKey:@"id"];
|
||||
__block BMKPointAnnotation *annotation;
|
||||
// __weak __typeof__(_mapView) weakMapView = _mapView;
|
||||
[_mapView.annotations enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
if ([ID isEqualToString:((BMKPointAnnotation *) obj).Id]) {
|
||||
annotation = (BMKPointAnnotation *) obj;
|
||||
*stop = YES;
|
||||
}
|
||||
}];
|
||||
if (!annotation) {
|
||||
NSLog(@"根据ID(%@)未找到对应的marker", ID);
|
||||
result(@NO);
|
||||
}
|
||||
|
||||
NSString *member = [call.arguments safeObjectForKey:@"member"];
|
||||
|
||||
if ([member isEqualToString:@"title"]) {
|
||||
annotation.title = [call.arguments safeObjectForKey:@"value"];
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"subtitle"]) {
|
||||
annotation.subtitle = [call.arguments safeObjectForKey:@"value"];
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"position"]) {
|
||||
BMFCoordinate *coord = [BMFCoordinate bmf_modelWith:[call.arguments safeObjectForKey:@"value"]];
|
||||
annotation.coordinate = [coord toCLLocationCoordinate2D];
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"isLockedToScreen"]) {
|
||||
annotation.isLockedToScreen = [[call.arguments safeObjectForKey:@"value"] boolValue];
|
||||
if (annotation.isLockedToScreen) {
|
||||
annotation.screenPointToLock = [[BMFMapPoint bmf_modelWith:[call.arguments safeObjectForKey:@"screenPointToLock"]] toCGPoint];
|
||||
}
|
||||
[_mapView setMapStatus:_mapView.getMapStatus];
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"icon"]) {
|
||||
BMKPinAnnotationView *view = (BMKPinAnnotationView *)[_mapView viewForAnnotation:annotation];
|
||||
view.image = [UIImage imageWithContentsOfFile:[[BMFFileManager defaultCenter] pathForFlutterImageName:[call.arguments safeObjectForKey:@"value"]]];
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"centerOffset"]) {
|
||||
BMKPinAnnotationView *view = (BMKPinAnnotationView *)[_mapView viewForAnnotation:annotation];
|
||||
BMFMapPoint *point = [BMFMapPoint bmf_modelWith:[call.arguments safeObjectForKey:@"value"]];
|
||||
view.centerOffset = [point toCGPoint];
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"enabled3D"]) {
|
||||
BMKPinAnnotationView *view = (BMKPinAnnotationView *)[_mapView viewForAnnotation:annotation];
|
||||
BOOL value = [[call.arguments safeObjectForKey:@"value"] boolValue];
|
||||
view.enabled3D = value;
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"enabled"]) {
|
||||
BMKPinAnnotationView *view = (BMKPinAnnotationView *)[_mapView viewForAnnotation:annotation];
|
||||
BOOL value = [[call.arguments safeObjectForKey:@"value"] boolValue];
|
||||
view.enabled = value;
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"draggable"]) {
|
||||
BMKPinAnnotationView *view = (BMKPinAnnotationView *)[_mapView viewForAnnotation:annotation];
|
||||
BOOL value = [[call.arguments safeObjectForKey:@"value"] boolValue];
|
||||
view.draggable = value;
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"zIndex"]) {
|
||||
NSLog(@"ios - 暂不支持设置zIndex");
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"visible"]) {
|
||||
NSLog(@"ios - 暂不支持设置visible");
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else {
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@ -0,0 +1,32 @@
|
||||
//
|
||||
// BMFHeatMapHandles.h
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zhangbaojin on 2020/4/3.
|
||||
//
|
||||
|
||||
#import "BMFMapViewHandle.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface BMFHeatMapHandles : NSObject
|
||||
/// BMFHeatMapHandles管理中心
|
||||
+ (instancetype)defalutCenter;
|
||||
|
||||
- (NSDictionary<NSString *, NSString *> *)heatMapHandles;
|
||||
@end
|
||||
#pragma mark - heatMap
|
||||
|
||||
@interface BMFShowHeatMap : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFAddHeatMap : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFRemoveHeatMap : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -0,0 +1,100 @@
|
||||
//
|
||||
// BMFHeatMapHandles.m
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zhangbaojin on 2020/4/3.
|
||||
//
|
||||
|
||||
#import "BMFHeatMapHandles.h"
|
||||
#import "BMFMapView.h"
|
||||
#import "BMFHeatMapConst.h"
|
||||
#import "NSObject+BMFVerify.h"
|
||||
#import "BMFHeatMapModel.h"
|
||||
@interface BMFHeatMapHandles ()
|
||||
{
|
||||
NSDictionary *_handles;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation BMFHeatMapHandles
|
||||
static BMFHeatMapHandles *_instance = nil;
|
||||
+ (instancetype)defalutCenter{
|
||||
if (!_instance) {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_instance = [[BMFHeatMapHandles alloc] init];
|
||||
});
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, NSString *> *)heatMapHandles{
|
||||
if (!_handles) {
|
||||
_handles = @{
|
||||
kBMFMapShowHeatMapMethod: NSStringFromClass([BMFShowHeatMap class]),
|
||||
kBMFMapAddHeatMapMethod: NSStringFromClass([BMFAddHeatMap class]),
|
||||
kBMFMapRemoveHeatMapMethod: NSStringFromClass([BMFRemoveHeatMap class]),
|
||||
};
|
||||
}
|
||||
return _handles;
|
||||
}
|
||||
@end
|
||||
|
||||
#pragma mark - heatMap
|
||||
|
||||
@implementation BMFShowHeatMap
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments || !call.arguments[@"show"]) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
_mapView.baiduHeatMapEnabled = [[call.arguments safeValueForKey:@"show"] boolValue];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFAddHeatMap
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments || !call.arguments[@"heatMap"]) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
BMFHeatMapModel *heatMap = [BMFHeatMapModel bmf_modelWith:[call.arguments safeObjectForKey:@"heatMap"]];
|
||||
[_mapView addHeatMap:[heatMap toBMKHeatMap]];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFRemoveHeatMap
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
[_mapView removeHeatMap];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
@end
|
||||
@ -0,0 +1,27 @@
|
||||
//
|
||||
// BMFMapView.h
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zbj on 2020/2/10.
|
||||
//
|
||||
#ifndef __BMFMapView__H__
|
||||
#define __BMFMapView__H__
|
||||
#ifdef __OBJC__
|
||||
#import <BaiduMapAPI_Map/BMKMapComponent.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface BMFMapView : BMKMapView
|
||||
+ (instancetype)viewWithFrame:(CGRect)frame;
|
||||
+ (instancetype)viewWithFrame:(CGRect)frame dic:(NSDictionary *)dic;
|
||||
|
||||
|
||||
/// 更新地图属性(初始化时,部分参数会不生效),在地图加载完成时调用
|
||||
- (BOOL)updateMapOptions;
|
||||
|
||||
- (BOOL)updateMapViewWith:(NSDictionary *)dic;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -0,0 +1,27 @@
|
||||
//
|
||||
// BMFMapViewController.h
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zbj on 2020/2/6.
|
||||
//
|
||||
|
||||
#import <Flutter/Flutter.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface BMFMapViewController : NSObject<FlutterPlatformView>
|
||||
|
||||
- (instancetype)initWithWithFrame:(CGRect)frame
|
||||
viewIdentifier:(int64_t)viewId
|
||||
arguments:(id _Nullable)args
|
||||
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface FlutterMapViewFactory : NSObject<FlutterPlatformViewFactory>
|
||||
|
||||
- (instancetype)initWithMessenger:(NSObject<FlutterBinaryMessenger>*)messager;
|
||||
|
||||
@end
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -0,0 +1,506 @@
|
||||
//
|
||||
// BMFMapViewController.m
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zbj on 2020/2/6.
|
||||
//
|
||||
|
||||
#import "BMFMapViewController.h"
|
||||
#import "BMFMapView.h"
|
||||
#import "BMFMapCallBackConst.h"
|
||||
#import "BMFMapViewHandles.h"
|
||||
#import "BMFAnnotationHandles.h"
|
||||
#import "BMFOverlayHandles.h"
|
||||
#import "BMFHeatMapHandles.h"
|
||||
#import "BMFUserLocationHandles.h"
|
||||
#import "BMFProjectionHandles.h"
|
||||
#import "BMFMapModels.h"
|
||||
#import "BMFMapStatusModel.h"
|
||||
#import "BMFMapPoiModel.h"
|
||||
#import "BMFIndoorMapInfoModel.h"
|
||||
#import "BMFAnnotation.h"
|
||||
#import "BMFFileManager.h"
|
||||
#import "BMFPolyline.h"
|
||||
#import "BMFArcline.h"
|
||||
#import "BMFCircle.h"
|
||||
#import "BMFPolygon.h"
|
||||
#import "UIColor+BMFString.h"
|
||||
|
||||
static NSString *kBMFMapChannelName = @"flutter_bmfmap/map_";
|
||||
static NSString *kMapMethods = @"flutter_bmfmap/map/";
|
||||
static NSString *kMarkerMethods = @"flutter_bmfmap/marker/";
|
||||
static NSString *kOverlayMethods = @"flutter_bmfmap/overlay/";
|
||||
static NSString *kHeatMapMethods = @"flutter_bmfmap/heatMap/";
|
||||
static NSString *kUserLocationMethods = @"flutter_bmfmap/userLocation/";
|
||||
static NSString *kProjectionMethods = @"flutter_bmfmap/projection/";
|
||||
|
||||
@interface BMFMapViewController()<BMKMapViewDelegate>
|
||||
{
|
||||
FlutterMethodChannel *_channel;
|
||||
BMFMapView *_mapView;
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@implementation BMFMapViewController
|
||||
|
||||
- (instancetype)initWithWithFrame:(CGRect)frame
|
||||
viewIdentifier:(int64_t)viewId
|
||||
arguments:(id _Nullable)args
|
||||
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger{
|
||||
if ([super init]) {
|
||||
int Id = (int)(viewId + 97);
|
||||
NSString *channelName = [NSString stringWithFormat:@"%@%@", kBMFMapChannelName, [NSString stringWithFormat:@"%c", Id]];
|
||||
_channel = [FlutterMethodChannel methodChannelWithName:channelName binaryMessenger:messenger];
|
||||
_mapView = [BMFMapView viewWithFrame:frame dic:(NSDictionary*)args];
|
||||
_mapView.delegate = self;
|
||||
|
||||
#pragma mark - flutter -> ios
|
||||
__weak __typeof__(_mapView) weakMapView = _mapView;
|
||||
[_channel setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult _Nonnull result) {
|
||||
NSObject<BMFMapViewHandler> *handler;
|
||||
// map
|
||||
if ([call.method hasPrefix:kMapMethods]) {
|
||||
handler = [NSClassFromString([BMFMapViewHandles defalutCenter].mapViewHandles[call.method]) new];
|
||||
}
|
||||
// marker
|
||||
if ([call.method hasPrefix:kMarkerMethods]) {
|
||||
handler = [NSClassFromString([BMFAnnotationHandles defalutCenter].annotationHandles[call.method]) new];
|
||||
}
|
||||
// overlay
|
||||
if ([call.method hasPrefix:kOverlayMethods]) {
|
||||
handler = [NSClassFromString([BMFOverlayHandles defalutCenter].overlayHandles[call.method]) new];
|
||||
}
|
||||
// 热力图
|
||||
if ([call.method hasPrefix:kHeatMapMethods]) {
|
||||
handler = [NSClassFromString([BMFHeatMapHandles defalutCenter].heatMapHandles[call.method]) new];
|
||||
}
|
||||
// 定位图层
|
||||
if ([call.method hasPrefix:kUserLocationMethods]) {
|
||||
handler = [NSClassFromString([BMFUserLocationHandles defalutCenter].userLocationHandles[call.method]) new];
|
||||
}
|
||||
// 数据转换
|
||||
if ([call.method hasPrefix:kProjectionMethods]) {
|
||||
handler = [NSClassFromString([BMFProjectionHandles defalutCenter].projectionHandles[call.method]) new];
|
||||
}
|
||||
|
||||
|
||||
if (handler) {
|
||||
[[handler initWith:weakMapView] handleMethodCall:call result:result];
|
||||
} else {
|
||||
if ([call.method isEqualToString:@"flutter_bmfmap/map/didUpdateWidget"]) {
|
||||
// NSLog(@"native - didUpdateWidget");
|
||||
return;
|
||||
}
|
||||
if ([call.method isEqualToString:@"flutter_bmfmap/map/reassemble"]) {
|
||||
// NSLog(@"native - reassemble");
|
||||
return;
|
||||
}
|
||||
result(FlutterMethodNotImplemented);
|
||||
}
|
||||
}];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
- (nonnull UIView *)view {
|
||||
return _mapView;
|
||||
}
|
||||
- (void)dealloc {
|
||||
_channel = nil;
|
||||
_mapView.delegate = nil;
|
||||
_mapView = nil;
|
||||
// NSLog(@"-BMFMapViewController-dealloc");
|
||||
}
|
||||
#pragma mark - ios -> flutter
|
||||
#pragma mark - BMKMapViewDelegate
|
||||
/// 地图加载完成
|
||||
- (void)mapViewDidFinishLoading:(BMKMapView *)mapView{
|
||||
if (_mapView) {
|
||||
// 对初始时不生效的属性,在此再调用一次.暂时这么解决
|
||||
[_mapView updateMapOptions];
|
||||
}
|
||||
if (!_channel) return;
|
||||
[_channel invokeMethod:kBMFMapDidLoadCallback arguments:@{@"success": @YES} result:nil];
|
||||
}
|
||||
/// 地图渲染完成
|
||||
- (void)mapViewDidFinishRendering:(BMKMapView *)mapView{
|
||||
if (!_channel) return;
|
||||
[_channel invokeMethod:kBMFMapDidRenderCallback arguments:@{@"success": @YES} result:nil];
|
||||
}
|
||||
|
||||
/// 地图渲染每一帧画面过程中,以及每次需要重绘地图时(例如添加覆盖物)都会调用此接口
|
||||
- (void)mapView:(BMKMapView *)mapView onDrawMapFrame:(BMKMapStatus*)status{
|
||||
if (!_channel) return;
|
||||
BMFMapStatusModel *mapStatus = [BMFMapStatusModel fromMapStatus:status];
|
||||
[_channel invokeMethod:kBMFMapOnDrawMapFrameCallback
|
||||
arguments:@{@"mapStatus": [mapStatus bmf_toDictionary]}
|
||||
result:nil];
|
||||
|
||||
}
|
||||
|
||||
/// 地图区域即将改变时会调用此接口
|
||||
- (void)mapView:(BMKMapView *)mapView regionWillChangeAnimated:(BOOL)animated{
|
||||
if (!_channel) return;
|
||||
BMFMapStatusModel *mapStatus = [BMFMapStatusModel fromMapStatus:[_mapView getMapStatus]];
|
||||
[_channel invokeMethod:kBMFMapRegionWillChangeCallback
|
||||
arguments:@{@"mapStatus": [mapStatus bmf_toDictionary]}
|
||||
result:nil];
|
||||
}
|
||||
|
||||
/// 地图区域即将改变时会调用此接口
|
||||
- (void)mapView:(BMKMapView *)mapView regionWillChangeAnimated:(BOOL)animated reason:(BMKRegionChangeReason)reason{
|
||||
if (!_channel) return;
|
||||
BMFMapStatusModel *mapStatus = [BMFMapStatusModel fromMapStatus:[_mapView getMapStatus]];
|
||||
[_channel invokeMethod:kBMFMapRegionWillChangeWithReasonCallback
|
||||
arguments:@{@"mapStatus": [mapStatus bmf_toDictionary], @"reason": @(reason)}
|
||||
result:nil];
|
||||
}
|
||||
|
||||
/// 地图区域改变完成后会调用此接口
|
||||
- (void)mapView:(BMKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
|
||||
if (!_channel) return;
|
||||
BMFMapStatusModel *mapStatus = [BMFMapStatusModel fromMapStatus:[_mapView getMapStatus]];
|
||||
[_channel invokeMethod:kBMFMapRegionDidChangeCallback
|
||||
arguments:@{@"mapStatus": [mapStatus bmf_toDictionary]}
|
||||
result:nil];
|
||||
}
|
||||
|
||||
/// 地图区域改变完成后会调用此接口
|
||||
- (void)mapView:(BMKMapView *)mapView regionDidChangeAnimated:(BOOL)animated reason:(BMKRegionChangeReason)reason{
|
||||
if (!_channel) return;
|
||||
BMFMapStatusModel *mapStatus = [BMFMapStatusModel fromMapStatus:[_mapView getMapStatus]];
|
||||
[_channel invokeMethod:kBMFMapRegionDidChangeWithReasonCallback
|
||||
arguments:@{@"mapStatus": [mapStatus bmf_toDictionary], @"reason": @(reason)}
|
||||
result:nil];
|
||||
}
|
||||
/// 点中底图标注后会回调此接口
|
||||
- (void)mapView:(BMKMapView *)mapView onClickedMapPoi:(BMKMapPoi *)mapPoi{
|
||||
if (!_channel) return;
|
||||
BMFMapPoiModel *model = [BMFMapPoiModel fromBMKMapPoi:mapPoi];
|
||||
[_channel invokeMethod:kBMFMapOnClickedMapPoiCallback arguments:@{@"poi": [model bmf_toDictionary]} result:nil];
|
||||
}
|
||||
/// 点中底图空白处会回调此接口
|
||||
- (void)mapView:(BMKMapView *)mapView onClickedMapBlank:(CLLocationCoordinate2D)coordinate{
|
||||
if (!_channel) return;
|
||||
BMFCoordinate *coord = [BMFCoordinate fromCLLocationCoordinate2D:coordinate];
|
||||
[_channel invokeMethod:kBMFMapOnClickedMapBlankCallback arguments:@{@"coord": [coord bmf_toDictionary]} result:nil];
|
||||
}
|
||||
|
||||
/// 双击地图时会回调此接口
|
||||
- (void)mapview:(BMKMapView *)mapView onDoubleClick:(CLLocationCoordinate2D)coordinate{
|
||||
if (!_channel) return;
|
||||
BMFCoordinate *coord = [BMFCoordinate fromCLLocationCoordinate2D:coordinate];
|
||||
[_channel invokeMethod:kBMFMapOnDoubleClickCallback arguments:@{@"coord": [coord bmf_toDictionary]} result:nil];
|
||||
}
|
||||
|
||||
/// 长按地图时会回调此接口
|
||||
- (void)mapview:(BMKMapView *)mapView onLongClick:(CLLocationCoordinate2D)coordinate{
|
||||
if (!_channel) return;
|
||||
BMFCoordinate *coord = [BMFCoordinate fromCLLocationCoordinate2D:coordinate];
|
||||
[_channel invokeMethod:kBMFMapOnLongClickCallback arguments:@{@"coord": [coord bmf_toDictionary]} result:nil];
|
||||
}
|
||||
|
||||
/// 3DTouch 按地图时会回调此接口(仅在支持3D Touch,且fouchTouchEnabled属性为YES时,会回调此接口)
|
||||
/// force 触摸该点的力度(参考UITouch的force属性)
|
||||
/// maximumPossibleForce 当前输入机制下的最大可能力度(参考UITouch的maximumPossibleForce属性)
|
||||
- (void)mapview:(BMKMapView *)mapView onForceTouch:(CLLocationCoordinate2D)coordinate force:(CGFloat)force maximumPossibleForce:(CGFloat)maximumPossibleForce{
|
||||
if (!_channel) return;
|
||||
BMFCoordinate *coord = [BMFCoordinate fromCLLocationCoordinate2D:coordinate];
|
||||
[_channel invokeMethod:kBMFMapOnForceTouchCallback arguments:@{@"coord": [coord bmf_toDictionary], @"force": @(force), @"maximumPossibleForce": @(maximumPossibleForce)} result:nil];
|
||||
}
|
||||
|
||||
///地图状态改变完成后会调用此接口
|
||||
- (void)mapStatusDidChanged:(BMKMapView *)mapView{
|
||||
if (!_channel) return;
|
||||
[_channel invokeMethod:kBMFMapStatusDidChangedCallback arguments:nil result:nil];
|
||||
}
|
||||
|
||||
- (void)mapview:(BMKMapView *)mapView baseIndoorMapWithIn:(BOOL)flag baseIndoorMapInfo:(BMKBaseIndoorMapInfo *)info{
|
||||
if (!_channel) return;
|
||||
BMFIndoorMapInfoModel *model = [BMFIndoorMapInfoModel new];
|
||||
model.strID = info.strID;
|
||||
model.strFloor = info.strFloor;
|
||||
model.listStrFloors = info.arrStrFloors;
|
||||
[_channel invokeMethod:kBMFMapInOrOutBaseIndoorMapCallback arguments:@{@"flag": @(flag), @"info": [model bmf_toDictionary]} result:nil];
|
||||
}
|
||||
#pragma mark - annotationView
|
||||
- (BMFAnnotationModel *)annotationModelfromAnnotionView:(BMKAnnotationView *)view{
|
||||
BMFAnnotationModel *model = [BMFAnnotationModel new];
|
||||
BMKPointAnnotation *an = (BMKPointAnnotation *)view.annotation;
|
||||
model.Id = an.Id;
|
||||
model.title = an.title;
|
||||
model.subtitle = an.subtitle;
|
||||
model.position = [BMFCoordinate fromCLLocationCoordinate2D:an.coordinate];
|
||||
model.isLockedToScreen = an.isLockedToScreen;
|
||||
model.screenPointToLock = [BMFMapPoint fromCGPoint:an.screenPointToLock];
|
||||
model.annotationViewOptions = an.annotationViewOptions;
|
||||
return model;
|
||||
}
|
||||
/// 根据anntation生成对应的View
|
||||
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation{
|
||||
if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
|
||||
BMFAnnotationViewOptions *options =((BMKPointAnnotation *)annotation).annotationViewOptions;
|
||||
NSString *identifier = options.identifier ? options.identifier : NSStringFromClass([BMKPointAnnotation class]);
|
||||
BMKPinAnnotationView *annotationView = (BMKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
|
||||
|
||||
if (!annotationView) {
|
||||
annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
|
||||
}
|
||||
|
||||
if (options.icon) {
|
||||
//TODO:image加入空值判断
|
||||
if ([[options.icon substringToIndex:1] isEqualToString:@"/"]) {
|
||||
annotationView.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:options.icon] scale:[[UIScreen mainScreen] scale]];
|
||||
} else {
|
||||
annotationView.image = [UIImage imageWithContentsOfFile:[[BMFFileManager defaultCenter] pathForFlutterImageName:options.icon]];
|
||||
}
|
||||
}
|
||||
|
||||
if (options.centerOffset) {
|
||||
annotationView.centerOffset = [options.centerOffset toCGPoint];
|
||||
}
|
||||
annotationView.selected = options.selected;
|
||||
annotationView.draggable = options.draggable;
|
||||
annotationView.enabled = options.enabled;
|
||||
annotationView.enabled3D = options.enabled3D;
|
||||
|
||||
return annotationView;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
/// 当mapView新添加annotation views时,调用此接口
|
||||
- (void)mapView:(BMKMapView *)mapView didAddAnnotationViews:(NSArray *)views{
|
||||
if (!_channel) return;
|
||||
}
|
||||
|
||||
/// 每次点击BMKAnnotationView都会回调此接口。
|
||||
- (void)mapView:(BMKMapView *)mapView clickAnnotationView:(BMKAnnotationView *)view{
|
||||
if (!_channel) return;
|
||||
if ([view isKindOfClass:NSClassFromString(@"BMKUserLocationView")]) {
|
||||
return;
|
||||
}
|
||||
// 改为回调id
|
||||
BMFAnnotationModel *model = [self annotationModelfromAnnotionView:view];
|
||||
[_channel invokeMethod:kBMFMapClickedMarkerCallback arguments:@{@"id": model.Id} result:^(id _Nullable result) {
|
||||
|
||||
}];
|
||||
}
|
||||
/// 当选中一个annotation views时,调用此接口
|
||||
/// @param mapView 地图View
|
||||
/// @param view 选中的annotation views
|
||||
- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view{
|
||||
if (!_channel) return;
|
||||
if ([view isKindOfClass:NSClassFromString(@"BMKUserLocationView")]) {
|
||||
return;
|
||||
}
|
||||
// 改为回调id
|
||||
BMFAnnotationModel *model = [self annotationModelfromAnnotionView:view];
|
||||
[_channel invokeMethod:kBMFMapDidSelectMarkerCallback arguments:@{@"id": model.Id} result:nil];
|
||||
}
|
||||
|
||||
/// 当取消选中一个annotationView时,调用此接口
|
||||
- (void)mapView:(BMKMapView *)mapView didDeselectAnnotationView:(BMKAnnotationView *)view{
|
||||
if (!_channel) return;
|
||||
// 改为回调id
|
||||
BMFAnnotationModel *model = [self annotationModelfromAnnotionView:view];
|
||||
[_channel invokeMethod:kBMFMapDidDeselectMarkerCallback arguments:@{@"id": model.Id} result:nil];
|
||||
}
|
||||
|
||||
/// 拖动annotation view时,若view的状态发生变化,会调用此函数。ios3.2以后支持
|
||||
- (void)mapView:(BMKMapView *)mapView annotationView:(BMKAnnotationView *)view didChangeDragState:(BMKAnnotationViewDragState)newState
|
||||
fromOldState:(BMKAnnotationViewDragState)oldState{
|
||||
if (!_channel) return;
|
||||
// 改为回调id
|
||||
BMFAnnotationModel *model = [self annotationModelfromAnnotionView:view];
|
||||
[_channel invokeMethod:kBMFMapDidDragMarkerCallback arguments:@{@"id": model.Id} result:nil];
|
||||
|
||||
}
|
||||
|
||||
/// 当点击annotationView的泡泡view时,调用此接口
|
||||
- (void)mapView:(BMKMapView *)mapView annotationViewForBubble:(BMKAnnotationView *)view{
|
||||
if (!_channel) return;
|
||||
// 改为回调id
|
||||
BMFAnnotationModel *model = [self annotationModelfromAnnotionView:view];
|
||||
[_channel invokeMethod:kBMFMapDidClickedPaoPaoCallback arguments:@{@"id": model.Id} result:nil];
|
||||
}
|
||||
#pragma mark - overlayView
|
||||
|
||||
- (BMFPolylineModel *)polylineModelWith:(BMKPolylineView *)view{
|
||||
BMFPolylineModel *model = [BMFPolylineModel new];
|
||||
BMKPolyline *line = view.polyline;
|
||||
model = line.polylineModel;
|
||||
return model;
|
||||
}
|
||||
- (BMKPolylineView *)viewForPolyline:(BMKPolyline *)polyline{
|
||||
BMFPolylineViewOptions *options = polyline.polylineModel.polylineOptions;
|
||||
BMKPolylineView *polylineView = [[BMKPolylineView alloc] initWithPolyline:polyline];
|
||||
polylineView.lineWidth = options.width;
|
||||
polylineView.lineDashType = options.lineDashType;
|
||||
polylineView.lineCapType = options.lineCapType;
|
||||
polylineView.lineJoinType = options.lineJoinType;
|
||||
|
||||
switch (polyline.lineType) {
|
||||
case kBMFDashLine:
|
||||
case kBMFColorLine:{
|
||||
if ([options.colors firstObject]) {
|
||||
polylineView.strokeColor = [UIColor fromColorString:[options.colors firstObject]];
|
||||
} else {
|
||||
// TODO:strokeColor 默认值
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kBMFMultiDashLine:
|
||||
case kBMFColorsLine:{
|
||||
size_t colorsCount = options.colors.count;
|
||||
NSMutableArray<UIColor *> *colors = [NSMutableArray array];
|
||||
for (size_t i = 0; i < colorsCount; i++) {
|
||||
// TODO:colors加入空值判断
|
||||
[colors addObject:[UIColor fromColorString:options.colors[i]]];
|
||||
}
|
||||
polylineView.colors = colors;
|
||||
break;
|
||||
}
|
||||
case kBMFTextureLine:{
|
||||
// TODO:iamge加入空值判断
|
||||
NSString *imagePath = [[BMFFileManager defaultCenter] pathForFlutterImageName:[options.textures firstObject]];
|
||||
[polylineView loadStrokeTextureImage:[UIImage imageWithContentsOfFile:imagePath]];
|
||||
break;
|
||||
}
|
||||
case kBMFTexturesLine:{
|
||||
NSMutableArray<UIImage *> *images = [NSMutableArray array];
|
||||
size_t imagesCount = options.textures.count;
|
||||
NSString *imagePath = nil;
|
||||
for (size_t i = 0; i < imagesCount; i++) {
|
||||
//TODO:image加入空值判断
|
||||
imagePath = options.textures[i];
|
||||
UIImage *image = [UIImage imageWithContentsOfFile:[[BMFFileManager defaultCenter] pathForFlutterImageName:imagePath]];
|
||||
[images addObject:image];
|
||||
}
|
||||
[polylineView loadStrokeTextureImages:images];
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return polylineView;
|
||||
}
|
||||
|
||||
- (BMKArclineView *)viewForArcline:(BMKArcline *)arcline{
|
||||
BMFArclineViewOptions *options = arcline.arclineViewOptions;
|
||||
BMKArclineView *arclineView = [[BMKArclineView alloc] initWithArcline:arcline];
|
||||
if (options.color) {
|
||||
arclineView.strokeColor = [UIColor fromColorString:options.color];
|
||||
} else {
|
||||
arclineView.strokeColor = [UIColor colorWithRed:0.f green:0.f blue:1.f alpha:1.f];
|
||||
}
|
||||
arclineView.lineWidth = options.width;
|
||||
arclineView.lineDashType = options.lineDashType;
|
||||
return arclineView;
|
||||
}
|
||||
|
||||
- (BMKPolygonView *)viewForPolygon:(BMKPolygon *)polygon{
|
||||
BMFPolygonViewOptions *options = polygon.polygonViewOptions;
|
||||
BMKPolygonView *polygonView = [[BMKPolygonView alloc] initWithPolygon:polygon];
|
||||
if (options.strokeColor) {
|
||||
polygonView.strokeColor = [UIColor fromColorString:options.strokeColor];
|
||||
} else {
|
||||
polygonView.strokeColor = [UIColor colorWithRed:0.f green:0.f blue:1.f alpha:1.f];
|
||||
}
|
||||
if (options.fillColor) {
|
||||
polygonView.fillColor = [UIColor fromColorString:options.fillColor];
|
||||
}
|
||||
polygonView.lineWidth = options.width;
|
||||
polygonView.lineDashType = options.lineDashType;
|
||||
return polygonView;
|
||||
}
|
||||
|
||||
- (BMKCircleView *)viewForCircleline:(BMKCircle *)circle{
|
||||
BMFCircleViewOptions *options = circle.circleViewOptions;
|
||||
BMKCircleView *circleView = [[BMKCircleView alloc] initWithCircle:circle];
|
||||
if (options.strokeColor) {
|
||||
circleView.strokeColor = [UIColor fromColorString:options.strokeColor];
|
||||
} else {
|
||||
circleView.strokeColor = [UIColor colorWithRed:0.f green:0.f blue:1.f alpha:1.f];
|
||||
}
|
||||
if (options.fillColor) {
|
||||
circleView.fillColor = [UIColor fromColorString:options.fillColor];
|
||||
}
|
||||
circleView.lineWidth = options.width;
|
||||
circleView.lineDashType = options.lineDashType;
|
||||
return circleView;
|
||||
}
|
||||
- (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id<BMKOverlay>)overlay{
|
||||
if ([overlay isKindOfClass:[BMKPolyline class]]) {
|
||||
return [self viewForPolyline:(BMKPolyline *)overlay];
|
||||
|
||||
} else if ([overlay isKindOfClass:[BMKArcline class]]) {
|
||||
return [self viewForArcline:(BMKArcline *)overlay];
|
||||
|
||||
} else if ([overlay isKindOfClass:[BMKPolygon class]]){
|
||||
return [self viewForPolygon:(BMKPolygon *)overlay];
|
||||
|
||||
} else if ([overlay isKindOfClass:[BMKCircle class]]) {
|
||||
return [self viewForCircleline:(BMKCircle *)overlay];
|
||||
|
||||
} else if ([overlay isKindOfClass:[BMKTileLayer class]]){
|
||||
return [[BMKTileLayerView alloc] initWithTileLayer:overlay];
|
||||
|
||||
} else if ([overlay isKindOfClass:[BMKGroundOverlay class]]) {
|
||||
return [[BMKGroundOverlayView alloc] initWithGroundOverlay:overlay];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
/**
|
||||
*当mapView新添加overlay views时,调用此接口
|
||||
*@param mapView 地图View
|
||||
*@param overlayViews 新添加的overlay views
|
||||
*/
|
||||
- (void)mapView:(BMKMapView *)mapView didAddOverlayViews:(NSArray *)overlayViews{
|
||||
if (!_channel) return;
|
||||
|
||||
//TODO:didAddOverlayViews
|
||||
}
|
||||
/**
|
||||
*点中覆盖物后会回调此接口,目前只支持点中BMKPolylineView时回调
|
||||
*@param mapView 地图View
|
||||
*@param overlayView 覆盖物view信息
|
||||
*/
|
||||
-(void)mapView:(BMKMapView *)mapView onClickedBMKOverlayView:(BMKOverlayView *)overlayView{
|
||||
if (!_channel) return;
|
||||
|
||||
if ([overlayView isKindOfClass:[BMKPolylineView class]]) {
|
||||
BMFPolylineModel *model = [self polylineModelWith:(BMKPolylineView *)overlayView];
|
||||
// NSLog(@"%@", [model bmf_toDictionary]);
|
||||
// 暂时只传id
|
||||
[_channel invokeMethod:kMapOnClickedOverlayCallback arguments:@{@"polyline": @{@"id" :model.Id}} result:nil];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
@interface FlutterMapViewFactory()
|
||||
{
|
||||
NSObject<FlutterBinaryMessenger> *_messenger;
|
||||
}
|
||||
@end
|
||||
@implementation FlutterMapViewFactory
|
||||
- (instancetype)initWithMessenger:(NSObject<FlutterBinaryMessenger> *)messager{
|
||||
if ([super init]) {
|
||||
_messenger = messager;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSObject<FlutterMessageCodec> *)createArgsCodec{
|
||||
return [FlutterStandardMessageCodec sharedInstance];
|
||||
}
|
||||
|
||||
- (NSObject<FlutterPlatformView> *)createWithFrame:(CGRect)frame viewIdentifier:(int64_t)viewId arguments:(id)args{
|
||||
BMFMapViewController *mapViewController = [[BMFMapViewController alloc] initWithWithFrame:frame viewIdentifier:viewId arguments:args binaryMessenger:_messenger];
|
||||
return mapViewController;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@ -0,0 +1,29 @@
|
||||
//
|
||||
// BMFMapViewHandle.h
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zbj on 2020/2/11.
|
||||
//
|
||||
|
||||
#import <Flutter/Flutter.h>
|
||||
|
||||
@class BMFMapView;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol BMFMapViewHandler <NSObject>
|
||||
|
||||
@required
|
||||
|
||||
/// mapView (弱引用)
|
||||
@property(nonatomic, weak) BMFMapView *_mapView;
|
||||
|
||||
/// 创建协议实例
|
||||
- (NSObject <BMFMapViewHandler> *)initWith:(BMFMapView *)mapView;
|
||||
|
||||
/// flutter --> ios
|
||||
- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -0,0 +1,197 @@
|
||||
//
|
||||
// BMFMapViewHandles.h
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zbj on 2020/2/11.
|
||||
//
|
||||
|
||||
#import "BMFMapViewHandle.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@interface BMFMapViewHandles : NSObject
|
||||
|
||||
/// BMFMapViewHandler管理中心
|
||||
+ (instancetype)defalutCenter;
|
||||
|
||||
- (NSDictionary<NSString *, NSString *> *)mapViewHandles;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark - map
|
||||
|
||||
@interface BMFUpdateMap : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFShowBaseIndoorMap : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFShowBaseIndoorMapPoi : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFSwitchBaseIndoorMapFloor : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetFocusedBaseIndoorMapInfo : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFSetCustomMapStyleEnable : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFSetCustomMapStylePath : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFSetCustomMapStyleWithOption : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFZoomIn : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFZoomOut : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFSetCustomTrafficColor : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFSetCenterCoordinate : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFTakeSnapshot : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFTakeSnapshotWithRect : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFSetCompassImage : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFSetVisibleMapBounds : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFSetVisibleMapBoundsWithPadding : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface BMFSetMapStatus : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark - Get
|
||||
|
||||
@interface BMFGetMapStatus : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetMapType : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetZoomLevel : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetMinZoomLevel : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetMaxZoomLevel : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetRotation : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetOverlooking : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface BMFGetMinOverlooking : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetBuildingsEnabled : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetShowMapPoi : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetTrafficEnabled : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetBaiduHeatMapEnabled : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetGesturesEnabled : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetZoomEnabled : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetZoomEnabledWithTap : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetScrollEnabled : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetOverlookEnabled : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetRotateEnabled : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetForceTouchEnabled : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetShowMapScaleBar : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetMapScaleBarPosition : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetLogoPosition : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetVisibleMapBounds : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetBaseIndoorMapEnabled : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFGetShowIndoorMapPoi : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -0,0 +1,886 @@
|
||||
//
|
||||
// BMFMapViewHandles.m
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zbj on 2020/2/11.
|
||||
//
|
||||
|
||||
#import "BMFMapViewHandles.h"
|
||||
#import "BMFMapView.h"
|
||||
#import "BMFMapMethodConst.h"
|
||||
#import "BMFAnnotationMethodConst.h"
|
||||
#import "BMFFileManager.h"
|
||||
#import "UIColor+BMFString.h"
|
||||
#import "BMFMapModels.h"
|
||||
#import "BMFEdgeInsets.h"
|
||||
#import "BMFIndoorMapInfoModel.h"
|
||||
#import "BMFMapStatusModel.h"
|
||||
|
||||
@interface BMFMapViewHandles ()
|
||||
{
|
||||
NSDictionary *_handles;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation BMFMapViewHandles
|
||||
|
||||
static BMFMapViewHandles *_instance = nil;
|
||||
+ (instancetype)defalutCenter{
|
||||
if (!_instance) {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_instance = [[BMFMapViewHandles alloc] init];
|
||||
});
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
- (NSDictionary<NSString *, NSString *> *)mapViewHandles{
|
||||
if (!_handles) {
|
||||
_handles = @{
|
||||
kBMFMapUpdateMethod: NSStringFromClass([BMFUpdateMap class]),
|
||||
kBMFMapShowBaseIndoorMapMethod: NSStringFromClass([BMFShowBaseIndoorMap class]),
|
||||
kBMFMapShowBaseIndoorMapPoiMethod: NSStringFromClass([BMFShowBaseIndoorMapPoi class]),
|
||||
kBMFMapSwitchBaseIndoorMapFloorMethod: NSStringFromClass([BMFSwitchBaseIndoorMapFloor class]),
|
||||
kBMFMapGetFocusedBaseIndoorMapInfoMethod: NSStringFromClass([BMFGetFocusedBaseIndoorMapInfo class]),
|
||||
kBMFMapSetCustomMapStyleEnableMethod: NSStringFromClass([BMFSetCustomMapStyleEnable class]),
|
||||
kBMFMapSetCustomMapStylePathMethod: NSStringFromClass([BMFSetCustomMapStylePath class]),
|
||||
kBMFMapSetCustomMapStyleWithOptionMethod: NSStringFromClass([BMFSetCustomMapStyleWithOption class]),
|
||||
kBMFMapZoomInMethod: NSStringFromClass([BMFZoomIn class]),
|
||||
kBMFMapZoomOutMethod: NSStringFromClass([BMFZoomOut class]),
|
||||
kBMFMapSetCustomTrafficColorMethod: NSStringFromClass([BMFSetCustomTrafficColor class]),
|
||||
kBMFMapSetCenterCoordinateMethod: NSStringFromClass([BMFSetCenterCoordinate class]),
|
||||
kBMFMapTakeSnapshotMethod: NSStringFromClass([BMFTakeSnapshot class]),
|
||||
kBMFMapTakeSnapshotWithRectMethod: NSStringFromClass([BMFTakeSnapshotWithRect class]),
|
||||
kBMFMapSetCompassImageMethod: NSStringFromClass([BMFSetCompassImage class]),
|
||||
kBMFMapSetVisibleMapBoundsMethod: NSStringFromClass([BMFSetVisibleMapBounds class]),
|
||||
kBMFMapSetVisibleMapBoundsWithPaddingMethod: NSStringFromClass([BMFSetVisibleMapBoundsWithPadding class]),
|
||||
kBMFMapSetMapStatusMethod: NSStringFromClass([BMFSetMapStatus class]),
|
||||
kBMFMapGetMapStatusMethod: NSStringFromClass([BMFGetMapStatus class]),
|
||||
kBMFMapGetMapTypeMethod: NSStringFromClass([BMFGetMapType class]),
|
||||
kBMFMapGetZoomLevelMethod: NSStringFromClass([BMFGetZoomLevel class]),
|
||||
kBMFMapGetMinZoomLevelMethod: NSStringFromClass([BMFGetMinZoomLevel class]),
|
||||
kBMFMapGetMaxZoomLevelMethod: NSStringFromClass([BMFGetMaxZoomLevel class]),
|
||||
kBMFMapGetRotationMethod: NSStringFromClass([BMFGetRotation class]),
|
||||
kBMFMapGetOverlookingMethod: NSStringFromClass([BMFGetOverlooking class]),
|
||||
kBMFMapGetMinOverlookingMethod: NSStringFromClass([BMFGetMinOverlooking class]),
|
||||
kBMFMapGetBuildingsEnabledMethod: NSStringFromClass([BMFGetBuildingsEnabled class]),
|
||||
kBMFMapGetShowMapPoiMethod: NSStringFromClass([BMFGetShowMapPoi class]),
|
||||
kBMFMapGetTrafficEnabledMethod: NSStringFromClass([BMFGetTrafficEnabled class]),
|
||||
kBMFMapGetBaiduHeatMapEnabledMethod: NSStringFromClass([BMFGetBaiduHeatMapEnabled class]),
|
||||
kBMFMapGetGesturesEnabledMethod: NSStringFromClass([BMFGetGesturesEnabled class]),
|
||||
kBMFMapGetZoomEnabledMethod: NSStringFromClass([BMFGetZoomEnabled class]),
|
||||
kBMFMapGetZoomEnabledWithTapMethod: NSStringFromClass([BMFGetZoomEnabledWithTap class]),
|
||||
kBMFMapGetScrollEnabledMethod: NSStringFromClass([BMFGetScrollEnabled class]),
|
||||
kBMFMapGetOverlookEnabledMethod: NSStringFromClass([BMFGetOverlookEnabled class]),
|
||||
kBMFMapGetRotateEnabledMethod: NSStringFromClass([BMFGetRotateEnabled class]),
|
||||
kBMFMapGetForceTouchEnabledMethod: NSStringFromClass([BMFGetForceTouchEnabled class]),
|
||||
kBMFMapGetShowMapScaleBarMethod: NSStringFromClass([BMFGetShowMapScaleBar class]),
|
||||
kBMFMapGetMapScaleBarPositionMethod: NSStringFromClass([BMFGetMapScaleBarPosition class]),
|
||||
kBMFMapGetLogoPositionMethod: NSStringFromClass([BMFGetLogoPosition class]),
|
||||
kBMFMapGetVisibleMapBoundsMethod: NSStringFromClass([BMFGetVisibleMapBounds class]),
|
||||
kBMFMapGetBaseIndoorMapEnabledMethod: NSStringFromClass([BMFGetBaseIndoorMapEnabled class]),
|
||||
kBMFMapGetShowIndoorMapPoiMethod: NSStringFromClass([BMFGetShowIndoorMapPoi class])
|
||||
|
||||
};
|
||||
}
|
||||
return _handles;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark - map
|
||||
|
||||
@implementation BMFUpdateMap
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
BOOL success = [_mapView updateMapViewWith:call.arguments];
|
||||
result(@(success));
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFShowBaseIndoorMap
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
_mapView.baseIndoorMapEnabled = [[call.arguments safeValueForKey:@"show"] boolValue];
|
||||
[_mapView setMapStatus:[_mapView getMapStatus]];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFShowBaseIndoorMapPoi
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments || !_mapView.baseIndoorMapEnabled) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
_mapView.showIndoorMapPoi = [[call.arguments safeValueForKey:@"showIndoorPoi"] boolValue];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFSwitchBaseIndoorMapFloor
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
BMKSwitchIndoorFloorError error;
|
||||
if (!call.arguments || !call.arguments[@"floorId"] || !call.arguments[@"indoorId"] || !_mapView.baseIndoorMapEnabled) {
|
||||
error = BMKSwitchIndoorFloorFailed;
|
||||
result(@{@"result":@(error)});
|
||||
return;
|
||||
}
|
||||
|
||||
error = [_mapView switchBaseIndoorMapFloor:[call.arguments safeValueForKey:@"floorId"] withID:[call.arguments safeValueForKey:@"indoorId"]];
|
||||
result(@{@"result":@(error)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetFocusedBaseIndoorMapInfo
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!_mapView.baseIndoorMapEnabled) {
|
||||
result(@{@"result": [NSNull null]});
|
||||
return;
|
||||
}
|
||||
BMKBaseIndoorMapInfo *info = [_mapView getFocusedBaseIndoorMapInfo];
|
||||
BMFIndoorMapInfoModel *model = [BMFIndoorMapInfoModel new];
|
||||
model.strID = info.strID;
|
||||
model.strFloor = info.strFloor;
|
||||
model.listStrFloors = info.arrStrFloors;
|
||||
result([model bmf_toDictionary]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFSetCustomMapStyleEnable
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
[_mapView setCustomMapStyleEnable:[[call.arguments safeValueForKey:@"enable"] boolValue]];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFSetCustomMapStylePath
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
NSString *path = [[BMFFileManager defaultCenter] pathForFlutterFileName:[call.arguments safeValueForKey:@"path"]];
|
||||
[_mapView setCustomMapStylePath:path mode:[[call.arguments safeValueForKey:@"mode"] intValue]];
|
||||
result(@YES);
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation BMFSetCustomMapStyleWithOption
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
BMKCustomMapStyleOption *options = [BMKCustomMapStyleOption new];
|
||||
options.customMapStyleID = [[call.arguments safeObjectForKey:@"customMapStyleOption"] safeValueForKey:@"customMapStyleID"];
|
||||
NSString *localPath = [[call.arguments safeObjectForKey:@"customMapStyleOption"] safeValueForKey:@"customMapStyleFilePath"];
|
||||
if (localPath && localPath.length > 0) {
|
||||
options.customMapStyleFilePath = [[BMFFileManager defaultCenter] pathForFlutterFileName:localPath];
|
||||
}
|
||||
[_mapView setCustomMapStyleWithOption:options preLoad:^(NSString *path) {
|
||||
if (path) {
|
||||
result(@{@"preloadPath": path});
|
||||
}
|
||||
} success:^(NSString *path) {
|
||||
if (path) {
|
||||
result(@{@"successPath": path});
|
||||
}
|
||||
} failure:^(NSError *error, NSString *path) {
|
||||
if (error) {
|
||||
result(@{@"errorCode": @(error.code), @"errorPath": path ? path : [NSNull null]});
|
||||
}
|
||||
// NSLog(@"failure-error=%@,path=%@", error, path);
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFZoomIn
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
BOOL flag = [_mapView zoomIn];
|
||||
result(@(flag));
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFZoomOut
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
BOOL flag = [_mapView zoomOut];
|
||||
result(@(flag));
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFSetCustomTrafficColor
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
UIColor *smooth = [UIColor fromColorString:[call.arguments safeValueForKey:@"smooth"]];
|
||||
UIColor *slow = [UIColor fromColorString:[call.arguments safeValueForKey:@"slow"]];
|
||||
UIColor *congestion = [UIColor fromColorString:[call.arguments safeValueForKey:@"congestion"]];
|
||||
UIColor *severeCongestion = [UIColor fromColorString:[call.arguments safeValueForKey:@"severeCongestion"]];
|
||||
if (smooth && slow && congestion && severeCongestion) {
|
||||
BOOL flag = [_mapView setCustomTrafficColorForSmooth:smooth slow:slow congestion:congestion severeCongestion:severeCongestion];
|
||||
result(@(flag));
|
||||
return;
|
||||
} else {
|
||||
result(@NO);
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation BMFSetCenterCoordinate
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
BMFCoordinate *coordinate = [BMFCoordinate bmf_modelWith:[call.arguments safeObjectForKey:@"coordinate"]];
|
||||
if (coordinate) {
|
||||
[_mapView setCenterCoordinate:[coordinate toCLLocationCoordinate2D] animated:[[call.arguments safeValueForKey:@"animated"] boolValue]];
|
||||
result(@YES);
|
||||
return;
|
||||
} else {
|
||||
result(@NO);
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation BMFTakeSnapshot
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
UIImage *image = [_mapView takeSnapshot];
|
||||
if (!image) {
|
||||
result(@[]);
|
||||
return;
|
||||
}
|
||||
NSData *data = UIImageJPEGRepresentation(image, 100);
|
||||
FlutterStandardTypedData *fData = [FlutterStandardTypedData typedDataWithBytes:data];
|
||||
result(fData);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFTakeSnapshotWithRect
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments || !call.arguments[@"rect"]) {
|
||||
result(@[]);
|
||||
return;
|
||||
}
|
||||
|
||||
CGRect rect = [[BMFMapRect bmf_modelWith:[call.arguments safeObjectForKey:@"rect"]] toCGRect];
|
||||
UIImage *image = [_mapView takeSnapshot:rect];
|
||||
if (!image) {
|
||||
result(@[]);
|
||||
return;
|
||||
}
|
||||
NSData *data = UIImageJPEGRepresentation(image, 100);
|
||||
FlutterStandardTypedData *fData = [FlutterStandardTypedData typedDataWithBytes:data];
|
||||
result(fData);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFSetCompassImage
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments || !call.arguments[@"imagePath"]) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
UIImage *image = [UIImage imageWithContentsOfFile:[[BMFFileManager defaultCenter] pathForFlutterImageName:[call.arguments safeValueForKey:@"imagePath"]]];
|
||||
[_mapView setCompassImage:image];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFSetVisibleMapBounds
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments || !call.arguments[@"visibleMapBounds"] || !call.arguments[@"animated"]) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
BMFCoordinateBounds *bounds = [BMFCoordinateBounds bmf_modelWith:[call.arguments safeObjectForKey:@"visibleMapBounds"]];
|
||||
[_mapView setVisibleMapRect:[bounds toBMKMapRect] animated:[[call.arguments safeValueForKey:@"animated"] boolValue]];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFSetVisibleMapBoundsWithPadding
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments || !call.arguments[@"visibleMapBounds"] || !call.arguments[@"insets"] || !call.arguments[@"animated"]) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
BMFCoordinateBounds *bounds = [BMFCoordinateBounds bmf_modelWith:[call.arguments safeObjectForKey:@"visibleMapBounds"]];
|
||||
BMFEdgeInsets *insets = [BMFEdgeInsets bmf_modelWith:[call.arguments safeObjectForKey:@"insets"]];
|
||||
[_mapView setVisibleMapRect:[bounds toBMKMapRect] edgePadding:[insets toUIEdgeInsets] animated:[[call.arguments safeValueForKey:@"animated"] boolValue]];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation BMFSetMapStatus
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments || !call.arguments[@"mapStatus"] || !call.arguments[@"animateDurationMs"] ) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
BMFMapStatusModel *status = [BMFMapStatusModel bmf_modelWith:[call.arguments safeObjectForKey:@"mapStatus"]];
|
||||
int animate = [[call.arguments safeValueForKey:@"animateDurationMs"] intValue];
|
||||
[_mapView setMapStatus:[status toMapStatus] withAnimation: animate!=0 ? YES : NO];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark - Get
|
||||
|
||||
@implementation BMFGetMapStatus
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
BMFMapStatusModel *status = [BMFMapStatusModel fromMapStatus:[_mapView getMapStatus]];
|
||||
status ? result(@{@"mapStatus":[status bmf_toDictionary]}) : result(@{@"mapStatus":[NSNull null]});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation BMFGetMapType
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"mapType" : @(_mapView.mapType)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetZoomLevel
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
|
||||
result(@{@"zoomLevel": @((int)_mapView.zoomLevel)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetMinZoomLevel
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"minZoomLevel": @((int)_mapView.minZoomLevel)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetMaxZoomLevel
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"maxZoomLevel" : @((int)_mapView.maxZoomLevel)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetRotation
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"rotation" : @((float)_mapView.rotation)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetOverlooking
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"overlooking": @((float)_mapView.overlooking)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetMinOverlooking
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"minOverlooking" : @(_mapView.minOverlooking)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetBuildingsEnabled
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"buildingsEnabled": @(_mapView.buildingsEnabled)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetShowMapPoi
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"showMapPoi" : @(_mapView.showMapPoi)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetTrafficEnabled
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"trafficEnabled": @(_mapView.trafficEnabled)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetBaiduHeatMapEnabled
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"baiduHeatMapEnabled": @(_mapView.baiduHeatMapEnabled)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetGesturesEnabled
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"gesturesEnabled" : @(_mapView.gesturesEnabled)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetZoomEnabled
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"zoomEnabled": @(_mapView.zoomEnabled)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetZoomEnabledWithTap
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"zoomEnabledWithTap" : @(_mapView.zoomEnabledWithTap)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetScrollEnabled
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"scrollEnabled" : @(_mapView.scrollEnabled)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetOverlookEnabled
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"overlookEnabled": @(_mapView.overlookEnabled)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetRotateEnabled
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"rotateEnabled": @(_mapView.rotateEnabled)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetForceTouchEnabled
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"forceTouchEnabled": @(_mapView.forceTouchEnabled)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetShowMapScaleBar
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"showMapScaleBar" : @(_mapView.showMapScaleBar)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetMapScaleBarPosition
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
BMFMapPoint *point = [BMFMapPoint fromCGPoint:_mapView.mapScaleBarPosition];
|
||||
result(@{@"mapScaleBarPosition": [point bmf_toDictionary]});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetLogoPosition
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"logoPosition" : @(_mapView.logoPosition)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetVisibleMapBounds
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
BMFMapRect *mapRect = [BMFMapRect fromBMKMapRect:_mapView.visibleMapRect];
|
||||
BMFCoordinateBounds *visibleMapBounds = [mapRect toBMFCoordinateBounds];
|
||||
result(@{@"visibleMapBounds": [visibleMapBounds bmf_toDictionary]});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetBaseIndoorMapEnabled
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"baseIndoorMapEnabled" : @(_mapView.baseIndoorMapEnabled)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFGetShowIndoorMapPoi
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
result(@{@"showIndoorMapPoi" : @(_mapView.showIndoorMapPoi)});
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@ -0,0 +1,57 @@
|
||||
//
|
||||
// BMFOverlayHandles.h
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zhangbaojin on 2020/2/12.
|
||||
//
|
||||
|
||||
#import "BMFMapViewHandle.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface BMFOverlayHandles : NSObject
|
||||
/// BMFOverlayHandler管理中心
|
||||
+ (instancetype)defalutCenter;
|
||||
|
||||
- (NSDictionary<NSString *, NSString *> *)overlayHandles;
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark - overlay
|
||||
|
||||
@interface BMFAddPolyline : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFAddArcline : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFAddPolygon : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFAddCircle : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFAddTile : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFAddGround : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFRemoveOverlay : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFRemoveTileOverlay : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFUpdatePolyline : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -0,0 +1,576 @@
|
||||
//
|
||||
// BMFOverlayHandles.m
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zhangbaojin on 2020/2/12.
|
||||
//
|
||||
|
||||
#import "BMFOverlayHandles.h"
|
||||
#import "BMFMapView.h"
|
||||
#import "BMFOverlayMethodConst.h"
|
||||
#import "BMFFileManager.h"
|
||||
#import "UIColor+BMFString.h"
|
||||
#import "BMFMapModels.h"
|
||||
#import "BMFPolyline.h"
|
||||
#import "BMFArcline.h"
|
||||
#import "BMFPolygon.h"
|
||||
#import "BMFCircle.h"
|
||||
#import "BMFTileModel.h"
|
||||
#import "BMFURLTileLayer.h"
|
||||
#import "BMFAsyncTileLayer.h"
|
||||
#import "BMFSyncTileLayer.h"
|
||||
#import "BMFGroundOverlay.h"
|
||||
|
||||
@interface BMFOverlayHandles ()
|
||||
{
|
||||
NSDictionary *_handles;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation BMFOverlayHandles
|
||||
|
||||
static BMFOverlayHandles *_instance = nil;
|
||||
+ (instancetype)defalutCenter{
|
||||
if (!_instance) {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_instance = [[BMFOverlayHandles alloc] init];
|
||||
});
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, NSString *> *)overlayHandles{
|
||||
if (!_handles) {
|
||||
_handles = @{
|
||||
kBMFMapAddPolylineMethod: NSStringFromClass([BMFAddPolyline class]),
|
||||
kBMFMapAddArcineMethod: NSStringFromClass([BMFAddArcline class]),
|
||||
kBMFMapAddPolygonMethod: NSStringFromClass([BMFAddPolygon class]),
|
||||
kBMFMapAddCircleMethod: NSStringFromClass([BMFAddCircle class]),
|
||||
kBMFMapAddTileMethod: NSStringFromClass([BMFAddTile class]),
|
||||
kBMFMapAddGroundMethod: NSStringFromClass([BMFAddGround class]),
|
||||
kBMFMapRemoveOverlayMethod: NSStringFromClass([BMFRemoveOverlay class]),
|
||||
kBMFMapRemoveTileMethod: NSStringFromClass([BMFRemoveTileOverlay class]),
|
||||
kBMFMapUpdatePolylineMemberMethod: NSStringFromClass([BMFUpdatePolyline class])
|
||||
};
|
||||
}
|
||||
return _handles;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark - overlay
|
||||
|
||||
@implementation BMFAddPolyline
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
BMKPolyline *polyline = [BMKPolyline polylineWith:call.arguments];
|
||||
if (polyline) {
|
||||
[_mapView addOverlay:polyline];
|
||||
result(@YES);
|
||||
} else {
|
||||
result(@NO);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFAddArcline
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
BMKArcline *arcline = [BMKArcline arclineWith:call.arguments];
|
||||
if (arcline) {
|
||||
[_mapView addOverlay:arcline];
|
||||
result(@YES);
|
||||
} else {
|
||||
result(@NO);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation BMFAddPolygon
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
BMKPolygon *polygon = [BMKPolygon polygonWith:call.arguments];
|
||||
if (polygon) {
|
||||
[_mapView addOverlay:polygon];
|
||||
result(@YES);
|
||||
} else {
|
||||
result(@NO);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation BMFAddCircle
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
BMKCircle *circle = [BMKCircle circlelineWith:call.arguments];
|
||||
if (circle) {
|
||||
[_mapView addOverlay:circle];
|
||||
result(@YES);
|
||||
return;
|
||||
} else {
|
||||
result(@NO);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFAddTile
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
BMFTileModel *model = [BMFTileModel bmf_modelWith:call.arguments];
|
||||
model.tileOptions = [BMFTileModelOptions bmf_modelWith:call.arguments];
|
||||
// NSLog(@"%@", [model bmf_toDictionary]);
|
||||
if (!model) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
if (model.tileOptions.tileLoadType == kBMFTileLoadUrl && model.tileOptions.url) {
|
||||
BMFURLTileLayer *urlTileLayer = [BMFURLTileLayer urlTileLayerWith:model];
|
||||
[_mapView addOverlay:urlTileLayer];
|
||||
result(@YES);
|
||||
return;
|
||||
} else if (model.tileOptions.tileLoadType == kBMFTileLoadLocalAsync) {
|
||||
BMFAsyncTileLayer *asyncTileLayer = [BMFAsyncTileLayer asyncTileLayerWith:model];
|
||||
[_mapView addOverlay:asyncTileLayer];
|
||||
result(@YES);
|
||||
return;
|
||||
} else if (model.tileOptions.tileLoadType == kBMFTileLoadLocalSync) {
|
||||
BMFSyncTileLayer *syncTileLayer = [BMFSyncTileLayer syncTileLayerWith:model];
|
||||
[_mapView addOverlay:syncTileLayer];
|
||||
result(@YES);
|
||||
return;
|
||||
} else {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFAddGround
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
BMKGroundOverlay *ground = [BMKGroundOverlay groundOverlayWith:call.arguments];
|
||||
if (ground) {
|
||||
[_mapView addOverlay:ground];
|
||||
result(@YES);
|
||||
return;
|
||||
} else {
|
||||
result(@NO);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFRemoveOverlay
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments || !call.arguments[@"id"]) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
NSString *ID = [call.arguments safeValueForKey:@"id"];
|
||||
__weak __typeof__(_mapView) weakMapView = _mapView;
|
||||
[_mapView.overlays enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
// 折线
|
||||
if ([obj isKindOfClass:[BMKPolyline class]]) {
|
||||
BMKPolyline *overlay = (BMKPolyline *)obj;
|
||||
if ([ID isEqualToString:overlay.Id]) {
|
||||
[weakMapView removeOverlay:obj];
|
||||
result(@YES);
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 多边形
|
||||
if ([obj isKindOfClass:[BMKPolygon class]]) {
|
||||
BMKPolygon *overlay = (BMKPolygon *)obj;
|
||||
if ([ID isEqualToString:overlay.Id]) {
|
||||
[weakMapView removeOverlay:obj];
|
||||
result(@YES);
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 弧线
|
||||
if ([obj isKindOfClass:[BMKArcline class]]) {
|
||||
BMKArcline *overlay = (BMKArcline *)obj;
|
||||
if ([ID isEqualToString:overlay.Id]) {
|
||||
[weakMapView removeOverlay:obj];
|
||||
result(@YES);
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 圆
|
||||
if ([obj isKindOfClass:[BMKCircle class]]) {
|
||||
BMKCircle *overlay = (BMKCircle *)obj;
|
||||
if ([ID isEqualToString:overlay.Id]) {
|
||||
[weakMapView removeOverlay:obj];
|
||||
result(@YES);
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// ground
|
||||
if ([obj isKindOfClass:[BMKGroundOverlay class]]) {
|
||||
BMKGroundOverlay *overlay = (BMKGroundOverlay *)obj;
|
||||
if ([ID isEqualToString:overlay.Id]) {
|
||||
[weakMapView removeOverlay:obj];
|
||||
result(@YES);
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 瓦片图
|
||||
if ([obj isKindOfClass:[BMFURLTileLayer class]]) {
|
||||
BMFURLTileLayer *overlay = (BMFURLTileLayer *)obj;
|
||||
if ([ID isEqualToString:overlay.Id]) {
|
||||
[weakMapView removeOverlay:obj];
|
||||
result(@YES);
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ([obj isKindOfClass:[BMFAsyncTileLayer class]]) {
|
||||
BMFAsyncTileLayer *overlay = (BMFAsyncTileLayer *)obj;
|
||||
if ([ID isEqualToString:overlay.Id]) {
|
||||
[weakMapView removeOverlay:obj];
|
||||
result(@YES);
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ([obj isKindOfClass:[BMFSyncTileLayer class]]) {
|
||||
BMFSyncTileLayer *overlay = (BMFSyncTileLayer *)obj;
|
||||
if ([ID isEqualToString:overlay.Id]) {
|
||||
[weakMapView removeOverlay:obj];
|
||||
result(@YES);
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFRemoveTileOverlay
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
|
||||
if (!call.arguments || !call.arguments[@"id"]) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
NSString *ID = [call.arguments safeValueForKey:@"id"];
|
||||
__weak __typeof__(_mapView) weakMapView = _mapView;
|
||||
[_mapView.overlays enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
// 瓦片图
|
||||
if ([obj isKindOfClass:[BMFURLTileLayer class]]) {
|
||||
BMFURLTileLayer *overlay = (BMFURLTileLayer *)obj;
|
||||
if ([ID isEqualToString:overlay.Id]) {
|
||||
[weakMapView removeOverlay:obj];
|
||||
result(@YES);
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ([obj isKindOfClass:[BMFAsyncTileLayer class]]) {
|
||||
BMFAsyncTileLayer *overlay = (BMFAsyncTileLayer *)obj;
|
||||
if ([ID isEqualToString:overlay.Id]) {
|
||||
[weakMapView removeOverlay:obj];
|
||||
result(@YES);
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ([obj isKindOfClass:[BMFSyncTileLayer class]]) {
|
||||
BMFSyncTileLayer *overlay = (BMFSyncTileLayer *)obj;
|
||||
if ([ID isEqualToString:overlay.Id]) {
|
||||
[weakMapView removeOverlay:obj];
|
||||
result(@YES);
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark - Update
|
||||
@implementation BMFUpdatePolyline
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments || !call.arguments[@"id"]) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
NSString *ID = [call.arguments safeValueForKey:@"id"];
|
||||
__block BMKPolyline *polyline;
|
||||
[_mapView.overlays enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
if ([obj isKindOfClass:[BMKPolyline class]]) {
|
||||
BMKPolyline *line = (BMKPolyline *)obj;
|
||||
if ([ID isEqualToString:line.Id]) {
|
||||
polyline = line;
|
||||
*stop = YES;
|
||||
}
|
||||
}
|
||||
}];
|
||||
if (!polyline) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
NSString *member = [call.arguments safeValueForKey:@"member"];
|
||||
|
||||
// kBMFColorLine = 0, ///< 单色折线
|
||||
// kBMFColorsLine, ///< 多色折线
|
||||
// kBMFTextureLine, ///< 单纹理折线
|
||||
// kBMFTexturesLine, ///< 多纹理折线
|
||||
// kBMFDashLine, ///< 虚线
|
||||
// kBMFMultiDashLine ///< 多色虚线
|
||||
|
||||
if ([member isEqualToString:@"coordinates"]) {
|
||||
|
||||
NSArray<NSDictionary *> *coordinates = [call.arguments safeObjectForKey:@"value"];
|
||||
if (!coordinates || coordinates.count <= 1) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
|
||||
CLLocationCoordinate2D coords[coordinates.count];
|
||||
for (size_t i = 0, count = coordinates.count; i < count; i++) {
|
||||
BMFCoordinate *coord = [BMFCoordinate bmf_modelWith:coordinates[i]];
|
||||
coords[i] = [coord toCLLocationCoordinate2D];
|
||||
}
|
||||
switch (polyline.lineType) {
|
||||
case kBMFColorLine:
|
||||
case kBMFTextureLine:
|
||||
case kBMFDashLine: {
|
||||
[polyline setPolylineWithCoordinates:coords count:coordinates.count];
|
||||
[_mapView setMapStatus:_mapView.getMapStatus];
|
||||
result(@YES);
|
||||
}
|
||||
break;
|
||||
case kBMFColorsLine:
|
||||
case kBMFTexturesLine:
|
||||
case kBMFMultiDashLine: {
|
||||
if (![call.arguments safeObjectForKey:@"indexs"]) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
NSMutableArray<NSNumber *> *indexs = [NSMutableArray array];
|
||||
for (NSNumber *value in call.arguments[@"indexs"]) {
|
||||
[indexs addObject:value];
|
||||
}
|
||||
[polyline setPolylineWithCoordinates:coords count:coordinates.count textureIndex:indexs];
|
||||
[_mapView setMapStatus:_mapView.getMapStatus];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} else if ([member isEqualToString:@"width"]) {
|
||||
BMKPolylineView *view = (BMKPolylineView *)[_mapView viewForOverlay:polyline];
|
||||
view.lineWidth = [[call.arguments safeValueForKey:@"value"] floatValue];
|
||||
[_mapView setMapStatus:_mapView.getMapStatus];
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"colors"]) {
|
||||
NSArray *colorsData = [call.arguments safeObjectForKey:@"value"];
|
||||
if (!colorsData || colorsData.count <= 0) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
BMKPolylineView *view = (BMKPolylineView *)[_mapView viewForOverlay:polyline];
|
||||
NSMutableArray<UIColor *> *colors = [NSMutableArray array];
|
||||
for (NSString *color in colorsData) {
|
||||
[colors addObject:[UIColor fromColorString:color]];
|
||||
}
|
||||
if (polyline.lineType == kBMFColorsLine || polyline.lineType == kBMFMultiDashLine) {
|
||||
view.colors = [colors copy];
|
||||
[_mapView setMapStatus:_mapView.getMapStatus];
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if (polyline.lineType ==kBMFColorLine || polyline.lineType == kBMFDashLine) {
|
||||
view.strokeColor = [colors firstObject];
|
||||
[_mapView setMapStatus:_mapView.getMapStatus];
|
||||
result(@YES);
|
||||
return;
|
||||
} else {
|
||||
NSLog(@"ios - 纹理折线不支持更新colors");
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
} else if ([member isEqualToString:@"lineDashType"]) {
|
||||
if (polyline.lineType == kBMFTextureLine || polyline.lineType == kBMFTexturesLine) {
|
||||
NSLog(@"ios - 纹理折线不支持虚线类型");
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
BMFPolylineModel *model = polyline.polylineModel;
|
||||
model.polylineOptions.lineDashType = [[call.arguments safeValueForKey:@"value"] intValue];
|
||||
[_mapView removeOverlay:polyline];
|
||||
|
||||
BMKPolyline *dashLine = [BMKPolyline polylineWithModel:model];
|
||||
[_mapView addOverlay:dashLine];
|
||||
// BMKPolylineView *view = (BMKPolylineView *)[_mapView viewForOverlay:polyline];
|
||||
// view.lineDashType = [[call.arguments safeValueForKey:@"value"] intValue];
|
||||
// [_mapView setMapStatus:_mapView.getMapStatus];
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"lineCapType"]) {
|
||||
if (polyline.lineType == kBMFDashLine || polyline.lineType == kBMFMultiDashLine) {
|
||||
NSLog(@"ios - lineCapType不支持虚线");
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
BMKPolylineView *view = (BMKPolylineView *)[_mapView viewForOverlay:polyline];
|
||||
view.lineCapType = [[call.arguments safeValueForKey:@"value"] intValue];
|
||||
[_mapView setMapStatus:_mapView.getMapStatus];
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"lineJoinType"]) {
|
||||
if (polyline.lineType == kBMFDashLine || polyline.lineType == kBMFMultiDashLine) {
|
||||
NSLog(@"ios - lineJoinType不支持虚线");
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
BMKPolylineView *view = (BMKPolylineView *)[_mapView viewForOverlay:polyline];
|
||||
view.lineJoinType = [[call.arguments safeValueForKey:@"value"] intValue];
|
||||
[_mapView setMapStatus:_mapView.getMapStatus];
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"isThined"]) {
|
||||
polyline.isThined = [[call.arguments safeValueForKey:@"value"] boolValue];
|
||||
[_mapView setMapStatus:_mapView.getMapStatus];
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"textures"]) {
|
||||
NSLog(@"ios - 暂不支持更新textures");
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"clickable"]) {
|
||||
NSLog(@"ios - 暂不支持设置clickable");
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"isKeepScale"]) {
|
||||
NSLog(@"ios - 暂不支持设置isKeepScale");
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"isFocus"]) {
|
||||
NSLog(@"ios - 暂不支持设置isFocus");
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"visible"]) {
|
||||
NSLog(@"ios - 暂不支持设置visible");
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else if ([member isEqualToString:@"zIndex"]) {
|
||||
NSLog(@"ios - 暂不支持设置zIndex");
|
||||
result(@YES);
|
||||
return;
|
||||
|
||||
} else {
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@ -0,0 +1,28 @@
|
||||
//
|
||||
// BMFProjectionHandles.h
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zhangbaojin on 2020/4/1.
|
||||
//
|
||||
|
||||
#import "BMFMapViewHandle.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface BMFProjectionHandles : NSObject
|
||||
/// BMFProjectionHandles管理中心
|
||||
+ (instancetype)defalutCenter;
|
||||
|
||||
- (NSDictionary<NSString *, NSString *> *)projectionHandles;
|
||||
@end
|
||||
|
||||
#pragma mark - convert
|
||||
|
||||
@interface BMFCoordinateFromBMFPoint : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFPointFromBMFCoordinate : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -0,0 +1,86 @@
|
||||
//
|
||||
// BMFProjectionHandles.m
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zhangbaojin on 2020/4/1.
|
||||
//
|
||||
|
||||
#import "BMFProjectionHandles.h"
|
||||
#import "BMFProjectionConst.h"
|
||||
#import "BMFMapView.h"
|
||||
#import "BMFMapModels.h"
|
||||
|
||||
@interface BMFProjectionHandles ()
|
||||
{
|
||||
NSDictionary *_handles;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation BMFProjectionHandles
|
||||
static BMFProjectionHandles *_instance = nil;
|
||||
+ (instancetype)defalutCenter{
|
||||
if (!_instance) {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_instance = [[BMFProjectionHandles alloc] init];
|
||||
});
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, NSString *> *)projectionHandles{
|
||||
if (!_handles) {
|
||||
_handles = @{
|
||||
kBMFCoordinateFromScreenPointMethod: NSStringFromClass([BMFCoordinateFromBMFPoint class]),
|
||||
kBMFScreenPointFromCoordinateMethod: NSStringFromClass([BMFPointFromBMFCoordinate class]),
|
||||
};
|
||||
}
|
||||
return _handles;
|
||||
}
|
||||
@end
|
||||
|
||||
#pragma mark - convert
|
||||
@implementation BMFCoordinateFromBMFPoint
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments || call.arguments[@"point"]) {
|
||||
result([NSNull null]);
|
||||
return;
|
||||
}
|
||||
BMFMapPoint *point = [BMFMapPoint bmf_modelWith:[call.arguments safeObjectForKey:@"point"]];
|
||||
CLLocationCoordinate2D coord = [_mapView convertPoint:[point toCGPoint] toCoordinateFromView:_mapView];
|
||||
BMFCoordinate *coordinate = [BMFCoordinate fromCLLocationCoordinate2D:coord];
|
||||
result(@{@"coordinate" : [coordinate bmf_toDictionary]});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation BMFPointFromBMFCoordinate
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments || call.arguments[@"coordinate"]) {
|
||||
result([NSNull null]);
|
||||
return;
|
||||
}
|
||||
BMFCoordinate *coord = [BMFCoordinate bmf_modelWith:[call.arguments safeObjectForKey:@"coordinate"]];
|
||||
CGPoint p = [_mapView convertCoordinate:[coord toCLLocationCoordinate2D] toPointToView:_mapView];
|
||||
BMFMapPoint *point = [BMFMapPoint fromCGPoint:p];
|
||||
result(@{@"point" : [point bmf_toDictionary]});
|
||||
}
|
||||
|
||||
@end
|
||||
@ -0,0 +1,40 @@
|
||||
//
|
||||
// BMFUserLocationHandles.h
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zhangbaojin on 2020/3/01.
|
||||
//
|
||||
|
||||
#import "BMFMapViewHandle.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface BMFUserLocationHandles : NSObject
|
||||
/// BMFUserLocationHandler管理中心
|
||||
+ (instancetype)defalutCenter;
|
||||
|
||||
- (NSDictionary<NSString *, NSString *> *)userLocationHandles;
|
||||
@end
|
||||
#pragma mark - userLocation
|
||||
|
||||
@interface BMFShowUserLocation : NSObject<BMFMapViewHandler>
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFSetUserTrackingMode : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFIsUserLocationVisible : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFUpdateLocationData : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
|
||||
@interface BMFUpdateLocationDisplayParam : NSObject<BMFMapViewHandler>
|
||||
|
||||
@end
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -0,0 +1,151 @@
|
||||
//
|
||||
// BMFUserLocationHandles.m
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zhangbaojin on 2020/3/01.
|
||||
//
|
||||
|
||||
#import "BMFUserLocationHandles.h"
|
||||
#import "BMFMapView.h"
|
||||
#import "BMFUserLocationConst.h"
|
||||
#import "NSObject+BMFVerify.h"
|
||||
#import "BMFUserLocationModel.h"
|
||||
|
||||
@interface BMFUserLocationHandles ()
|
||||
{
|
||||
NSDictionary *_handles;
|
||||
}
|
||||
@end
|
||||
@implementation BMFUserLocationHandles
|
||||
static BMFUserLocationHandles *_instance = nil;
|
||||
+ (instancetype)defalutCenter{
|
||||
if (!_instance) {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_instance = [[BMFUserLocationHandles alloc] init];
|
||||
});
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, NSString *> *)userLocationHandles{
|
||||
if (!_handles) {
|
||||
_handles = @{
|
||||
kBMFMapShowUserLocationMethod: NSStringFromClass([BMFShowUserLocation class]),
|
||||
kBMFMapUserTrackingModeMethod: NSStringFromClass([BMFSetUserTrackingMode class]),
|
||||
kBMFMapIsUserLocationVisibleMethod : NSStringFromClass([BMFIsUserLocationVisible class]),
|
||||
kBMFMapUpdateLocationDataMethod: NSStringFromClass([BMFUpdateLocationData class]),
|
||||
kBMFMapUpdateLocationDisplayParamMethod : NSStringFromClass([BMFUpdateLocationDisplayParam class]),
|
||||
};
|
||||
}
|
||||
return _handles;
|
||||
}
|
||||
@end
|
||||
|
||||
#pragma mark - userLocation
|
||||
|
||||
@implementation BMFShowUserLocation
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments || !call.arguments[@"show"]) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
// NSLog(@"ios-call.arguments=%@", call.arguments);
|
||||
_mapView.showsUserLocation = [[call.arguments safeValueForKey:@"show"] boolValue];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFSetUserTrackingMode
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
if (!call.arguments || !call.arguments[@"userTrackingMode"]) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
_mapView.userTrackingMode = [[call.arguments safeValueForKey:@"userTrackingMode"] intValue];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFIsUserLocationVisible
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
// NSLog(@"ios-BMFIsUserLocationVisible");
|
||||
if (!_mapView.showsUserLocation) {
|
||||
result(@{@"userLocationVisible": @NO});
|
||||
return;
|
||||
}
|
||||
|
||||
result(@{@"userLocationVisible": @(_mapView.userLocationVisible)});
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFUpdateLocationData
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
// NSLog(@"ios-BMFUpdateLocationData-call.arguments=%@", call.arguments);
|
||||
if (!call.arguments || !call.arguments[@"userLocation"]) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
BMFUserLocationModel *userLocation = [BMFUserLocationModel bmf_modelWith:[call.arguments safeObjectForKey:@"userLocation"]];
|
||||
[_mapView updateLocationData:[userLocation toBMKUserLocation]];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BMFUpdateLocationDisplayParam
|
||||
|
||||
@synthesize _mapView;
|
||||
|
||||
- (nonnull NSObject<BMFMapViewHandler> *)initWith:(nonnull BMFMapView *)mapView {
|
||||
_mapView = mapView;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleMethodCall:(nonnull FlutterMethodCall *)call result:(nonnull FlutterResult)result {
|
||||
// NSLog(@"ios-BMFUpdateLocationDisplayParam-call.arguments=%@", call.arguments);
|
||||
if (!call.arguments || !call.arguments[@"userlocationDisplayParam"]) {
|
||||
result(@NO);
|
||||
return;
|
||||
}
|
||||
BMFLocationViewDisplayParam *displayParam = [BMFLocationViewDisplayParam bmf_modelWith:[call.arguments safeObjectForKey:@"userlocationDisplayParam"]];
|
||||
[_mapView updateLocationViewWithParam:[displayParam toBMKLocationViewDisplayParam]];
|
||||
result(@YES);
|
||||
}
|
||||
|
||||
@end
|
||||
@ -0,0 +1,32 @@
|
||||
//
|
||||
// BMFAnnotation.h
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zbj on 2020/2/11.
|
||||
//
|
||||
|
||||
#ifndef __BMFAnnotation__H__
|
||||
#define __BMFAnnotation__H__
|
||||
#ifdef __OBJC__
|
||||
#import <BaiduMapAPI_Map/BMKMapComponent.h>
|
||||
#endif
|
||||
#endif
|
||||
#import "BMFAnnotationModel.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// 改为分类,继承会出现固定屏幕不生效
|
||||
@interface BMKPointAnnotation (BMFAnnotation)
|
||||
|
||||
/// BMFAnnotation
|
||||
+ (instancetype)annotationWith:(NSDictionary *)dic;
|
||||
|
||||
/// annotation唯一id
|
||||
@property (nonatomic, copy,readonly) NSString *Id;
|
||||
|
||||
/// annotationView的属性配置model
|
||||
@property (nonatomic, strong,readonly) BMFAnnotationViewOptions *annotationViewOptions;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -0,0 +1,65 @@
|
||||
//
|
||||
// BMFAnnotation.m
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zbj on 2020/2/11.
|
||||
//
|
||||
|
||||
#import "BMFAnnotation.h"
|
||||
#import <objc/runtime.h>
|
||||
#import "BMFMapModels.h"
|
||||
|
||||
static const void *IDKey = &IDKey;
|
||||
static const void *annotationViewOptionsKey = &annotationViewOptionsKey;
|
||||
|
||||
@implementation BMKPointAnnotation (BMFAnnotation)
|
||||
- (NSString *)Id{
|
||||
return objc_getAssociatedObject(self, IDKey);
|
||||
}
|
||||
- (void)setId:(NSString * _Nonnull)Id{
|
||||
objc_setAssociatedObject(self, IDKey, Id, OBJC_ASSOCIATION_COPY);
|
||||
}
|
||||
|
||||
- (BMFAnnotationViewOptions *)annotationViewOptions{
|
||||
return objc_getAssociatedObject(self, annotationViewOptionsKey);
|
||||
}
|
||||
- (void)setAnnotationViewOptions:(BMFAnnotationViewOptions * _Nonnull)annotationViewOptions {
|
||||
objc_setAssociatedObject(self, annotationViewOptionsKey, annotationViewOptions, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
+ (instancetype)annotationWith:(NSDictionary *)dic{
|
||||
return [[self alloc] initWith:dic];
|
||||
}
|
||||
- (instancetype)initWith:(NSDictionary *)dic{
|
||||
if ([super init]) {
|
||||
if (dic) {
|
||||
BMFAnnotationModel *model = [BMFAnnotationModel bmf_modelWith:dic];
|
||||
model.annotationViewOptions = [BMFAnnotationViewOptions bmf_modelWith:dic];
|
||||
[self configAnnotation:model];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)configAnnotation:(BMFAnnotationModel*)model{
|
||||
if (model.Id) {
|
||||
self.Id = model.Id;
|
||||
}
|
||||
if (model.title) {
|
||||
self.title = model.title;
|
||||
}
|
||||
if (model.subtitle) {
|
||||
self.subtitle = model.subtitle;
|
||||
}
|
||||
if (model.position) {
|
||||
self.coordinate = [model.position toCLLocationCoordinate2D];
|
||||
}
|
||||
self.isLockedToScreen = model.isLockedToScreen;
|
||||
if (model.screenPointToLock) {
|
||||
self.screenPointToLock = [model.screenPointToLock toCGPoint];
|
||||
}
|
||||
|
||||
self.annotationViewOptions = model.annotationViewOptions;
|
||||
}
|
||||
|
||||
@end
|
||||
@ -0,0 +1,31 @@
|
||||
//
|
||||
// BMFArcline.h
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zbj on 2020/2/15.
|
||||
//
|
||||
|
||||
#ifndef __BMFArcline__H__
|
||||
#define __BMFArcline__H__
|
||||
#ifdef __OBJC__
|
||||
#import <BaiduMapAPI_Map/BMKMapComponent.h>
|
||||
#endif
|
||||
#endif
|
||||
#import "BMFArclineModel.h"
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface BMKArcline (BMFArcline)
|
||||
|
||||
/// arclineView唯一id
|
||||
@property (nonatomic, copy, readonly) NSString *Id;
|
||||
|
||||
/// arclineViewOptions
|
||||
@property (nonatomic, strong, readonly) BMFArclineViewOptions *arclineViewOptions;
|
||||
|
||||
+ (BMKArcline *)arclineWith:(NSDictionary *)dic;
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -0,0 +1,51 @@
|
||||
//
|
||||
// BMFArcline.m
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zbj on 2020/2/15.
|
||||
//
|
||||
|
||||
#import "BMFArcline.h"
|
||||
#import <objc/runtime.h>
|
||||
#import "BMFMapModels.h"
|
||||
|
||||
static const void *IDKey = &IDKey;
|
||||
static const void *arclineViewOptionsKey = &arclineViewOptionsKey;
|
||||
|
||||
@implementation BMKArcline (BMFArcline)
|
||||
+ (BMKArcline *)arclineWith:(NSDictionary *)dic{
|
||||
if (dic) {
|
||||
BMFArclineModel *model = [BMFArclineModel bmf_modelWith:dic];
|
||||
model.arclineOptions = [BMFArclineViewOptions bmf_modelWith:dic];
|
||||
int _coordsCount = (int)model.coordinates.count;
|
||||
if (_coordsCount < 3) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
CLLocationCoordinate2D *coords = new CLLocationCoordinate2D[_coordsCount];
|
||||
for (int i = 0; i < _coordsCount; i++) {
|
||||
coords[i] = [model.coordinates[i] toCLLocationCoordinate2D];
|
||||
}
|
||||
BMKArcline *arcline = [BMKArcline arclineWithCoordinates:coords];
|
||||
arcline.Id = model.Id;
|
||||
arcline.arclineViewOptions = model.arclineOptions;
|
||||
return arcline;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSString *)Id{
|
||||
return objc_getAssociatedObject(self, IDKey);
|
||||
}
|
||||
- (void)setId:(NSString * _Nonnull)Id{
|
||||
objc_setAssociatedObject(self, IDKey, Id, OBJC_ASSOCIATION_COPY);
|
||||
}
|
||||
|
||||
- (BMFArclineViewOptions *)arclineViewOptions{
|
||||
return objc_getAssociatedObject(self, arclineViewOptionsKey);
|
||||
}
|
||||
- (void)setArclineViewOptions:(BMFArclineViewOptions * _Nonnull)arclineViewOptions{
|
||||
objc_setAssociatedObject(self, arclineViewOptionsKey, arclineViewOptions, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
@end
|
||||
@ -0,0 +1,30 @@
|
||||
//
|
||||
// BMFCircle.h
|
||||
// flutter_bmfmap
|
||||
//
|
||||
// Created by zbj on 2020/2/15.
|
||||
//
|
||||
|
||||
#ifndef __BMFCircle__H__
|
||||
#define __BMFCircle__H__
|
||||
#ifdef __OBJC__
|
||||
#import <BaiduMapAPI_Map/BMKMapComponent.h>
|
||||
#endif
|
||||
#endif
|
||||
#import "BMFCircleModel.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface BMKCircle (BMFCircle)
|
||||
|
||||
/// circleView唯一id
|
||||
@property (nonatomic, copy, readonly) NSString *Id;
|
||||
|
||||
/// circleViewOptions
|
||||
@property (nonatomic, strong, readonly) BMFCircleViewOptions *circleViewOptions;
|
||||
|
||||
+ (BMKCircle *)circlelineWith:(NSDictionary *)dic;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||