Skip to content

Commit 602ca5c

Browse files
committed
chore: typings
1 parent a75fc27 commit 602ca5c

File tree

4 files changed

+37
-41
lines changed

4 files changed

+37
-41
lines changed

src/mapbox.android.ts

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import { request } from '@nativescript-community/perms';
8-
import { AndroidApplication, Application, Color, File, Trace, Utils, knownFolders, path, ImageSource, Image } from '@nativescript/core';
8+
import { AndroidApplication, Application, Color, File, Image, ImageSource, Trace, Utils, knownFolders, path } from '@nativescript/core';
99
import { getImage } from '@nativescript/core/http';
1010
import { FilterParser } from './filter/filter-parser.android';
1111
import { GeoUtils } from './geo.utils';
@@ -100,7 +100,6 @@ export class MapboxView extends MapboxViewBase {
100100
}
101101
}
102102

103-
104103
/**
105104
* programmatically include settings
106105
*/
@@ -347,7 +346,6 @@ export class MapboxView extends MapboxViewBase {
347346
}
348347
}
349348

350-
351349
/**
352350
* A NativeScript shim for the Mapbox API.
353351
*
@@ -1118,7 +1116,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
11181116

11191117
const builder = new com.mapbox.mapboxsdk.maps.Style.Builder();
11201118
this._mapboxMapInstance.setStyle(builder.fromUri(mapStyle));
1121-
11221119
} catch (ex) {
11231120
if (Trace.isEnabled()) {
11241121
CLog(CLogTypes.error, 'Error in mapbox.setMapStyle', style, ex);
@@ -1131,7 +1128,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
11311128
async getImage(imageId: string, nativeMap?: any): Promise<ImageSource> {
11321129
return new Promise((resolve, reject) => {
11331130
const theMap = nativeMap || this._mapboxMapInstance;
1134-
1131+
11351132
if (!theMap) {
11361133
reject('No map has been loaded');
11371134
return;
@@ -1141,51 +1138,51 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
11411138
const nativeImage = theMap.getStyle().getImage(imageId);
11421139
const img = new ImageSource(nativeImage);
11431140

1144-
resolve(img);
1141+
resolve(img);
11451142
} catch (ex) {
1146-
reject("Error during getImage: " + ex);
1143+
reject('Error during getImage: ' + ex);
11471144

11481145
if (Trace.isEnabled()) {
11491146
CLog(CLogTypes.info, 'Error in mapbox.getImage: ' + ex);
11501147
}
11511148
throw ex;
1152-
}
1149+
}
11531150
});
11541151
}
11551152

11561153
async addImage(imageId: string, image: string, nativeMap?: any): Promise<void> {
11571154
return new Promise((resolve, reject) => {
11581155
const theMap = nativeMap || this._mapboxMapInstance;
1159-
1156+
11601157
if (!theMap) {
11611158
reject('No map has been loaded');
11621159
return;
11631160
}
11641161

1165-
if (!image.startsWith("res://")) {
1162+
if (!image.startsWith('res://')) {
11661163
image = path.join(knownFolders.currentApp().path, image.replace('~/', ''));
11671164
}
1168-
1165+
11691166
const img = ImageSource.fromFileOrResourceSync(image);
11701167

11711168
try {
11721169
theMap.getStyle().addImage(imageId, img.android);
11731170
resolve();
11741171
} catch (ex) {
1175-
reject("Error during addImage: " + ex);
1172+
reject('Error during addImage: ' + ex);
11761173

11771174
if (Trace.isEnabled()) {
11781175
CLog(CLogTypes.info, 'Error in mapbox.addImage: ' + ex);
11791176
}
11801177
throw ex;
1181-
}
1178+
}
11821179
});
11831180
}
11841181

11851182
async removeImage(imageId: string, nativeMap?: any): Promise<void> {
11861183
return new Promise((resolve, reject) => {
11871184
const theMap = nativeMap || this._mapboxMapInstance;
1188-
1185+
11891186
if (!theMap) {
11901187
reject('No map has been loaded');
11911188
return;
@@ -1195,13 +1192,13 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
11951192
theMap.getStyle().removeImage(imageId);
11961193
resolve();
11971194
} catch (ex) {
1198-
reject("Error during removeImage: " + ex);
1195+
reject('Error during removeImage: ' + ex);
11991196

12001197
if (Trace.isEnabled()) {
12011198
CLog(CLogTypes.info, 'Error in mapbox.removeImage: ' + ex);
12021199
}
12031200
throw ex;
1204-
}
1201+
}
12051202
});
12061203
}
12071204

@@ -1233,7 +1230,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
12331230
* @deprecated
12341231
* @link https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-annotation
12351232
*/
1236-
12371233
_addMarkers(markers: MapboxMarker[], nativeMap?) {
12381234
if (!markers) {
12391235
if (Trace.isEnabled()) {
@@ -1399,7 +1395,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
13991395
}
14001396
}
14011397

1402-
14031398
setCenter(options: SetCenterOptions, nativeMap?): Promise<void> {
14041399
return new Promise((resolve, reject) => {
14051400
try {
@@ -2407,8 +2402,11 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
24072402
}
24082403

24092404
const geoJsonSource = new com.mapbox.mapboxsdk.style.sources.GeoJsonSource(id, geojsonOptions);
2410-
const geoJsonString = JSON.stringify(options.data);
2411-
geoJsonSource.setGeoJson(geoJsonString);
2405+
if(options.data) {
2406+
const geoJsonString = JSON.stringify(options.data);
2407+
geoJsonSource.setGeoJson(geoJsonString);
2408+
}
2409+
24122410
source = geoJsonSource;
24132411

24142412
break;
@@ -2436,7 +2434,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
24362434
tileSet.setBounds(options.bounds.map((val) => new java.lang.Float(val)));
24372435
}
24382436

2439-
source = new com.mapbox.mapboxsdk.style.sources.RasterSource(id, tileSet, options.tileSize);
2437+
source = new com.mapbox.mapboxsdk.style.sources.RasterSource(id, tileSet, options.tileSize || 256);
24402438
break;
24412439
default:
24422440
reject('Invalid source type: ' + options['type']);
@@ -2478,7 +2476,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
24782476

24792477
const isRemoved = theMap.getStyle().removeSource(id);
24802478
if (!isRemoved) {
2481-
reject(`Could not remove source with id: ${id}`)
2479+
reject(`Could not remove source with id: ${id}`);
24822480
}
24832481

24842482
resolve();
@@ -2565,17 +2563,17 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
25652563
try {
25662564
const sId = !!sourceId ? sourceId : id + '_source';
25672565
const lineSource = this._mapboxMapInstance.getStyle().getSource(sId) as com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
2568-
2566+
25692567
if (!lineSource) {
25702568
throw new Error(`no source found with id: ${sId}`);
25712569
}
25722570

25732571
const lineFeatures = lineSource.querySourceFeatures(FilterParser.parseJson(['==', '$type', 'LineString']));
2574-
2572+
25752573
if (lineFeatures.size() === 0) {
2576-
throw new Error("no line string feature found");
2574+
throw new Error('no line string feature found');
25772575
}
2578-
2576+
25792577
const feature = lineFeatures.get(0);
25802578

25812579
const newPoints = new java.util.ArrayList<com.mapbox.geojson.Point>(feature.geometry().coordinates());
@@ -2788,7 +2786,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
27882786
}
27892787

27902788
return mapboxMapOptions;
2791-
}
2789+
}
27922790

27932791
/**
27942792
* convert string to camera mode constant.
@@ -3006,7 +3004,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
30063004
reject(ex);
30073005
}
30083006
});
3009-
}
3007+
}
30103008

30113009
/**
30123010
* hide (destroy) the user location marker
@@ -3089,7 +3087,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
30893087
});
30903088
}
30913089

3092-
30933090
/**
30943091
* force updating of user location
30953092
*

src/mapbox.common.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Color, ContentView, Property, Trace, booleanConverter, ImageSource } from '@nativescript/core';
1+
import { Color, ContentView, ImageSource, Property, Trace, booleanConverter } from '@nativescript/core';
22

33
export const MapboxTraceCategory = 'NativescriptMapbox';
44
export enum CLogTypes {
@@ -9,7 +9,7 @@ export enum CLogTypes {
99
}
1010

1111
export const CLog = (type: CLogTypes, ...args) => {
12-
Trace.write(args.map(a=>(a && typeof a === 'object'? JSON.stringify(a) :a)).join(' '), MapboxTraceCategory, type);
12+
Trace.write(args.map((a) => (a && typeof a === 'object' ? JSON.stringify(a) : a)).join(' '), MapboxTraceCategory, type);
1313
};
1414

1515
// ------------------------------------------------------------
@@ -830,7 +830,7 @@ export interface MapboxViewApi {
830830

831831
getLayers(nativeMap?: any): Promise<LayerCommon[]>;
832832

833-
getImage(imageId: string, nativeMap?: any): Promise<ImageSource>
833+
getImage(imageId: string, nativeMap?: any): Promise<ImageSource>;
834834

835835
addImage(imageId: string, image: string, nativeMap?: any): Promise<void>;
836836

src/mapbox.ios.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
983983
async getImage(imageId: string, nativeMap?: any): Promise<ImageSource> {
984984
return new Promise((resolve, reject) => {
985985
const theMap: MGLMapView = nativeMap || this._mapboxViewInstance;
986-
986+
987987
if (!theMap) {
988988
reject('No map has been loaded');
989989
return;
@@ -992,16 +992,16 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
992992
try {
993993
const nativeImage = theMap.style.imageForName(imageId);
994994
const img = new ImageSource(nativeImage);
995-
996-
resolve(img);
995+
996+
resolve(img);
997997
} catch (ex) {
998-
reject("Error during getImage: " + ex);
998+
reject('Error during getImage: ' + ex);
999999

10001000
if (Trace.isEnabled()) {
10011001
CLog(CLogTypes.info, 'Error in mapbox.getImage: ' + ex);
10021002
}
10031003
throw ex;
1004-
}
1004+
}
10051005
});
10061006
}
10071007

@@ -1469,7 +1469,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
14691469

14701470
/**
14711471
* @deprecated
1472-
*/
1472+
*/
14731473
addPolygon(options: AddPolygonOptions, nativeMap?): Promise<void> {
14741474
return new Promise((resolve, reject) => {
14751475
const theMap = nativeMap || this._mapboxViewInstance;
@@ -2521,7 +2521,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
25212521
});
25222522
}
25232523

2524-
getLayers(nativeMap?: any): Promise<Array<LayerCommon>> {
2524+
getLayers(nativeMap?: any): Promise<LayerCommon[]> {
25252525
return new Promise((resolve, reject) => {
25262526
try {
25272527
const theMap: MGLMapView = nativeMap || this._mapboxViewInstance;
@@ -2595,7 +2595,6 @@ const _downloadMarkerImages = (markers: MapboxMarker[]) => {
25952595
return Promise.all(iterations).then(() => result);
25962596
};
25972597

2598-
25992598
/**
26002599
* "Delegate" for catching mapview events
26012600
*
@@ -2712,7 +2711,6 @@ class MGLMapViewDelegateImpl extends NSObject implements MGLMapViewDelegate {
27122711
}
27132712
}
27142713

2715-
27162714
/**
27172715
* Callback when the style has been loaded.
27182716
*

src/typings/Mapbox.ios.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ interface MGLCoordinateBounds {
388388
ne: CLLocationCoordinate2D;
389389
}
390390
declare var MGLCoordinateBounds: interop.StructType<MGLCoordinateBounds>;
391+
declare function MGLCoordinateBoundsMake(arg1, arg2);
391392

392393
declare class MGLCoordinateFormatter extends NSFormatter {
393394
static alloc(): MGLCoordinateFormatter; // inherited from NSObject

0 commit comments

Comments
 (0)