diff --git a/arcgis_map_sdk/lib/src/arcgis_map_sdk.dart b/arcgis_map_sdk/lib/src/arcgis_map_sdk.dart index 1d28fb82..cef66303 100644 --- a/arcgis_map_sdk/lib/src/arcgis_map_sdk.dart +++ b/arcgis_map_sdk/lib/src/arcgis_map_sdk.dart @@ -16,10 +16,11 @@ int _nextMapCreationId = 0; class ArcgisMap extends StatefulWidget { const ArcgisMap({ - required this.apiKey, required this.initialCenter, required this.zoom, required this.mapStyle, + this.apiKey, + this.licenseKey, this.basemap, this.showLabelsBeneathGraphics = false, this.defaultUiList = const [], @@ -45,7 +46,8 @@ class ArcgisMap extends StatefulWidget { (vectorTileLayerUrls != null && (vectorTileLayerUrls.length > 0)), ); - final String apiKey; + final String? apiKey; + final String? licenseKey; final BaseMap? basemap; final List defaultUiList; final bool isPopupEnabled; @@ -86,6 +88,7 @@ class _ArcgisMapState extends State { late ArcgisMapOptions _arcgisMapOptions = ArcgisMapOptions( apiKey: widget.apiKey, + licenseKey: widget.licenseKey, mapStyle: widget.mapStyle, basemap: widget.basemap, ground: widget.ground, @@ -137,6 +140,7 @@ class _ArcgisMapState extends State { } _arcgisMapOptions = ArcgisMapOptions( apiKey: widget.apiKey, + licenseKey: widget.licenseKey, mapStyle: widget.mapStyle, basemap: widget.basemap, ground: widget.ground, diff --git a/arcgis_map_sdk_android/android/src/main/kotlin/dev/fluttercommunity/arcgis_map_sdk_android/ArcgisMapView.kt b/arcgis_map_sdk_android/android/src/main/kotlin/dev/fluttercommunity/arcgis_map_sdk_android/ArcgisMapView.kt index c7086c52..c23ccb79 100644 --- a/arcgis_map_sdk_android/android/src/main/kotlin/dev/fluttercommunity/arcgis_map_sdk_android/ArcgisMapView.kt +++ b/arcgis_map_sdk_android/android/src/main/kotlin/dev/fluttercommunity/arcgis_map_sdk_android/ArcgisMapView.kt @@ -57,14 +57,15 @@ internal class ArcgisMapView( override fun getView(): View = view init { - ArcGISRuntimeEnvironment.setApiKey(mapOptions.apiKey) + mapOptions.apiKey?.let(ArcGISRuntimeEnvironment::setApiKey) + mapOptions.licenseKey?.let(ArcGISRuntimeEnvironment::setLicense) + mapView = view.findViewById(R.id.mapView) if (mapOptions.basemap != null) { map.basemap = Basemap(mapOptions.basemap) } else { val layers = mapOptions.vectorTilesUrls.map { url -> ArcGISVectorTiledLayer(url) } - map.basemap = Basemap(layers, null) } diff --git a/arcgis_map_sdk_android/android/src/main/kotlin/dev/fluttercommunity/arcgis_map_sdk_android/model/ArcgisMapOptions.kt b/arcgis_map_sdk_android/android/src/main/kotlin/dev/fluttercommunity/arcgis_map_sdk_android/model/ArcgisMapOptions.kt index b3ba770d..693edb77 100644 --- a/arcgis_map_sdk_android/android/src/main/kotlin/dev/fluttercommunity/arcgis_map_sdk_android/model/ArcgisMapOptions.kt +++ b/arcgis_map_sdk_android/android/src/main/kotlin/dev/fluttercommunity/arcgis_map_sdk_android/model/ArcgisMapOptions.kt @@ -3,7 +3,8 @@ package dev.fluttercommunity.arcgis_map_sdk_android.model import com.esri.arcgisruntime.mapping.BasemapStyle data class ArcgisMapOptions( - val apiKey: String, + val apiKey: String?, + val licenseKey: String?, val basemap: BasemapStyle?, val vectorTilesUrls: List, val initialCenter: LatLng, diff --git a/arcgis_map_sdk_ios/ios/Classes/ArcgisMapView.swift b/arcgis_map_sdk_ios/ios/Classes/ArcgisMapView.swift index bc376210..d79547c0 100644 --- a/arcgis_map_sdk_ios/ios/Classes/ArcgisMapView.swift +++ b/arcgis_map_sdk_ios/ios/Classes/ArcgisMapView.swift @@ -53,7 +53,17 @@ class ArcgisMapView: NSObject, FlutterPlatformView { ) centerPositionEventChannel.setStreamHandler(centerPositionStreamHandler) - AGSArcGISRuntimeEnvironment.apiKey = mapOptions.apiKey + if let apiKey = mapOptions.apiKey { + AGSArcGISRuntimeEnvironment.apiKey = apiKey + } + if let licenseKey = mapOptions.licenseKey { + do { + try AGSArcGISRuntimeEnvironment.setLicenseKey(licenseKey) + } catch { + print("setLicenseKey failed. \(error)") + } + } + mapView = AGSMapView.init(frame: frame) super.init() @@ -96,20 +106,12 @@ class ArcgisMapView: NSObject, FlutterPlatformView { } - let viewport = AGSViewpoint( + let viewpoint = AGSViewpoint( latitude: mapOptions.initialCenter.latitude, longitude: mapOptions.initialCenter.longitude, scale: getMapScale(Int(mapOptions.zoom)) ) - mapView.setViewpoint(viewport, duration: 0) { _ in - } - - /* - map.maxExtent = AGSEnvelope( - min: AGSPoint(x: Double(mapOptions.xMin), y: Double(mapOptions.yMin), spatialReference: .wgs84()), - max: AGSPoint(x: Double(mapOptions.xMin), y: Double(mapOptions.yMax), spatialReference: .wgs84()) - ) - */ + mapView.setViewpoint(viewpoint) setMapInteractive(mapOptions.isInteractive) setupMethodChannel() diff --git a/arcgis_map_sdk_ios/ios/Classes/Models/ArcgisMapOptions.swift b/arcgis_map_sdk_ios/ios/Classes/Models/ArcgisMapOptions.swift index 834f003f..bb3cb8f8 100644 --- a/arcgis_map_sdk_ios/ios/Classes/Models/ArcgisMapOptions.swift +++ b/arcgis_map_sdk_ios/ios/Classes/Models/ArcgisMapOptions.swift @@ -8,7 +8,8 @@ import Foundation struct ArcgisMapOptions: Codable { - let apiKey: String + let apiKey: String? + let licenseKey: String? let basemap: String? let vectorTilesUrls: Array? let initialCenter: LatLng; diff --git a/arcgis_map_sdk_method_channel/lib/src/model_extension.dart b/arcgis_map_sdk_method_channel/lib/src/model_extension.dart index ac78bc4f..79999e6b 100644 --- a/arcgis_map_sdk_method_channel/lib/src/model_extension.dart +++ b/arcgis_map_sdk_method_channel/lib/src/model_extension.dart @@ -24,6 +24,7 @@ extension ArcgisMapOptionsJsonExtension on ArcgisMapOptions { Map toMap() { return { 'apiKey': apiKey, + 'licenseKey': licenseKey, 'basemap': basemap?.name, "vectorTilesUrls": vectorTilesUrls, 'initialCenter': initialCenter.toMap(), diff --git a/arcgis_map_sdk_platform_interface/lib/src/types/arcgis_map_options.dart b/arcgis_map_sdk_platform_interface/lib/src/types/arcgis_map_options.dart index 585672b4..aea7b3ac 100644 --- a/arcgis_map_sdk_platform_interface/lib/src/types/arcgis_map_options.dart +++ b/arcgis_map_sdk_platform_interface/lib/src/types/arcgis_map_options.dart @@ -10,7 +10,8 @@ import 'package:arcgis_map_sdk_platform_interface/arcgis_map_sdk_platform_interf /// an attribution must still be provided, according to following layout and design guidelines from Esri /// https://developers.arcgis.com/documentation/mapping-apis-and-services/deployment/basemap-attribution/#layout-and-design-guidelines class ArcgisMapOptions { - final String apiKey; + final String? apiKey; + final String? licenseKey; final MapStyle mapStyle; final LatLng initialCenter; final bool showLabelsBeneathGraphics; @@ -35,6 +36,7 @@ class ArcgisMapOptions { const ArcgisMapOptions({ required this.apiKey, + required this.licenseKey, required this.mapStyle, required this.initialCenter, required this.isInteractive, @@ -60,7 +62,7 @@ class ArcgisMapOptions { @override String toString() { - return 'ArcgisMapOptions{apiKey: $apiKey, 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}'; } } diff --git a/arcgis_map_sdk_web/lib/src/layer_controller.dart b/arcgis_map_sdk_web/lib/src/layer_controller.dart index e6b273e8..bd418130 100644 --- a/arcgis_map_sdk_web/lib/src/layer_controller.dart +++ b/arcgis_map_sdk_web/lib/src/layer_controller.dart @@ -1149,7 +1149,7 @@ class LayerController { required JsView view, required BaseMap baseMap, required JsEsriMap map, - required String apiKey, + required String? apiKey, bool? showLabelsBeneathGraphics, }) async { final basemapToggle = BasemapToggle( @@ -1204,7 +1204,7 @@ class LayerController { void moveBaseMapLabelsToBackground({ required JsEsriMap map, required JsBaseMap baseMap, - required String apiKey, + required String? apiKey, }) { // Get the reference layer of the base map, which is the labels layer. final labelsLayers = baseMap.referenceLayers;