Skip to content

Commit

Permalink
Nativescript Angular 2 issue while using MapBox inside the HTML #56 -…
Browse files Browse the repository at this point in the history
… Android
  • Loading branch information
EddyVerbruggen committed Nov 16, 2016
1 parent 55efe8a commit ebaa857
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions mapbox.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,46 @@ var Mapbox = (function (_super) {
}

Mapbox.prototype._createUI = function () {
var settings = mapbox.merge(this.config, mapbox.defaults);
if (settings.accessToken === undefined) {
setTimeout(function() {
var dialogs = require("ui/dialogs");
dialogs.alert("Please set the 'accessToken' property because now there will be no map :)");
}, 0);
return;
}

com.mapbox.mapboxsdk.MapboxAccountManager.start(application.android.context, settings.accessToken);

var context = application.android.currentContext;

this._android = new android.widget.FrameLayout(context);

var that = this;

function drawMap() {
that.mapView = new com.mapbox.mapboxsdk.maps.MapView(
application.android.context,
mapbox._getMapboxMapOptions(settings));
var createUI = function() {

that.mapView.getMapAsync(
new com.mapbox.mapboxsdk.maps.OnMapReadyCallback({
onMapReady: function (mbMap) {
that.mapView.mapboxMap = mbMap;
that.notifyMapReady();
}
})
);
that._android.addView(that.mapView);
that.mapView.onCreate(null);
}
var settings = mapbox.merge(that.config, mapbox.defaults);
if (settings.accessToken === undefined) {
setTimeout(function() {
var dialogs = require("ui/dialogs");
dialogs.alert("Please set the 'accessToken' property because now there will be no map :)");
}, 0);
return;
}

com.mapbox.mapboxsdk.MapboxAccountManager.start(application.android.context, settings.accessToken);

var drawMap = function() {
that.mapView = new com.mapbox.mapboxsdk.maps.MapView(
application.android.context,
mapbox._getMapboxMapOptions(settings));

that.mapView.getMapAsync(
new com.mapbox.mapboxsdk.maps.OnMapReadyCallback({
onMapReady: function (mbMap) {
that.mapView.mapboxMap = mbMap;
that.notifyMapReady();
}
})
);
that._android.addView(that.mapView);
that.mapView.onCreate(null);
};

setTimeout(drawMap, settings.delay);
};

setTimeout(drawMap, settings.delay);
// postpone drawing the map for cases where this plugin is used in an Angular-powered app
setTimeout(createUI, 0);
};

Object.defineProperty(Mapbox.prototype, "android", {
Expand Down

0 comments on commit ebaa857

Please sign in to comment.