Skip to content

Commit

Permalink
implement licenseKey and make apiKey optional (#63)
Browse files Browse the repository at this point in the history
Co-authored-by: Julian Bissekkou <[email protected]>
  • Loading branch information
JulianBissekkou and JulianBissekkou authored Dec 11, 2023
1 parent d3395cb commit ac15a44
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 21 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 @@ -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)
}

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

0 comments on commit ac15a44

Please sign in to comment.