Skip to content

Commit

Permalink
Hide map attribution (#73)
Browse files Browse the repository at this point in the history
* Add isAttributionTextVisible to hide map attribution

* Add isAttributionTextVisible for iOS

* Add dependency_overrides

* implement changing attribution text

---------

Co-authored-by: Julian Bissekkou <[email protected]>
  • Loading branch information
JeanTapped and JulianBissekkou authored Jul 22, 2024
1 parent e77476f commit ae2a758
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 32 deletions.
1 change: 1 addition & 0 deletions arcgis_map_sdk/lib/src/arcgis_location_display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ArcgisLocationDisplay {

ArcgisLocationDisplay({int? mapId}) : _mapId = mapId;

// ignore: use_setters_to_change_properties
void attachToMap(int mapId) => _mapId = mapId;

void deattachFromMap() => _mapId = null;
Expand Down
5 changes: 5 additions & 0 deletions arcgis_map_sdk/lib/src/arcgis_map_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,9 @@ class ArcgisMapController {
},
);
}

Future<void> updateIsAttributionTextVisible(bool isAttributionTextVisible) {
return ArcgisMapPlatform.instance
.updateIsAttributionTextVisible(mapId, isAttributionTextVisible);
}
}
10 changes: 10 additions & 0 deletions arcgis_map_sdk/lib/src/arcgis_map_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ArcgisMap extends StatefulWidget {
this.yMax = 66,
this.onMapCreated,
this.vectorTileLayerUrls,
this.isAttributionTextVisible,
super.key,
}) : assert(
basemap != null ||
Expand Down Expand Up @@ -70,6 +71,7 @@ class ArcgisMap extends StatefulWidget {
final double xMax;
final double yMin;
final double yMax;
final bool? isAttributionTextVisible;

/// Adds vector tile layers to the map. You can add more than one.
/// When the [vectorTileLayerUrls] is not empty, the [basemap] field
Expand Down Expand Up @@ -110,6 +112,7 @@ class _ArcgisMapState extends State<ArcgisMap> {
yMin: widget.yMin,
yMax: widget.yMax,
vectorTilesUrls: widget.vectorTileLayerUrls,
isAttributionTextVisible: widget.isAttributionTextVisible,
);

Future<void> onPlatformViewCreated(int id) async {
Expand Down Expand Up @@ -138,6 +141,12 @@ class _ArcgisMapState extends State<ArcgisMap> {
if ((widget.basemap != null) && oldWidget.basemap != widget.basemap) {
controller.toggleBaseMap(baseMap: widget.basemap!);
}
if (widget.isAttributionTextVisible != null &&
widget.isAttributionTextVisible != oldWidget.isAttributionTextVisible) {
controller.updateIsAttributionTextVisible(
widget.isAttributionTextVisible!,
);
}
_arcgisMapOptions = ArcgisMapOptions(
apiKey: widget.apiKey,
licenseKey: widget.licenseKey,
Expand All @@ -161,6 +170,7 @@ class _ArcgisMapState extends State<ArcgisMap> {
yMax: widget.yMax,
vectorTilesUrls: widget.vectorTileLayerUrls,
defaultUiList: widget.defaultUiList,
isAttributionTextVisible: widget.isAttributionTextVisible,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ internal class ArcgisMapView(

mapView = view.findViewById(R.id.mapView)

map.apply {
mapOptions.isAttributionTextVisible?.let { mapView.isAttributionTextVisible = it }

map.apply {
basemap = if (mapOptions.basemap != null) {
Basemap(mapOptions.basemap)
} else {
Expand Down Expand Up @@ -182,11 +183,27 @@ internal class ArcgisMapView(
result
)

"update_is_attribution_text_visible" -> onUpdateIsAttributionTextVisible(
call,
result
)

else -> result.notImplemented()
}
}
}

private fun onUpdateIsAttributionTextVisible(call: MethodCall, result: MethodChannel.Result) {
val isVisible = call.arguments as? Boolean
if (isVisible == null) {
result.error("invalid_argument", "isAttributionTextVisible must be a boolean", null)
return
}

mapView.isAttributionTextVisible = isVisible
result.success(true)
}

private fun onStartLocationDisplayDataSource(result: MethodChannel.Result) {
result.finishWithFuture { mapView.locationDisplay.locationDataSource.startAsync() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ data class ArcgisMapOptions(
val xMax: Double,
val yMin: Double,
val yMax: Double,
val isAttributionTextVisible: Boolean?,
)
15 changes: 15 additions & 0 deletions arcgis_map_sdk_ios/ios/Classes/ArcgisMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
mapView = AGSMapView.init(frame: frame)

super.init()

if let isAttributionTextVisible = mapOptions.isAttributionTextVisible {
mapView.isAttributionTextVisible = isAttributionTextVisible
}

if mapOptions.basemap != nil {
map.basemap = AGSBasemap(style: parseBaseMapStyle(mapOptions.basemap!))
Expand Down Expand Up @@ -153,6 +157,7 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
case "location_display_set_use_course_symbol_on_move" : onSetLocationDisplayUseCourseSymbolOnMove(call, result)
case "location_display_update_display_source_position_manually" : onUpdateLocationDisplaySourcePositionManually(call, result)
case "location_display_set_data_source_type" : onSetLocationDisplayDataSourceType(call, result)
case "update_is_attribution_text_visible": onUpdateIsAttributionTextVisible(call, result)
default:
result(FlutterError(code: "Unimplemented", message: "No method matching the name \(call.method)", details: nil))
}
Expand Down Expand Up @@ -501,6 +506,16 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
result(FlutterError(code: "invalid_data", message: "Unknown data source type \(String(describing: type))", details: nil))
}
}

private func onUpdateIsAttributionTextVisible(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
guard let isVisible = call.arguments as? Bool else {
result(FlutterError(code: "missing_data", message: "Invalid arguments", details: nil))
return
}

mapView.isAttributionTextVisible = isVisible
result(true)
}

private func operationWithSymbol(_ call: FlutterMethodCall, _ result: @escaping FlutterResult, handler: (AGSSymbol) -> Void) {
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ struct ArcgisMapOptions: Codable {
let xMax: Int
let yMin: Int
let yMax: Int
let isAttributionTextVisible: Bool?
}
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,15 @@ class MethodChannelArcgisMapPlugin extends ArcgisMapPlatform {
type,
);
}

@override
Future<void> updateIsAttributionTextVisible(
int mapId,
bool isAttributionTextVisible,
) {
return _methodChannelBuilder(mapId).invokeMethod(
"update_is_attribution_text_visible",
isAttributionTextVisible,
);
}
}
1 change: 1 addition & 0 deletions arcgis_map_sdk_method_channel/lib/src/model_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ extension ArcgisMapOptionsJsonExtension on ArcgisMapOptions {
'xMax': xMax,
'yMin': yMin,
'yMax': yMax,
'isAttributionTextVisible': isAttributionTextVisible,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,13 @@ class ArcgisMapPlatform extends PlatformInterface {
'setLocationDisplay() has not been implemented.',
);
}

Future<void> updateIsAttributionTextVisible(
int mapId,
bool isAttributionTextVisible,
) {
throw UnimplementedError(
'updateIsAttributionTextVisible() has not been implemented.',
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import 'package:arcgis_map_sdk_platform_interface/arcgis_map_sdk_platform_interf
///
/// [xMin], [xMax], [yMin] and [yMax] are the coordinates of an extent envelope that constrains the panning in the map.
///
/// Warning!! If [hideAttribution] is set to true,
/// an attribution must still be provided, according to following layout and design guidelines from Esri
/// [isAttributionTextVisible] will hide the map attribution (e.g. the logo). Review the guidelines before disabling the attribution:
/// https://developers.arcgis.com/documentation/mapping-apis-and-services/deployment/basemap-attribution/#layout-and-design-guidelines
class ArcgisMapOptions {
final String? apiKey;
Expand All @@ -33,6 +32,7 @@ class ArcgisMapOptions {
final List<String>? vectorTilesUrls;
final List<DefaultWidget> defaultUiList;
final bool isPopupEnabled;
final bool? isAttributionTextVisible;

const ArcgisMapOptions({
required this.apiKey,
Expand All @@ -58,11 +58,12 @@ class ArcgisMapOptions {
this.ground,
this.vectorTilesUrls,
this.isPopupEnabled = false,
this.isAttributionTextVisible,
});

@override
String toString() {
return 'ArcgisMapOptions{apiKey: $apiKey, licenseKey: $licenseKey, mapStyle: $mapStyle, initialCenter: $initialCenter, showLabelsBeneathGraphics: $showLabelsBeneathGraphics, isInteractive: $isInteractive, zoom: $zoom, tilt: $tilt, initialHeight: $initialHeight, heading: $heading, padding: $padding, rotationEnabled: $rotationEnabled, minZoom: $minZoom, maxZoom: $maxZoom, xMin: $xMin, xMax: $xMax, yMin: $yMin, yMax: $yMax, basemap: $basemap, ground: $ground, vectorTilesUrls: $vectorTilesUrls, defaultUiList: $defaultUiList, isPopupEnabled: $isPopupEnabled}';
return 'ArcgisMapOptions{apiKey: $apiKey, licenseKey: $licenseKey, mapStyle: $mapStyle, initialCenter: $initialCenter, showLabelsBeneathGraphics: $showLabelsBeneathGraphics, isInteractive: $isInteractive, zoom: $zoom, tilt: $tilt, initialHeight: $initialHeight, heading: $heading, padding: $padding, rotationEnabled: $rotationEnabled, minZoom: $minZoom, maxZoom: $maxZoom, xMin: $xMin, xMax: $xMax, yMin: $yMin, yMax: $yMax, basemap: $basemap, ground: $ground, vectorTilesUrls: $vectorTilesUrls, defaultUiList: $defaultUiList, isPopupEnabled: $isPopupEnabled, isAttributionTextVisible: $isAttributionTextVisible}';
}
}

Expand Down
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SPEC CHECKSUMS:
ArcGIS-Runtime-SDK-iOS: 6ab51d28f8831ac73c00d34998cff3a555fe304f
ArcGIS-Runtime-Toolkit-iOS: e30bb45bd0bd0152bcb1ec73f9b99022a5c7d02d
arcgis_map_sdk_ios: ee1d8dee42e0c11c95cd26afa2a8cb0e7a69cb23
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
geolocator_apple: cc556e6844d508c95df1e87e3ea6fa4e58c50401

PODFILE CHECKSUM: cc1f88378b4bfcf93a6ce00d2c587857c6008d3b
Expand Down
8 changes: 4 additions & 4 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -344,7 +344,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -422,7 +422,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -471,7 +471,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
33 changes: 26 additions & 7 deletions example/lib/vector_layer_example_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,37 @@ class VectorLayerExamplePage extends StatefulWidget {
}

class _VectorLayerExamplePageState extends State<VectorLayerExamplePage> {
bool _isAttributionTextVisible = true;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: ArcgisMap(
apiKey: arcGisApiKey,
initialCenter: const LatLng(51.16, 10.45),
zoom: 13,
vectorTileLayerUrls: const [
"https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer",
body: Stack(
alignment: Alignment.bottomLeft,
children: [
ArcgisMap(
apiKey: arcGisApiKey,
initialCenter: const LatLng(51.16, 10.45),
zoom: 13,
vectorTileLayerUrls: const [
"https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer",
],
mapStyle: MapStyle.twoD,
isAttributionTextVisible: _isAttributionTextVisible,
),
Padding(
padding: const EdgeInsets.all(16),
child: ElevatedButton(
onPressed: () {
setState(() {
_isAttributionTextVisible = !_isAttributionTextVisible;
});
},
child: Text("Toggle isAttributionTextVisible"),
),
),
],
mapStyle: MapStyle.twoD,
),
);
}
Expand Down
28 changes: 14 additions & 14 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -198,26 +198,26 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.dev"
source: hosted
version: "10.0.4"
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "3.0.3"
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "2.0.1"
lint:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -246,10 +246,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.12.0"
version: "1.11.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -323,10 +323,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.7.0"
version: "0.6.1"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -355,10 +355,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: a75f83f14ad81d5fe4b3319710b90dec37da0e22612326b696c9e1b8f34bbf48
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "14.2.0"
version: "13.0.0"
sdks:
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
dart: ">=3.2.0-0 <4.0.0"
flutter: ">=3.10.0"
Loading

0 comments on commit ae2a758

Please sign in to comment.