Skip to content

Commit

Permalink
release 1.0.7, Close Issue #10 , 添加Logo位置设置
Browse files Browse the repository at this point in the history
  • Loading branch information
kuloud committed Jul 28, 2024
1 parent 7e3759b commit 064bb77
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 33 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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一起更新了
Expand Down
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;

import androidx.annotation.IntRange;
import androidx.lifecycle.LifecycleOwner;

import com.amap.api.maps.AMapOptions;
Expand All @@ -10,6 +11,7 @@
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;
Expand All @@ -22,7 +24,7 @@
* @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;
Expand All @@ -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;

Expand Down Expand Up @@ -82,6 +88,10 @@ AMapPlatformView build(int id,
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;
Expand Down Expand Up @@ -195,6 +205,27 @@ public void setScaleEnabled(boolean scaleEnabled) {
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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +15,7 @@
* @mail hongming.whm@alibaba-inc.com
* @since
*/
public interface AMapOptionsSink {
public interface AMapOptionsSink extends UISettingsSink {

void setCamera(CameraPosition camera);

Expand Down Expand Up @@ -42,7 +45,6 @@ public interface AMapOptionsSink {

public void setScaleEnabled(boolean scaleEnabled);


public void setZoomGesturesEnabled(boolean zoomGesturesEnabled);

public void setScrollGesturesEnabled(boolean scrollGesturesEnabled);
Expand Down
25 changes: 25 additions & 0 deletions android/src/main/java/com/amap/flutter/map/core/MapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,29 @@ public void setInitialPolygons(Object polygonsObject) {
}


@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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
15 changes: 15 additions & 0 deletions android/src/main/java/com/amap/flutter/map/utils/ConvertUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,21 @@ public static void interpretAMapOptions(Object o, @NonNull AMapOptionsSink sink)
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);
}
Expand Down
55 changes: 54 additions & 1 deletion example/lib/pages/interactive/map_ui_options.dart
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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(
Expand All @@ -34,6 +47,9 @@ class _BodyState extends State<MapUIDemoPage> {
compassEnabled: _compassEnabled,
labelsEnabled: _labelsEnabled,
scaleEnabled: _scaleEnabled,
logoPosition: _logoPosition,
logoBottomMargin: _logoBottomMargin,
logoLeftMargin: _logoLeftMargin,
);

//ui控制
Expand Down Expand Up @@ -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();
});
},
),
],
),
);
Expand All @@ -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,
),
Expand Down
20 changes: 9 additions & 11 deletions example/lib/widgets/amap_radio_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
},
),
],
Expand Down
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 064bb77

Please sign in to comment.