Skip to content

feat: added missing api methods to VectorElement #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/ui-carto/ui/cssproperties.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CssProperty, Style, booleanConverter } from '@nativescript/core';
import { LatitudeKey, LongitudeKey } from '../core';
import { GenericMapPos } from '../core/index.common';
import { GenericMapPos, LatitudeKey, LongitudeKey } from '../core';

export const zoomProperty = new CssProperty<Style, number>({
name: 'zoom',
Expand Down
3 changes: 1 addition & 2 deletions src/ui-carto/vectorelements/group.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BasePointVectorElement, PointVectorElementOptions, VectorElement, VectorElementVector } from '.';
import { MapPos } from '../core';
import { DefaultLatLonKeys, GenericMapPos, MapPos } from '../core';
import { Projection } from '../projections';
import { DefaultLatLonKeys, GenericMapPos } from '../core/index.common';

export class GroupOptions<T = DefaultLatLonKeys> extends PointVectorElementOptions<T> {
elements: { id: string; element: VectorElement<any, any> }[];
Expand Down
35 changes: 30 additions & 5 deletions src/ui-carto/vectorelements/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { AnimationStyle, BillboardStyleBuilderOptions, LineVectorElementOptions,
// import { BaseVectorElement } from './vectorelements.common';
import { nativeProperty } from '../index.common';
import { BaseNative } from '../BaseNative';
import { nativeMapToJS } from '../utils';
import { JSVariantToNative, nativeMapToJS, nativeVariantToJS } from '../utils';
import { Projection } from '../projections';
import { MapPos, MapPosVector, fromNativeMapPos, toNativeMapPos } from '../core';
import { MapPos, MapPosVector, fromNativeMapBounds, fromNativeMapPos, toNativeMapPos } from '../core';
import { mapPosVectorFromArgs } from '..';
import { BaseVectorElementStyleBuilder } from './index.common';
export { BaseVectorElementStyleBuilder };
Expand Down Expand Up @@ -38,24 +38,26 @@ export abstract class BaseVectorElement<T extends com.carto.vectorelements.Vecto
createNative(options: U) {
return null;
}

get metaData(): { [k: string]: string } {
if (this.native) {
return nativeMapToJS(this.native.getMetaData());
} else {
return this.options.metaData;
}
return this.options.metaData;
}
set metaData(value: { [k: string]: string }) {
this.options.metaData = value;
if (this.native) {
const theMap = new com.carto.core.StringVariantMap();
for (const key in value) {
theMap.set(key, new com.carto.core.Variant(value[key]));
theMap.set(key, JSVariantToNative(value[key]));
}
this.native.setMetaData(theMap);
}
}

abstract buildStyle();

rebuildStyle() {
(this.native as any).setStyle(this.buildStyle());
}
Expand Down Expand Up @@ -118,6 +120,29 @@ export abstract class BaseLineVectorElement<
}

export class VectorElement extends BaseVectorElement<com.carto.vectorelements.VectorElement, VectorElementOptions> {
@nativeProperty id: number;

containsMetaDataKey(key: string): boolean {
return this.native ? this.native.containsMetaDataKey(key) : false;
}
getMetadataElement(key: string): { [k: string]: string } {
if (this.native) {
return nativeVariantToJS(this.native.getMetaDataElement(key));
}
return undefined;
}
setMetadataElement(key: string, element: { [k: string]: string }): void {
if (this.native) {
this.native.setMetaDataElement(key, JSVariantToNative(element));
}
}
getGeometry() {
return this.getNative().getGeometry();
}
getBounds() {
return fromNativeMapBounds(this.getNative().getBounds());
}

buildStyle() {}
}

Expand Down
12 changes: 9 additions & 3 deletions src/ui-carto/vectorelements/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseNative } from '..';
import { MapPos, MapPosVector } from '../core';
import { DefaultLatLonKeys, GenericMapPos, MapBounds, MapPos, MapPosVector } from '../core';
import { Projection } from '../projections';
import { DefaultLatLonKeys, GenericMapPos } from '../core/index.common';
import { Geometry } from '../geometry';

declare enum BillboardOrientation {
FACE_CAMERA,
Expand Down Expand Up @@ -70,7 +70,13 @@ export abstract class BaseLineVectorElement<T, U extends LineVectorElementOption
positions?: MapPosVector<K> | GenericMapPos<K>[];
projection?: Projection;
}
export class VectorElement<T, U extends VectorElementOptions> extends BaseVectorElement<T, U> {}
export class VectorElement<T, U extends VectorElementOptions> extends BaseVectorElement<T, U> {
id?: number;
getBounds(): MapBounds<DefaultLatLonKeys>;
getGeometry(): Geometry<DefaultLatLonKeys>;
getMetadataElement(key: string): { [k: string]: string };
setMetadataElement(key: string, element: { [k: string]: string }): void;
}
export abstract class BaseVectorElementStyleBuilder<T, U extends VectorElementStyleBuilderOptions> extends BaseNative<T, U> {
buildStyle(): any;
}
Expand Down
35 changes: 30 additions & 5 deletions src/ui-carto/vectorelements/index.ios.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AnimationStyle, BillboardStyleBuilderOptions, LineVectorElementOptions, PointVectorElementOptions, VectorElementOptions } from '.';
import { nativeProperty } from '../index.common';
import { BaseNative } from '../BaseNative';
import { nativeMapToJS } from '../utils';
import { JSVariantToNative, nativeMapToJS, nativeVariantToJS } from '../utils';
import { Projection } from '../projections';
import { MapPos, MapPosVector, fromNativeMapPos, toNativeMapPos } from '../core';
import { MapPos, MapPosVector, fromNativeMapBounds, fromNativeMapPos, toNativeMapPos } from '../core';
import { mapPosVectorFromArgs } from '..';
import { BaseVectorElementStyleBuilder } from './index.common';
export { BaseVectorElementStyleBuilder };
Expand Down Expand Up @@ -37,24 +37,26 @@ export abstract class BaseVectorElement<T extends NTVectorElement, U extends Vec
createNative(options: U) {
return null;
}

get metaData(): { [k: string]: string } {
if (this.native) {
return nativeMapToJS(this.native.getMetaData());
} else {
return this.options.metaData;
}
return this.options.metaData;
}
set metaData(value: { [k: string]: string }) {
this.options.metaData = value;
if (this.native) {
const theMap = NTStringVariantMap.alloc().init();
for (const key in value) {
theMap.setX(key, NTVariant.alloc().initWithString(value[key]));
theMap.setX(key, JSVariantToNative(value[key]));
}
this.native.setMetaData(theMap);
}
}

abstract buildStyle();

rebuildStyle() {
(this.native as any).setStyle(this.buildStyle());
}
Expand Down Expand Up @@ -124,6 +126,29 @@ export abstract class BaseLineVectorElement<
}

export class VectorElement extends BaseVectorElement<NTVectorElement, VectorElementOptions> {
@nativeProperty id: number;

containsMetaDataKey(key: string): boolean {
return this.native ? this.native.containsMetaDataKey(key) : false;
}
getMetadataElement(key: string): { [k: string]: string } {
if (this.native) {
return nativeVariantToJS(this.native.getMetaDataElement(key));
}
return undefined;
}
setMetadataElement(key: string, element: { [k: string]: string }): void {
if (this.native) {
this.native.setMetaDataElementElement(key, JSVariantToNative(element));
}
}
getGeometry() {
return this.getNative().getGeometry();
}
getBounds() {
return fromNativeMapBounds(this.getNative().getBounds());
}

buildStyle() {}
}
export class VectorElementVector extends BaseNative<NTVectorElementVector, any> {
Expand Down
20 changes: 10 additions & 10 deletions src/ui-carto/vectorelements/line.android.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Color } from '@nativescript/core';
import { geometryFromArgs, mapPosVectorFromArgs, nativeAndroidEnumProperty, nativeColorProperty, nativeProperty } from '..';
import { geometryFromArgs, mapPosVectorFromArgs, nativeColorProperty, nativeProperty } from '..';
import { MapBounds, MapPos, MapPosVector, fromNativeMapBounds } from '../core';
import { LineGeometry } from '../geometry';
import { BaseLineVectorElement } from './index.android';
Expand Down Expand Up @@ -115,27 +115,27 @@ export class Line extends BaseLineVectorElement<com.carto.vectorelements.Line, L
this.rebuildStyle();
}
}

setPoses(positions: MapPosVector | MapPos[]) {
this.positions = positions;
if (this.native) {
this.native.setPoses(mapPosVectorFromArgs(positions, this.options.ignoreAltitude));
}
get geometry(): com.carto.geometry.LineGeometry {
return this.getGeometry();
}
set geometry(geometry: LineGeometry) {
if (this.native) {
this.native.setGeometry(geometryFromArgs(geometry));
}
}
setPoses(positions: MapPosVector | MapPos[]) {
this.positions = positions;
if (this.native) {
this.native.setPoses(mapPosVectorFromArgs(positions, this.options.ignoreAltitude));
}
}
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);
return fromNativeMapBounds(this.getNative().getBounds());
}
}
3 changes: 1 addition & 2 deletions src/ui-carto/vectorelements/line.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Projection } from '../projections';
import { MapBounds, MapPos, MapPosVector } from '../core';
import { DefaultLatLonKeys, GenericMapPos, MapBounds, MapPosVector } from '../core';
import { BaseLineVectorElement, BaseVectorElementStyleBuilder, LineVectorElementOptions, VectorElementOptions } from '.';
import { Color } from '@nativescript/core';
import { Geometry, LineGeometry } from '../geometry';
import { DefaultLatLonKeys, GenericMapPos } from '../core/index.common';

declare enum LineJointType {
FaceCamera,
Expand Down
6 changes: 4 additions & 2 deletions src/ui-carto/vectorelements/line.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ export class Line extends BaseLineVectorElement<NTLine, LineOptions> {
getPoses() {
return this.positions;
}
get geometry(): NTLineGeometry {
return this.getGeometry();
}
set geometry(geometry: LineGeometry) {
if (this.native) {
this.native.setGeometry(geometryFromArgs(geometry));
Expand All @@ -132,7 +135,6 @@ export class Line extends BaseLineVectorElement<NTLine, LineOptions> {
return this.getNative().getGeometry();
}
getBounds() {
const nBounds = this.getNative().getBounds();
return fromNativeMapBounds(nBounds);
return fromNativeMapBounds(this.getNative().getBounds());
}
}