@nativescript-community/ui-carto
Version:
NativeScript plugin for CARTO Mobile SDK
170 lines • 5.28 kB
JavaScript
/* eslint-disable no-redeclare */
import { Color } from '@nativescript/core';
import { fromNativeMapVec, toNativeMapPos, toNativeMapVec } from './core';
import { _createImageSourceFromSrc, nativeProperty } from './index.common';
export { nativeProperty };
export { BaseNative } from './BaseNative';
export function getCartoBitmap(src) {
const bitmap = _createImageSourceFromSrc(src);
const result = com.carto.utils.BitmapUtils.createBitmapFromAndroidBitmap(bitmap.android);
bitmap.android.recycle();
return result;
}
export function nativeColorProperty(...args) {
return nativeProperty({
converter: {
fromNative(value) {
if (typeof value === 'string') {
return value;
}
return new Color(value.getARGB());
},
toNative(value) {
const theColor = value instanceof Color ? value : value._argb ? new Color(value._argb) : new Color(value);
return new com.carto.graphics.Color(theColor.r, theColor.g, theColor.b, theColor.a);
}
}
}, ...args);
}
export function nativeNColorProperty(...args) {
return nativeProperty({
converter: {
fromNative(value) {
return new Color(value);
},
toNative(value) {
const theColor = value instanceof Color ? value : value._argb ? new Color(value._argb) : new Color(value);
return theColor.android;
}
}
}, ...args);
}
export function nativeFontProperty(...args) {
return nativeProperty({
converter: {
fromNative(value) {
// no easy from typeface to Font
return value;
},
toNative(value) {
return value?.getAndroidTypeface();
}
}
}, ...args);
}
export function nativeEnumProperty(...args) {
return nativeProperty({}, ...args);
}
export function nativeAndroidEnumProperty(androidEnum, options) {
return nativeProperty(Object.assign(options || {}, {
converter: {
fromNative(value) {
return value.swigValue();
},
toNative(value) {
return androidEnum.swigToEnum(value);
}
}
}));
}
export function nativeCartoImageProperty(...args) {
return nativeProperty({
converter: {
fromNative(value, key) {
return this.options[key];
},
toNative(value) {
return getCartoBitmap(value);
}
}
}, ...args);
}
export function nativeImageProperty(...args) {
return nativeProperty({
converter: {
fromNative(value, key) {
return this.options[key];
},
toNative(value) {
value = _createImageSourceFromSrc(value);
return value?.android;
}
}
}, ...args);
}
export function featureCollectionFromArgs(collection) {
if (!collection) {
return null;
}
let nativeCollection = collection;
if (typeof collection.getNative === 'function') {
nativeCollection = collection.getNative();
}
return nativeCollection;
}
export function styleFromArgs(style) {
if (!style) {
return null;
}
let nativeStyle = style;
if (typeof style.buildStyle === 'function') {
nativeStyle = style.buildStyle();
}
return nativeStyle;
}
export function geometryFromArgs(geometry) {
if (!geometry) {
return null;
}
let nativegeometry = geometry;
if (typeof geometry.getNative === 'function') {
nativegeometry = geometry.getNative();
}
return nativegeometry;
}
export function mapPosVectorFromArgs(positions, ignoreAltitude = true) {
if (!positions) {
return null;
}
let nativePoses = positions;
if (typeof positions.getNative === 'function') {
nativePoses = positions.getNative();
}
else if (!(positions instanceof com.carto.core.MapPosVector)) {
const arrayPoses = positions;
nativePoses = new com.carto.core.MapPosVector();
// if (projection) {
// arrayPoses.forEach(p => {
// nativePoses.add(projection.getNative().fromWgs84(toNativeMapPos(p)));
// });
// } else {
arrayPoses.forEach((p) => {
nativePoses.add(toNativeMapPos(p, ignoreAltitude));
});
// }
}
return nativePoses;
}
export function mapPosVectorVectorFromArgs(positions, ignoreAltitude = true) {
let nativePoses;
if (typeof positions.getNative === 'function') {
nativePoses = positions.getNative();
}
else {
const arrayPoses = positions;
nativePoses = new com.carto.core.MapPosVectorVector();
arrayPoses.forEach((p) => {
nativePoses.add(mapPosVectorFromArgs(p, ignoreAltitude));
});
}
return nativePoses;
}
export function nativeMapVecProperty(...args) {
return nativeProperty({
converter: {
fromNative: fromNativeMapVec,
toNative: toNativeMapVec
}
}, ...args);
}
//# sourceMappingURL=index.android.js.map