代码整理
This commit is contained in:
parent
080c198951
commit
cd017f876b
51
README.md
51
README.md
|
@ -8,11 +8,7 @@
|
|||
## 准备工作
|
||||
* 登录[高德开放平台官网](https://lbs.amap.com/)申请ApiKey。Android平台申请配置key请参考[Android获取key](https://lbs.amap.com/api/poi-sdk-android/develop/create-project/get-key/?sug_index=2), iOS平台申请配置请参考[iOS获取key](https://lbs.amap.com/api/poi-sdk-ios/develop/create-project/get-key/?sug_index=1)。
|
||||
* 引入高德地图SDK,Android平台请参考[Android Sudio配置工程](https://lbs.amap.com/api/android-sdk/guide/create-project/android-studio-create-project), iOS平台请参考[ios安装地图SDK](https://lbs.amap.com/api/ios-sdk/guide/create-project/cocoapods)
|
||||
* iOS端插件使用特殊配置:Flutter 1.22.0 之前(之后的版本可以不添加该配置),iOS端的UiKitView还只是preview状态, 默认是不支持的, 需要手动打开开关, 需要在iOS工程的info.plist添加如下配置:
|
||||
``` XML
|
||||
<key>io.flutter.embedded_views_preview</key>
|
||||
<string>YES</string>
|
||||
```
|
||||
|
||||
|
||||
## 使用示例
|
||||
``` Dart
|
||||
|
@ -20,7 +16,7 @@ import 'package:amap_map_example/base_page.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:amap_map/amap_map.dart';
|
||||
import 'package:amap_map/amap_map.dart';
|
||||
import 'package:x_amap_base/x_amap_base.dart';
|
||||
|
||||
class ShowMapPage extends BasePage {
|
||||
ShowMapPage(String title, String subTitle) : super(title, subTitle);
|
||||
|
@ -40,7 +36,6 @@ class _ShowMapPageState extends State<_ShowMapPageBody> {
|
|||
target: LatLng(39.909187, 116.397451),
|
||||
zoom: 10.0,
|
||||
);
|
||||
List<Widget> _approvalNumberWidget = List<Widget>();
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final AMapWidget map = AMapWidget(
|
||||
|
@ -50,24 +45,10 @@ class _ShowMapPageState extends State<_ShowMapPageBody> {
|
|||
|
||||
return ConstrainedBox(
|
||||
constraints: BoxConstraints.expand(),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Container(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: map,
|
||||
),
|
||||
Positioned(
|
||||
right: 10,
|
||||
bottom: 15,
|
||||
child: Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: _approvalNumberWidget),
|
||||
))
|
||||
],
|
||||
child: Container(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: map,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -76,29 +57,9 @@ class _ShowMapPageState extends State<_ShowMapPageBody> {
|
|||
void onMapCreated(AMapController controller) {
|
||||
setState(() {
|
||||
_mapController = controller;
|
||||
getApprovalNumber();
|
||||
});
|
||||
}
|
||||
|
||||
/// 获取审图号
|
||||
void getApprovalNumber() async {
|
||||
//普通地图审图号
|
||||
String mapContentApprovalNumber =
|
||||
await _mapController?.getMapContentApprovalNumber();
|
||||
//卫星地图审图号
|
||||
String satelliteImageApprovalNumber =
|
||||
await _mapController?.getSatelliteImageApprovalNumber();
|
||||
setState(() {
|
||||
if (null != mapContentApprovalNumber) {
|
||||
_approvalNumberWidget.add(Text(mapContentApprovalNumber));
|
||||
}
|
||||
if (null != satelliteImageApprovalNumber) {
|
||||
_approvalNumberWidget.add(Text(satelliteImageApprovalNumber));
|
||||
}
|
||||
});
|
||||
print('地图审图号(普通地图): $mapContentApprovalNumber');
|
||||
print('地图审图号(卫星地图): $satelliteImageApprovalNumber');
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
group 'com.amap.flutter.amap_map'
|
||||
group 'com.amap.flutter.map'
|
||||
version '1.0'
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||
classpath 'com.android.tools.build:gradle:3.5.3'
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.amap.flutter.amap_map">
|
||||
</manifest>
|
||||
<manifest package="com.amap.flutter.map"></manifest>
|
||||
|
|
|
@ -9,7 +9,6 @@ import androidx.lifecycle.LifecycleOwner;
|
|||
|
||||
import com.amap.flutter.map.utils.LogUtil;
|
||||
|
||||
|
||||
import io.flutter.embedding.engine.plugins.FlutterPlugin;
|
||||
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
|
||||
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
|
||||
|
@ -23,10 +22,11 @@ public class AMapFlutterMapPlugin implements
|
|||
FlutterPlugin,
|
||||
ActivityAware {
|
||||
private static final String CLASS_NAME = "AMapFlutterMapPlugin";
|
||||
private FlutterPluginBinding pluginBinding;
|
||||
private static final String VIEW_TYPE = "com.amap.flutter.map";
|
||||
private Lifecycle lifecycle;
|
||||
|
||||
private static final String VIEW_TYPE = "com.amap.flutter.map";
|
||||
public AMapFlutterMapPlugin() {
|
||||
}
|
||||
|
||||
public static void registerWith(PluginRegistry.Registrar registrar) {
|
||||
LogUtil.i(CLASS_NAME, "registerWith=====>");
|
||||
|
@ -58,15 +58,11 @@ public class AMapFlutterMapPlugin implements
|
|||
}
|
||||
}
|
||||
|
||||
public AMapFlutterMapPlugin() {
|
||||
}
|
||||
|
||||
// FlutterPlugin
|
||||
|
||||
@Override
|
||||
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
|
||||
LogUtil.i(CLASS_NAME, "onAttachedToEngine==>");
|
||||
pluginBinding = binding;
|
||||
binding
|
||||
.getPlatformViewRegistry()
|
||||
.registerViewFactory(
|
||||
|
@ -85,7 +81,6 @@ public class AMapFlutterMapPlugin implements
|
|||
@Override
|
||||
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
|
||||
LogUtil.i(CLASS_NAME, "onDetachedFromEngine==>");
|
||||
pluginBinding = null;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.amap.flutter.map;
|
|||
|
||||
import android.content.Context;
|
||||
|
||||
|
||||
import com.amap.api.maps.AMapOptions;
|
||||
import com.amap.api.maps.model.CameraPosition;
|
||||
import com.amap.api.maps.model.CustomMapStyleOptions;
|
||||
|
@ -11,7 +10,6 @@ import com.amap.api.maps.model.MyLocationStyle;
|
|||
import com.amap.flutter.map.core.AMapOptionsSink;
|
||||
import com.amap.flutter.map.utils.LogUtil;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.flutter.plugin.common.BinaryMessenger;
|
||||
|
@ -67,7 +65,7 @@ class AMapOptionsBuilder implements AMapOptionsSink {
|
|||
&& anchorY <= 1.0
|
||||
&& anchorY >= 0) {
|
||||
|
||||
aMapPlatformView.getMapController().setScreenAnchor( anchorX, anchorY);
|
||||
aMapPlatformView.getMapController().setScreenAnchor(anchorX, anchorY);
|
||||
}
|
||||
|
||||
aMapPlatformView.getMapController().setMinZoomLevel(minZoomLevel);
|
||||
|
|
|
@ -42,18 +42,14 @@ public class AMapPlatformView
|
|||
PlatformView {
|
||||
private static final String CLASS_NAME = "AMapPlatformView";
|
||||
private final MethodChannel methodChannel;
|
||||
|
||||
private final Map<String, MyMethodCallHandler> myMethodCallHandlerMap;
|
||||
private MapController mapController;
|
||||
private MarkersController markersController;
|
||||
private PolylinesController polylinesController;
|
||||
private PolygonsController polygonsController;
|
||||
|
||||
private TextureMapView mapView;
|
||||
|
||||
private boolean disposed = false;
|
||||
|
||||
private final Map<String, MyMethodCallHandler> myMethodCallHandlerMap;
|
||||
|
||||
AMapPlatformView(int id,
|
||||
Context context,
|
||||
BinaryMessenger binaryMessenger,
|
||||
|
|
|
@ -23,6 +23,7 @@ class AMapPlatformViewFactory extends PlatformViewFactory {
|
|||
private static final String CLASS_NAME = "AMapPlatformViewFactory";
|
||||
private final BinaryMessenger binaryMessenger;
|
||||
private final LifecycleProvider lifecycleProvider;
|
||||
|
||||
AMapPlatformViewFactory(BinaryMessenger binaryMessenger,
|
||||
LifecycleProvider lifecycleProvider) {
|
||||
super(StandardMessageCodec.INSTANCE);
|
||||
|
@ -37,13 +38,13 @@ class AMapPlatformViewFactory extends PlatformViewFactory {
|
|||
try {
|
||||
ConvertUtil.density = context.getResources().getDisplayMetrics().density;
|
||||
params = (Map<String, Object>) args;
|
||||
LogUtil.i(CLASS_NAME,"create params==>" + params);
|
||||
LogUtil.i(CLASS_NAME, "create params==>" + params);
|
||||
if (params.containsKey("privacyStatement")) {
|
||||
ConvertUtil.setPrivacyStatement(context, params.get("privacyStatement"));
|
||||
}
|
||||
|
||||
Object options = ((Map<String, Object>) args).get("options");
|
||||
if(null != options) {
|
||||
if (null != options) {
|
||||
ConvertUtil.interpretAMapOptions(options, builder);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.amap.flutter.map;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
||||
|
@ -14,10 +13,12 @@ import io.flutter.plugin.common.MethodChannel;
|
|||
*/
|
||||
public interface MyMethodCallHandler {
|
||||
|
||||
public void doMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result);
|
||||
void doMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result);
|
||||
|
||||
/**
|
||||
* 获取注册的{@link io.flutter.plugin.common.MethodCall#method}
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract String[] getRegisterMethodIdArray();
|
||||
String[] getRegisterMethodIdArray();
|
||||
}
|
||||
|
|
|
@ -20,8 +20,7 @@ import com.amap.flutter.map.utils.LogUtil;
|
|||
public class ProxyLifecycleProvider
|
||||
implements
|
||||
Application.ActivityLifecycleCallbacks,
|
||||
LifecycleOwner,
|
||||
LifecycleProvider {
|
||||
LifecycleOwner {
|
||||
private static final String CLASS_NAME = "ProxyLifecycleProvider";
|
||||
private final LifecycleRegistry lifecycle = new LifecycleRegistry(this);
|
||||
private final int registrarActivityHashCode;
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.amap.api.maps.model.CameraPosition;
|
|||
import com.amap.api.maps.model.CustomMapStyleOptions;
|
||||
import com.amap.api.maps.model.LatLngBounds;
|
||||
import com.amap.api.maps.model.MyLocationStyle;
|
||||
import com.amap.api.maps.model.MyTrafficStyle;
|
||||
|
||||
/**
|
||||
* @author whm
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.amap.flutter.map.core;
|
|||
import android.graphics.Bitmap;
|
||||
import android.location.Location;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
|
@ -43,16 +42,15 @@ public class MapController
|
|||
AMap.OnMapClickListener,
|
||||
AMap.OnMapLongClickListener,
|
||||
AMap.OnPOIClickListener {
|
||||
private static final String CLASS_NAME = "MapController";
|
||||
private static boolean hasStarted = false;
|
||||
private final MethodChannel methodChannel;
|
||||
private final AMap amap;
|
||||
private final TextureMapView mapView;
|
||||
private MethodChannel.Result mapReadyResult;
|
||||
protected int[] myArray = {};
|
||||
|
||||
private static final String CLASS_NAME = "MapController";
|
||||
|
||||
private MethodChannel.Result mapReadyResult;
|
||||
private boolean mapLoaded = false;
|
||||
private boolean myLocationShowing = false;
|
||||
|
||||
public MapController(MethodChannel methodChannel, TextureMapView mapView) {
|
||||
this.methodChannel = methodChannel;
|
||||
|
@ -72,7 +70,6 @@ public class MapController
|
|||
return Const.METHOD_ID_LIST_FOR_MAP;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
|
||||
LogUtil.i(CLASS_NAME, "doMethodCall===>" + call.method);
|
||||
|
@ -89,61 +86,47 @@ public class MapController
|
|||
mapReadyResult = result;
|
||||
break;
|
||||
case Const.METHOD_MAP_SATELLITE_IMAGE_APPROVAL_NUMBER:
|
||||
if (null != amap) {
|
||||
result.success(amap.getSatelliteImageApprovalNumber());
|
||||
}
|
||||
result.success(amap.getSatelliteImageApprovalNumber());
|
||||
break;
|
||||
case Const.METHOD_MAP_CONTENT_APPROVAL_NUMBER:
|
||||
if (null != amap) {
|
||||
result.success(amap.getMapContentApprovalNumber());
|
||||
}
|
||||
result.success(amap.getMapContentApprovalNumber());
|
||||
break;
|
||||
case Const.METHOD_MAP_UPDATE:
|
||||
if (amap != null) {
|
||||
ConvertUtil.interpretAMapOptions(call.argument("options"), this);
|
||||
result.success(ConvertUtil.cameraPositionToMap(getCameraPosition()));
|
||||
}
|
||||
ConvertUtil.interpretAMapOptions(call.argument("options"), this);
|
||||
result.success(ConvertUtil.cameraPositionToMap(getCameraPosition()));
|
||||
break;
|
||||
case Const.METHOD_MAP_MOVE_CAMERA:
|
||||
if (null != amap) {
|
||||
final CameraUpdate cameraUpdate = ConvertUtil.toCameraUpdate(call.argument("cameraUpdate"));
|
||||
final Object animatedObject = call.argument("animated");
|
||||
final Object durationObject = call.argument("duration");
|
||||
final CameraUpdate cameraUpdate = ConvertUtil.toCameraUpdate(call.argument("cameraUpdate"));
|
||||
final Object animatedObject = call.argument("animated");
|
||||
final Object durationObject = call.argument("duration");
|
||||
|
||||
moveCamera(cameraUpdate, animatedObject, durationObject);
|
||||
}
|
||||
moveCamera(cameraUpdate, animatedObject, durationObject);
|
||||
break;
|
||||
case Const.METHOD_MAP_SET_RENDER_FPS:
|
||||
if (null != amap) {
|
||||
amap.setRenderFps((Integer) call.argument("fps"));
|
||||
result.success(null);
|
||||
}
|
||||
amap.setRenderFps((Integer) call.argument("fps"));
|
||||
result.success(null);
|
||||
break;
|
||||
case Const.METHOD_MAP_TAKE_SNAPSHOT:
|
||||
if (amap != null) {
|
||||
final MethodChannel.Result _result = result;
|
||||
amap.getMapScreenShot(new AMap.OnMapScreenShotListener() {
|
||||
@Override
|
||||
public void onMapScreenShot(Bitmap bitmap) {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
||||
byte[] byteArray = stream.toByteArray();
|
||||
bitmap.recycle();
|
||||
_result.success(byteArray);
|
||||
}
|
||||
final MethodChannel.Result _result = result;
|
||||
amap.getMapScreenShot(new AMap.OnMapScreenShotListener() {
|
||||
@Override
|
||||
public void onMapScreenShot(Bitmap bitmap) {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
||||
byte[] byteArray = stream.toByteArray();
|
||||
bitmap.recycle();
|
||||
_result.success(byteArray);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapScreenShot(Bitmap bitmap, int i) {
|
||||
@Override
|
||||
public void onMapScreenShot(Bitmap bitmap, int i) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
case Const.METHOD_MAP_CLEAR_DISK:
|
||||
if (null != amap) {
|
||||
amap.removecache();
|
||||
result.success(null);
|
||||
}
|
||||
amap.removecache();
|
||||
result.success(null);
|
||||
break;
|
||||
default:
|
||||
LogUtil.w(CLASS_NAME, "onMethodCall not find methodId:" + call.method);
|
||||
|
@ -187,8 +170,6 @@ public class MapController
|
|||
}
|
||||
}
|
||||
|
||||
private boolean myLocationShowing = false;
|
||||
|
||||
@Override
|
||||
public void setMyLocationStyle(MyLocationStyle myLocationStyle) {
|
||||
if (null != amap) {
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
package com.amap.flutter.map.overlays;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.TextureMapView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
|
@ -23,7 +18,8 @@ public abstract class AbstractOverlayController<T> {
|
|||
protected final Map<String, String> idMapByOverlyId;
|
||||
protected final MethodChannel methodChannel;
|
||||
protected final AMap amap;
|
||||
public AbstractOverlayController(MethodChannel methodChannel, AMap amap){
|
||||
|
||||
public AbstractOverlayController(MethodChannel methodChannel, AMap amap) {
|
||||
this.methodChannel = methodChannel;
|
||||
this.amap = amap;
|
||||
controllerMapByDartId = new HashMap<String, T>(12);
|
||||
|
|
|
@ -30,12 +30,17 @@ class MarkerController implements MarkerOptionsSink {
|
|||
}
|
||||
|
||||
public LatLng getPosition() {
|
||||
if(null != marker) {
|
||||
if (null != marker) {
|
||||
return marker.getPosition();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(LatLng position) {
|
||||
marker.setPosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(float alpha) {
|
||||
marker.setAlpha(alpha);
|
||||
|
@ -71,11 +76,6 @@ class MarkerController implements MarkerOptionsSink {
|
|||
marker.setSnippet(snippet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(LatLng position) {
|
||||
marker.setPosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(float rotation) {
|
||||
marker.setRotateAngle(rotation);
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.amap.flutter.map.overlays.marker;
|
|||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.amap.flutter.map.overlays.marker.MarkerOptionsSink;
|
||||
import com.amap.flutter.map.utils.ConvertUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -53,7 +52,7 @@ public class MarkerUtil {
|
|||
}
|
||||
final Object rotation = data.get("rotation");
|
||||
if (rotation != null) {
|
||||
sink.setRotation(Math.abs(360- ConvertUtil.toFloat(rotation)));
|
||||
sink.setRotation(Math.abs(360 - ConvertUtil.toFloat(rotation)));
|
||||
}
|
||||
final Object visible = data.get("visible");
|
||||
if (visible != null) {
|
||||
|
@ -66,7 +65,7 @@ public class MarkerUtil {
|
|||
|
||||
final Object infoWindowEnable = data.get("infoWindowEnable");
|
||||
|
||||
if(infoWindowEnable != null) {
|
||||
if (infoWindowEnable != null) {
|
||||
sink.setInfoWindowEnable(ConvertUtil.toBoolean(infoWindowEnable));
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,10 @@ import android.text.TextUtils;
|
|||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.TextureMapView;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.amap.api.maps.model.MarkerOptions;
|
||||
import com.amap.api.maps.model.Poi;
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.flutter.map.MyMethodCallHandler;
|
||||
import com.amap.flutter.map.overlays.AbstractOverlayController;
|
||||
import com.amap.flutter.map.utils.Const;
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.amap.flutter.map.overlays.polygon;
|
|||
import com.amap.api.maps.model.AMapPara;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.Polygon;
|
||||
import com.amap.api.maps.model.PolygonOptions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -13,11 +12,12 @@ import java.util.List;
|
|||
* @mail hongming.whm@alibaba-inc.com
|
||||
* @since
|
||||
*/
|
||||
class PolygonController implements PolygonOptionsSink{
|
||||
class PolygonController implements PolygonOptionsSink {
|
||||
|
||||
private final Polygon polygon;
|
||||
private final String id;
|
||||
PolygonController(Polygon polygon){
|
||||
|
||||
PolygonController(Polygon polygon) {
|
||||
this.polygon = polygon;
|
||||
this.id = polygon.getId();
|
||||
}
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package com.amap.flutter.map.overlays.polygon;
|
||||
|
||||
import com.amap.api.maps.model.AMapPara;
|
||||
import com.amap.api.maps.model.BitmapDescriptor;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.PolygonOptions;
|
||||
import com.amap.api.maps.model.PolylineOptions;
|
||||
import com.amap.flutter.map.overlays.polyline.PolylineOptionsSink;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -17,13 +14,14 @@ import java.util.List;
|
|||
*/
|
||||
class PolygonOptionsBuilder implements PolygonOptionsSink {
|
||||
final PolygonOptions polygonOptions;
|
||||
|
||||
PolygonOptionsBuilder() {
|
||||
polygonOptions = new PolygonOptions();
|
||||
//必须设置为true,否则会出现线条转折处出现断裂的现象
|
||||
polygonOptions.usePolylineStroke(true);
|
||||
}
|
||||
|
||||
public PolygonOptions build(){
|
||||
public PolygonOptions build() {
|
||||
return polygonOptions;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.amap.flutter.map.overlays.polygon;
|
||||
|
||||
import com.amap.api.maps.model.AMapPara;
|
||||
import com.amap.flutter.map.overlays.polyline.PolylineOptionsSink;
|
||||
import com.amap.flutter.map.utils.ConvertUtil;
|
||||
|
||||
import java.util.Map;
|
||||
|
|
|
@ -37,7 +37,7 @@ public class PolygonsController
|
|||
@Override
|
||||
public void doMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
|
||||
String methodId = call.method;
|
||||
LogUtil.i(CLASS_NAME, "doMethodCall===>" +methodId);
|
||||
LogUtil.i(CLASS_NAME, "doMethodCall===>" + methodId);
|
||||
switch (methodId) {
|
||||
case Const.METHOD_POLYGON_UPDATE:
|
||||
invokePolylineOptions(call, result);
|
||||
|
@ -51,7 +51,6 @@ public class PolygonsController
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param methodCall
|
||||
* @param result
|
||||
*/
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.List;
|
|||
class PolylineController implements PolylineOptionsSink {
|
||||
final Polyline polyline;
|
||||
final String polylineId;
|
||||
|
||||
PolylineController(Polyline polyline) {
|
||||
this.polyline = polyline;
|
||||
this.polylineId = polyline.getId();
|
||||
|
@ -26,10 +27,11 @@ class PolylineController implements PolylineOptionsSink {
|
|||
}
|
||||
|
||||
public void remove() {
|
||||
if(null != polyline) {
|
||||
if (null != polyline) {
|
||||
polyline.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPoints(List<LatLng> points) {
|
||||
polyline.setPoints(points);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.amap.flutter.map.overlays.polyline;
|
||||
|
||||
import com.amap.api.maps.model.AMapPara;
|
||||
import com.amap.api.maps.model.BitmapDescriptor;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.PolylineOptions;
|
||||
|
@ -95,7 +94,7 @@ class PolylineOptionsBuilder implements PolylineOptionsSink {
|
|||
polylineOptions.lineJoinType(joinType);
|
||||
}
|
||||
|
||||
public PolylineOptions build(){
|
||||
public PolylineOptions build() {
|
||||
return polylineOptions;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class PolylineUtil {
|
|||
|
||||
private static final String CLASS_NAME = "PolylineUtil";
|
||||
//虚线类型
|
||||
private static final int[] DASH_LINE_TYPE = {-1,0,1};
|
||||
private static final int[] DASH_LINE_TYPE = {-1, 0, 1};
|
||||
|
||||
static String interpretOptions(Object o, PolylineOptionsSink sink) {
|
||||
final Map<?, ?> data = ConvertUtil.toMap(o);
|
||||
|
@ -60,7 +60,7 @@ class PolylineUtil {
|
|||
if (rawType > DASH_LINE_TYPE.length) {
|
||||
rawType = 0;
|
||||
}
|
||||
if(DASH_LINE_TYPE[rawType] == -1) {
|
||||
if (DASH_LINE_TYPE[rawType] == -1) {
|
||||
sink.setDashLine(false);
|
||||
} else {
|
||||
sink.setDashLine(true);
|
||||
|
@ -100,7 +100,7 @@ class PolylineUtil {
|
|||
}
|
||||
|
||||
final String dartId = (String) data.get("id");
|
||||
if(TextUtils.isEmpty(dartId)) {
|
||||
if (TextUtils.isEmpty(dartId)) {
|
||||
Log.w(CLASS_NAME, "没有传入正确的dart层ID, 请确认对应的key值是否正确!!!");
|
||||
}
|
||||
return dartId;
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.text.TextUtils;
|
|||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.TextureMapView;
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.maps.model.PolylineOptions;
|
||||
import com.amap.flutter.map.MyMethodCallHandler;
|
||||
|
@ -68,7 +67,6 @@ public class PolylinesController
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param methodCall
|
||||
* @param result
|
||||
*/
|
||||
|
@ -145,5 +143,4 @@ public class PolylinesController
|
|||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ import android.graphics.Point;
|
|||
import android.location.Location;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.CameraUpdate;
|
||||
import com.amap.api.maps.CameraUpdateFactory;
|
||||
|
@ -28,8 +30,6 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import io.flutter.view.FlutterMain;
|
||||
|
||||
/**
|
||||
|
@ -41,7 +41,7 @@ import io.flutter.view.FlutterMain;
|
|||
public class ConvertUtil {
|
||||
|
||||
private static final String CLASS_NAME = "ConvertUtil";
|
||||
|
||||
private static final int[] LocationTypeMap = new int[]{MyLocationStyle.LOCATION_TYPE_SHOW, MyLocationStyle.LOCATION_TYPE_FOLLOW, MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE};
|
||||
public static float density;
|
||||
private static String apiKey;
|
||||
|
||||
|
@ -72,7 +72,7 @@ public class ConvertUtil {
|
|||
if (null != hasAgreeObj) {
|
||||
boolean hasAgree = toBoolean(hasAgreeObj);
|
||||
//使用反射的方法调用适配之前的版本
|
||||
try{
|
||||
try {
|
||||
Method method = clazz.getMethod("updatePrivacyAgree", Context.class, boolean.class);
|
||||
method.invoke(null, context, hasAgree);
|
||||
} catch (Throwable e) {
|
||||
|
@ -119,8 +119,8 @@ public class ConvertUtil {
|
|||
return CameraUpdateFactory.newLatLngZoom(toLatLng(data.get(1)), toFloat(data.get(2)));
|
||||
case "scrollBy":
|
||||
return CameraUpdateFactory.scrollBy( //
|
||||
toFloatPixels(data.get(1)), //
|
||||
toFloatPixels(data.get(2)));
|
||||
toFloatPixels(data.get(1)), //
|
||||
toFloatPixels(data.get(2)));
|
||||
case "zoomBy":
|
||||
if (data.size() == 2) {
|
||||
return CameraUpdateFactory.zoomBy(toFloat(data.get(1)));
|
||||
|
@ -138,7 +138,6 @@ public class ConvertUtil {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private static Point toPoint(Object o) {
|
||||
final List<?> data = toList(o);
|
||||
return new Point(toPixels(data.get(0)), toPixels(data.get(1)));
|
||||
|
@ -297,8 +296,6 @@ public class ConvertUtil {
|
|||
return customMapStyleOptions;
|
||||
}
|
||||
|
||||
private static final int[] LocationTypeMap = new int[]{MyLocationStyle.LOCATION_TYPE_SHOW, MyLocationStyle.LOCATION_TYPE_FOLLOW, MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE};
|
||||
|
||||
private static MyLocationStyle toMyLocationStyle(Object o, float density) {
|
||||
final Map<?, ?> map = toMap(o);
|
||||
final MyLocationStyle myLocationStyle = new MyLocationStyle();
|
||||
|
|
|
@ -10,29 +10,31 @@ import android.util.Log;
|
|||
* @since
|
||||
*/
|
||||
public class LogUtil {
|
||||
public static boolean isDebugMode = false;
|
||||
private static final String TAG = "AMapFlutter_";
|
||||
public static boolean isDebugMode = false;
|
||||
|
||||
public static void i(String className, String message) {
|
||||
if(isDebugMode) {
|
||||
Log.i(TAG+className, message);
|
||||
if (isDebugMode) {
|
||||
Log.i(TAG + className, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void d(String className, String message) {
|
||||
if(isDebugMode) {
|
||||
Log.d(TAG+className, message);
|
||||
if (isDebugMode) {
|
||||
Log.d(TAG + className, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void w(String className, String message) {
|
||||
if(isDebugMode) {
|
||||
Log.w(TAG+className, message);
|
||||
if (isDebugMode) {
|
||||
Log.w(TAG + className, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void e(String className, String methodName, Throwable e) {
|
||||
if (isDebugMode) {
|
||||
Log.e(TAG+className, methodName + " exception!!", e);
|
||||
Log.e(TAG + className, methodName + " exception!!", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
|
|||
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
compileSdkVersion 33
|
||||
|
||||
lintOptions {
|
||||
disable 'InvalidPackage'
|
||||
|
@ -35,7 +35,7 @@ android {
|
|||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||
applicationId "com.amap.flutter.amap_map_example"
|
||||
minSdkVersion flutter.minSdkVersion
|
||||
targetSdkVersion 29
|
||||
targetSdkVersion 33
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
versionName flutterVersionName
|
||||
}
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
<!-- Flutter needs it to communicate with the running application
|
||||
to allow setting breakpoints, to provide hot reload, etc.
|
||||
-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
</manifest>
|
||||
|
|
|
@ -5,48 +5,47 @@
|
|||
In most cases you can leave this as-is, but you if you want to provide
|
||||
additional functionality it is fine to subclass or reimplement
|
||||
FlutterApplication and put your custom class here. -->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<application
|
||||
android:name="${applicationName}"
|
||||
android:label="amap_map_example"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="amap_map_example">
|
||||
<!-- <meta-data
|
||||
android:name="com.amap.api.v2.apikey"
|
||||
android:value="900f72eeee0f21e435cebb0ef155582a" /> -->
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/LaunchTheme"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/LaunchTheme"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<!-- Specifies an Android theme to apply to this Activity as soon as
|
||||
the Android process has started. This theme is visible to the user
|
||||
while the Flutter UI initializes. After that, this theme continues
|
||||
to determine the Window background behind the Flutter UI. -->
|
||||
<meta-data
|
||||
android:name="io.flutter.embedding.android.NormalTheme"
|
||||
android:resource="@style/NormalTheme"
|
||||
/>
|
||||
android:name="io.flutter.embedding.android.NormalTheme"
|
||||
android:resource="@style/NormalTheme" />
|
||||
<!-- Displays an Android View that continues showing the launch screen
|
||||
Drawable until Flutter paints its first frame, then this splash
|
||||
screen fades out. A splash screen is useful to avoid any visual
|
||||
gap between the end of Android's launch screen and the painting of
|
||||
Flutter's first frame. -->
|
||||
<meta-data
|
||||
android:name="io.flutter.embedding.android.SplashScreenDrawable"
|
||||
android:resource="@drawable/launch_background"
|
||||
/>
|
||||
android:name="io.flutter.embedding.android.SplashScreenDrawable"
|
||||
android:resource="@drawable/launch_background" />
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- Don't delete the meta-data below.
|
||||
|
|
|
@ -3,4 +3,4 @@ package com.amap.flutter.amap_map_example;
|
|||
import io.flutter.embedding.android.FlutterActivity;
|
||||
|
||||
public class MainActivity extends FlutterActivity {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Modify this file to customize your launch splash screen -->
|
||||
<?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" />
|
||||
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
<!-- Flutter needs it to communicate with the running application
|
||||
to allow setting breakpoints, to provide hot reload, etc.
|
||||
-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
</manifest>
|
||||
|
|
|
@ -5,7 +5,7 @@ buildscript {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||
classpath 'com.android.tools.build:gradle:4.2.2'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue