UNPKG

@nativescript-community/ui-carto

Version:
156 lines 4.71 kB
/* eslint-disable no-redeclare */ import { Color } from '@nativescript/core'; import { fromNativeMapVec, toNativeMapPos, toNativeMapVec } from './core'; import { _createImageSourceFromSrc, nativeProperty } from './index.common'; export { BaseNative } from './BaseNative'; export { nativeProperty }; export function getCartoBitmap(src) { const bitmap = _createImageSourceFromSrc(src); return NTBitmapUtils.createBitmapFromUIImage(bitmap.ios); } export function nativeColorProperty(...args) { return nativeProperty({ converter: { fromNative(value) { return new Color(value.getARGB()); }, toNative(value) { const theColor = value instanceof Color ? value : value._argb ? new Color(value._argb) : new Color(value); return NTColor.alloc().initWithRGBA(theColor.r, theColor.g, theColor.b, theColor.a); } } }, ...args); } export function nativeNColorProperty(...args) { return nativeProperty({ converter: { fromNative(value) { return value; }, toNative(value) { const theColor = value instanceof Color ? value : value._argb ? new Color(value._argb) : new Color(value); return theColor.ios; } } }, ...args); } export function nativeFontProperty(...args) { return nativeProperty({ converter: { fromNative(value) { // no easy from typeface to Font return value; }, toNative(value) { return value?.getUIFont(UIFont.systemFontOfSize(17)); } } }, ...args); } export function nativeEnumProperty(...args) { return nativeProperty({ converter: { fromNative(value) { return value.ordinal(); }, toNative(value) { return value; } } }, ...args); } 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?.ios; } } }, ...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 NTMapPosVector)) { const arrayPoses = positions; nativePoses = NTMapPosVector.alloc().init(); arrayPoses.forEach((p) => { nativePoses.add(toNativeMapPos(p, ignoreAltitude)); }); } return nativePoses; } export function mapPosVectorVectorFromArgs(positions, ignoreAltitude = false) { let nativePoses; if (typeof positions.getNative === 'function') { nativePoses = positions.getNative(); } else { const arrayPoses = positions; nativePoses = NTMapPosVectorVector.alloc().init(); arrayPoses.forEach((p) => { nativePoses.add(mapPosVectorFromArgs(p, ignoreAltitude)); }); } return nativePoses; } export function nativeMapVecProperty(...args) { return nativeProperty({ converter: { fromNative: fromNativeMapVec, toNative: toNativeMapVec } }, ...args); } //# sourceMappingURL=index.ios.js.map