@nativescript-community/ui-carto
Version:
NativeScript plugin for CARTO Mobile SDK
155 lines • 5.36 kB
JavaScript
import { geometryFromArgs, mapPosVectorFromArgs, nativeColorProperty, nativeProperty } from '..';
import { MapBounds, MapPosVector, fromNativeMapBounds } from '../core';
import { BaseVectorElementStyleBuilder } from './index.common';
import { BaseLineVectorElement } from './index.ios';
export { MapBounds };
export var LineJointType;
(function (LineJointType) {
LineJointType[LineJointType["BEVEL"] = 2] = "BEVEL";
LineJointType[LineJointType["MITER"] = 1] = "MITER";
LineJointType[LineJointType["NONE"] = 0] = "NONE";
LineJointType[LineJointType["ROUND"] = 3] = "ROUND";
})(LineJointType || (LineJointType = {}));
export var LineEndType;
(function (LineEndType) {
LineEndType[LineEndType["ROUND"] = 2] = "ROUND";
LineEndType[LineEndType["SQUARE"] = 1] = "SQUARE";
LineEndType[LineEndType["NONE"] = 0] = "NONE";
})(LineEndType || (LineEndType = {}));
export class LineStyleBuilder extends BaseVectorElementStyleBuilder {
createNative(options) {
return NTLineStyleBuilder.alloc().init();
}
buildStyle() {
if (!this.mBuildStyle) {
this.mBuildStyle = this.getNative().buildStyle();
}
return this.mBuildStyle;
}
}
__decorate([
nativeProperty
], LineStyleBuilder.prototype, "width", void 0);
__decorate([
nativeColorProperty
], LineStyleBuilder.prototype, "color", void 0);
__decorate([
nativeProperty({
nativeSetterName: 'setLineJoinType',
nativeGetterName: 'getLineJoinType'
})
], LineStyleBuilder.prototype, "joinType", void 0);
__decorate([
nativeProperty({
nativeSetterName: 'setLineEndType',
nativeGetterName: 'getLineEndType'
})
], LineStyleBuilder.prototype, "endType", void 0);
__decorate([
nativeProperty
], LineStyleBuilder.prototype, "clickWidth", void 0);
__decorate([
nativeProperty
], LineStyleBuilder.prototype, "stretchFactor", void 0);
function styleBuilderProperty(target, propertyKey, desc) {
Object.defineProperty(target, propertyKey, {
get() {
return this.options.styleBuilder[propertyKey];
},
set(value) {
this.options.styleBuilder[propertyKey] = value;
this.rebuildStyle();
}
});
}
export class Line extends BaseLineVectorElement {
constructor(options = {}, native) {
super(options, native);
this.options = options;
if (native && !options.styleBuilder) {
const nStyle = native.getStyle();
const nStyleBuilder = NTLineStyleBuilder.alloc().init();
nStyleBuilder.setBitmap(nStyle.getBitmap());
nStyleBuilder.setColor(nStyle.getColor());
nStyleBuilder.setWidth(nStyle.getWidth());
nStyleBuilder.setClickWidth(nStyle.getClickWidth());
nStyleBuilder.setLineEndType(nStyle.getLineEndType());
nStyleBuilder.setLineJoinType(nStyle.getLineJoinType());
options.styleBuilder = new LineStyleBuilder(undefined, nStyleBuilder);
options.positions = new MapPosVector(native.getPoses());
}
}
createNative(options) {
const style = this.buildStyle();
if (options.positions) {
return NTLine.alloc().initWithPosesStyle(mapPosVectorFromArgs(options.positions, options.ignoreAltitude), style);
}
else if (options.geometry) {
return NTLine.alloc().initWithGeometryStyle(geometryFromArgs(options.geometry), style);
}
return null;
}
buildStyle() {
let style;
const styleBuilder = this.options.styleBuilder;
if (styleBuilder instanceof NTLineStyle) {
style = styleBuilder;
}
else if (styleBuilder instanceof LineStyleBuilder) {
style = styleBuilder.buildStyle();
}
else if (styleBuilder.hasOwnProperty) {
style = new LineStyleBuilder(styleBuilder).buildStyle();
}
return style;
}
get styleBuilder() {
return this.native ? this.native.getStyle() : this.options.styleBuilder;
}
set styleBuilder(value) {
if (this.native && !this.duringInit) {
this.options.styleBuilder = value;
this.native.setStyle(this.buildStyle());
}
}
setPoses(positions) {
this.positions = positions;
if (this.native) {
this.native.setPoses(mapPosVectorFromArgs(positions, this.options.ignoreAltitude));
}
}
getPoses() {
return this.positions;
}
set geometry(geometry) {
if (this.native) {
this.native.setGeometry(geometryFromArgs(geometry));
}
}
getGeometry() {
return this.getNative().getGeometry();
}
getBounds() {
const nBounds = this.getNative().getBounds();
return fromNativeMapBounds(nBounds);
}
}
__decorate([
styleBuilderProperty
], Line.prototype, "color", void 0);
__decorate([
styleBuilderProperty
], Line.prototype, "width", void 0);
__decorate([
styleBuilderProperty
], Line.prototype, "joinType", void 0);
__decorate([
styleBuilderProperty
], Line.prototype, "endType", void 0);
__decorate([
styleBuilderProperty
], Line.prototype, "clickWidth", void 0);
__decorate([
styleBuilderProperty
], Line.prototype, "stretchFactor", void 0);
//# sourceMappingURL=line.ios.js.map