release 1.0.7, Close Issue #10 , 添加Logo位置设置

This commit is contained in:
Kuloud 2024-07-29 00:28:45 +08:00
parent 7e3759b638
commit 064bb77cf1
14 changed files with 274 additions and 33 deletions

View File

@ -1,3 +1,7 @@
## 1.0.6
2024-07-28.
* Close Issue [#10](https://github.com/kuloud/amap_map/issues/10) 添加Logo位置设置参见example: map_ui_options.dart
## 1.0.6
2024-06-27.
* 升级amap android sdk版本 V10.0.700_loc6.4.5_sea9.7.2 2024-05-13 看高德更新日志应该是计划后续版本捆绑loc+search一起更新了

View File

@ -34,5 +34,6 @@ android {
dependencies {
implementation 'com.amap.api:3dmap-location-search:10.0.700_loc6.4.5_sea9.7.2'
implementation 'androidx.annotation:annotation:1.8.1'
}

View File

@ -2,6 +2,7 @@ package com.amap.flutter.map;
import android.content.Context;
import androidx.annotation.IntRange;
import androidx.lifecycle.LifecycleOwner;
import com.amap.api.maps.AMapOptions;
@ -10,6 +11,7 @@ import com.amap.api.maps.model.CustomMapStyleOptions;
import com.amap.api.maps.model.LatLngBounds;
import com.amap.api.maps.model.MyLocationStyle;
import com.amap.flutter.map.core.AMapOptionsSink;
import com.amap.flutter.map.core.UISettingsSink;
import com.amap.flutter.map.utils.LogUtil;
import java.util.List;
@ -22,7 +24,7 @@ import io.flutter.plugin.common.BinaryMessenger;
* @mail hongming.whm@alibaba-inc.com
* @since
*/
class AMapOptionsBuilder implements AMapOptionsSink {
class AMapOptionsBuilder implements AMapOptionsSink, UISettingsSink {
private static final String CLASS_NAME = "AMapOptionsBuilder";
private final AMapOptions options = new AMapOptions();
private CustomMapStyleOptions customMapStyleOptions;
@ -36,6 +38,10 @@ class AMapOptionsBuilder implements AMapOptionsSink {
private boolean buildingsEnabled = true;
private boolean labelsEnabled = true;
private int logoPosition = AMapOptions.LOGO_POSITION_BOTTOM_LEFT;
private int logoBottomMargin = 0;
private int logoLeftMargin = 0;
private float anchorX = 2.0F;
private float anchorY = 2.0F;
@ -82,6 +88,10 @@ class AMapOptionsBuilder implements AMapOptionsSink {
aMapPlatformView.getMapController().setBuildingsEnabled(buildingsEnabled);
aMapPlatformView.getMapController().setLabelsEnabled(labelsEnabled);
aMapPlatformView.getMapController().setLogoPosition(logoPosition);
aMapPlatformView.getMapController().setLogoBottomMargin(logoBottomMargin);
aMapPlatformView.getMapController().setLogoLeftMargin(logoLeftMargin);
if (null != initialMarkers) {
List<Object> markerList = (List<Object>) initialMarkers;
@ -195,6 +205,27 @@ class AMapOptionsBuilder implements AMapOptionsSink {
options.scaleControlsEnabled(scaleEnabled);
}
@Override
public void setLogoPosition(@IntRange(from = AMapOptions.LOGO_POSITION_BOTTOM_LEFT, to = AMapOptions.LOGO_POSITION_BOTTOM_RIGHT) int logoPosition) {
options.logoPosition(logoPosition);
this.logoPosition = logoPosition;
}
@Override
public int getLogoPosition() {
return options.getLogoPosition();
}
@Override
public void setLogoBottomMargin(int pixels) {
this.logoBottomMargin = pixels;
}
@Override
public void setLogoLeftMargin(int pixels) {
this.logoLeftMargin = pixels;
}
@Override
public void setInitialMarkers(Object markersObject) {

View File

@ -1,5 +1,8 @@
package com.amap.flutter.map.core;
import androidx.annotation.IntRange;
import com.amap.api.maps.AMapOptions;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.CustomMapStyleOptions;
import com.amap.api.maps.model.LatLngBounds;
@ -12,7 +15,7 @@ import com.amap.api.maps.model.MyLocationStyle;
* @mail hongming.whm@alibaba-inc.com
* @since
*/
public interface AMapOptionsSink {
public interface AMapOptionsSink extends UISettingsSink {
void setCamera(CameraPosition camera);
@ -42,7 +45,6 @@ public interface AMapOptionsSink {
public void setScaleEnabled(boolean scaleEnabled);
public void setZoomGesturesEnabled(boolean zoomGesturesEnabled);
public void setScrollGesturesEnabled(boolean scrollGesturesEnabled);

View File

@ -356,4 +356,29 @@ public class MapController
}
@Override
public void setLogoPosition(int logoPosition) {
if (null != amap) {
amap.getUiSettings().setLogoPosition(logoPosition);
}
}
@Override
public int getLogoPosition() {
return null != amap ? amap.getUiSettings().getLogoPosition() : 0;
}
@Override
public void setLogoBottomMargin(int pixels) {
if (null != amap) {
amap.getUiSettings().setLogoBottomMargin(pixels);
}
}
@Override
public void setLogoLeftMargin(int pixels) {
if (null != amap) {
amap.getUiSettings().setLogoLeftMargin(pixels);
}
}
}

View File

@ -0,0 +1,41 @@
package com.amap.flutter.map.core;
import androidx.annotation.IntRange;
import com.amap.api.maps.AMapOptions;
/**
* @author kuloud
*/
public interface UISettingsSink {
/**
* 设置高德地图Logo的位置
*
* @param logoPosition
*/
void setLogoPosition(@IntRange(from = AMapOptions.LOGO_POSITION_BOTTOM_LEFT, to = AMapOptions.LOGO_POSITION_BOTTOM_RIGHT) int logoPosition);
/**
* 获取高德地图Logo的位置
*
* @return
*/
int getLogoPosition();
/**
* 设置Logo下边界距离屏幕底部的边距
* Note: SDK 内有setLogoMarginRate接口按比例设置Logo位置但是高德官方文档没有相关参数描述
*
* @param pixels
*/
void setLogoBottomMargin(int pixels);
/**
* 设置Logo左边界距离屏幕左侧的边距
* Note: SDK 内有setLogoMarginRate接口按比例设置Logo位置但是高德官方文档没有相关参数描述
*
* @param pixels
*/
void setLogoLeftMargin(int pixels);
}

View File

@ -278,6 +278,21 @@ public class ConvertUtil {
if (null != zoomGesturesEnabled) {
sink.setZoomGesturesEnabled(toBoolean(zoomGesturesEnabled));
}
final Object logoPosition = data.get("logoPosition");
if (null != logoPosition) {
sink.setLogoPosition(toInt(logoPosition));
}
final Object logoBottomMargin = data.get("logoBottomMargin");
if (null != logoBottomMargin) {
sink.setLogoBottomMargin(toInt(logoBottomMargin));
}
final Object logoLeftMargin = data.get("logoLeftMargin");
if (null != logoLeftMargin) {
sink.setLogoLeftMargin(toInt(logoLeftMargin));
}
} catch (Throwable e) {
LogUtil.e(CLASS_NAME, "interpretAMapOptions", e);
}

View File

@ -1,7 +1,10 @@
import 'package:amap_map/amap_map.dart';
import 'package:amap_map_example/widgets/amap_gridview.dart';
import 'package:amap_map_example/widgets/amap_radio_group.dart';
import 'package:amap_map_example/widgets/amap_switch_button.dart';
import 'package:flutter/material.dart';
import 'package:x_amap_base/x_amap_base.dart';
import 'package:x_common/utils/logger.dart';
class MapUIDemoPage extends StatefulWidget {
MapUIDemoPage({Key? key}) : super(key: key);
@ -26,6 +29,16 @@ class _BodyState extends State<MapUIDemoPage> {
///
bool _scaleEnabled = true;
LogoPosition _logoPosition = LogoPosition.BOTTOM_LEFT;
int _logoBottomMargin = 0;
int _logoLeftMargin = 0;
final Map<String, LogoPosition?> _radioValueMap = {
'底部居左': LogoPosition.BOTTOM_LEFT,
'底部居中': LogoPosition.BOTTOM_CENTER,
'底部居右': LogoPosition.BOTTOM_RIGHT,
};
@override
Widget build(BuildContext context) {
final AMapWidget map = AMapWidget(
@ -34,6 +47,9 @@ class _BodyState extends State<MapUIDemoPage> {
compassEnabled: _compassEnabled,
labelsEnabled: _labelsEnabled,
scaleEnabled: _scaleEnabled,
logoPosition: _logoPosition,
logoBottomMargin: _logoBottomMargin,
logoLeftMargin: _logoLeftMargin,
);
//ui控制
@ -97,6 +113,43 @@ class _BodyState extends State<MapUIDemoPage> {
padding: EdgeInsets.only(left: 10),
child: AMapGradView(childrenWidgets: _uiOptions),
),
AMapRadioGroup<LogoPosition?>(
groupLabel: 'Logo位置',
groupValue: _logoPosition,
radioValueMap: _radioValueMap,
onChanged: (value) => {
//
setState(() {
_logoPosition = value!;
})
},
),
Text('Logo底部边距: $_logoBottomMargin'),
Slider(
value: _logoBottomMargin.toDouble(),
min: 0,
max: 100,
divisions: 100,
label: _logoBottomMargin.round().toString(),
onChanged: (double value) {
setState(() {
_logoBottomMargin = value.round();
});
},
),
Text('Logo左侧边距: $_logoLeftMargin'),
Slider(
value: _logoLeftMargin.toDouble(),
min: 0,
max: 100,
divisions: 100,
label: _logoLeftMargin.round().toString(),
onChanged: (double value) {
setState(() {
_logoLeftMargin = value.round();
});
},
),
],
),
);
@ -110,7 +163,7 @@ class _BodyState extends State<MapUIDemoPage> {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
height: MediaQuery.of(context).size.height * 0.7,
height: MediaQuery.of(context).size.height * 0.5,
width: MediaQuery.of(context).size.width,
child: map,
),

View File

@ -5,7 +5,7 @@ class AMapRadioGroup<T> extends StatefulWidget {
final String? groupLabel;
final T? groupValue;
final Map<String, T>? radioValueMap;
final ValueChanged<T>? onChanged;
final ValueChanged<T?>? onChanged;
AMapRadioGroup(
{Key? key,
this.groupLabel,
@ -15,37 +15,35 @@ class AMapRadioGroup<T> extends StatefulWidget {
: super(key: key);
@override
_AMapRadioGroupState createState() => _AMapRadioGroupState();
_AMapRadioGroupState<T> createState() => _AMapRadioGroupState<T>();
}
class _AMapRadioGroupState extends State<AMapRadioGroup> {
dynamic _groupValue;
class _AMapRadioGroupState<T> extends State<AMapRadioGroup<T>> {
T? _groupValue;
@override
void initState() {
super.initState();
_groupValue = widget.groupValue ?? null;
_groupValue = (widget.groupValue ?? null) as T?;
}
@override
Widget build(BuildContext context) {
List<Widget> radioList = <Widget>[];
_groupValue = widget.groupValue ?? null;
_groupValue = (widget.groupValue ?? null) as T?;
Widget _myRadio(String label, dynamic radioValue) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(label),
Radio<dynamic>(
Radio<T>(
value: radioValue,
groupValue: _groupValue,
onChanged: (_value) {
onChanged: (T? _value) {
setState(() {
_groupValue = _value;
});
if (null != widget.onChanged) {
widget.onChanged!(_value);
}
widget.onChanged!(_value);
},
),
],

View File

@ -22,6 +22,7 @@ dependencies:
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
x_common: ^1.0.4
# amap_map_extensions: ^0.0.1
# amap_map_extensions:

View File

@ -3,6 +3,7 @@
// amap_map
//
// Created by lly on 2020/10/30.
// Updated by kuloud on 2024/07/29.
//
#import "MAMapView+Flutter.h"
@ -217,6 +218,50 @@
if (rotateCameraEnable) {
self.rotateCameraEnabled = [rotateCameraEnable boolValue];
}
NSNumber *logoPosition = dict[@"logoPosition"];
NSNumber *logoBottomMargin = dict[@"logoBottomMargin"];
NSNumber *logoLeftMargin = dict[@"logoLeftMargin"];
CGSize mapSize = self.bounds.size;
CGSize logoSize = CGSizeMake(110, 40); // _mapView.logoCenter = CGPointMake(CGRectGetWidth(self.view.bounds)-55, 450);logo110x40
CGPoint logoCenter = CGPointZero;
if (logoBottomMargin || logoLeftMargin) {
CGFloat bottomMargin = logoBottomMargin ? [logoBottomMargin floatValue] : 0;
CGFloat leftMargin = logoLeftMargin ? [logoLeftMargin floatValue] : 0;
logoCenter.x = leftMargin + logoSize.width / 2;
logoCenter.y = mapSize.height - bottomMargin - logoSize.height / 2;
} else if (logoPosition) {
NSInteger position = [logoPosition integerValue];
switch (position) {
case 0: // LOGO_POSITION_BOTTOM_LEFT
logoCenter = CGPointMake(logoSize.width / 2, mapSize.height - logoSize.height / 2);
break;
case 1: // LOGO_POSITION_BOTTOM_CENTER
logoCenter = CGPointMake(mapSize.width / 2, mapSize.height - logoSize.height / 2);
break;
case 2: // LOGO_POSITION_BOTTOM_RIGHT
logoCenter = CGPointMake(mapSize.width - logoSize.width / 2, mapSize.height - logoSize.height / 2);
break;
default:
//
logoCenter = CGPointMake(logoSize.width / 2, mapSize.height - logoSize.height / 2);
break;
}
} else {
logoCenter = CGPointMake(logoSize.width / 2, mapSize.height - logoSize.height / 2);
}
// logoCentermapView.bounds
logoCenter.x = MAX(logoSize.width / 2, MIN(logoCenter.x, mapSize.width - logoSize.width / 2));
logoCenter.y = MAX(logoSize.height / 2, MIN(logoCenter.y, mapSize.height - logoSize.height / 2));
// logo
self.logoCenter = logoCenter;
}
@end

View File

@ -24,6 +24,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:x_common/utils/logger.dart';
export 'package:amap_map/src/types/types.dart';

View File

@ -64,6 +64,12 @@ class AMapWidget extends StatefulWidget {
///
final bool tiltGesturesEnabled;
final LogoPosition? logoPosition;
final int? logoBottomMargin;
final int? logoLeftMargin;
/// Marker
final Set<Marker> markers;
@ -140,7 +146,10 @@ class AMapWidget extends StatefulWidget {
this.markers = const <Marker>{},
this.polylines = const <Polyline>{},
this.polygons = const <Polygon>{},
this.extensions = const []})
this.extensions = const [],
this.logoPosition,
this.logoBottomMargin,
this.logoLeftMargin})
: super(key: key);
///
@ -362,6 +371,12 @@ class _AMapOptions {
///
final bool? tiltGesturesEnabled;
/// logo的位置
final int? logoPosition;
final int? logoBottomMargin;
final int? logoLeftMargin;
_AMapOptions({
this.mapType = MapType.normal,
this.buildingsEnabled,
@ -378,26 +393,31 @@ class _AMapOptions {
this.scrollGesturesEnabled,
this.tiltGesturesEnabled,
this.zoomGesturesEnabled,
this.logoPosition,
this.logoBottomMargin,
this.logoLeftMargin,
});
static _AMapOptions fromWidget(AMapWidget map) {
return _AMapOptions(
mapType: map.mapType,
buildingsEnabled: map.buildingsEnabled,
compassEnabled: map.compassEnabled,
labelsEnabled: map.labelsEnabled,
limitBounds: map.limitBounds,
minMaxZoomPreference: map.minMaxZoomPreference,
scaleEnabled: map.scaleEnabled,
touchPoiEnabled: map.touchPoiEnabled,
trafficEnabled: map.trafficEnabled,
rotateGesturesEnabled: map.rotateGesturesEnabled,
scrollGesturesEnabled: map.scrollGesturesEnabled,
tiltGesturesEnabled: map.tiltGesturesEnabled,
zoomGesturesEnabled: map.zoomGesturesEnabled,
customStyleOptions: map.customStyleOptions?.clone(),
myLocationStyleOptions: map.myLocationStyleOptions?.clone(),
);
mapType: map.mapType,
buildingsEnabled: map.buildingsEnabled,
compassEnabled: map.compassEnabled,
labelsEnabled: map.labelsEnabled,
limitBounds: map.limitBounds,
minMaxZoomPreference: map.minMaxZoomPreference,
scaleEnabled: map.scaleEnabled,
touchPoiEnabled: map.touchPoiEnabled,
trafficEnabled: map.trafficEnabled,
rotateGesturesEnabled: map.rotateGesturesEnabled,
scrollGesturesEnabled: map.scrollGesturesEnabled,
tiltGesturesEnabled: map.tiltGesturesEnabled,
zoomGesturesEnabled: map.zoomGesturesEnabled,
customStyleOptions: map.customStyleOptions?.clone(),
myLocationStyleOptions: map.myLocationStyleOptions?.clone(),
logoPosition: map.logoPosition?.index,
logoBottomMargin: map.logoBottomMargin,
logoLeftMargin: map.logoLeftMargin);
}
Map<String, dynamic> toMap() {
@ -423,6 +443,9 @@ class _AMapOptions {
addIfNonNull('tiltGesturesEnabled', tiltGesturesEnabled);
addIfNonNull('zoomGesturesEnabled', zoomGesturesEnabled);
addIfNonNull('myLocationStyle', myLocationStyleOptions?.clone().toMap());
addIfNonNull('logoPosition', logoPosition);
addIfNonNull('logoBottomMargin', logoBottomMargin);
addIfNonNull('logoLeftMargin', logoLeftMargin);
return optionsMap;
}

View File

@ -1,6 +1,6 @@
name: amap_map
description: Amap SDK Flutter plugin for integrating AMapSDK in iOS and Android applications.
version: 1.0.6
version: 1.0.7
homepage: https://github.com/kuloud/amap_map
issue_tracker: https://github.com/kuloud/amap_map/issues
platforms:
@ -22,6 +22,7 @@ dependencies:
stream_transform: ^2.0.0
x_amap_base: ^1.0.3
x_common: ^1.0.4
# provider: ^6.1.1
# x_amap_base:
# path: ../x_amap_base