Skip to content

Commit 65957fe

Browse files
committed
fix(ios): Layers fix
1 parent feed49e commit 65957fe

File tree

3 files changed

+103
-42
lines changed

3 files changed

+103
-42
lines changed

Diff for: src/ui-carto/ui/index.android.ts

+47-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ import {
77
fromNativeMapBounds,
88
fromNativeMapPos,
99
fromNativeScreenPos,
10+
nativeVectorToArray,
1011
toNativeMapBounds,
1112
toNativeMapPos,
1213
toNativeScreenBounds,
1314
toNativeScreenPos
1415
} from '../core';
15-
import { TileLayer } from '../layers';
16+
import { Layer, TileLayer } from '../layers';
1617
import { IProjection } from '../projections';
1718
import { restrictedPanningProperty } from './cssproperties';
1819
import {
20+
Layers as BaseLayers,
1921
CartoViewBase,
20-
Layers,
2122
MapClickedEvent,
2223
MapIdleEvent,
2324
MapInteractionEvent,
@@ -249,7 +250,7 @@ export class CartoMap<T = DefaultLatLonKeys> extends CartoViewBase {
249250

250251
getLayers() {
251252
if (this.mapView) {
252-
return new Layers<com.carto.components.Layers>(this.mapView.getLayers());
253+
return new Layers(this.mapView.getLayers());
253254
}
254255
return null;
255256
}
@@ -336,3 +337,46 @@ export const useTextureViewProperty = new Property<CartoMap, boolean>({
336337
valueConverter: booleanConverter
337338
});
338339
useTextureViewProperty.register(CartoMap);
340+
341+
export class Layers extends BaseLayers<com.carto.components.Layers> {
342+
count() {
343+
return this.native.count();
344+
}
345+
insert(index: number, layer: Layer<any, any>) {
346+
return this.native.insert(index, layer.getNative());
347+
}
348+
//@ts-ignore
349+
set(index: number, layer: Layer<any, any>) {
350+
return this.native.set(index, layer.getNative());
351+
}
352+
removeAll(layers: Layer<any, any>[]) {
353+
layers.forEach(this.remove);
354+
}
355+
remove(layer: Layer<any, any>) {
356+
return this.native.remove(layer.getNative());
357+
}
358+
add(layer: Layer<any, any>) {
359+
return this.native.add(layer.getNative());
360+
}
361+
//@ts-ignore
362+
get(index: number) {
363+
return this.native.get(index);
364+
}
365+
addAll(layers: Layer<any, any>[]) {
366+
layers.forEach(this.add);
367+
}
368+
setAll(layers: Layer<any, any>[]) {
369+
this.clear();
370+
this.addAll(layers);
371+
}
372+
getAll() {
373+
return nativeVectorToArray(this.native.getAll());
374+
}
375+
clear() {
376+
return this.native.clear();
377+
}
378+
379+
// public getNative() {
380+
// return this.native;
381+
// }
382+
}

Diff for: src/ui-carto/ui/index.common.ts

+12-35
Original file line numberDiff line numberDiff line change
@@ -78,46 +78,23 @@ export function mapProperty(...args) {
7878
}
7979
}
8080

81-
export class Layers<T extends any> extends BaseNative<any, {}> {
81+
export abstract class Layers<T = any> extends BaseNative<T, {}> {
8282
constructor(native) {
8383
super(null, native);
8484
}
85-
count() {
86-
return this.native.count();
87-
}
88-
insert(index: number, layer: Layer<any, any>) {
89-
return this.native.insert(index, layer.getNative());
90-
}
85+
abstract count(): number;
86+
abstract insert(index: number, layer: Layer<any, any>);
87+
abstract removeAll(layers: Layer<any, any>[]);
88+
abstract remove(layer: Layer<any, any>);
89+
abstract add(layer: Layer<any, any>);
9190
//@ts-ignore
92-
set(index: number, layer: Layer<any, any>) {
93-
return this.native.set(index, layer.getNative());
94-
}
95-
removeAll(layers: Layer<any, any>[]) {
96-
layers.forEach(this.remove);
97-
}
98-
remove(layer: Layer<any, any>) {
99-
return this.native.remove(layer.getNative());
100-
}
101-
add(layer: Layer<any, any>) {
102-
return this.native.add(layer.getNative());
103-
}
91+
abstract set(index: number, layer: Layer<any, any>);
10492
//@ts-ignore
105-
get(index: number) {
106-
return this.native.get(index);
107-
}
108-
addAll(layers: Layer<any, any>[]) {
109-
layers.forEach(this.add);
110-
}
111-
setAll(layers: Layer<any, any>[]) {
112-
this.clear();
113-
this.addAll(layers);
114-
}
115-
getAll() {
116-
return nativeVectorToArray(this.native.getAll());
117-
}
118-
clear() {
119-
return this.native.clear();
120-
}
93+
abstract get(index: number): Layer<any, any>;
94+
abstract addAll(layers: Layer<any, any>[]);
95+
abstract setAll(layers: Layer<any, any>[]);
96+
abstract getAll(): Layer<any, any>[];
97+
abstract clear();
12198

12299
// public getNative() {
123100
// return this.native;

Diff for: src/ui-carto/ui/index.ios.ts

+44-4
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ import {
77
fromNativeMapBounds,
88
fromNativeMapPos,
99
fromNativeScreenPos,
10+
nativeVectorToArray,
1011
toNativeMapPos,
1112
toNativeScreenBounds,
1213
toNativeScreenPos
1314
} from '../core';
14-
import { TileLayer } from '../layers';
15+
import { Layer, TileLayer } from '../layers';
1516
import { EPSG4326 } from '../projections/epsg4326';
1617
import { IProjection } from '../projections';
1718
import { restrictedPanningProperty } from './cssproperties';
1819
import { MapOptions } from '.';
1920
import {
21+
Layers as BaseLayers,
2022
CartoViewBase,
21-
Layers,
2223
MapClickedEvent,
2324
MapIdleEvent,
2425
MapInteractionEvent,
@@ -74,7 +75,7 @@ function mainThread(target: any, propertyKey: string, descriptor: PropertyDescri
7475
}
7576

7677
@NativeClass
77-
class AKMapEventListenerImpl extends NSObject implements AKMapEventListener {
78+
class AKMapEventListenerImpl extends NSObject implements AKMapEventListener {
7879
public static ObjCProtocols = [AKMapEventListener];
7980
private _owner: WeakRef<CartoMap<any>>;
8081

@@ -308,7 +309,7 @@ export class CartoMap<T = DefaultLatLonKeys> extends CartoViewBase {
308309

309310
getLayers() {
310311
if (this.mapView) {
311-
return new Layers<NTLayers>(this.mapView.getLayers());
312+
return new Layers(this.mapView.getLayers());
312313
}
313314
return null;
314315
}
@@ -382,3 +383,42 @@ export class CartoMap<T = DefaultLatLonKeys> extends CartoViewBase {
382383
});
383384
}
384385
}
386+
387+
export class Layers extends BaseLayers<NTLayers> {
388+
count() {
389+
return this.native.count();
390+
}
391+
insert(index: number, layer: Layer<any, any>) {
392+
return this.native.insertLayer(index, layer.getNative());
393+
}
394+
//@ts-ignore
395+
set(index: number, layer: Layer<any, any>) {
396+
return this.native.setLayer(index, layer.getNative());
397+
}
398+
removeAll(layers: Layer<any, any>[]) {
399+
layers.forEach(this.remove);
400+
}
401+
remove(layer: Layer<any, any>) {
402+
return this.native.remove(layer.getNative());
403+
}
404+
add(layer: Layer<any, any>) {
405+
return this.native.add(layer.getNative());
406+
}
407+
//@ts-ignore
408+
get(index: number) {
409+
return this.native.get(index);
410+
}
411+
addAll(layers: Layer<any, any>[]) {
412+
layers.forEach(this.add);
413+
}
414+
setAll(layers: Layer<any, any>[]) {
415+
this.clear();
416+
this.addAll(layers);
417+
}
418+
getAll() {
419+
return nativeVectorToArray(this.native.getAll());
420+
}
421+
clear() {
422+
return this.native.clear();
423+
}
424+
}

0 commit comments

Comments
 (0)