Skip to content

Commit c35ecb1

Browse files
committed
fix: a lot of fixes and improvements
# Conflicts: # src/index.ios.ts # src/projections/epsg3857.d.ts # src/projections/epsg4326.d.ts # src/projections/index.d.ts # src/search/index.d.ts
1 parent 5037837 commit c35ecb1

26 files changed

+92
-60
lines changed

plugin/platforms/android/java/com/akylas/carto/additions/AKVectorTileSearchService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ public AKVectorTileSearchService(TileDataSource source, VectorTileDecoder decode
2222
static Handler mainHandler = null;
2323

2424
public void findFeaturesCallback(final SearchRequest request, final VectorTileSearchServiceCallback callback) {
25+
final AKVectorTileSearchService that = this;
2526
new Thread(new Runnable() {
2627
@Override
2728
public void run() {
28-
final VectorTileFeatureCollection results = AKVectorTileSearchService.this.findFeatures(request);
29+
final VectorTileFeatureCollection results = that.findFeatures(request);
2930
if (AKMapView.RUN_ON_MAIN_THREAD) {
3031
if (mainHandler == null) {
3132
mainHandler = new Handler(android.os.Looper.getMainLooper());

src/core/index.android.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ export function toNativeMapRange(value: MapRange) {
114114
// ignore z for now as points can get under the map!
115115
return new com.carto.core.MapRange(value.min, value.max);
116116
}
117-
export function toNativeMapVec(value: MapVec) {
117+
export function toNativeMapVec(value: MapVec | [number, number, number]) {
118+
if (Array.isArray(value)) {
119+
return new com.carto.core.MapVec(value[0], value[1], value[2]);
120+
}
118121
if (value instanceof com.carto.core.MapVec) {
119122
return value;
120123
}

src/core/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export declare function toNativeScreenPos(position: ScreenPos): any;
1313
export declare function fromNativeScreenBounds(pos): ScreenBounds;
1414
export declare function toNativeScreenBounds(position: ScreenBounds): any;
1515
export declare function fromNativeMapVec(value): MapVec;
16-
export declare function toNativeMapVec(value: MapVec): any;
16+
export declare function toNativeMapVec(value: MapVec | [number, number, number]): any;
1717
export declare function fromNativeMapRange(value): MapRange;
1818
export declare function toNativeMapRange(value: MapRange): any;
1919
export declare function setMapPosKeys(latitude: LatitudeKeys, longitude: LongitudeKeys, altitude?: AltitudeKeys);

src/core/index.ios.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ export function toNativeMapRange(value: MapRange) {
105105
// ignore z for now as points can get under the map!
106106
return NTMapRange.alloc().initWithMinMax(value.min, value.max);
107107
}
108-
export function toNativeMapVec(value: MapVec) {
108+
export function toNativeMapVec(value: MapVec | [number, number, number]) {
109+
if (Array.isArray(value)) {
110+
return NTMapVec.alloc().initWithXYZ(value[0], value[1], value[2]);
111+
}
109112
if (value instanceof NTMapVec) {
110113
return value;
111114
}

src/datasources/index.android.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DataSourceOptions, GeoJSONVectorTileDataSourceOptions, MergedMBVTTileDataSourceOptions, OrderedTileDataSourceOptions, TileDataSourceOptions } from '.';
1+
import { CombinedTileDataSourceOptions, DataSourceOptions, GeoJSONVectorTileDataSourceOptions, MergedMBVTTileDataSourceOptions, OrderedTileDataSourceOptions, TileDataSourceOptions } from '.';
22
import { BaseNative } from '../index.common';
33
import { Projection } from '../projections';
44
import { FeatureCollection } from '../geometry/feature';
@@ -33,17 +33,21 @@ export class TileDataSource<T extends com.carto.datasources.TileDataSource, U ex
3333

3434
export class OrderedTileDataSource extends TileDataSource<com.carto.datasources.OrderedTileDataSource, OrderedTileDataSourceOptions> {
3535
createNative(options: OrderedTileDataSourceOptions) {
36-
const array: com.carto.datasources.TileDataSource[] = Array.create(com.carto.datasources.TileDataSource, options.dataSources.length);
37-
options.dataSources.forEach((d, i) => (array[i] = d.getNative()));
38-
return new com.carto.datasources.OrderedTileDataSource(array[0], array[1]);
36+
const dataSources: com.carto.datasources.TileDataSource[] = options.dataSources.map((d) => d.getNative());
37+
return new com.carto.datasources.OrderedTileDataSource(dataSources[0], dataSources[1]);
38+
}
39+
}
40+
export class CombinedTileDataSource extends TileDataSource<com.carto.datasources.CombinedTileDataSource, CombinedTileDataSourceOptions> {
41+
createNative(options: CombinedTileDataSourceOptions) {
42+
const dataSources: com.carto.datasources.TileDataSource[] = options.dataSources.map((d) => d.getNative());
43+
return new com.carto.datasources.CombinedTileDataSource(dataSources[0], dataSources[1], options.zoomLevel);
3944
}
4045
}
4146

4247
export class MergedMBVTTileDataSource extends TileDataSource<com.carto.datasources.MergedMBVTTileDataSource, MergedMBVTTileDataSourceOptions> {
4348
createNative(options: MergedMBVTTileDataSourceOptions) {
44-
const array: com.carto.datasources.TileDataSource[] = Array.create(com.carto.datasources.TileDataSource, options.dataSources.length);
45-
options.dataSources.forEach((d, i) => (array[i] = d.getNative()));
46-
return new com.carto.datasources.MergedMBVTTileDataSource(array[0], array[1]);
49+
const dataSources: com.carto.datasources.TileDataSource[] = options.dataSources.map((d) => d.getNative());
50+
return new com.carto.datasources.MergedMBVTTileDataSource(dataSources[0], dataSources[1]);
4751
}
4852
}
4953

src/datasources/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ export class TileDataSource<T, U extends TileDataSourceOptions> extends DataSour
1818
export interface OrderedTileDataSourceOptions extends DataSourceOptions {
1919
dataSources: TileDataSource<any, any>[];
2020
}
21+
export interface CombinedTileDataSourceOptions extends DataSourceOptions {
22+
dataSources: TileDataSource<any, any>[];
23+
zoomLevel: number;
24+
}
2125
export class OrderedTileDataSource<T, U extends OrderedTileDataSourceOptions> extends TileDataSource<T, U> {}
2226

2327
export interface MergedMBVTTileDataSourceOptions extends DataSourceOptions {
2428
dataSources: TileDataSource<any, any>[];
2529
}
2630
export class MergedMBVTTileDataSource<T, U extends MergedMBVTTileDataSourceOptions> extends TileDataSource<T, U> {}
31+
export class CombinedTileDataSource<T, U extends CombinedTileDataSourceOptions> extends TileDataSource<T, U> {}
2732

2833
export interface GeoJSONVectorTileDataSourceOptions extends TileDataSourceOptions {}
2934
export class GeoJSONVectorTileDataSource extends TileDataSource<any, GeoJSONVectorTileDataSourceOptions> {

src/datasources/index.ios.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BaseNative } from '../index.common';
2-
import { DataSourceOptions, GeoJSONVectorTileDataSourceOptions, MergedMBVTTileDataSourceOptions, OrderedTileDataSourceOptions, TileDataSourceOptions } from '.';
2+
import { CombinedTileDataSourceOptions, DataSourceOptions, GeoJSONVectorTileDataSourceOptions, MergedMBVTTileDataSourceOptions, OrderedTileDataSourceOptions, TileDataSourceOptions } from '.';
33
import { JSVariantToNative } from '../utils';
44
import { FeatureCollection } from '../geometry/feature.ios';
55
import { Projection } from '../projections';
@@ -25,6 +25,12 @@ export class OrderedTileDataSource extends TileDataSource<NTOrderedTileDataSourc
2525
}
2626
}
2727

28+
export class CombinedTileDataSource extends TileDataSource<NTCombinedTileDataSource, CombinedTileDataSourceOptions> {
29+
createNative(options: CombinedTileDataSourceOptions) {
30+
const dataSources: NTTileDataSource[] = options.dataSources.map((d) => d.getNative());
31+
return NTCombinedTileDataSource.alloc().initWithDataSource1DataSource2ZoomLevel(dataSources[0], dataSources[1], options.zoomLevel);
32+
}
33+
}
2834
export class MergedMBVTTileDataSource extends TileDataSource<NTMergedMBVTTileDataSource, MergedMBVTTileDataSourceOptions> {
2935
createNative(options: MergedMBVTTileDataSourceOptions) {
3036
const dataSources: NTTileDataSource[] = options.dataSources.map(d => d.getNative());

src/geometry/feature.android.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ export class FeatureCollection implements IFeatureCollection {
3434
for (let index = 0; index < featureCount; index++) {
3535
const geometry = this.getGeometry(index);
3636
const bounds = fromNativeMapBounds(geometry.getBounds());
37-
minLat = Math.min(minLat, bounds.northeast[LatitudeKey]);
38-
minLon = Math.min(minLon, bounds.northeast[LongitudeKey]);
39-
maxLat = Math.max(maxLat, bounds.southwest[LatitudeKey]);
40-
maxLon = Math.max(maxLon, bounds.southwest[LongitudeKey]);
37+
minLat = Math.min(minLat, bounds.southwest[LatitudeKey]);
38+
minLon = Math.min(minLon, bounds.southwest[LongitudeKey]);
39+
maxLat = Math.max(maxLat, bounds.northeast[LatitudeKey]);
40+
maxLon = Math.max(maxLon, bounds.northeast[LongitudeKey]);
4141
}
4242
return new MapBounds(
43-
{
44-
[LatitudeKey]: minLat,
45-
[LongitudeKey]: minLon,
46-
},
4743
{
4844
[LatitudeKey]: maxLat,
4945
[LongitudeKey]: maxLon,
46+
},
47+
{
48+
[LatitudeKey]: minLat,
49+
[LongitudeKey]: minLon,
5050
}
5151
);
5252
}

src/geometry/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export interface PointGeometryOptions<T = DefaultLatLonKeys> extends GeometryOpt
1111
pos: GenericMapPos<T>;
1212
}
1313
export interface LineGeometryOptions<T = DefaultLatLonKeys> extends GeometryOptions<T> {
14-
poses: MapPosVector<T>;
14+
poses: MapPosVector<T> | GenericMapPos<T>[];
1515
}
1616
export interface PolygonGeometryOptions<T = DefaultLatLonKeys> extends GeometryOptions<T> {
17-
poses: MapPosVector<T>;
17+
poses: MapPosVector<T> | GenericMapPos<T>[];
1818
}
1919
export class PointGeometry<T = DefaultLatLonKeys> extends Geometry<T, PointGeometryOptions<T>> {
2020
getPos(): GenericMapPos<T>;

src/index.android.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable no-redeclare */
22
import { Color } from '@nativescript/core/color';
33
import { NativePropertyOptions } from '.';
4-
import { BaseNative, _createImageSourceFromSrc, nativeProperty } from './index.common';
4+
import { BaseNative, _createImageSourceFromSrc, nativeMapVecProperty, nativeProperty } from './index.common';
55
import { DefaultLatLonKeys, GenericMapPos, MapPos, MapPosVector, MapPosVectorVector, toNativeMapPos } from './core';
66
import { FeatureCollection } from './geometry/feature';
77
import { Geometry } from './geometry';
8-
export { BaseNative, nativeProperty };
8+
export { BaseNative, nativeProperty, nativeMapVecProperty };
99

1010
export function nativeColorProperty(target: any, k?, desc?: PropertyDescriptor): any;
1111
export function nativeColorProperty(options: NativePropertyOptions): (target: any, k?, desc?: PropertyDescriptor) => any;

0 commit comments

Comments
 (0)