Skip to content

Commit

Permalink
release: 1.0.9, add map language support
Browse files Browse the repository at this point in the history
  • Loading branch information
kuloud committed Aug 24, 2024
1 parent b582025 commit 4602f30
Show file tree
Hide file tree
Showing 16 changed files with 186 additions and 46 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.9
2024-08-24
* 设置地图语言,支持中文、英文(按SDK描述:1、不能和自定义地图样式同时使用;2、英文状态只在标准地图生效)

## 1.0.8
2024-07-29.
* 升级amap android sdk版本 10.0.800_loc6.4.5_sea9.7.2 | 2024-07-19
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ class AMapWidget extends StatefulWidget {
///拓展插件,提供更多定制化功能
final List<AMapExtension> extensions;
/// 设置地图语言
final MapLanguage? mapLanguage;
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class AMapOptionsBuilder implements AMapOptionsSink, UISettingsSink {

private Object initialPolygons;

private String mapLanguage;

AMapPlatformView build(int id,
Context context,
BinaryMessenger binaryMessenger,
Expand Down Expand Up @@ -107,6 +109,8 @@ AMapPlatformView build(int id,
List<Object> polygonList = (List<Object>) initialPolygons;
aMapPlatformView.getPolygonsController().addByList(polygonList);
}

aMapPlatformView.getMapController().setMapLanguage(mapLanguage);
return aMapPlatformView;
} catch (Throwable e) {
LogUtil.e(CLASS_NAME, "build", e);
Expand Down Expand Up @@ -242,5 +246,9 @@ public void setInitialPolygons(Object polygonsObject) {
this.initialPolygons = polygonsObject;
}

@Override
public void setMapLanguage(String mapLanguage) {
this.mapLanguage = mapLanguage;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,11 @@ public interface AMapOptionsSink extends UISettingsSink {
public void setInitialPolylines(Object initialPolylines);

public void setInitialPolygons(Object initialPolygons);

/**
* 设置地图语言
*
* @param mapLanguage {@link com.amap.api.maps.AMap#CHINESE }, {@link com.amap.api.maps.AMap#ENGLISH }
*/
void setMapLanguage(String mapLanguage);
}
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,13 @@ public void setInitialPolygons(Object polygonsObject) {
//不实现
}

@Override
public void setMapLanguage(String mapLanguage) {
if (null != amap) {
amap.setMapLanguage(mapLanguage);
}
}


@Override
public void setLogoPosition(int logoPosition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ public static void interpretAMapOptions(Object o, @NonNull AMapOptionsSink sink)
if (null != logoLeftMargin) {
sink.setLogoLeftMargin(toInt(logoLeftMargin));
}

final Object mapLanguage = data.get("mapLanguage");
if (null != mapLanguage) {
sink.setMapLanguage(toString(mapLanguage));
}
} catch (Throwable e) {
LogUtil.e(CLASS_NAME, "interpretAMapOptions", e);
}
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PODS:
- AMap3DMap (10.0.800):
- AMapFoundation (>= 1.8.0)
- amap_map (1.0.3):
- amap_map (1.0.8):
- AMap3DMap
- Flutter
- AMapFoundation (1.8.2)
Expand Down Expand Up @@ -29,7 +29,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
AMap3DMap: 6761e0381f517978312e4f795ce77b2b9f6781a6
amap_map: 8773e5cacc760edf208b1e6e61000241d26385fa
amap_map: 5be213f350872f6ea406be964031572ab9a0d6e1
AMapFoundation: 9885c48fc3a78fdfb84a0299a2293e56ea3c9fec
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2
Expand Down
9 changes: 9 additions & 0 deletions example/lib/data/demos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:collection';

import 'package:amap_map_example/main.dart';
import 'package:amap_map_example/pages/interactive/map_ui_options.dart';
import 'package:amap_map_example/pages/map/change_map_lang.dart';
import 'package:amap_map_example/pages/map/limit_map_bounds.dart';
import 'package:amap_map_example/pages/map/map_my_location.dart';
import 'package:amap_map_example/pages/map/map_with_extension_page.dart';
Expand Down Expand Up @@ -47,6 +48,14 @@ List<Demo> mapDemos() {
configurations: [
DemoConfiguration(buildRoute: (context) => LimitMapBoundsPage())
]),
Demo(
title: '地图显示语言',
category: DemoCategory.basic,
subtitle: '演示限定手机屏幕显示地图的范围',
slug: 'map-lang',
configurations: [
DemoConfiguration(buildRoute: (context) => ChangeMapLangPage())
]),
];
}

Expand Down
1 change: 0 additions & 1 deletion example/lib/pages/interactive/map_ui_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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 Down
73 changes: 73 additions & 0 deletions example/lib/pages/map/change_map_lang.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2024 kuloud

// 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,

import 'package:amap_map/amap_map.dart';
import 'package:amap_map_example/widgets/amap_radio_group.dart';
import 'package:flutter/material.dart';

class ChangeMapLangPage extends StatefulWidget {
ChangeMapLangPage({Key? key}) : super(key: key);

@override
_PageBodyState createState() => _PageBodyState();
}

class _PageBodyState extends State<ChangeMapLangPage> {
MapLanguage? _mapLang;
final Map<String, MapLanguage> _radioValueMap = {
'中文': MapLanguage.chinese,
'English': MapLanguage.english,
};
@override
void initState() {
super.initState();
_mapLang = MapLanguage.chinese;
}

@override
Widget build(BuildContext context) {
//创建地图
final AMapWidget map = AMapWidget(
mapLanguage: _mapLang,
);
return Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
height: MediaQuery.of(context).size.height * 0.6,
width: MediaQuery.of(context).size.width,
child: map,
),
Expanded(
child: SingleChildScrollView(
child: Container(
child: AMapRadioGroup(
groupLabel: '地图语言',
groupValue: _mapLang,
radioValueMap: _radioValueMap,
onChanged: (value) => {
setState(() {
_mapLang = value;
})
},
),
),
),
),
],
),
);
}
}
2 changes: 0 additions & 2 deletions example/lib/pages/map/map_with_extension_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
// import 'package:amap_map_extensions/amap_map_extensions.dart';
import 'package:flutter/material.dart';

import 'dart:typed_data';

import 'package:amap_map/amap_map.dart';

class MapWithExtensionPage extends StatefulWidget {
Expand Down
5 changes: 3 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ dependencies:
flutter:
sdk: flutter

permission_handler: ^11.3.0
flutter_plugin_android_lifecycle: ^2.0.17
permission_handler: ^11.3.1
flutter_plugin_android_lifecycle: ^2.0.21

amap_map:
# When depending on this package from a real application you should use:
Expand All @@ -23,6 +23,7 @@ dependencies:
# the parent directory to use the current plugin's version.
path: ../
x_common: ^1.0.4
x_amap_base: ^1.0.3

# amap_map_extensions: ^0.0.1
# amap_map_extensions:
Expand Down
9 changes: 9 additions & 0 deletions ios/Classes/Category/MAMapView+Flutter.m
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ - (void)updateMapViewOption:(NSDictionary *)dict withRegistrar:(NSObject<Flutter

// 设置logo的位置
self.logoCenter = logoCenter;

// 设置地图语言
NSString *mapLanguage = dict[@"mapLanguage"];
// 中文:@0: 英文:@1. 英文使用注意事项:1、不能和自定义地图样式同时使用;2、英文状态只在MAMapTypeStandard生效
if ([mapLanguage isEqualToString:@"zh_cn"]) {
self.mapLanguage = @0;
} else if ([mapLanguage isEqualToString:@"en"]) {
self.mapLanguage = @1;
}
}

@end
1 change: 0 additions & 1 deletion lib/amap_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ 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';

Expand Down
85 changes: 47 additions & 38 deletions lib/src/amap_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class AMapWidget extends StatefulWidget {

final List<AMapExtension> extensions;

/// 设置地图语言
final MapLanguage? mapLanguage;

/// 创建一个展示高德地图的widget
///
/// 在app首次启动时必须传入高德合规声明配置[privacyStatement],后续如果没有变化不需要重复设置
Expand Down Expand Up @@ -150,6 +153,7 @@ class AMapWidget extends StatefulWidget {
this.polylines = const <Polyline>{},
this.polygons = const <Polygon>{},
this.extensions = const [],
this.mapLanguage,
this.logoPosition,
this.logoBottomMargin,
this.logoLeftMargin})
Expand Down Expand Up @@ -380,47 +384,51 @@ class _AMapOptions {
final int? logoBottomMargin;
final int? logoLeftMargin;

_AMapOptions({
this.mapType = MapType.normal,
this.buildingsEnabled,
this.customStyleOptions,
this.myLocationStyleOptions,
this.compassEnabled,
this.labelsEnabled,
this.limitBounds,
this.minMaxZoomPreference,
this.scaleEnabled,
this.touchPoiEnabled,
this.trafficEnabled,
this.rotateGesturesEnabled,
this.scrollGesturesEnabled,
this.tiltGesturesEnabled,
this.zoomGesturesEnabled,
this.logoPosition,
this.logoBottomMargin,
this.logoLeftMargin,
});
final MapLanguage? mapLanguage;

_AMapOptions(
{this.mapType = MapType.normal,
this.buildingsEnabled,
this.customStyleOptions,
this.myLocationStyleOptions,
this.compassEnabled,
this.labelsEnabled,
this.limitBounds,
this.minMaxZoomPreference,
this.scaleEnabled,
this.touchPoiEnabled,
this.trafficEnabled,
this.rotateGesturesEnabled,
this.scrollGesturesEnabled,
this.tiltGesturesEnabled,
this.zoomGesturesEnabled,
this.logoPosition,
this.logoBottomMargin,
this.logoLeftMargin,
this.mapLanguage});

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(),
logoPosition: map.logoPosition?.index,
logoBottomMargin: map.logoBottomMargin,
logoLeftMargin: map.logoLeftMargin);
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,
mapLanguage: map.mapLanguage,
);
}

Map<String, dynamic> toMap() {
Expand Down Expand Up @@ -449,6 +457,7 @@ class _AMapOptions {
addIfNonNull('logoPosition', logoPosition);
addIfNonNull('logoBottomMargin', logoBottomMargin);
addIfNonNull('logoLeftMargin', logoLeftMargin);
addIfNonNull('mapLanguage', mapLanguage?.value);
return optionsMap;
}

Expand Down
9 changes: 9 additions & 0 deletions lib/src/types/ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ enum MapType {
bus,
}

/// 地图底图语言,目前支持中文底图和英文底图
enum MapLanguage {
chinese('zh_cn'),
english('en');

final String value;
const MapLanguage(this.value);
}

// 设置摄像机的边界.
class CameraTargetBounds {
/// 使用指定的边界框或空值创建摄影机目标边界
Expand Down

0 comments on commit 4602f30

Please sign in to comment.