Skip to content

Commit 1739e45

Browse files
committed
feat: geometry features
1 parent 6d61945 commit 1739e45

22 files changed

+393
-79
lines changed

src/geometry/feature.android.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ export class FeatureCollection implements IFeatureCollection {
99
const nResult = this.native.getFeature(index);
1010
return {
1111
properties: nativeVariantToJS(nResult.getProperties()),
12-
geometry: nResult.getGeometry() as Geometry,
12+
geometry: nResult.getGeometry(),
1313
} as Feature;
1414
}
1515
getGeometry(index: number) {
16-
return this.native.getFeature(index).getGeometry() as Geometry;
16+
return this.native.getFeature(index).getGeometry();
1717
}
1818
getFeatureCount() {
1919
return this.native.getFeatureCount();
@@ -35,7 +35,7 @@ export class VectorTileFeatureCollection extends FeatureCollection {
3535
const nResult = this.native.getFeature(index) as com.carto.geometry.VectorTileFeature;
3636
return {
3737
properties: nativeVariantToJS(nResult.getProperties()),
38-
geometry: nResult.getGeometry() as Geometry,
38+
geometry: nResult.getGeometry(),
3939
id: nResult.getId(),
4040
layerName: nResult.getLayerName(),
4141
} as VectorTileFeature;

src/geometry/feature.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Geometry } from '.';
22

3-
export interface Feature {
3+
export interface Feature<T = DefaultLatLonKeys> {
44
properties: {};
5-
geometry: Geometry;
5+
geometry: Geometry<T> | any;
66
// getProperties(): any;
77

88
// getGeometry(): Geometry;
@@ -14,14 +14,14 @@ export interface VectorTileFeature extends Feature {
1414
mapTile: any;
1515
}
1616

17-
export class FeatureCollection {
17+
export class FeatureCollection<T = DefaultLatLonKeys> {
1818
constructor(native: any);
19-
getFeature(index: number): Feature;
20-
getGeometry(index: number): Geometry;
19+
getFeature(index: number): Feature<T>;
20+
getGeometry(index: number): Geometry<T> | any;
2121
getFeatureCount(): number;
2222
readonly featureCount: number;
2323
getNative();
2424
}
25-
export class VectorTileFeatureCollection extends FeatureCollection {
26-
getFeature(index: number): VectorTileFeature;
25+
export class VectorTileFeatureCollection<T = DefaultLatLonKeys> extends FeatureCollection {
26+
getFeature(index: number): VectorTileFeature<T>;
2727
}

src/geometry/feature.ios.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Feature, FeatureCollection as IFeatureCollection, VectorTileFeature } from './feature';
22
import { nativeVariantToJS } from '../utils';
33
import { Geometry } from '.';
4+
import { DefaultLatLonKeys } from '../core';
45

56
export class FeatureCollection implements IFeatureCollection {
67
constructor(protected native: NTFeatureCollection) {}
@@ -10,11 +11,11 @@ export class FeatureCollection implements IFeatureCollection {
1011
// const nGeo = nResult.getGeometry();
1112
return {
1213
properties: nativeVariantToJS(nResult.getProperties()),
13-
geometry: nResult.getGeometry() as Geometry,
14+
geometry: nResult.getGeometry() as any,
1415
} as Feature;
1516
}
1617
getGeometry(index: number) {
17-
return this.native.getFeature(index).getGeometry() as Geometry;
18+
return this.native.getFeature(index).getGeometry() as any;
1819
}
1920

2021
getFeatureCount() {
@@ -37,7 +38,7 @@ export class VectorTileFeatureCollection extends FeatureCollection {
3738
const nResult = this.native.getFeature(index);
3839
return {
3940
properties: nativeVariantToJS(nResult.getProperties()),
40-
geometry: nResult.getGeometry() as Geometry,
41+
geometry: nResult.getGeometry(),
4142
id: nResult.getId(),
4243
layerName: nResult.getLayerName(),
4344
} as VectorTileFeature;

src/geometry/geojsonreader.android.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/geometry/geojsonreader.d.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/geometry/geojsonreader.ios.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/geometry/index.android.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { GeometryOptions, LineGeometryOptions, PointGeometryOptions } from '.';
2+
import { mapPosVectorFromArgs } from '..';
3+
import { MapPosVector, fromNativeMapBounds, fromNativeMapPos, toNativeMapPos } from '../core';
4+
import { BaseNative } from '../index.common';
5+
6+
export abstract class Geometry<T extends com.carto.geometry.Geometry, U extends GeometryOptions> extends BaseNative<T, U> {
7+
getCenterPos() {
8+
return fromNativeMapPos(this.getNative().getCenterPos());
9+
}
10+
getBounds() {
11+
return fromNativeMapBounds(this.getNative().getBounds());
12+
}
13+
}
14+
export class PointGeometry extends Geometry<com.carto.geometry.PointGeometry, PointGeometryOptions> {
15+
createNative(options: PointGeometryOptions) {
16+
return new com.carto.geometry.PointGeometry(toNativeMapPos(options.pos));
17+
}
18+
19+
getPos() {
20+
return fromNativeMapPos(this.getNative().getPos());
21+
}
22+
}
23+
export class LineGeometry extends Geometry<com.carto.geometry.LineGeometry, LineGeometryOptions> {
24+
createNative(options: LineGeometryOptions) {
25+
console.log('create native LineGeometry', options.poses, mapPosVectorFromArgs(options.poses));
26+
return new com.carto.geometry.LineGeometry(mapPosVectorFromArgs(options.poses));
27+
}
28+
29+
getPoses() {
30+
return new MapPosVector(this.getNative().getPoses());
31+
}
32+
}

src/geometry/index.d.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
import { MapBounds, MapPos } from '../core';
1+
import { DefaultLatLonKeys, GenericMapPos, MapBounds, MapPos, MapPosVector } from '../core';
2+
import { BaseNative } from '../index.common';
23

3-
export interface Geometry {
4-
getCenterPos(): any; // native pos
5-
getBounds(): any; // native bounds
4+
export interface GeometryOptions<T = DefaultLatLonKeys> {}
5+
export abstract class Geometry<T = DefaultLatLonKeys, U extends GeometryOptions = GeometryOptions> extends BaseNative<any, U> {
6+
getCenterPos(): GenericMapPos<T>;
7+
getBounds(): MapBounds<T>;
68
}
7-
export interface PointGeometry extends Geometry {
8-
getPos(): any; // native pos,
9+
10+
export interface PointGeometryOptions<T = DefaultLatLonKeys> extends GeometryOptions<T> {
11+
pos: GenericMapPos<T>;
12+
}
13+
export interface LineGeometryOptions<T = DefaultLatLonKeys> extends GeometryOptions<T> {
14+
poses: MapPosVector<T>;
15+
}
16+
export class PointGeometry<T = DefaultLatLonKeys> extends Geometry<T, PointGeometryOptions<T>> {
17+
getPos(): GenericMapPos<T>;
18+
}
19+
20+
export class LineGeometry<T = DefaultLatLonKeys> extends Geometry<T, LineGeometryOptions<T>> {
21+
getPoses(): MapPosVector<T>;
922
}

src/geometry/index.ios.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { GeometryOptions, LineGeometryOptions, PointGeometryOptions } from '.';
2+
import { mapPosVectorFromArgs } from '..';
3+
import { MapPosVector, fromNativeMapBounds, fromNativeMapPos, toNativeMapPos } from '../core';
4+
import { BaseNative } from '../index.common';
5+
6+
export abstract class Geometry<T extends NTGeometry, U extends GeometryOptions> extends BaseNative<T, U> {
7+
getCenterPos() {
8+
return fromNativeMapPos(this.getNative().getCenterPos());
9+
}
10+
getBounds() {
11+
return fromNativeMapBounds(this.getNative().getBounds());
12+
}
13+
}
14+
export class PointGeometry extends Geometry<NTPointGeometry, PointGeometryOptions> {
15+
createNative(options: PointGeometryOptions) {
16+
return NTPointGeometry.alloc().initWithPos(toNativeMapPos(options.pos));
17+
}
18+
19+
getPos() {
20+
return fromNativeMapPos(this.getNative().getPos());
21+
}
22+
}
23+
export class LineGeometry extends Geometry<NTLineGeometry, LineGeometryOptions> {
24+
createNative(options: LineGeometryOptions) {
25+
return NTLineGeometry.alloc().initWithPoses(mapPosVectorFromArgs(options.poses));
26+
}
27+
28+
getPoses() {
29+
return new MapPosVector(this.getNative().getPoses());
30+
}
31+
}

src/geometry/reader.android.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { BaseNative } from '../index.common';
2+
import { GeoJSONGeometryReaderOptions, WKBGeometryReaderOptions, WKTGeometryReaderOptions } from './reader';
3+
import { FeatureCollection } from './feature';
4+
import { Projection } from '../projections';
5+
import { nativeProperty } from '..';
6+
import { MapPosVector } from '../core';
7+
import { Geometry } from '.';
8+
import { LineGeometry, PointGeometry } from './index.android';
9+
10+
export class GeoJSONGeometryReader extends BaseNative<com.carto.geometry.GeoJSONGeometryReader, GeoJSONGeometryReaderOptions> {
11+
createNative() {
12+
return new com.carto.geometry.GeoJSONGeometryReader();
13+
}
14+
readFeatureCollection(str: string) {
15+
return new FeatureCollection(this.getNative().readFeatureCollection(str));
16+
}
17+
readGeometry(value: string) {
18+
const result = this.getNative().readGeometry(value);
19+
if (result instanceof com.carto.geometry.LineGeometry) {
20+
return new LineGeometry(null, result);
21+
} else if (result instanceof com.carto.geometry.PointGeometry) {
22+
return new PointGeometry(null, result);
23+
}
24+
return null;
25+
}
26+
set targetProjection(value: Projection) {
27+
this.native && this.native.setTargetProjection(value.getNative());
28+
}
29+
get targetProjection() {
30+
return this.options.targetProjection;
31+
}
32+
}
33+
34+
export class WKBGeometryReader extends BaseNative<com.carto.geometry.WKBGeometryReader, WKBGeometryReaderOptions> {
35+
@nativeProperty z: boolean;
36+
createNative() {
37+
return new com.carto.geometry.WKBGeometryReader();
38+
}
39+
readGeometry(value: number[] | ArrayBuffer | com.carto.core.BinaryData) {
40+
console.log('readGeometry', value instanceof com.carto.core.BinaryData);
41+
if (!(value instanceof com.carto.core.BinaryData)) {
42+
value = new com.carto.core.BinaryData(value as any);
43+
}
44+
const result = this.getNative().readGeometry(value);
45+
if (result instanceof com.carto.geometry.LineGeometry) {
46+
return new LineGeometry(null, result);
47+
} else if (result instanceof com.carto.geometry.PointGeometry) {
48+
return new PointGeometry(null, result);
49+
}
50+
return null;
51+
}
52+
}
53+
54+
export class WKTGeometryReader extends BaseNative<com.carto.geometry.WKTGeometryReader, WKTGeometryReaderOptions> {
55+
@nativeProperty z: boolean;
56+
createNative() {
57+
return new com.carto.geometry.WKTGeometryReader();
58+
}
59+
readGeometry(value) {
60+
const result = this.getNative().readGeometry(value);
61+
if (result instanceof com.carto.geometry.LineGeometry) {
62+
return new LineGeometry(null, result);
63+
} else if (result instanceof com.carto.geometry.PointGeometry) {
64+
return new PointGeometry(null, result);
65+
}
66+
return null;
67+
}
68+
}

0 commit comments

Comments
 (0)