Skip to content

Commit

Permalink
implement licenseKey and make apiKey optional
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianBissekkou committed Nov 29, 2023
1 parent 199734c commit 0ee9e3e
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 35 deletions.
8 changes: 6 additions & 2 deletions arcgis_map_sdk/lib/src/arcgis_map_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 [],
Expand All @@ -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<DefaultWidget> defaultUiList;
final bool isPopupEnabled;
Expand Down Expand Up @@ -86,6 +88,7 @@ class _ArcgisMapState extends State<ArcgisMap> {

late ArcgisMapOptions _arcgisMapOptions = ArcgisMapOptions(
apiKey: widget.apiKey,
licenseKey: widget.licenseKey,
mapStyle: widget.mapStyle,
basemap: widget.basemap,
ground: widget.ground,
Expand Down Expand Up @@ -137,6 +140,7 @@ class _ArcgisMapState extends State<ArcgisMap> {
}
_arcgisMapOptions = ArcgisMapOptions(
apiKey: widget.apiKey,
licenseKey: widget.licenseKey,
mapStyle: widget.mapStyle,
basemap: widget.basemap,
ground: widget.ground,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
val initialCenter: LatLng,
Expand Down
24 changes: 13 additions & 11 deletions arcgis_map_sdk_ios/ios/Classes/ArcgisMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion arcgis_map_sdk_ios/ios/Classes/Models/ArcgisMapOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import Foundation

struct ArcgisMapOptions: Codable {
let apiKey: String
let apiKey: String?
let licenseKey: String?
let basemap: String?
let vectorTilesUrls: Array<String>?
let initialCenter: LatLng;
Expand Down
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 @@ -24,6 +24,7 @@ extension ArcgisMapOptionsJsonExtension on ArcgisMapOptions {
Map<String, dynamic> toMap() {
return <String, Object?>{
'apiKey': apiKey,
'licenseKey': licenseKey,
'basemap': basemap?.name,
"vectorTilesUrls": vectorTilesUrls,
'initialCenter': initialCenter.toMap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,6 +36,7 @@ class ArcgisMapOptions {

const ArcgisMapOptions({
required this.apiKey,
required this.licenseKey,
required this.mapStyle,
required this.initialCenter,
required this.isInteractive,
Expand All @@ -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}';
}
}

Expand Down
4 changes: 2 additions & 2 deletions arcgis_map_sdk_web/lib/src/layer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: cc1f88378b4bfcf93a6ce00d2c587857c6008d3b

COCOAPODS: 1.13.0
COCOAPODS: 1.12.1
26 changes: 13 additions & 13 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
url: "https://pub.dev"
source: hosted
version: "1.18.0"
version: "1.17.2"
cupertino_icons:
dependency: "direct main"
description:
Expand Down Expand Up @@ -166,10 +166,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.9.1"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -203,18 +203,18 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
url: "https://pub.dev"
source: hosted
version: "1.11.1"
version: "1.11.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
version: "2.1.1"
string_scanner:
dependency: transitive
description:
Expand All @@ -235,10 +235,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
url: "https://pub.dev"
source: hosted
version: "0.6.1"
version: "0.6.0"
vector_math:
dependency: transitive
description:
Expand All @@ -251,10 +251,10 @@ packages:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.3.0"
version: "0.1.4-beta"
sdks:
dart: ">=3.2.0-194.0.dev <4.0.0"
dart: ">=3.1.0 <4.0.0"
flutter: ">=3.10.0"

0 comments on commit 0ee9e3e

Please sign in to comment.