Skip to content

Commit 7608ebb

Browse files
committed
chore: android raster click
# Conflicts: # src/layers/raster.android.ts
1 parent e63c0f9 commit 7608ebb

File tree

1 file changed

+64
-5
lines changed

1 file changed

+64
-5
lines changed

src/layers/raster.android.ts

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
import { CartoOnlineRasterTileLayerOptions, HillshadeRasterTileLayerOptions, RasterTileFilterMode as IRasterTileFilterMode, RasterTileLayerOptions } from './raster';
1+
import {
2+
CartoOnlineRasterTileLayerOptions,
3+
HillshadeRasterTileLayerOptions,
4+
RasterTileEventListener as IRasterTileEventListener,
5+
RasterTileFilterMode as IRasterTileFilterMode,
6+
RasterTileLayerOptions,
7+
} from './raster';
28
import { RasterTileLayerBase } from './raster.common';
39
import { mapPosVectorFromArgs, nativeAndroidEnumProperty, nativeColorProperty, nativeProperty } from '../';
410
import { Color } from '@nativescript/core/color';
5-
import { IntVector, MapPos, MapPosVector, toNativeMapPos } from '../core';
11+
import { IntVector, MapPos, MapPosVector, MapVec, fromNativeMapPos, toNativeMapPos } from '../core';
12+
import { Projection } from '../projections';
613

714
export const RasterTileFilterMode = {
815
get RASTER_TILE_FILTER_MODE_NEAREST() {
@@ -16,8 +23,60 @@ export const RasterTileFilterMode = {
1623
},
1724
};
1825

19-
export class RasterTileLayer extends RasterTileLayerBase<com.carto.layers.RasterTileLayer, RasterTileLayerOptions> {
20-
@nativeAndroidEnumProperty(com.carto.layers.RasterTileFilterMode, {}) tileFilterMode: IRasterTileFilterMode;
26+
export abstract class RasterTileLayerCommon<NativeClass extends com.carto.layers.RasterTileLayer, U extends RasterTileLayerOptions> extends RasterTileLayerBase<NativeClass, U> {
27+
projection?: Projection;
28+
clickListener?: IRasterTileEventListener;
29+
nClickListener?: com.akylas.carto.additions.AKRasterTileEventListener;
30+
constructor(options) {
31+
super(options);
32+
for (const property of ['elementListener', 'nElementListener']) {
33+
const descriptor = Object.getOwnPropertyDescriptor(RasterTileLayer.prototype, property);
34+
if (descriptor) {
35+
descriptor.enumerable = false;
36+
}
37+
}
38+
}
39+
setRasterTileEventListener(listener: IRasterTileEventListener, projection?: Projection) {
40+
this.clickListener = listener;
41+
this.projection = projection;
42+
if (listener) {
43+
if (!this.nClickListener) {
44+
this.nClickListener = new com.akylas.carto.additions.AKRasterTileEventListener(
45+
new com.akylas.carto.additions.AKRasterTileEventListener.Listener({
46+
onRasterTileClicked: this.onRasterTileClicked.bind(this),
47+
})
48+
);
49+
}
50+
this.getNative().setRasterTileEventListener(this.nClickListener);
51+
} else {
52+
this.nClickListener = null;
53+
this.getNative().setRasterTileEventListener(null);
54+
}
55+
}
56+
onRasterTileClicked(info: com.carto.ui.RasterTileClickInfo) {
57+
if (this.clickListener && this.clickListener.onRasterTileClicked) {
58+
let position = info.getClickPos();
59+
if (this.projection) {
60+
const layerProj = this.getNative().getDataSource().getProjection();
61+
const nProj = this.projection.getNative();
62+
position = nProj.fromWgs84(layerProj.toWgs84(position));
63+
}
64+
return (
65+
this.clickListener.onRasterTileClicked.call(this.clickListener, {
66+
clickType: info.getClickType().swigValue(),
67+
layer: this,
68+
nearestColor: new Color(info.getNearestColor().getARGB()),
69+
interpolatedColor: new Color(info.getInterpolatedColor().getARGB()),
70+
position: fromNativeMapPos(position),
71+
}) || false
72+
);
73+
}
74+
return false;
75+
}
76+
}
77+
78+
export class RasterTileLayer extends RasterTileLayerCommon<com.carto.layers.RasterTileLayer, RasterTileLayerOptions> {
79+
@nativeProperty tileFilterMode: IRasterTileFilterMode;
2180
createNative(options: RasterTileLayerOptions) {
2281
return new com.carto.layers.RasterTileLayer(options.dataSource.getNative());
2382
}
@@ -29,7 +88,7 @@ export class CartoOnlineRasterTileLayer extends RasterTileLayerBase<com.carto.la
2988
}
3089
}
3190

32-
export class HillshadeRasterTileLayer extends RasterTileLayerBase<com.akylas.carto.additions.AKHillshadeRasterTileLayer, HillshadeRasterTileLayerOptions> {
91+
export class HillshadeRasterTileLayer extends RasterTileLayerCommon<com.akylas.carto.additions.AKHillshadeRasterTileLayer, HillshadeRasterTileLayerOptions> {
3392
@nativeProperty heightScale: number;
3493
@nativeProperty contrast: number;
3594
@nativeProperty illuminationDirection: number;

0 commit comments

Comments
 (0)