UNPKG

@nativescript-community/ui-carto

Version:
154 lines 4.77 kB
/* eslint-disable no-redeclare */ import { CSSType, ContentView } from '@nativescript/core'; import { BaseNative } from '../BaseNative'; import { LatitudeKey, fromNativeMapPos } from '../core'; import { bearingProperty, focusPosProperty, tiltProperty, zoomProperty } from './cssproperties'; export const MapReadyEvent = 'mapReady'; export const MapStableEvent = 'mapStable'; export const MapIdleEvent = 'mapIdle'; export const MapMovedEvent = 'mapMoved'; export const MapInteractionEvent = 'mapInteraction'; export const MapClickedEvent = 'mapClicked'; function createGetter(key, options) { const nativeGetterName = ((__ANDROID__ ? options.android : options.ios) || options).nativeGetterName || 'get' + key.charAt(0).toUpperCase() + key.slice(1); const getConverter = options.getConverter; return function () { let result; if (this.nativeViewProtected && this.nativeViewProtected[nativeGetterName]) { result = this.nativeViewProtected[nativeGetterName](); } else { result = this.style[key] || options.defaultValue; } result = getConverter ? getConverter.call(this, result) : result; return result; }; } function createSetter(key, options) { return function (newVal) { const actualVal = options.converter ? options.converter(newVal) : newVal; this.style[key] = actualVal; }; } function mapPropertyGenerator(target, key, options) { Object.defineProperty(target, key, { get: createGetter(key, options), set: createSetter(key, options), enumerable: true, configurable: true }); } export function mapProperty(...args) { const options = args[0]; if (args[1] === undefined) { return function (target, key, descriptor) { return mapPropertyGenerator(target, key, options); }; } else { return mapPropertyGenerator(args[0], args[1], {}); } } export class Layers extends BaseNative { constructor(native) { super(null, native); } } let CartoViewBase = class CartoViewBase extends ContentView { constructor() { super(...arguments); this.mapReady = false; } sendEvent(eventName, data) { if (this.hasListeners(eventName)) { this.notify({ eventName, data }); } } onLoaded() { super.onLoaded(); if (!this.mapReady) { this.mapReady = true; setTimeout(() => this.sendEvent(MapReadyEvent), 0); } } disposeNativeView() { this.mapReady = false; super.disposeNativeView(); } [focusPosProperty.setNative](value) { if (!this.nativeViewProtected || !this.nativeProjection) { return; } this.setFocusPos(value, 0); } [zoomProperty.setNative](value) { if (!this.nativeViewProtected) { return; } this.setZoom(value, 0); } [tiltProperty.setNative](value) { if (!this.nativeViewProtected) { return; } this.setTilt(value, 0); } [bearingProperty.setNative](value) { if (!this.nativeViewProtected) { return; } this.setBearing(value, 0); } get metersPerPixel() { if (this.nativeViewProtected) { const pos = this.focusPos; const zoom = this.zoom; return (156543.03390625 * Math.cos((pos[LatitudeKey] * Math.PI) / 180)) / Math.pow(2, zoom); } return 0; } }; CartoViewBase.mapReadyEvent = MapReadyEvent; CartoViewBase.mapStableEvent = MapStableEvent; CartoViewBase.mapIdleEvent = MapIdleEvent; CartoViewBase.mapMovedEvent = MapMovedEvent; CartoViewBase.mapInteractionEvent = MapInteractionEvent; CartoViewBase.mapClickedEvent = MapClickedEvent; __decorate([ mapProperty({ getConverter: (value) => fromNativeMapPos(value) }) ], CartoViewBase.prototype, "focusPos", void 0); __decorate([ mapProperty ], CartoViewBase.prototype, "zoom", void 0); __decorate([ mapProperty({ ios: { nativeGetterName: 'getRotation' }, android: { nativeGetterName: 'getMapRotation' } }) ], CartoViewBase.prototype, "bearing", void 0); __decorate([ mapProperty ], CartoViewBase.prototype, "tilt", void 0); __decorate([ mapProperty ], CartoViewBase.prototype, "minZoom", void 0); __decorate([ mapProperty ], CartoViewBase.prototype, "maxZoom", void 0); __decorate([ mapProperty ], CartoViewBase.prototype, "restrictedPanning", void 0); CartoViewBase = __decorate([ CSSType('CartoMap') ], CartoViewBase); export { CartoViewBase }; //# sourceMappingURL=index.common.js.map