UNPKG

nativescript-mapbox

Version:

A Nativescript plugin for Mapbox Native Maps.

2,630 lines 115 kB
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var utils = require("tns-core-modules/utils/utils");
var application = require("tns-core-modules/application");
var fs = require("tns-core-modules/file-system");
var color_1 = require("tns-core-modules/color");
var http = require("tns-core-modules/http");
var location_1 = require("nativescript-advanced-permissions/location");
var mapbox_common_1 = require("./mapbox.common");
exports.MapStyle = mapbox_common_1.MapStyle;
var geo_utils_1 = require("./geo.utils");
var ACCESS_FINE_LOCATION_PERMISSION_REQUEST_CODE = 111;
var BundleKludge;
(function (BundleKludge) {
    BundleKludge.bundle = { test: 'test' };
})(BundleKludge = exports.BundleKludge || (exports.BundleKludge = {}));
var MapboxView = (function (_super) {
    __extends(MapboxView, _super);
    function MapboxView() {
        var _this = _super.call(this) || this;
        _this.settings = null;
        _this.initialized = false;
        
        _this.gcFixInit();
        return _this;
    }
    MapboxView.prototype.setConfig = function (settings) {
        if (settings.zoomLevel && !settings.center) {
            settings.center = {
                lat: 48.858093,
                lng: 2.294694
            };
        }
        this.settings = settings;
    };
    MapboxView.prototype.gcFixInit = function () {
        if (typeof global['MapboxView'] == 'undefined') {
            this.gcFixIndex = 0;
            global['MapboxView'] = [
                {}
            ];
        }
        else {
            global['MapboxView'].push({});
            this.gcFixIndex = global['MapboxView'].length - 1;
        }
        
    };
    MapboxView.prototype.gcFix = function (key, ref) {
        global['MapboxView'][this.gcFixIndex][key] = ref;
    };
    MapboxView.prototype.gcClear = function () {
        global['MapboxView'][this.gcFixIndex] = null;
    };
    MapboxView.prototype.getNativeMapView = function () {
        return this.nativeMapView;
    };
    MapboxView.prototype.getMapboxApi = function () {
        return this.mapbox;
    };
    MapboxView.prototype.createNativeView = function () {
        
        var nativeView = new android.widget.FrameLayout(this._context);
        this.gcFix('android.widget.FrameLayout', nativeView);
        
        return nativeView;
    };
    MapboxView.prototype.initNativeView = function () {
        var _this = this;
        
        this.nativeView.owner = this;
        _super.prototype.initNativeView.call(this);
        this.on('loaded', function () {
            
            if (!_this.initialized) {
                _this.initMap();
                _this.initialized = true;
            }
        });
        this.on('unloaded', function () {
            
        });
        
    };
    MapboxView.prototype.disposeNativeView = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        
                        this.nativeView.owner = null;
                        return [4, this.mapbox.destroy()];
                    case 1:
                        _a.sent();
                        
                        this.gcClear();
                        _super.prototype.disposeNativeView.call(this);
                        
                        return [2];
                }
            });
        });
    };
    MapboxView.prototype.initMap = function () {
        var _this = this;
        
        if (!this.nativeMapView && (this.config.accessToken || this.settings.accessToken)) {
            this.mapbox = new Mapbox();
            var options = {
                context: this._context,
                parentView: this.nativeView,
                onLocationPermissionGranted: function (event) {
                    _this.notify({
                        eventName: mapbox_common_1.MapboxViewBase.locationPermissionGrantedEvent,
                        object: _this,
                        map: _this,
                        android: _this.nativeMapView
                    });
                },
                onLocationPermissionDenied: function (event) {
                    _this.notify({
                        eventName: mapbox_common_1.MapboxViewBase.locationPermissionDeniedEvent,
                        object: _this,
                        map: _this,
                        android: _this.nativeMapView
                    });
                },
                onMapReady: function (map) {
                    
                    if (_this.hasListeners(mapbox_common_1.MapboxViewBase.mapReadyEvent)) {
                        
                    }
                    else {
                        
                    }
                    _this.notify({
                        eventName: mapbox_common_1.MapboxViewBase.mapReadyEvent,
                        object: _this,
                        map: _this,
                        android: _this.nativeMapView
                    });
                },
                onScrollEvent: function (event) {
                    
                    _this.notify({
                        eventName: mapbox_common_1.MapboxViewBase.scrollEvent,
                        object: _this,
                        event: event,
                        map: _this,
                        android: _this.nativeMapView
                    });
                },
                onMoveBeginEvent: function (event) {
                    
                    _this.notify({
                        eventName: mapbox_common_1.MapboxViewBase.moveBeginEvent,
                        object: _this,
                        event: event,
                        map: _this,
                        android: _this.nativeMapView
                    });
                }
            };
            
            if (!this.settings) {
                this.settings = Mapbox.merge(this.config, Mapbox.defaults);
            }
            else {
                this.settings = Mapbox.merge(this.settings, Mapbox.defaults);
            }
            this.settings = Mapbox.merge(this.settings, options);
            
            this.mapbox.show(this.settings);
            
        }
    };
    return MapboxView;
}(mapbox_common_1.MapboxViewBase));
exports.MapboxView = MapboxView;
var Mapbox = (function (_super) {
    __extends(Mapbox, _super);
    function Mapbox() {
        var _this = _super.call(this) || this;
        _this._locationComponent = false;
        _this._permissionsManager = false;
        _this._accessToken = '';
        _this.circleManager = null;
        _this.lineManager = null;
        _this.symbolManager = null;
        _this._markers = [];
        _this._polylines = [];
        _this._polygons = [];
        _this.circles = [];
        _this.lines = [];
        _this.eventCallbacks = [];
        _this._markerIconDownloadCache = [];
        
        _this.eventCallbacks['click'] = [];
        _this._activity = application.android.foregroundActivity;
        application.android.on(application.AndroidApplication.activityStartedEvent, function (args) {
            
            if (_this._mapboxViewInstance && _this._activity === args.activity) {
                
                _this._mapboxViewInstance.onStart();
            }
        });
        application.android.on(application.AndroidApplication.activityPausedEvent, function (args) {
            
            if (_this._mapboxViewInstance && _this._activity === args.activity) {
                
                _this._mapboxViewInstance.onPause();
            }
        });
        application.android.on(application.AndroidApplication.activityResumedEvent, function (args) {
            
            if (_this._mapboxViewInstance && _this._activity === args.activity) {
                ((_this._mapboxViewInstance.isDestroyed()) && 0);
                _this._mapboxViewInstance.onResume();
            }
        });
        application.android.on(application.AndroidApplication.activityStoppedEvent, function (args) {
            
            if (_this._mapboxViewInstance && _this._activity === args.activity) {
                
                _this._mapboxViewInstance.onStop();
            }
        });
        application.android.on(application.AndroidApplication.activityDestroyedEvent, function (args) {
            
            if (_this._activity === args.activity) {
                if (_this.lineManager) {
                    _this.lineManager.onDestroy();
                }
                if (_this.circleManager) {
                    _this.circleManager.onDestroy();
                }
                if (_this.symbolManager) {
                    _this.symbolManager.onDestroy();
                }
                if (_this._mapboxViewInstance) {
                    
                    _this._mapboxViewInstance.onDestroy();
                }
            }
        });
        application.android.on(application.AndroidApplication.saveActivityStateEvent, function (args) {
            
            if (_this._mapboxViewInstance && _this._activity === args.activity) {
                
                _this._mapboxViewInstance.onSaveInstanceState(args.bundle);
            }
        });
        application.android.on(application.AndroidApplication.activityResultEvent, function (args) {
            
        });
        application.android.on(application.AndroidApplication.activityBackPressedEvent, function (args) {
            
        });
        
        return _this;
    }
    Mapbox.prototype.gcFix = function (key, ref) {
        if (typeof global['Mapbox'] == 'undefined') {
            global['Mapbox'] = {};
        }
        global['Mapbox'][key] = ref;
    };
    Mapbox.prototype.gcClear = function () {
        global['Mapbox'] = {};
    };
    Mapbox.prototype.setMapboxViewInstance = function (mapboxViewInstance) {
    };
    Mapbox.prototype.setMapboxMapInstance = function (mapboxMapInstance) {
    };
    Mapbox.prototype.show = function (options) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var settings_1 = Mapbox.merge(options, Mapbox.defaults);
                var showIt = function () {
                    
                    if (settings_1.accessToken === undefined) {
                        reject("Please set the 'accessToken' parameter");
                        return;
                    }
                    if (_this._mapboxViewInstance) {
                        
                        var viewGroup = _this._mapboxViewInstance.getParent();
                        if (viewGroup !== null) {
                            
                            viewGroup.removeView(_this._mapboxViewInstance);
                        }
                    }
                    _this._accessToken = settings_1.accessToken;
                    var context = application.android.context;
                    if (settings_1.context) {
                        context = settings_1.context;
                    }
                    
                    com.mapbox.mapboxsdk.Mapbox.getInstance(context, _this._accessToken);
                    var mapboxMapOptions = _this._getMapboxMapOptions(settings_1);
                    _this._mapboxViewInstance = new com.mapbox.mapboxsdk.maps.MapView(context, mapboxMapOptions);
                    _this._mapboxViewInstance.onCreate(null);
                    _this.onDidFailLoadingMapListener = new com.mapbox.mapboxsdk.maps.MapView.OnDidFailLoadingMapListener({
                        onDidFailLoadingMap: function (error) {
                            
                        }
                    });
                    
                    _this._mapboxViewInstance.addOnDidFailLoadingMapListener(_this.onDidFailLoadingMapListener);
                    _this.gcFix('com.mapbox.mapboxsdk.maps.MapView.OnDidFailLoadingMapListener', _this.onDidFailLoadingMapListener);
                    _this.onDidFinishLoadingMapListener = new com.mapbox.mapboxsdk.maps.MapView.OnDidFinishLoadingMapListener({
                        onDidFinishLoadingMap: function (map) {
                            
                        }
                    });
                    _this._mapboxViewInstance.addOnDidFinishLoadingMapListener(_this.onDidFinishLoadingMapListener);
                    _this.gcFix('com.mapbox.mapboxsdk.maps.MapView.OnDidFinishLoadingMapListener', _this.onDidFinishLoadingMapListener);
                    
                    _this.onMapReadyCallback = new com.mapbox.mapboxsdk.maps.OnMapReadyCallback({
                        onMapReady: function (mbMap) {
                            _this._mapboxMapInstance = mbMap;
                            
                            
                            _this.setMapStyle(settings_1.style).then(function (style) {
                                
                                _this.initEventHandlerShim(settings_1, _this._mapboxViewInstance);
                                _this._addMarkers(settings_1.markers, _this._mapboxViewInstance);
                                if (settings_1.showUserLocation) {
                                    _this.requestFineLocationPermission().then(function () {
                                        _this.showUserLocationMarker({});
                                        if (settings_1.onLocationPermissionGranted) {
                                            settings_1.onLocationPermissionGranted(_this._mapboxMapInstance);
                                        }
                                    }).catch(function (err) {
                                        if (settings_1.onLocationPermissionDenied) {
                                            settings_1.onLocationPermissionDenied(_this._mapboxMapInstance);
                                        }
                                    });
                                }
                                if (settings_1.onMapReady) {
                                    settings_1.onMapReady(_this._mapboxMapInstance);
                                }
                                resolve({
                                    android: _this._mapboxViewInstance
                                });
                            });
                        }
                    });
                    _this._mapboxViewInstance.getMapAsync(_this.onMapReadyCallback);
                    _this.gcFix('com.mapbox.mapboxsdk.maps.OnMapReadyCallback', _this.onMapReadyCallback);
                    
                    if (settings_1.parentView) {
                        
                        settings_1.parentView.addView(_this._mapboxViewInstance);
                    }
                    else if (settings_1.container) {
                        
                        context = application.android.foregroundActivity;
                        if (!context) {
                            context = application.android.startActivity;
                        }
                        var mapViewLayout = new android.widget.FrameLayout(context);
                        
                        mapViewLayout.addView(_this._mapboxViewInstance);
                        
                        settings_1.container.addChild(mapViewLayout);
                    }
                    
                };
                setTimeout(showIt, settings_1.delay ? settings_1.delay : 200);
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.hide = function () {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (_this._mapboxViewInstance) {
                    var viewGroup = _this._mapboxViewInstance.getParent();
                    if (viewGroup !== null) {
                        viewGroup.setVisibility(android.view.View.INVISIBLE);
                    }
                }
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.unhide = function () {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (_this._mapboxViewInstance) {
                    _this._mapboxViewInstance.getParent().setVisibility(android.view.View.VISIBLE);
                    resolve();
                }
                else {
                    reject("No map found");
                }
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.destroy = function (nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
            var viewGroup;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this.clearEventListeners();
                        this.gcClear();
                        
                        if (this.lineManager) {
                            this.lineManager.onDestroy();
                            this.lineManager = null;
                        }
                        if (this.circleManager) {
                            this.circleManager.onDestroy();
                            this.circleManager = null;
                        }
                        if (this.symbolManager) {
                            this.symbolManager.onDestroy();
                            this.symbolManager = null;
                        }
                        if (!this._locationComponent) return [3, 2];
                        
                        return [4, this.hideUserLocationMarker()];
                    case 1:
                        _a.sent();
                        _a.label = 2;
                    case 2:
                        if (this._mapboxViewInstance) {
                            viewGroup = this._mapboxViewInstance.getParent();
                            if (viewGroup !== null) {
                                
                                viewGroup.removeView(this._mapboxViewInstance);
                            }
                            this._mapboxViewInstance.onPause();
                            this._mapboxViewInstance.onStop();
                            this._mapboxViewInstance.destroyDrawingCache();
                            this._mapboxViewInstance.onDestroy();
                            this._mapboxViewInstance = null;
                            this._mapboxMapInstance = null;
                        }
                        resolve();
                        return [2];
                }
            });
        }); });
    };
    Mapbox.prototype.clearEventListeners = function () {
        if (this.onDidFailLoadingMapListener) {
            this._mapboxViewInstance.removeOnDidFailLoadingMapListener(this.onDidFailLoadingMapListener);
        }
        if (this.onDidFinishLoadingMapListener) {
            this._mapboxViewInstance.removeOnDidFinishLoadingMapListener(this.onDidFinishLoadingMapListener);
        }
        if (this.onDidFinishLoadingStyleListener) {
            this._mapboxViewInstance.removeOnDidFinishLoadingStyleListener(this.onDidFinishLoadingStyleListener);
        }
        if (this.onAnnotationClickListener) {
            this.lineManager.removeClickListener(this.onAnnotationClickListener);
        }
        if (this.onDidFailLoadingMapListener) {
            this._mapboxViewInstance.removeOnDidFailLoadingMapListener(this.onDidFailLoadingMapListener);
        }
        if (this.onMapClickListener) {
            this._mapboxMapInstance.removeOnMapClickListener(this.onMapClickListener);
        }
        if (this.onMapLongClickListener) {
            this._mapboxMapInstance.removeOnMapLongClickListener(this.onMapLongClickListener);
        }
        if (this.onMoveListener) {
            this._mapboxMapInstance.removeOnMoveListener(this.onMoveListener);
        }
        if (this.onScrollListener) {
            this._mapboxMapInstance.removeOnMoveListener(this.onScrollListener);
        }
        if (this.onFlingListener) {
            this._mapboxMapInstance.removeOnFlingListener(this.onFlingListener);
        }
        if (this.onCameraMoveListener) {
            this._mapboxMapInstance.removeOnCameraMoveListener(this.onCameraMoveListener);
        }
        if (this.onCameraMoveCancelListener) {
            this._mapboxMapInstance.removeOnCameraMoveCancelListener(this.onCameraMoveCancelListener);
        }
        if (this.onCameraIdleListener) {
            this._mapboxMapInstance.removeOnCameraIdleListener(this.onCameraIdleListener);
        }
        if (this.onLocationClickListener) {
            this._locationComponent.removeOnLocationClickListener(this.onLocationClickListener);
        }
    };
    Mapbox.prototype.onStart = function (nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            _this._mapboxViewInstance.onStart();
            resolve();
        });
    };
    Mapbox.prototype.onResume = function (nativeMapViewInstance) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            
            _this._mapboxViewInstance.onResume();
            
            resolve();
        });
    };
    Mapbox.prototype.onPause = function (nativeMapViewInstance) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            
            _this._mapboxViewInstance.onPause();
            resolve();
        });
    };
    Mapbox.prototype.onStop = function (nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            _this._mapboxViewInstance.onStop();
            resolve();
        });
    };
    Mapbox.prototype.onLowMemory = function (nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            _this._mapboxViewInstance.onLowMemory();
            resolve();
        });
    };
    Mapbox.prototype.onDestroy = function (nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            _this._mapboxViewInstance.onDestroy();
            resolve();
        });
    };
    Mapbox.prototype.initEventHandlerShim = function (settings, mapboxNativeViewInstance) {
        var _this = this;
        
        this.setOnMapClickListener(function (point) {
            return _this.checkForCircleClickEvent(point);
        }, mapboxNativeViewInstance);
        this.setOnMoveBeginListener(function (point) {
            
            if (typeof settings.onMoveBeginEvent != 'undefined') {
                settings.onMoveBeginEvent(point);
            }
        }, mapboxNativeViewInstance);
    };
    Mapbox.prototype.onMapEvent = function (eventName, id, callback, nativeMapView) {
        var _this = this;
        if (typeof this.eventCallbacks[eventName] == 'undefined') {
            this.eventCallbacks[eventName] = [];
        }
        var lineEntry = this.lines.find(function (entry) { return entry.id == id; });
        if (lineEntry) {
            
            this.addClickableLineOverlay(lineEntry.id, nativeMapView)
                .then(function (clickOverlay) {
                lineEntry.clickOverlay = clickOverlay;
                
                _this.eventCallbacks[eventName].push({
                    id: id,
                    callback: callback
                });
            });
        }
        else {
            this.eventCallbacks[eventName].push({
                id: id,
                callback: callback
            });
        }
    };
    Mapbox.prototype.offMapEvent = function (eventName, id, nativeMapView) {
        if (typeof this.eventCallbacks[eventName] == 'undefined') {
            return;
        }
        this.eventCallbacks[eventName] = this.eventCallbacks[eventName].filter(function (entry) {
            return entry.id != id;
        });
    };
    Mapbox.prototype.handleLineClickEvent = function (clickOverlay) {
        var lineEntry = this.lines.find(function (entry) {
            
            return entry.clickOverlay == clickOverlay;
        });
        if (!lineEntry) {
            
            return false;
        }
        for (var x = 0; x < this.eventCallbacks['click'].length; x++) {
            var entry = this.eventCallbacks['click'][x];
            
            if (entry.id == lineEntry.id) {
                
                return entry.callback(lineEntry);
            }
        }
        return false;
    };
    Mapbox.prototype.checkForCircleClickEvent = function (point) {
        
        for (var i = 0; i < this.circles.length; i++) {
            
            if (geo_utils_1.GeoUtils.isLocationInCircle(point.lng, point.lat, this.circles[i].center[0], this.circles[i].center[1], this.circles[i].radius)) {
                
                for (var x = 0; x < this.eventCallbacks['click'].length; x++) {
                    var entry = this.eventCallbacks['click'][x];
                    if (entry.id == this.circles[i].id) {
                        
                        return entry.callback(point);
                    }
                }
            }
        }
        return false;
    };
    Mapbox.prototype.addClickableLineOverlay = function (lineId, nativeMapView) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var lineEntry = _this.lines.find(function (entry) { return entry.id == lineId; });
                if (!lineEntry) {
                    reject("No such line with id '" + lineId + "'");
                    return;
                }
                var width = lineEntry.layer.getLineWidth().getValue();
                
                var feature = lineEntry.feature;
                
                feature.addNumberProperty('line-opacity', new java.lang.Float(0));
                feature.addNumberProperty('line-width', width);
                
                var featureCollection = new com.mapbox.geojson.FeatureCollection.fromFeature(feature);
                _this.gcFix('com.mapbox.geojson.FeatureCollection', featureCollection);
                var clickOverlay = _this.lineManager.create(featureCollection).get(0);
                
                resolve(clickOverlay);
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.hasFineLocationPermission = function () {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                resolve(_this._fineLocationPermissionGranted());
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.requestFineLocationPermission = function () {
        return new Promise(function (resolve, reject) {
            
            if (location_1.hasLocationPermissions()) {
                resolve();
                return;
            }
            if (!location_1.isLocationEnabled) {
                
                reject("Location services are not turned on.");
                return;
            }
            ;
            location_1.requestLocationPermissions(true, "We use this permission to show you your current location.").then(function (hasPermission) {
                
                if (location_1.hasLocationPermissions()) {
                    
                    resolve(true);
                    return;
                }
                else {
                    
                    reject("Location Permission Not granted");
                    return;
                }
                ;
            });
        });
    };
    Mapbox.prototype.onRequestPermissionsResults = function (requestCode, permissions, grantResults) {
        
        this._permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
    };
    Mapbox.prototype.setMapStyle = function (style, nativeMapViewInstance) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var mapStyle = _this._getMapStyle(style);
                
                _this.onDidFinishLoadingStyleListener = new com.mapbox.mapboxsdk.maps.MapView.OnDidFinishLoadingStyleListener({
                    onDidFinishLoadingStyle: function (style) {
                        
                        _this.lineManager = new com.mapbox.mapboxsdk.plugins.annotation.LineManager(_this._mapboxViewInstance, _this._mapboxMapInstance, _this._mapboxMapInstance.getStyle());
                        _this.gcFix('lineManager', _this.lineManager);
                        _this.onAnnotationClickListener = new com.mapbox.mapboxsdk.plugins.annotation.OnAnnotationClickListener({
                            onAnnotationClick: function (line) {
                                
                                _this.handleLineClickEvent(line);
                                return true;
                            }
                        });
                        _this.lineManager.addClickListener(_this.onAnnotationClickListener);
                        _this.gcFix('com.mapbox.mapboxsdk.plugins.annotation.OnAnnotationClickListener', _this.onAnnotationClickListener);
                        resolve(style);
                    }
                });
                _this._mapboxViewInstance.addOnDidFinishLoadingStyleListener(_this.onDidFinishLoadingStyleListener);
                _this.gcFix('com.mapbox.mapboxsdk.maps.MapView.OnDidFinishLoadingStyleListener', _this.onDidFinishLoadingStyleListener);
                _this.onDidFailLoadingMapListener = new com.mapbox.mapboxsdk.maps.MapView.OnDidFailLoadingMapListener({
                    onDidFailLoadingMap: function (error) {
                        
                        reject(error);
                    }
                });
                
                _this._mapboxViewInstance.addOnDidFailLoadingMapListener(_this.onDidFailLoadingMapListener);
                _this.gcFix('com.mapbox.mapboxsdk.maps.MapView.OnDidFailLoadingMapListener', _this.onDidFailLoadingMapListener);
                var builder = new com.mapbox.mapboxsdk.maps.Style.Builder();
                _this._mapboxMapInstance.setStyle(builder.fromUrl(mapStyle));
                _this.gcFix('com.mapbox.mapboxsdk.maps.Style.Builder', builder);
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.addMarkers = function (markers, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                _this._addMarkers(markers, _this._mapboxViewInstance);
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.removeMarkers = function (ids, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                _this._removeMarkers(ids, _this._mapboxViewInstance);
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype._addMarkers = function (markers, nativeMap) {
        var _this = this;
        if (!markers) {
            
            return;
        }
        if (!Array.isArray(markers)) {
            
            return;
        }
        if (!this._mapboxMapInstance) {
            return;
        }
        this._mapboxMapInstance.setOnMarkerClickListener(new com.mapbox.mapboxsdk.maps.MapboxMap.OnMarkerClickListener({
            onMarkerClick: function (marker) {
                var cachedMarker = _this._getClickedMarkerDetails(marker);
                if (cachedMarker && cachedMarker.onTap) {
                    cachedMarker.onTap(cachedMarker);
                }
                return false;
            }
        }));
        this._mapboxMapInstance.setOnInfoWindowClickListener(new com.mapbox.mapboxsdk.maps.MapboxMap.OnInfoWindowClickListener({
            onInfoWindowClick: function (marker) {
                var cachedMarker = _this._getClickedMarkerDetails(marker);
                if (cachedMarker && cachedMarker.onCalloutTap) {
                    cachedMarker.onCalloutTap(cachedMarker);
                }
                return true;
            }
        }));
        var iconFactory = com.mapbox.mapboxsdk.annotations.IconFactory.getInstance(application.android.context);
        this._downloadMarkerImages(markers).then(function (updatedMarkers) {
            var _loop_1 = function (m) {
                var marker = updatedMarkers[m];
                _this._markers.push(marker);
                var markerOptions = new com.mapbox.mapboxsdk.annotations.MarkerOptions();
                markerOptions.setTitle(marker.title);
                markerOptions.setSnippet(marker.subtitle);
                markerOptions.setPosition(new com.mapbox.mapboxsdk.geometry.LatLng(parseFloat(marker.lat), parseFloat(marker.lng)));
                if (marker.icon) {
                    if (marker.icon.startsWith("res://")) {
                        var resourcename = marker.icon.substring(6);
                        var res = utils.ad.getApplicationContext().getResources();
                        var identifier = res.getIdentifier(resourcename, "drawable", utils.ad.getApplication().getPackageName());
                        if (identifier === 0) {
                            
                        }
                        else {
                            markerOptions.setIcon(iconFactory.fromResource(identifier));
                        }
                    }
                    else if (marker.icon.startsWith("http")) {
                        if (marker.iconDownloaded !== null) {
                            markerOptions.setIcon(iconFactory.fromBitmap(marker.iconDownloaded));
                        }
                    }
                    else {
                        
                    }
                }
                else if (marker.iconPath) {
                    var iconFullPath = fs.knownFolders.currentApp().path + "/" + marker.iconPath;
                    if (fs.File.exists(iconFullPath)) {
                        markerOptions.setIcon(iconFactory.fromPath(iconFullPath));
                    }
                    else {
                        
                    }
                }
                marker.android = _this._mapboxMapInstance.addMarker(markerOptions);
                if (marker.selected) {
                    _this._mapboxMapInstance.selectMarker(marker.android);
                }
                marker.update = function (newSettings) {
                    for (var m_1 in _this._markers) {
                        var _marker = _this._markers[m_1];
                        if (marker.id === _marker.id) {
                            if (newSettings.onTap !== undefined) {
                                _marker.onTap = newSettings.onTap;
                            }
                            if (newSettings.onCalloutTap !== undefined) {
                                _marker.onCalloutTap = newSettings.onCalloutTap;
                            }
                            if (newSettings.title !== undefined) {
                                _marker.title = newSettings.title;
                                _marker.android.setTitle(newSettings.title);
                            }
                            if (newSettings.subtitle !== undefined) {
                                _marker.subtitle = newSettings.title;
                                _marker.android.setSnippet(newSettings.subtitle);
                            }
                            if (newSettings.lat && newSettings.lng) {
                                _marker.lat = newSettings.lat;
                                _marker.lng = newSettings.lng;
                                _marker.android.setPosition(new com.mapbox.mapboxsdk.geometry.LatLng(parseFloat(newSettings.lat), parseFloat(newSettings.lng)));
                            }
                            if (newSettings.selected) {
                                _this._mapboxMapInstance.selectMarker(_marker.android);
                            }
                        }
                    }
                };
            };
            for (var m in updatedMarkers) {
                _loop_1(m);
            }
        });
    };
    Mapbox.prototype._removeMarkers = function (ids, nativeMap) {
        if (!this._mapboxMapInstance) {
            return;
        }
        for (var m in this._markers) {
            var marker = this._markers[m];
            if (!ids || (marker && marker.id && ids.indexOf(marker.id) > -1)) {
                if (marker && marker.android) {
                    this._mapboxMapInstance.removeAnnotation(marker.android);
                }
            }
        }
        if (ids) {
            this._markers = this._markers.filter(function (marker) { return ids.indexOf(marker.id) === -1; });
        }
        else {
            this._markers = [];
        }
    };
    Mapbox.prototype.setCenter = function (options, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var cameraPosition = new com.mapbox.mapboxsdk.camera.CameraPosition.Builder()
                    .target(new com.mapbox.mapboxsdk.geometry.LatLng(options.lat, options.lng))
                    .build();
                _this.gcFix('com.mapbox.mapboxsdk.camera.CameraPosition.Builder', cameraPosition);
                if (options.animated === true) {
                    var newCameraPosition = com.mapbox.mapboxsdk.camera.CameraUpdateFactory.newCameraPosition(cameraPosition);
                    _this._mapboxMapInstance.animateCamera(newCameraPosition, 1000, null);
                    _this.gcFix('com.mapbox.mapboxsdk.camera.CameraUpdateFactory.newCameraPosition', newCameraPosition);
                }
                else {
                    _this._mapboxMapInstance.setCameraPosition(cameraPosition);
                }
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.getCenter = function (nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var coordinate = _this._mapboxMapInstance.getCameraPosition().target;
                resolve({
                    lat: coordinate.getLatitude(),
                    lng: coordinate.getLongitude()
                });
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.setZoomLevel = function (options, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var animated = options.animated === undefined || options.animated;
                var level = options.level;
                if (level >= 0 && level <= 20) {
                    var cameraUpdate = com.mapbox.mapboxsdk.camera.CameraUpdateFactory.zoomTo(level);
                    _this.gcFix('com.mapbox.mapboxsdk.camera.CameraUpdateFactory.zoomTo', cameraUpdate);
                    if (animated) {
                        _this._mapboxMapInstance.easeCamera(cameraUpdate);
                    }
                    else {
                        _this._mapboxMapInstance.moveCamera(cameraUpdate);
                    }
                    resolve();
                }
                else {
                    reject("invalid zoomlevel, use any double value from 0 to 20 (like 8.3)");
                }
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.getZoomLevel = function (nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var level = _this._mapboxMapInstance.getCameraPosition().zoom;
                resolve(level);
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.setTilt = function (options, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var tilt = options.tilt ? options.tilt : 30;
                var cameraPositionBuilder = new com.mapbox.mapboxsdk.camera.CameraPosition.Builder()
                    .tilt(tilt);
                _this.gcFix('com.mapbox.mapboxsdk.camera.CameraPosition.Builder', cameraPositionBuilder);
                var cameraUpdate = com.mapbox.mapboxsdk.camera.CameraUpdateFactory.newCameraPosition(cameraPositionBuilder.build());
                _this.gcFix('com.mapbox.mapboxsdk.camera.CameraUpdateFactory.newCameraPosition', cameraUpdate);
                var durationMs = options.duration ? options.duration : 5000;
                _this._mapboxMapInstance.easeCamera(cameraUpdate, durationMs);
                setTimeout(function () {
                    resolve();
                }, durationMs);
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.getTilt = function (nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var tilt = _this._mapboxMapInstance.getCameraPosition().tilt;
                resolve(tilt);
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.getUserLocation = function () {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var loc = _this._locationComponent ? _this._locationComponent.getLastKnownLocation() : null;
                if (loc === null) {
                    reject("Location not available");
                }
                else {
                    resolve({
                        location: {
                            lat: loc.getLatitude(),
                            lng: loc.getLongitude()
                        },
                        speed: loc.getSpeed()
                    });
                }
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.queryRenderedFeatures = function (options, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var point = options.point;
                if (point === undefined) {
                    reject("Please set the 'point' parameter");
                    return;
                }
                var mapboxPoint = new com.mapbox.mapboxsdk.geometry.LatLng(options.point.lat, options.point.lng);
                var screenLocation = _this._mapboxMapInstance.getProjection().toScreenLocation(mapboxPoint);
                if (_this._mapboxMapInstance.queryRenderedFeatures) {
                    var features = _this._mapboxMapInstance.queryRenderedFeatures(screenLocation, null, options.layerIds);
                    var result = [];
                    for (var i = 0; i < features.size(); i++) {
                        var feature = features.get(i);
                        result.push({
                            id: feature.id(),
                            type: feature.type(),
                            properties: JSON.parse(feature.properties().toString())
                        });
                    }
                    resolve(result);
                }
                else {
                    reject("Feature not supported by this Mapbox version");
                }
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.addPolygon = function (options, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var points = options.points;
                if (points === undefined) {
                    reject("Please set the 'points' parameter");
                    return;
                }
                var polygonOptions = new com.mapbox.mapboxsdk.annotations.PolygonOptions();
                for (var p in points) {
                    var point = points[p];
                    polygonOptions.add(new com.mapbox.mapboxsdk.geometry.LatLng(point.lat, point.lng));
                }
                polygonOptions.fillColor(Mapbox.getAndroidColor(options.fillColor));
                polygonOptions.alpha(options.fillOpacity === undefined ? 1 : options.fillOpacity);
                if (options.strokeColor) {
                    polygonOptions.strokeColor(Mapbox.getAndroidColor(options.strokeColor));
                }
                _this._polygons.push({
                    id: options.id || new Date().getTime(),
                    android: _this._mapboxMapInstance.addPolygon(polygonOptions)
                });
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.addPolyline = function (options, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var points = options.points;
                if (points === undefined) {
                    reject("Please set the 'points' parameter");
                    return;
                }
                var polylineOptions = new com.mapbox.mapboxsdk.annotations.PolylineOptions();
                polylineOptions.width(options.width || 5);
                polylineOptions.color(Mapbox.getAndroidColor(options.color));
                polylineOptions.alpha(options.opacity === undefined ? 1 : options.opacity);
                for (var p in points) {
                    var point = points[p];
                    polylineOptions.add(new com.mapbox.mapboxsdk.geometry.LatLng(point.lat, point.lng));
                }
                _this._polylines.push({
                    id: options.id || new Date().getTime(),
                    android: _this._mapboxMapInstance.addPolyline(polylineOptions)
                });
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.removePolygons = function (ids, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                for (var p in _this._polygons) {
                    var polygon = _this._polygons[p];
                    if (!ids || (polygon.id && ids.indexOf(polygon.id) > -1)) {
                        _this._mapboxMapInstance.removePolygon(polygon.android);
                    }
                }
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.removePolylines = function (ids, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                for (var p in _this._polylines) {
                    var polyline = _this._polylines[p];
                    if (!ids || (polyline.id && ids.indexOf(polyline.id) > -1)) {
                        _this._mapboxMapInstance.removePolyline(polyline.android);
                    }
                }
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.animateCamera = function (options, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var target = options.target;
                if (target === undefined) {
                    reject("Please set the 'target' parameter");
                    return;
                }
                var cameraPositionBuilder = new com.mapbox.mapboxsdk.camera.CameraPosition.Builder(_this._mapboxMapInstance.getCameraPosition())
                    .target(new com.mapbox.mapboxsdk.geometry.LatLng(target.lat, target.lng));
                if (options.bearing) {
                    cameraPositionBuilder.bearing(options.bearing);
                }
                if (options.tilt) {
                    cameraPositionBuilder.tilt(options.tilt);
                }
                if (options.zoomLevel) {
                    cameraPositionBuilder.zoom(options.zoomLevel);
                }
                var durationMs = options.duration ? options.duration : 10000;
                _this._mapboxMapInstance.animateCamera(com.mapbox.mapboxsdk.camera.CameraUpdateFactory.newCameraPosition(cameraPositionBuilder.build()), durationMs, null);
                setTimeout(function () {
                    resolve();
                }, durationMs);
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.setOnMapClickListener = function (listener, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (!_this._mapboxMapInstance) {
                    reject("No map has been loaded");
                    return;
                }
                _this.onMapClickListener = new com.mapbox.mapboxsdk.maps.MapboxMap.OnMapClickListener({
                    onMapClick: function (point) {
                        
                        return listener({
                            lat: point.getLatitude(),
                            lng: point.getLongitude()
                        });
                    }
                });
                _this._mapboxMapInstance.addOnMapClickListener(_this.onMapClickListener);
                _this.gcFix('com.mapbox.mapboxsdk.maps.MapboxMap.OnMapClickListener', _this.onMapClickListener);
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.setOnMapLongClickListener = function (listener, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (!_this._mapboxMapInstance) {
                    reject("No map has been loaded");
                    return;
                }
                _this.onMapLongClickListener = new com.mapbox.mapboxsdk.maps.MapboxMap.OnMapLongClickListener({
                    onMapLongClick: function (point) {
                        return listener({
                            lat: point.getLatitude(),
                            lng: point.getLongitude()
                        });
                    }
                });
                _this._mapboxMapInstance.addOnMapLongClickListener(_this.onMapLongClickListener);
                _this.gcFix('com.mapbox.mapboxsdk.maps.MapboxMap.OnMapLongClickListener', _this.onMapLongClickListener);
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.setOnMoveBeginListener = function (listener, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (!_this._mapboxMapInstance) {
                    reject("No map has been loaded");
                    return;
                }
                
                _this.onMoveListener = new com.mapbox.mapboxsdk.maps.MapboxMap.OnMoveListener({
                    onMoveBegin: function (detector) {
                        var coordinate = _this._mapboxMapInstance.getCameraPosition().target;
                        return listener({
                            lat: coordinate.getLatitude(),
                            lng: coordinate.getLongitude()
                        });
                    },
                    onMove: function (detector) {
                    },
                    onMoveEnd: function (detector) {
                    }
                });
                _this._mapboxMapInstance.addOnMoveListener(_this.onMoveListener);
                _this.gcFix('com.mapbox.mapboxsdk.maps.MapboxMap.OnMoveListener', _this.onMoveListener);
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.setOnScrollListener = function (listener, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (!_this._mapboxMapInstance) {
                    reject("No map has been loaded");
                    return;
                }
                
                _this.onScrollListener = new com.mapbox.mapboxsdk.maps.MapboxMap.OnMoveListener({
                    onMoveBegin: function (detector) {
                    },
                    onMove: function (detector) {
                        var coordinate = _this._mapboxMapInstance.getCameraPosition().target;
                        return listener({
                            lat: coordinate.getLatitude(),
                            lng: coordinate.getLongitude()
                        });
                    },
                    onMoveEnd: function (detector) {
                    }
                });
                _this._mapboxMapInstance.addOnMoveListener(_this.onScrollListener);
                _this.gcFix('com.mapbox.mapboxsdk.maps.MapboxMap.OnScrollListener', _this.onScrollListener);
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.setOnFlingListener = function (listener, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (!_this._mapboxMapInstance) {
                    reject("No map has been loaded");
                    return;
                }
                _this.onFlingListener = new com.mapbox.mapboxsdk.maps.MapboxMap.OnFlingListener({
                    onFling: function () {
                        return listener();
                    }
                });
                _this._mapboxMapInstance.addOnFlingListener(_this.onFlingListener);
                _this.gcFix('com.mapbox.mapboxsdk.maps.MapboxMap.OnFlingListener', _this.onFlingListener);
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.setOnCameraMoveListener = function (listener, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (!_this._mapboxMapInstance) {
                    reject("No map has been loaded");
                    return;
                }
                _this.onCameraMoveListener = new com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveListener({
                    onCameraMove: function () {
                        return listener();
                    }
                });
                _this._mapboxMapInstance.addOnCameraMoveListener(_this.onCameraMoveListener);
                _this.gcFix('com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveListener', _this.onCameraMoveListener);
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.setOnCameraMoveCancelListener = function (listener, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (!_this._mapboxMapInstance) {
                    reject("No map has been loaded");
                    return;
                }
                _this.onCameraMoveCancelListener = new com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveCanceledListener({
                    onCameraMoveCanceled: function () {
                        return listener();
                    }
                });
                _this._mapboxMapInstance.addOnCameraMoveCancelListener(_this.onCameraMoveCancelListener);
                _this.gcFix('com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveCanceledListener', _this.onCameraMoveCancelListener);
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.setOnCameraIdleListener = function (listener, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (!_this._mapboxMapInstance) {
                    reject("No map has been loaded");
                    return;
                }
                _this.onCameraIdleListener = new com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraIdleListener({
                    onCameraIdle: function () {
                        return listener();
                    }
                });
                _this._mapboxMapInstance.addOnCameraIdleListener(_this.onCameraIdleListener);
                _this.gcFix('com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraIdleListener', _this.onCameraIdleListener);
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.getViewport = function (nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (!_this._mapboxMapInstance) {
                    reject("No map has been loaded");
                    return;
                }
                var bounds = _this._mapboxMapInstance.getProjection().getVisibleRegion().latLngBounds;
                resolve({
                    bounds: {
                        north: bounds.getLatNorth(),
                        east: bounds.getLonEast(),
                        south: bounds.getLatSouth(),
                        west: bounds.getLonWest()
                    },
                    zoomLevel: _this._mapboxMapInstance.getCameraPosition().zoom
                });
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.setViewport = function (options, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (!_this._mapboxMapInstance) {
                    reject("No map has been loaded");
                    return;
                }
                var bounds = new com.mapbox.mapboxsdk.geometry.LatLngBounds.Builder()
                    .include(new com.mapbox.mapboxsdk.geometry.LatLng(options.bounds.north, options.bounds.east))
                    .include(new com.mapbox.mapboxsdk.geometry.LatLng(options.bounds.south, options.bounds.west))
                    .build();
                var padding = 25, animated = options.animated === undefined || options.animated, durationMs = animated ? 1000 : 0;
                if (animated) {
                    _this._mapboxMapInstance.easeCamera(com.mapbox.mapboxsdk.camera.CameraUpdateFactory.newLatLngBounds(bounds, padding), durationMs);
                }
                else {
                    _this._mapboxMapInstance.moveCamera(com.mapbox.mapboxsdk.camera.CameraUpdateFactory.newLatLngBounds(bounds, padding));
                }
                setTimeout(function () {
                    resolve();
                }, durationMs);
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.downloadOfflineRegion = function (options) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var styleURL = _this._getMapStyle(options.style);
                var bounds = new com.mapbox.mapboxsdk.geometry.LatLngBounds.Builder()
                    .include(new com.mapbox.mapboxsdk.geometry.LatLng(options.bounds.north, options.bounds.east))
                    .include(new com.mapbox.mapboxsdk.geometry.LatLng(options.bounds.south, options.bounds.west))
                    .build();
                var retinaFactor = utils.layout.getDisplayDensity();
                var offlineRegionDefinition = new com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition(styleURL, bounds, options.minZoom, options.maxZoom, retinaFactor);
                var info = '{name:"' + options.name + '"}';
                var infoStr = new java.lang.String(info);
                var encodedMetadata = infoStr.getBytes();
                if (!_this._accessToken && !options.accessToken) {
                    reject("First show a map, or pass in an 'accessToken' param");
                    return;
                }
                if (!_this._accessToken) {
                    _this._accessToken = options.accessToken;
                    com.mapbox.mapboxsdk.Mapbox.getInstance(application.android.context, _this._accessToken);
                }
                _this._getOfflineManager().createOfflineRegion(offlineRegionDefinition, encodedMetadata, new com.mapbox.mapboxsdk.offline.OfflineManager.CreateOfflineRegionCallback({
                    onError: function (error) {
                        reject(error);
                    },
                    onCreate: function (offlineRegion) {
                        offlineRegion.setDownloadState(com.mapbox.mapboxsdk.offline.OfflineRegion.STATE_ACTIVE);
                        offlineRegion.setObserver(new com.mapbox.mapboxsdk.offline.OfflineRegion.OfflineRegionObserver({
                            onStatusChanged: function (status) {
                                var percentage = status.getRequiredResourceCount() >= 0 ?
                                    (100.0 * status.getCompletedResourceCount() / status.getRequiredResourceCount()) :
                                    0.0;
                                if (options.onProgress) {
                                    options.onProgress({
                                        name: options.name,
                                        completedSize: status.getCompletedResourceSize(),
                                        completed: status.getCompletedResourceCount(),
                                        expected: status.getRequiredResourceCount(),
                                        percentage: Math.round(percentage * 100) / 100,
                                        complete: status.isComplete()
                                    });
                                }
                                if (status.isComplete()) {
                                    resolve();
                                }
                                else if (status.isRequiredResourceCountPrecise()) {
                                }
                            },
                            onError: function (error) {
                                reject(error.getMessage() + ", reason: " + error.getReason());
                            },
                            mapboxTileCountLimitExceeded: function (limit) {
                                
                            }
                        }));
                    }
                }));
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.listOfflineRegions = function (options) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (!_this._accessToken && !options.accessToken) {
                    reject("First show a map, or pass in an 'accessToken' param");
                    return;
                }
                if (!_this._accessToken) {
                    _this._accessToken = options.accessToken;
                    com.mapbox.mapboxsdk.Mapbox.getInstance(application.android.context, _this._accessToken);
                }
                _this._getOfflineManager().listOfflineRegions(new com.mapbox.mapboxsdk.offline.OfflineManager.ListOfflineRegionsCallback({
                    onError: function (error) {
                        reject(error);
                    },
                    onList: function (offlineRegions) {
                        var regions = [];
                        if (offlineRegions !== null) {
                            for (var i = 0; i < offlineRegions.length; i++) {
                                var offlineRegion = offlineRegions[i];
                                var name_1 = _this._getRegionName(offlineRegion);
                                var offlineRegionDefinition = offlineRegion.getDefinition();
                                var bounds = offlineRegionDefinition.getBounds();
                                regions.push({
                                    name: name_1,
                                    style: offlineRegionDefinition.getStyleURL(),
                                    minZoom: offlineRegionDefinition.getMinZoom(),
                                    maxZoom: offlineRegionDefinition.getMaxZoom(),
                                    bounds: {
                                        north: bounds.getLatNorth(),
                                        east: bounds.getLonEast(),
                                        south: bounds.getLatSouth(),
                                        west: bounds.getLonWest()
                                    }
                                });
                            }
                        }
                        resolve(regions);
                    }
                }));
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.deleteOfflineRegion = function (options) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (!options || !options.name) {
                    reject("Pass in the 'name' param");
                    return;
                }
                _this._getOfflineManager().listOfflineRegions(new com.mapbox.mapboxsdk.offline.OfflineManager.ListOfflineRegionsCallback({
                    onError: function (error) {
                        reject(error);
                    },
                    onList: function (offlineRegions) {
                        var regions = [];
                        var found = false;
                        if (offlineRegions !== null) {
                            for (var i = 0; i < offlineRegions.length; i++) {
                                var offlineRegion = offlineRegions[i];
                                var name_2 = _this._getRegionName(offlineRegion);
                                if (name_2 === options.name) {
                                    found = true;
                                    offlineRegion.delete(new com.mapbox.mapboxsdk.offline.OfflineRegion.OfflineRegionDeleteCallback({
                                        onError: function (error) {
                                            reject(error);
                                        },
                                        onDelete: function () {
                                            resolve();
                                        }
                                    }));
                                }
                            }
                        }
                        if (!found) {
                            reject("Region not found");
                        }
                    }
                }));
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype._getOfflineManager = function () {
        if (!this._offlineManager) {
            this._offlineManager = com.mapbox.mapboxsdk.offline.OfflineManager.getInstance(application.android.context);
        }
        return this._offlineManager;
    };
    ;
    Mapbox.prototype.addExtrusion = function (options, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var fillExtrusionLayer = new com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer("3d-buildings", "composite");
                fillExtrusionLayer.setSourceLayer("building");
                fillExtrusionLayer.setFilter(com.mapbox.mapboxsdk.style.expressions.Expression.eq(com.mapbox.mapboxsdk.style.expressions.Expression.get("extrude"), "true"));
                fillExtrusionLayer.setMinZoom(15);
                fillExtrusionLayer.setProperties(com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionColor(android.graphics.Color.LTGRAY), com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionHeight(com.mapbox.mapboxsdk.style.functions.Function.property("height", new com.mapbox.mapboxsdk.style.functions.stops.IdentityStops())), com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionBase(com.mapbox.mapboxsdk.style.functions.Function.property("min_height", new com.mapbox.mapboxsdk.style.functions.stops.IdentityStops())), com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionOpacity(new java.lang.Float(0.6)));
                _this._mapboxMapInstance.addLayer(fillExtrusionLayer);
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.addSource = function (id, options, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var url = options.url, type = options.type;
                var theMap = nativeMap;
                var source = void 0;
                if (!theMap) {
                    reject("No map has been loaded");
                    return;
                }
                if (theMap.mapboxMap.getSource(id)) {
                    reject("Source exists: " + id);
                    return;
                }
                switch (type) {
                    case "vector":
                        source = new com.mapbox.mapboxsdk.style.sources.VectorSource(id, url);
                        break;
                    case 'geojson':
                        
                        var geojsonString = JSON.stringify(options.data);
                        var feature = com.mapbox.geojson.Feature.fromJson(geojsonString);
                        
                        var geoJsonSource = new com.mapbox.mapboxsdk.style.sources.GeoJsonSource(id, feature);
                        _this._mapboxMapInstance.getStyle().addSource(geoJsonSource);
                        _this.gcFix('com.mapbox.mapboxsdk.style.sources.GeoJsonSource', geoJsonSource);
                        if (options.data.geometry.type == 'LineString') {
                            _this.lines.push({
                                type: 'line',
                                id: id,
                                feature: feature
                            });
                        }
                        else if (options.data.geometry.type == 'Point') {
                            _this.circles.push({
                                type: 'line',
                                id: id,
                                center: options.data.geometry.coordinates
                            });
                        }
                        break;
                    default:
                        reject("Invalid source type: " + type);
                        return;
                }
                if (!source) {
                    var ex = "No source to add";
                    
                    reject(ex);
                    return;
                }
                theMap.mapboxMap.addSource(source);
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.removeSource = function (id, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var theMap = nativeMap;
                if (!theMap) {
                    reject("No map has been loaded");
                    return;
                }
                theMap.mapboxMap.removeSource(id);
                var offset = _this.lines.findIndex(function (entry) { return entry.id == id; });
                if (offset != -1) {
                    _this.lines.splice(offset, 1);
                }
                offset = _this.circles.findIndex(function (entry) { return entry.id == id; });
                if (offset != -1) {
                    _this.circles.splice(offset, 1);
                }
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.addLayer = function (style, nativeMapView) {
        var retval;
        switch (style.type) {
            case 'line':
                retval = this.addLineLayer(style, nativeMapView);
                break;
            case 'circle':
                retval = this.addCircleLayer(style, nativeMapView);
                break;
            default:
                retval = Promise.reject("Mapbox:addLayer() Unsupported geometry type '" + style.type + "'");
                break;
        }
        return retval;
    };
    Mapbox.prototype.removeLayer = function (id, nativeMapViewInstance) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                _this._mapboxMapInstance.getStyle().removeLayer(id);
                
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.addLineLayer = function (style, nativeMapViewInstance) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (style.type != 'line') {
                    reject("Non line style passed to addLineLayer()");
                }
                var sourceId_1 = null;
                if (typeof style.source != 'string') {
                    sourceId_1 = style.id + '_source';
                    _this.addSource(sourceId_1, style.source);
                }
                else {
                    sourceId_1 = style.source;
                }
                var line = new com.mapbox.mapboxsdk.style.layers.LineLayer(style.id, sourceId_1);
                
                var lineProperties = [];
                if (typeof style.paint == 'undefined') {
                    
                    lineProperties = [
                        com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineColor('red'),
                        com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth(new java.lang.Float(7)),
                        com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOpacity(new java.lang.Float(1))
                    ];
                }
                else {
                    if (style.paint['line-color']) {
                        lineProperties.push(com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineColor(style.paint['line-color']));
                    }
                    if (style.paint['line-opacity']) {
                        lineProperties.push(com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOpacity(new java.lang.Float(style.paint['line-opacity'])));
                    }
                    
                    if (style.paint['line-width']) {
                        lineProperties.push(com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth(new java.lang.Float(style.paint['line-width'])));
                    }
                    if (style.paint['line-dash-array']) {
                        var dashArray = Array.create("java.lang.Float", style.paint['line-dash-array'].length);
                        for (var i = 0; i < style.paint['line-dash-array'].length; i++) {
                            dashArray[i] = new java.lang.Float(style.paint['line-dash-array'][i]);
                        }
                        lineProperties.push(com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineDasharray(dashArray));
                    }
                }
                if (typeof style.layout == 'undefined') {
                    lineProperties = [
                        com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineCap(com.mapbox.mapboxsdk.style.layers.PropertyFactory.LINE_CAP_ROUND),
                        com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineJoin(com.mapbox.mapboxsdk.style.layers.PropertyFactory.LINE_JOIN_ROUND)
                    ];
                }
                else {
                    if (style.layout['line-cap']) {
                        var property = void 0;
                        switch (style.layout['line-cap']) {
                            case 'round':
                                property = com.mapbox.mapboxsdk.style.layers.PropertyFactory.LINE_CAP_ROUND;
                                break;
                            case 'square':
                                property = com.mapbox.mapboxsdk.style.layers.PropertyFactory.LINE_CAP_SQUARE;
                                break;
                        }
                        lineProperties.push(com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineCap(property));
                    }
                    if (style.layout['line-join']) {
                        var property = void 0;
                        switch (style.layout['line-join']) {
                            case 'round':
                                property = com.mapbox.mapboxsdk.style.layers.PropertyFactory.LINE_JOIN_ROUND;
                                break;
                            case 'square':
                                property = com.mapbox.mapboxsdk.style.layers.PropertyFactory.LINE_JOIN_SQUARE;
                                break;
                        }
                        lineProperties.push(com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineJoin(property));
                    }
                }
                line.setProperties(lineProperties);
                _this._mapboxMapInstance.getStyle().addLayer(line);
                var lineEntry = _this.lines.find(function (entry) { return entry.id == sourceId_1; });
                if (lineEntry) {
                    lineEntry.layer = line;
                }
                
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.addLinePoint = function (id, lnglat, nativeMapView) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                var lineEntry = _this.lines.find(function (entry) { return entry.id == id; });
                if (!lineEntry) {
                    reject("No such line layer '" + id + "'");
                    return;
                }
                var geometry = lineEntry.feature.geometry();
                var coordinates = geometry.coordinates();
                
                var newPoint = com.mapbox.geojson.Point.fromLngLat(lnglat[0], lnglat[1]);
                
                geometry.coordinates().add(newPoint);
                lineEntry.feature = com.mapbox.geojson.Feature.fromGeometry(geometry);
                var lineSource = _this._mapboxMapInstance.getStyle().getSource(id + '_source');
                lineSource.setGeoJson(lineEntry.feature);
                
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.addCircleLayer = function (style, nativeMapViewInstance) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (style.type != 'circle') {
                    reject("Non circle style passed to addCircle()");
                }
                var sourceId_2 = null;
                if (typeof style.source != 'string') {
                    sourceId_2 = style.id + '_source';
                    _this.addSource(sourceId_2, style.source);
                }
                else {
                    sourceId_2 = style.source;
                }
                var circle = new com.mapbox.mapboxsdk.style.layers.CircleLayer(style.id, sourceId_2);
                
                var circleProperties = [];
                if (typeof style.paint == 'undefined') {
                    
                    circleProperties = [
                        com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor('red'),
                        com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius(com.mapbox.mapboxsdk.style.expressions.Expression.interpolate(com.mapbox.mapboxsdk.style.expressions.Expression.exponential(new java.lang.Float(2.0)), com.mapbox.mapboxsdk.style.expressions.Expression.zoom(), [
                            com.mapbox.mapboxsdk.style.expressions.Expression.stop(new java.lang.Float(0), new java.lang.Float(0)),
                            com.mapbox.mapboxsdk.style.expressions.Expression.stop(new java.lang.Float(20), new java.lang.Float(6000))
                        ])),
                        com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleBlur(new java.lang.Float(0.2))
                    ];
                }
                else {
                    if (style.paint['circle-color']) {
                        circleProperties.push(com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor(style.paint['circle-color']));
                    }
                    if (style.paint['circle-opacity']) {
                        circleProperties.push(com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleOpacity(new java.lang.Float(style.paint['circle-opacity'])));
                    }
                    
                    if (style.paint['circle-stroke-width']) {
                        circleProperties.push(com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleStrokeWidth(new java.lang.Float(style.paint['circle-stroke-width'])));
                    }
                    if (style.paint['circle-stroke-color']) {
                        circleProperties.push(com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleStrokeColor(style.paint['circle-stroke-color']));
                    }
                    if (!style.paint['circle-radius']) {
                        circleProperties.push(com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius(new java.lang.Float(30)));
                    }
                    else {
                        if (typeof style.paint['circle-radius'] == 'number') {
                            circleProperties.push(com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius(new java.lang.Float(style.paint.radius)));
                        }
                        else {
                            if (!style.paint['circle-radius'].stops) {
                                reject("No radius or stops provided to addCircleLayer.");
                            }
                            var stopArgs = [];
                            
                            for (var i = 0; i < style.paint['circle-radius'].stops.length; i++) {
                                var stop_1 = style.paint['circle-radius'].stops[i];
                                stopArgs.push(com.mapbox.mapboxsdk.style.expressions.Expression.stop(new java.lang.Float(stop_1[0]), new java.lang.Float(stop_1[1])));
                            }
                            var base = 2;
                            if (style.paint['circle-radius'].stops.base) {
                                base = style.paint['circle-radius'].stops.base;
                            }
                            
                            circleProperties.push(com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius(com.mapbox.mapboxsdk.style.expressions.Expression.interpolate(com.mapbox.mapboxsdk.style.expressions.Expression.exponential(new java.lang.Float(base)), com.mapbox.mapboxsdk.style.expressions.Expression.zoom(), stopArgs)));
                        }
                    }
                }
                circle.setProperties(circleProperties);
                _this._mapboxMapInstance.getStyle().addLayer(circle);
                
                var circleEntry = _this.circles.find(function (entry) { return entry.id == sourceId_2; });
                if (circleEntry) {
                    circleEntry.radius = style['circle-radius'];
                    circleEntry.layer = circle;
                }
                
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.addGeoJsonClustered = function (options, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                _this._mapboxMapInstance.getStyle().addSource(new com.mapbox.mapboxsdk.style.sources.GeoJsonSource(options.name, new java.net.URL(options.data), new com.mapbox.mapboxsdk.style.sources.GeoJsonOptions()
                    .withCluster(true)
                    .withClusterMaxZoom(options.clusterMaxZoom || 13)
                    .withClusterRadius(options.clusterRadius || 40)));
                var layers = [];
                if (options.clusters) {
                    for (var i = 0; i < options.clusters.length; i++) {
                        layers.push([options.clusters[i].points, new color_1.Color(options.clusters[i].color).android]);
                    }
                }
                else {
                    layers.push([150, new color_1.Color("red").android]);
                    layers.push([20, new color_1.Color("green").android]);
                    layers.push([0, new color_1.Color("blue").android]);
                }
                var unclustered = new com.mapbox.mapboxsdk.style.layers.SymbolLayer("unclustered-points", options.name);
                unclustered.setProperties([
                    com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor(new color_1.Color("red").android),
                    com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius(new java.lang.Float(16.0)),
                    com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleBlur(new java.lang.Float(0.2))
                ]);
                ((com.mapbox.mapboxsdk.style.expressions.Expression.get("cluster")) && 0);
                unclustered.setFilter(com.mapbox.mapboxsdk.style.expressions.Expression.neq(com.mapbox.mapboxsdk.style.expressions.Expression.get("cluster"), true));
                _this._mapboxMapInstance.getStyle().addLayer(unclustered);
                for (var i = 0; i < layers.length; i++) {
                    var circles = new com.mapbox.mapboxsdk.style.layers.CircleLayer("cluster-" + i, options.name);
                    circles.setProperties([
                        com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor(layers[i][1]),
                        com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius(new java.lang.Float(22.0)),
                        com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleBlur(new java.lang.Float(0.2))
                    ]);
                    var pointCount = com.mapbox.mapboxsdk.style.expressions.Expression.toNumber(com.mapbox.mapboxsdk.style.expressions.Expression.get("point_count"));
                    circles.setFilter(i === 0 ?
                        com.mapbox.mapboxsdk.style.expressions.Expression.gte(pointCount, com.mapbox.mapboxsdk.style.expressions.Expression.literal(java.lang.Integer.valueOf(layers[i][0]))) :
                        com.mapbox.mapboxsdk.style.expressions.Expression.all([
                            com.mapbox.mapboxsdk.style.expressions.Expression.gte(pointCount, com.mapbox.mapboxsdk.style.expressions.Expression.literal(java.lang.Integer.valueOf(layers[i][0]))),
                            com.mapbox.mapboxsdk.style.expressions.Expression.lt(pointCount, com.mapbox.mapboxsdk.style.expressions.Expression.literal(java.lang.Integer.valueOf(layers[i - 1][0])))
                        ]));
                    _this._mapboxMapInstance.getStyle().addLayer(circles);
                }
                var count = new com.mapbox.mapboxsdk.style.layers.SymbolLayer("count", options.name);
                count.setProperties([
                    com.mapbox.mapboxsdk.style.layers.PropertyFactory.textField(com.mapbox.mapboxsdk.style.expressions.Expression.get("point_count")),
                    com.mapbox.mapboxsdk.style.layers.PropertyFactory.textSize(new java.lang.Float(12.0)),
                    com.mapbox.mapboxsdk.style.layers.PropertyFactory.textColor(new color_1.Color("white").android)
                ]);
                _this._mapboxMapInstance.getStyle().addLayer(count);
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.trackUser = function (options, nativeMap) {
        var _this = this;
        
        return new Promise(function (resolve, reject) {
            try {
                if (!_this._mapboxMapInstance) {
                    reject("No map has been loaded");
                    return;
                }
                _this.requestFineLocationPermission().then(function () {
                    _this.showUserLocationMarker({
                        useDefaultLocationEngine: true
                    });
                }).catch(function (err) {
                    
                });
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.getAndroidColor = function (color) {
        var androidColor;
        if (color && color_1.Color.isValid(color)) {
            androidColor = new color_1.Color("" + color).android;
        }
        else {
            androidColor = new color_1.Color('#000').android;
        }
        return androidColor;
    };
    Mapbox.prototype._getMapStyle = function (input) {
        
        var Style = com.mapbox.mapboxsdk.maps.Style;
        
        if (/^mapbox:\/\/styles/.test(input) || /^http:\/\//.test(input) || /^https:\/\//.test(input)) {
            return input;
        }
        else if (/^~\//.test(input)) {
            var assetsPath = 'asset://app/';
            input = input.replace(/^~\//, assetsPath);
            return input;
        }
        else if (input === mapbox_common_1.MapStyle.LIGHT || input === mapbox_common_1.MapStyle.LIGHT.toString()) {
            return Style.LIGHT;
        }
        else if (input === mapbox_common_1.MapStyle.DARK || input === mapbox_common_1.MapStyle.DARK.toString()) {
            return Style.DARK;
        }
        else if (input === mapbox_common_1.MapStyle.OUTDOORS || input === mapbox_common_1.MapStyle.OUTDOORS.toString()) {
            return Style.OUTDOORS;
        }
        else if (input === mapbox_common_1.MapStyle.SATELLITE || input === mapbox_common_1.MapStyle.SATELLITE.toString()) {
            return Style.SATELLITE;
        }
        else if (input === mapbox_common_1.MapStyle.SATELLITE_STREETS || input === mapbox_common_1.MapStyle.SATELLITE_STREETS.toString()) {
            return Style.SATELLITE_STREETS;
        }
        else if (input === mapbox_common_1.MapStyle.TRAFFIC_DAY || input === mapbox_common_1.MapStyle.TRAFFIC_DAY.toString()) {
            return Style.TRAFFIC_DAY;
        }
        else if (input === mapbox_common_1.MapStyle.TRAFFIC_NIGHT || input === mapbox_common_1.MapStyle.TRAFFIC_NIGHT.toString()) {
            return Style.TRAFFIC_NIGHT;
        }
        else {
            return Style.MAPBOX_STREETS;
        }
    };
    Mapbox.prototype._getMapboxMapOptions = function (settings) {
        var mapboxMapOptions = new com.mapbox.mapboxsdk.maps.MapboxMapOptions()
            .compassEnabled(!settings.hideCompass)
            .rotateGesturesEnabled(!settings.disableRotation)
            .scrollGesturesEnabled(!settings.disableScroll)
            .tiltGesturesEnabled(!settings.disableTilt)
            .zoomGesturesEnabled(!settings.disableZoom)
            .attributionEnabled(!settings.hideAttribution)
            .logoEnabled(!settings.hideLogo);
        if (settings.zoomLevel && !settings.center) {
            settings.center = {
                lat: 48.858093,
                lng: 2.294694
            };
        }
        if (settings.center && settings.center.lat && settings.center.lng) {
            var cameraPositionBuilder = new com.mapbox.mapboxsdk.camera.CameraPosition.Builder()
                .zoom(settings.zoomLevel)
                .target(new com.mapbox.mapboxsdk.geometry.LatLng(settings.center.lat, settings.center.lng));
            mapboxMapOptions.camera(cameraPositionBuilder.build());
        }
        return mapboxMapOptions;
    };
    Mapbox.prototype._stringToCameraMode = function (mode) {
        var modeRef = com.mapbox.mapboxsdk.location.modes.CameraMode;
        switch (mode) {
            case "NONE":
                return modeRef.NONE;
            case "NONE_COMPASS":
                return modeRef.NONE_COMPASS;
            case "NONE_GPS":
                return modeRef.NONE_GPS;
            case "TRACKING":
                return modeRef.TRACKING;
            case "TRACK_COMPASS":
                return modeRef.TRACK_COMPASS;
            case "TRACKING_GPS":
                return modeRef.TRACKING_GPS;
            case "TRACK_GPS_NORTH":
                return modeRef.TRACK_GPS_NORTH;
        }
    };
    Mapbox.prototype._stringToRenderMode = function (mode) {
        var renderMode;
        switch (mode) {
            case 'NORMAL':
                renderMode = com.mapbox.mapboxsdk.location.modes.RenderMode.NORMAL;
                break;
            case 'COMPASS':
                renderMode = com.mapbox.mapboxsdk.location.modes.RenderMode.COMPASS;
                break;
            case 'GPS':
                renderMode = com.mapbox.mapboxsdk.location.modes.RenderMode.GPS;
                break;
        }
        return renderMode;
    };
    Mapbox.prototype._fineLocationPermissionGranted = function () {
        var hasPermission = android.os.Build.VERSION.SDK_INT < 23;
        if (!hasPermission) {
            hasPermission = com.mapbox.android.core.permissions.PermissionsManager.areLocationPermissionsGranted(application.android.context);
        }
        return hasPermission;
    };
    Mapbox.prototype._getRegionName = function (offlineRegion) {
        var metadata = offlineRegion.getMetadata();
        var jsonStr = new java.lang.String(metadata, "UTF-8");
        var jsonObj = new org.json.JSONObject(jsonStr);
        return jsonObj.getString("name");
    };
    Mapbox.prototype.showUserLocationMarker = function (options, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                
                if (!_this._mapboxMapInstance) {
                    reject("No map has been loaded");
                    return;
                }
                if (!com.mapbox.android.core.permissions.PermissionsManager.areLocationPermissionsGranted(application.android.context)) {
                    
                    reject("Location permissions not granted.");
                    return;
                }
                var componentOptionsBuilder = com.mapbox.mapboxsdk.location.LocationComponentOptions.builder(application.android.context);
                if (typeof options.elevation != 'undefined') {
                    componentOptionsBuilder.elevation(new java.lang.Float(options.elevation));
                }
                if (typeof options.accuracyColor != 'undefined') {
                    componentOptionsBuilder.accuracyColor(android.graphics.Color.parseColor(options.accuracyColor));
                }
                if (typeof options.accuracyAlpha != 'undefined') {
                    componentOptionsBuilder.accuracyAlpha(new java.lang.Float(options.accuracyAlpha));
                }
                var componentOptions = componentOptionsBuilder.build();
                
                _this._locationComponent = _this._mapboxMapInstance.getLocationComponent();
                
                var activationOptionsBuilder = com.mapbox.mapboxsdk.location.LocationComponentActivationOptions.builder(application.android.context, _this._mapboxMapInstance.getStyle());
                
                activationOptionsBuilder.locationComponentOptions(componentOptions);
                var useDefaultEngine = true;
                if (typeof options.useDefaultLocationEngine != 'undefined') {
                    useDefaultEngine = options.useDefaultLocationEngine;
                }
                
                activationOptionsBuilder.useDefaultLocationEngine(useDefaultEngine);
                
                var locationComponentActivationOptions = activationOptionsBuilder.build();
                
                _this._locationComponent.activateLocationComponent(locationComponentActivationOptions);
                _this._locationComponent.setLocationComponentEnabled(true);
                var cameraMode = _this._stringToCameraMode('TRACKING');
                if (typeof options.cameraMode != 'undefined') {
                    cameraMode = _this._stringToCameraMode(options.cameraMode);
                }
                _this._locationComponent.setCameraMode(cameraMode);
                var renderMode = com.mapbox.mapboxsdk.location.modes.RenderMode.COMPASS;
                if (typeof options.renderMode != 'undefined') {
                    renderMode = _this._stringToRenderMode(options.renderMode);
                }
                _this._locationComponent.setRenderMode(renderMode);
                
                if (typeof options.clickListener != 'undefined') {
                    _this.onLocationClickListener = new com.mapbox.mapboxsdk.location.OnLocationClickListener({
                        onLocationComponentClick: function (component) {
                            options.clickListener(component);
                        }
                    });
                    _this._locationComponent.addOnLocationClickListener(_this.onLocationClickListener);
                    _this.gcFix('com.mapbox.mapboxsdk.location.OnLocationClickListener', _this.onLocationClickListener);
                }
                if (typeof options.cameraTrackingChangedListener != 'undefined') {
                    _this._locationComponent.addOnCameraTrackingChangedListener(options.cameraTrackingChangedListener);
                }
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.hideUserLocationMarker = function (nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                
                if (!_this._mapboxMapInstance) {
                    reject("No map has been loaded");
                    return;
                }
                if (!_this._locationComponent) {
                    
                    resolve();
                    return;
                }
                _this._locationComponent.setLocationComponentEnabled(false);
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.changeUserLocationMarkerMode = function (renderModeString, cameraModeString, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                if (!_this._locationComponent) {
                    reject("No location component has been loaded");
                    return;
                }
                ((_this._locationComponent.getRenderMode()) && 0);
                
                var cameraMode = _this._stringToCameraMode(cameraModeString);
                var renderMode = _this._stringToRenderMode(renderModeString);
                _this._locationComponent.setCameraMode(cameraMode);
                _this._locationComponent.setRenderMode(renderMode);
                ((_this._locationComponent.getRenderMode()) && 0);
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.forceUserLocationUpdate = function (location, nativeMap) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                
                if (!_this._locationComponent) {
                    reject("No location component has been loaded");
                    return;
                }
                var nativeLocation = new android.location.Location('background');
                nativeLocation.setLatitude(location.latitude);
                nativeLocation.setLongitude(location.longitude);
                nativeLocation.setAltitude(location.altitude);
                _this._locationComponent.forceLocationUpdate(nativeLocation);
                resolve();
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    ;
    Mapbox.prototype._getClickedMarkerDetails = function (clicked) {
        for (var m in this._markers) {
            var cached = this._markers[m];
            if (cached.lat == clicked.getPosition().getLatitude() &&
                cached.lng == clicked.getPosition().getLongitude() &&
                cached.title == clicked.getTitle() &&
                cached.subtitle == clicked.getSnippet()) {
                return cached;
            }
        }
    };
    Mapbox.prototype._downloadImage = function (marker) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            if (_this._markerIconDownloadCache[marker.icon]) {
                marker.iconDownloaded = _this._markerIconDownloadCache[marker.icon];
                resolve(marker);
                return;
            }
            http.getImage(marker.icon).then(function (output) {
                marker.iconDownloaded = output.android;
                _this._markerIconDownloadCache[marker.icon] = marker.iconDownloaded;
                resolve(marker);
            }, function (e) {
                
                resolve(marker);
            });
        });
    };
    Mapbox.prototype._downloadMarkerImages = function (markers) {
        var iterations = [];
        var result = [];
        for (var i = 0; i < markers.length; i++) {
            var marker = markers[i];
            if (marker.icon && marker.icon.startsWith("http")) {
                var p = this._downloadImage(marker).then(function (mark) {
                    result.push(mark);
                });
                iterations.push(p);
            }
            else {
                result.push(marker);
            }
        }
        return Promise.all(iterations).then(function (output) {
            return result;
        });
    };
    Mapbox.prototype.addCircleAnnotation = function (geojson, nativeMapViewInstance) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                
                
                var geojsonString = JSON.stringify(geojson);
                var layer = _this.circleManager.create(geojsonString);
                
                resolve(layer);
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.addLineAnnotation = function (geojson, nativeMapViewInstance) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            try {
                
                var geojsonString = JSON.stringify(geojson);
                
                var line = _this.lineManager.create(geojsonString);
                
                resolve(line);
            }
            catch (ex) {
                
                reject(ex);
            }
        });
    };
    Mapbox.prototype.testLineAnnotation = function (nativeMapView) {
        return __awaiter(this, void 0, void 0, function () {
            var geojson, dashArray, i, line;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        geojson = {
                            "type": "FeatureCollection",
                            "features": [{
                                    "type": "Feature",
                                    "geometry": {
                                        "type": "LineString",
                                        "coordinates": this.getTestCoords()
                                    },
                                    "properties": {
                                        "line-color": "white",
                                        "line-width": "8",
                                        "line-dash-array": [2, 4, 2, 1]
                                    }
                                }]
                        };
                        dashArray = Array.create("java.lang.Float", geojson.features[0].properties['line-dash-array'].length);
                        for (i = 0; i < geojson.features[0].properties['line-dash-array'].length; i++) {
                            dashArray[i] = new java.lang.Float(geojson.features[0].properties['line-dash-array'][i]);
                        }
                        return [4, this.addLineAnnotation(geojson, nativeMapView)];
                    case 1:
                        line = _a.sent();
                        this.lineManager.setLineDashArray(dashArray);
                        return [2];
                }
            });
        });
    };
    Mapbox.prototype.getTestCoords = function () {
        return [
            [-76.926164, 39.019062],
            [-76.926100, 39.019168],
            [-76.926013, 39.019257],
            [-76.925905, 39.019328],
            [-76.925777, 39.019380],
            [-76.925632, 39.019408],
            [-76.925481, 39.019405],
            [-76.925337, 39.019372],
            [-76.925209, 39.019313],
            [-76.925104, 39.019234],
            [-76.925026, 39.019136],
            [-76.925010, 39.018851],
            [-76.925054, 39.018724],
            [-76.925139, 39.018616],
            [-76.925252, 39.018528],
            [-76.925387, 39.018465],
            [-76.925539, 39.018433],
            [-76.925694, 39.018422],
            [-76.925857, 39.018426],
            [-76.926027, 39.018437],
            [-76.927847, 39.018652],
            [-76.930178, 39.019155],
            [-76.932151, 39.019811],
            [-76.934475, 39.020730],
            [-76.938543, 39.022225],
            [-76.941642, 39.022854],
            [-76.944704, 39.023275],
            [-76.946380, 39.024124],
            [-76.948033, 39.025760],
            [-76.948497, 39.027019],
            [-76.948306, 39.028576],
            [-76.947345, 39.030150],
            [-76.945672, 39.031692],
            [-76.943317, 39.033067],
            [-76.941067, 39.034591],
            [-76.938712, 39.036849],
            [-76.937134, 39.039019],
            [-76.934067, 39.043621],
            [-76.931722, 39.047206],
            [-76.929912, 39.050756],
            [-76.928589, 39.053624],
            [-76.927063, 39.056683],
            [-76.925731, 39.058167],
            [-76.924575, 39.059077],
            [-76.922749, 39.060070],
            [-76.920061, 39.061071],
            [-76.918383, 39.061644],
            [-76.915324, 39.062765],
            [-76.913071, 39.063800],
            [-76.910303, 39.065627],
            [-76.908491, 39.067117],
            [-76.907337, 39.068725],
            [-76.906080, 39.071488],
            [-76.905077, 39.073318],
            [-76.904587, 39.074003],
            [-76.904400, 39.074114],
            [-76.904184, 39.074189],
            [-76.903946, 39.074212],
            [-76.903712, 39.074192],
            [-76.903464, 39.074145],
            [-76.903301, 39.074030],
            [-76.903158, 39.073875],
            [-76.903071, 39.073696],
            [-76.903039, 39.073516],
            [-76.903065, 39.073338],
            [-76.903149, 39.073168],
            [-76.903282, 39.073021],
            [-76.903465, 39.072896],
            [-76.903679, 39.072819],
            [-76.903903, 39.072786],
            [-76.904124, 39.072797],
            [-76.904329, 39.072851],
            [-76.904518, 39.072940],
            [-76.904706, 39.073029],
            [-76.904855, 39.073158],
            [-76.906221, 39.074084],
            [-76.908129, 39.074828],
            [-76.910401, 39.075078],
            [-76.913482, 39.074758],
            [-76.924829, 39.073772],
            [-76.930687, 39.073591],
            [-76.936115, 39.073664],
            [-76.945228, 39.074826],
            [-76.948338, 39.075918],
            [-76.954834, 39.079209],
            [-76.958566, 39.081175],
            [-76.962182, 39.082907],
            [-76.964617, 39.083332],
            [-76.967407, 39.083191],
            [-76.969484, 39.083412],
            [-76.971742, 39.084170],
            [-76.976687, 39.086114],
            [-76.983025, 39.088788],
            [-76.985704, 39.089512],
            [-76.988488, 39.089779],
            [-76.991281, 39.089590],
            [-76.997539, 39.088687],
            [-77.001787, 39.088312],
            [-77.008541, 39.087897],
            [-77.013845, 39.087128],
            [-77.020459, 39.085992],
            [-77.023236, 39.085835],
            [-77.025211, 39.086389],
            [-77.026750, 39.087508],
            [-77.027710, 39.089008],
            [-77.028146, 39.090903],
            [-77.029034, 39.093259],
            [-77.030437, 39.094859],
            [-77.032618, 39.096362],
            [-77.035143, 39.097464],
            [-77.038513, 39.098369],
            [-77.042130, 39.099532],
            [-77.044851, 39.100887],
            [-77.047813, 39.102913],
            [-77.050996, 39.105187],
            [-77.055267, 39.108274],
            [-77.058337, 39.110646],
            [-77.061623, 39.113689],
            [-77.064504, 39.115979],
            [-77.066908, 39.117065],
            [-77.069589, 39.117678],
            [-77.081940, 39.120455],
            [-77.087705, 39.123085],
            [-77.091849, 39.124533],
            [-77.096482, 39.125620],
            [-77.101050, 39.126210],
            [-77.106463, 39.126419],
            [-77.113894, 39.126642],
            [-77.118437, 39.126990],
            [-77.120607, 39.127777],
            [-77.122318, 39.129042],
            [-77.124218, 39.131225],
            [-77.126393, 39.133643],
            [-77.128644, 39.135491],
            [-77.131388, 39.136958],
            [-77.138116, 39.139101],
            [-77.140084, 39.138936],
            [-77.141828, 39.138163],
            [-77.143102, 39.136928],
            [-77.144688, 39.135612],
            [-77.146269, 39.135118],
            [-77.147972, 39.135110],
            [-77.149904, 39.135622],
            [-77.155834, 39.137330],
            [-77.158453, 39.137591],
            [-77.161087, 39.137398],
            [-77.163593, 39.136765],
            [-77.166115, 39.135549],
            [-77.167949, 39.134050],
            [-77.171853, 39.129988],
            [-77.175581, 39.126120],
            [-77.179622, 39.122026],
            [-77.180894, 39.121131],
            [-77.181190, 39.121005],
            [-77.181495, 39.120898],
            [-77.181806, 39.120804],
            [-77.182127, 39.120726],
            [-77.182461, 39.120671],
            [-77.182803, 39.120637],
            [-77.183148, 39.120626],
            [-77.183494, 39.120636],
            [-77.183839, 39.120665],
            [-77.184182, 39.120715],
            [-77.184520, 39.120787],
            [-77.184852, 39.120878],
            [-77.185494, 39.121106],
            [-77.189478, 39.122770],
            [-77.191456, 39.123177],
            [-77.194133, 39.123137],
            [-77.197993, 39.123036],
            [-77.198559, 39.123151],
            [-77.198828, 39.123246],
            [-77.199081, 39.123364],
            [-77.199314, 39.123501],
            [-77.199519, 39.123656],
            [-77.199701, 39.123827],
            [-77.199863, 39.124012],
            [-77.200012, 39.124209],
            [-77.201714, 39.126527],
            [-77.203814, 39.128927],
            [-77.206368, 39.131478],
            [-77.208734, 39.134112],
            [-77.210918, 39.137302],
            [-77.212660, 39.140680],
            [-77.214526, 39.145223],
            [-77.215510, 39.146948],
            [-77.217811, 39.149987],
            [-77.220639, 39.152707],
            [-77.224698, 39.155944],
            [-77.228768, 39.158858],
            [-77.233073, 39.161274],
            [-77.237891, 39.163827],
            [-77.240401, 39.165853],
            [-77.242376, 39.168174]
        ];
    };
    return Mapbox;
}(mapbox_common_1.MapboxCommon));
exports.Mapbox = Mapbox;