Skip to content

Commit 546852b

Browse files
committed
fix: refactor to avoid import circular references
1 parent 177576b commit 546852b

File tree

8 files changed

+32
-96
lines changed

8 files changed

+32
-96
lines changed

src/core/index.android.ts

Lines changed: 2 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { AltitudeKey, DefaultLatLonKeys, GenericMapPos, LatitudeKey, LongitudeKey, MapPos, MapRange, MapVec, ScreenBounds, ScreenPos, setMapPosKeys } from './index.common';
2-
import { BaseNative, _createImageSourceFromSrc } from '../index.common';
3-
import { Color } from '@nativescript/core';
1+
import { BaseNative } from '../index.common';
2+
import { AltitudeKey, DefaultLatLonKeys, GenericMapPos, LatitudeKey, LongitudeKey, MapPos, MapVec, ScreenBounds, ScreenPos, setMapPosKeys } from './index.common';
43
export { LatitudeKey, LongitudeKey, MapPos, ScreenBounds, ScreenPos, setMapPosKeys };
54

65
export const CartoMapStyle = {
@@ -102,82 +101,6 @@ export function toNativeScreenPos(position: ScreenPos) {
102101
return new com.carto.core.ScreenPos(position.x, position.y);
103102
}
104103

105-
// export class Converter {
106-
// NColor = {
107-
// fromNative(value) {
108-
// if (typeof value === 'string') {
109-
// return value;
110-
// }
111-
// return value;
112-
// },
113-
// toNative(value): android.graphics.Color {
114-
// const theColor = value instanceof Color ? value : value._argb ? new Color(value._argb) : new Color(value);
115-
// return theColor.ios;
116-
// },
117-
// };
118-
// Color = {
119-
// fromNative(value) {
120-
// if (typeof value === 'string') {
121-
// return value;
122-
// }
123-
// return new Color((value as com.carto.graphics.Color).getARGB());
124-
// },
125-
// toNative(value) {
126-
// const theColor = value instanceof Color ? value : value._argb ? new Color(value._argb) : new Color(value);
127-
// return new com.carto.graphics.Color(theColor.r, theColor.g, theColor.b, theColor.a);
128-
// },
129-
// };
130-
// MapRange = {
131-
// fromNative(value) {
132-
// return value;
133-
// },
134-
// toNative(value) {
135-
// const theColor = value instanceof Color ? value : value._argb ? new Color(value._argb) : new Color(value);
136-
// return theColor.ios;
137-
// },
138-
// };
139-
// Font = {
140-
// fromNative(value) {
141-
// // no easy from typeface to Font
142-
// return value;
143-
// },
144-
// toNative(value) {
145-
// return value?.getAndroidTypeface();
146-
// },
147-
// };
148-
// CartoImage = {
149-
// fromNative(value) {
150-
// // no easy from typeface to Font
151-
// return value;
152-
// },
153-
// toNative(value) {
154-
// value = _createImageSourceFromSrc(value);
155-
// return com.carto.utils.BitmapUtils.createBitmapFromAndroidBitmap(value.android as android.graphics.Bitmap);
156-
// },
157-
// };
158-
// AndroidEnum(androidEnum) {
159-
// return {
160-
// fromNative(value) {
161-
// // no easy from typeface to Font
162-
// return value.swigValue();
163-
// },
164-
// toNative(value) {
165-
// return androidEnum.swigToEnum(value);
166-
// },
167-
// };
168-
// }
169-
// }
170-
export function fromNativeMapRange(value: com.carto.core.MapRange) {
171-
return [value.getMax(), value.getMin()] as MapRange;
172-
}
173-
export function toNativeMapRange(value: MapRange) {
174-
if (value instanceof com.carto.core.MapRange) {
175-
return value;
176-
}
177-
// ignore z for now as points can get under the map!
178-
return new com.carto.core.MapRange(value[0], value[1]);
179-
}
180-
181104
export function toNativeMapVec(value: MapVec | [number, number, number]) {
182105
if (Array.isArray(value)) {
183106
return new com.carto.core.MapVec(value[0], value[1], value[2]);

src/core/index.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ export declare function fromNativeScreenBounds(pos): ScreenBounds;
1414
export declare function toNativeScreenBounds(position: ScreenBounds): any;
1515
export declare function fromNativeMapVec(value): MapVec;
1616
export declare function toNativeMapVec(value: MapVec | [number, number, number]): any;
17-
export declare function fromNativeMapRange(value): MapRange;
18-
export declare function toNativeMapRange(value: MapRange): any;
1917
export declare function setMapPosKeys(latitude: LatitudeKeys, longitude: LongitudeKeys, altitude?: AltitudeKeys);
2018

2119
export class CartoMapStyle {

src/core/index.ios.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BaseNative } from '../index.common';
2-
import { AltitudeKey, DefaultLatLonKeys, GenericMapPos, LatitudeKey, LongitudeKey, MapPos, MapRange, MapVec, ScreenBounds, ScreenPos, setMapPosKeys } from './index.common';
2+
import { AltitudeKey, DefaultLatLonKeys, GenericMapPos, LatitudeKey, LongitudeKey, MapPos, MapVec, ScreenBounds, ScreenPos, setMapPosKeys } from './index.common';
33
export { LatitudeKey, LongitudeKey, MapPos, ScreenBounds, ScreenPos, setMapPosKeys };
44

55
export enum CartoMapStyle {
@@ -91,16 +91,6 @@ export function toNativeScreenPos(position: ScreenPos | NTScreenPos) {
9191
// ignore z for now as points can get under the map!
9292
return NTScreenPos.alloc().initWithXY(position.x, position.y);
9393
}
94-
export function fromNativeMapRange(value: NTMapRange) {
95-
return [value.getMax(), value.getMin()] as MapRange;
96-
}
97-
export function toNativeMapRange(value: MapRange) {
98-
if (value instanceof NTMapRange) {
99-
return value;
100-
}
101-
// ignore z for now as points can get under the map!
102-
return NTMapRange.alloc().initWithMinMax(value[0], value[1]);
103-
}
10494
export function toNativeMapVec(value: MapVec | [number, number, number]) {
10595
if (Array.isArray(value)) {
10696
return NTMapVec.alloc().initWithXYZ(value[0], value[1], value[2]);

src/index.common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { RESOURCE_PREFIX, isDataURI, isFileOrResourcePath } from '@nativescript/
66
import { isAndroid } from '@nativescript/core/platform';
77
import { knownFolders, path } from '@nativescript/core/file-system';
88
import { NativePropertyOptions } from '.';
9-
import { fromNativeMapRange, toNativeMapRange } from './core';
9+
import { fromNativeMapRange, toNativeMapRange } from './utils';
1010

1111
function createGetter(key: string, options: NativePropertyOptions) {
1212
const nativeGetterName = ((isAndroid ? options.android : options.ios) || options).nativeGetterName || 'get' + key.charAt(0).toUpperCase() + key.slice(1);

src/layers/index.common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BaseNative, nativeProperty } from '../index.common';
1+
import { BaseNative, nativeProperty } from '..';
22
import { LayerOptions, TileSubstitutionPolicy } from '.';
33
import { TileDataSource } from '../datasources';
44
import { Projection } from '../projections';

src/utils/index.android.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BaseNative, getFileName, getRelativePathToApp, nonenumerable } from '../index.common';
22
import { DirAssetPackageOptions, ZippedAssetPackageOptions } from '.';
33
import { File, FileSystemEntity, Folder, knownFolders, path } from '@nativescript/core/file-system';
4-
import { DefaultLatLonKeys, GenericMapPos, MapPos, MapPosVector, toNativeMapPos } from '../core';
4+
import { DefaultLatLonKeys, GenericMapPos, MapPos, MapPosVector, MapRange, toNativeMapPos } from '../core';
55
import { mapPosVectorFromArgs } from '..';
66

77
export function nativeVectorToArray(nVector: com.carto.core.StringVector) {
@@ -207,3 +207,14 @@ export function isLocationOnPath<T = DefaultLatLonKeys>(
207207
): number {
208208
return com.akylas.carto.additions.Utils.isLocationOnPath(toNativeMapPos<T>(point), mapPosVectorFromArgs<T>(coordinates), closed, geodesic, toleranceEarth);
209209
}
210+
211+
export function fromNativeMapRange(value: com.carto.core.MapRange) {
212+
return [value.getMax(), value.getMin()] as MapRange;
213+
}
214+
export function toNativeMapRange(value: MapRange) {
215+
if (value instanceof com.carto.core.MapRange) {
216+
return value;
217+
}
218+
// ignore z for now as points can get under the map!
219+
return new com.carto.core.MapRange(value[0], value[1]);
220+
}

src/utils/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ export function isLocationOnPath<T = DefaultLatLonKeys>(
3333
geodesic?: boolean,
3434
toleranceEarth?: number
3535
): number;
36+
37+
export declare function fromNativeMapRange(value): MapRange;
38+
export declare function toNativeMapRange(value: MapRange): any;

src/utils/index.ios.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BaseNative, getFileName, getRelativePathToApp } from '../index.common';
22
import { DirAssetPackageOptions, ZippedAssetPackageOptions } from '.';
33
import { File, FileSystemEntity, Folder, knownFolders, path } from '@nativescript/core/file-system';
4-
import { DefaultLatLonKeys, GenericMapPos, MapPosVector, toNativeMapPos } from '../core';
4+
import { DefaultLatLonKeys, GenericMapPos, MapPosVector, MapRange, toNativeMapPos } from '../core';
55
import { mapPosVectorFromArgs } from '..';
66

77
export function nativeVectorToArray(nVector: NTStringVector) {
@@ -159,3 +159,14 @@ export function isLocationOnPath<T = DefaultLatLonKeys>(
159159
): number {
160160
return CartoAdditionsUtils.isLocationOnPolyClosedGeodesicToleranceEarth(toNativeMapPos<T>(point), mapPosVectorFromArgs<T>(coordinates), closed, geodesic, toleranceEarth);
161161
}
162+
163+
export function fromNativeMapRange(value: NTMapRange) {
164+
return [value.getMax(), value.getMin()] as MapRange;
165+
}
166+
export function toNativeMapRange(value: MapRange) {
167+
if (value instanceof NTMapRange) {
168+
return value;
169+
}
170+
// ignore z for now as points can get under the map!
171+
return NTMapRange.alloc().initWithMinMax(value[0], value[1]);
172+
}

0 commit comments

Comments
 (0)