UNPKG

@nativescript-community/ui-carto

Version:

NativeScript plugin for CARTO Mobile SDK

216 lines 6.42 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 new com.carto.core.MapBounds(toNativeMapPos(this.southwest), toNativeMapPos(this.northeast)); } else { return new com.carto.core.MapBounds(); } } contains(position) { if (position['southwest']) { return this.getNative().contains(toNativeMapBounds(position)); } else { return this.getNative().contains(toNativeMapPos(position)); } } intersects(position) { return this.getNative().intersects(toNativeMapBounds(position)); } shrinkToIntersection(position) { return this.getNative().shrinkToIntersection(toNativeMapBounds(position)); } equals(position) { return this.getNative().equals(toNativeMapBounds(position)); } getCenter() { return fromNativeMapPos(this.getNative().getCenter()); } getMin() { return fromNativeMapPos(this.getNative().getMin()); } getMax() { return fromNativeMapPos(this.getNative().getMax()); } 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 com.carto.core.MapPos) { return position; } if (position[LongitudeKey] === undefined || position[LatitudeKey] === undefined) { throw new Error(`toNativeMapPos: missing lat/lon parameters in ${position}`); } const result = new com.carto.core.MapPos(position[LongitudeKey], position[LatitudeKey], !ignoreAltitude && position[AltitudeKey] > 0 ? position[AltitudeKey] : 0); // ignore z for now as points can get under the map! return result; } export function fromNativeScreenPos(position) { return { x: position.getY(), y: position.getX() }; } export function toNativeScreenPos(position) { if (position instanceof com.carto.core.ScreenPos) { return position; } return new com.carto.core.ScreenPos(position.x, position.y); } export function toNativeMapVec(value) { if (Array.isArray(value)) { return new com.carto.core.MapVec(value[0], value[1], value[2]); } if (value instanceof com.carto.core.MapVec) { return value; } return new com.carto.core.MapVec(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 com.carto.core.MapBounds) { return bounds; } else if (bounds.getNative) { return bounds.getNative(); } return new com.carto.core.MapBounds(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 com.carto.core.ScreenBounds) { return bounds; } if (bounds) { return new com.carto.core.ScreenBounds(toNativeScreenPos(bounds.min), toNativeScreenPos(bounds.max)); } return new com.carto.core.ScreenBounds(); } export class NativeVector extends BaseNative { constructor(native) { super(null, native); } size() { //@ts-ignore return this.getNative().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().set(index, position); } toArray() { const result = []; for (let i = 0; i < this.size(); i++) { result.push(this.get(i)); } return result; } } export class MapPosVector extends NativeVector { createNative() { return new com.carto.core.MapPosVector(); } add(position) { if (position instanceof com.carto.core.MapPos) { 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 IntVector extends NativeVector { createNative() { return new com.carto.core.IntVector(); } } export class DoubleVector extends NativeVector { createNative() { return new com.carto.core.DoubleVector(); } } export class MapPosVectorVector extends NativeVector { createNative() { return new com.carto.core.MapPosVectorVector(); } add(position) { if (position instanceof MapPosVector) { return this.getNative().add(position.getNative()); } return this.getNative().add(position); } } //# sourceMappingURL=index.android.js.map