UNPKG

@nativescript-community/ui-carto

Version:

NativeScript plugin for CARTO Mobile SDK

193 lines 5.71 kB
import { BaseNative } from '../BaseNative'; import { AltitudeKey, LatitudeKey, LongitudeKey } from './index.common'; export * from './index.common'; export class MapBounds extends BaseNative { constructor(northeast, southwest, native) { super(undefined, native); this.northeast = northeast; this.southwest = southwest; } createNative() { if (this.southwest && this.northeast) { return NTMapBounds.alloc().initWithMinMax(toNativeMapPos(this.southwest), toNativeMapPos(this.northeast)); } else { return NTMapBounds.alloc().init(); } } contains(position) { if (position['southwest']) { return this.getNative().containsBounds(toNativeMapBounds(position)); } else { return this.getNative().containsPos(toNativeMapPos(position)); } } intersects(position) { return this.getNative().intersects(toNativeMapBounds(position)); } shrinkToIntersection(position) { return this.getNative().shrinkToIntersection(toNativeMapBounds(position)); } equals(position) { return this.getNative().isEqualInternal(toNativeMapBounds(position)); } getCenter() { return fromNativeMapPos(this.getNative().getCenter()); } toJSON() { return { southwest: this.southwest, northeast: this.northeast }; } } export function fromNativeMapPos(position) { if (!position) { return null; } return { [LatitudeKey]: position.getY(), [LongitudeKey]: position.getX(), [AltitudeKey]: position.getZ() }; } export function toNativeMapPos(position, ignoreAltitude = false) { if (!position) { return null; } if (position instanceof NTMapPos) { return position; } // ignore z for now as points can get under the map! return NTMapPos.alloc().initWithXYZ(position[LongitudeKey], position[LatitudeKey], !ignoreAltitude && position[AltitudeKey] > 0 ? position[AltitudeKey] : 0); } export function fromNativeScreenPos(position) { return { x: position.getY(), y: position.getX() }; } export function toNativeScreenPos(position) { if (position instanceof NTScreenPos) { return position; } // ignore z for now as points can get under the map! return NTScreenPos.alloc().initWithXY(position.x, position.y); } export function toNativeMapVec(value) { if (Array.isArray(value)) { return NTMapVec.alloc().initWithXYZ(value[0], value[1], value[2]); } if (value instanceof NTMapVec) { return value; } return NTMapVec.alloc().initWithXYZ(value.x, value.y, value.z); } export function fromNativeMapVec(value) { return { x: value.getX(), y: value.getY(), z: value.getZ() }; } export function fromNativeMapBounds(bounds) { return new MapBounds(fromNativeMapPos(bounds.getMax()), fromNativeMapPos(bounds.getMin())); } export function toNativeMapBounds(bounds) { if (bounds instanceof NTMapBounds) { return bounds; } if (typeof bounds.getNative === 'function') { return bounds.getNative(); } return NTMapBounds.alloc().initWithMinMax(toNativeMapPos(bounds.southwest), toNativeMapPos(bounds.northeast)); } export function fromNativeScreenBounds(bounds) { return { min: fromNativeScreenPos(bounds.getMin()), max: fromNativeScreenPos(bounds.getMax()) }; } export function toNativeScreenBounds(bounds) { if (bounds instanceof NTScreenBounds) { return bounds; } if (bounds) { return NTScreenBounds.alloc().initWithMinMax(toNativeScreenPos(bounds.min), toNativeScreenPos(bounds.max)); } return NTScreenBounds.alloc().init(); } export class NativeVector extends BaseNative { constructor(native) { super(null, native); } createNative(options) { return null; } size() { //@ts-ignore return this.native.size(); } reserve(size) { //@ts-ignore return this.getNative().reserve(size); } //@ts-ignore get(index) { //@ts-ignore return this.getNative().get(index); } add(position) { //@ts-ignore return this.getNative().add(position); } capacity() { //@ts-ignore return this.getNative().capacity(); } clear() { //@ts-ignore return this.getNative().clear(); } isEmpty() { //@ts-ignore return this.getNative().isEmpty(); } //@ts-ignore set(index, position) { //@ts-ignore return this.getNative().setVal(index, position); } } export class MapPosVector extends NativeVector { createNative() { return NTMapPosVector.alloc().init(); } add(position) { if (position instanceof NTMapPos) { position = toNativeMapPos(position); return this.getNative().add(position); } return this.getNative().add(toNativeMapPos(position)); } getPos(index) { return fromNativeMapPos(this.get(index)); } toArray() { const result = []; for (let i = 0; i < this.size(); i++) { result.push(fromNativeMapPos(this.get(i))); } return result; } } export class MapPosVectorVector extends NativeVector { createNative() { return NTMapPosVectorVector.alloc().init(); } add(position) { if (position instanceof MapPosVector) { return this.getNative().add(position.getNative()); } return this.getNative().add(position); } } //# sourceMappingURL=index.ios.js.map