@nativescript-community/ui-carto
Version:
NativeScript plugin for CARTO Mobile SDK
157 lines • 5.28 kB
JavaScript
import { geometryFromArgs, mapPosVectorFromArgs, nativeColorProperty, nativeProperty } from '..';
import { MapBounds, MapPosVector, fromNativeMapBounds } from '../core';
import { BaseLineVectorElement } from './index.android';
import { BaseVectorElementStyleBuilder, styleBuilderProperty } from './index.common';
export { MapBounds };
export const LineJointType = {
get BEVEL() {
return com.carto.styles.LineJoinType.LINE_JOIN_TYPE_BEVEL;
},
get MITER() {
return com.carto.styles.LineJoinType.LINE_JOIN_TYPE_MITER;
},
get NONE() {
return com.carto.styles.LineJoinType.LINE_JOIN_TYPE_NONE;
},
get ROUND() {
return com.carto.styles.LineJoinType.LINE_JOIN_TYPE_ROUND;
}
};
export const LineEndType = {
get ROUND() {
return com.carto.styles.LineEndType.LINE_END_TYPE_ROUND;
},
get SQUARE() {
return com.carto.styles.LineEndType.LINE_END_TYPE_SQUARE;
},
get NONE() {
return com.carto.styles.LineEndType.LINE_END_TYPE_NONE;
}
};
export class LineStyleBuilder extends BaseVectorElementStyleBuilder {
createNative(options) {
return new com.carto.styles.LineStyleBuilder();
}
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);
export class Line extends BaseLineVectorElement {
constructor(options = {}, native) {
super(options, native);
this.options = options;
if (native && !options.styleBuilder) {
const nStyle = native.getStyle();
const nStyleBuilder = new com.carto.styles.LineStyleBuilder();
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 new com.carto.vectorelements.Line(mapPosVectorFromArgs(options.positions, options.ignoreAltitude), style);
}
else if (options.geometry) {
return new com.carto.vectorelements.Line(geometryFromArgs(options.geometry), style);
}
return null;
}
buildStyle() {
let style;
const styleBuilder = this.options.styleBuilder;
if (styleBuilder instanceof com.carto.styles.LineStyle) {
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.rebuildStyle();
}
}
setPoses(positions) {
this.positions = positions;
if (this.native) {
this.native.setPoses(mapPosVectorFromArgs(positions, this.options.ignoreAltitude));
}
}
set geometry(geometry) {
if (this.native) {
this.native.setGeometry(geometryFromArgs(geometry));
}
}
getPoses() {
return this.positions || this.getNative().getPoses();
}
getGeometry() {
return this.getNative().getGeometry();
}
getBounds() {
const nBounds = this.getNative().getBounds();
// const nProjection = this.projection.getNative();
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.android.js.map