|
1 | | -import { CartoOnlineRasterTileLayerOptions, HillshadeRasterTileLayerOptions, RasterTileLayerOptions } from './raster'; |
| 1 | +import { CartoOnlineRasterTileLayerOptions, HillshadeRasterTileLayerOptions, RasterTileEventListener as IRasterTileEventListener, RasterTileLayerOptions } from './raster'; |
2 | 2 | import { RasterTileLayerBase } from './raster.common'; |
3 | 3 | import { nativeProperty } from '../'; |
| 4 | +import { Projection } from '../projections'; |
| 5 | +import { fromNativeMapPos } from '../core'; |
| 6 | +import { Color } from '@nativescript/core'; |
4 | 7 |
|
5 | | -export class RasterTileLayer extends RasterTileLayerBase<NTRasterTileLayer, RasterTileLayerOptions> { |
| 8 | +@NativeClass |
| 9 | +export class NTRasterTileEventListenerImpl extends NTRasterTileEventListener { |
| 10 | + private _layer: WeakRef<RasterTileLayer>; |
| 11 | + private _owner: WeakRef<IRasterTileEventListener>; |
| 12 | + private projection?: Projection; |
| 13 | + |
| 14 | + public static initWithOwner(owner: WeakRef<IRasterTileEventListener>, layer: WeakRef<RasterTileLayer>, projection?: Projection): NTRasterTileEventListenerImpl { |
| 15 | + const delegate = NTRasterTileEventListenerImpl.new() as NTRasterTileEventListenerImpl; |
| 16 | + delegate._owner = owner; |
| 17 | + delegate._layer = layer; |
| 18 | + delegate.projection = projection; |
| 19 | + return delegate; |
| 20 | + } |
| 21 | + public onRasterTileClicked(info: NTRasterTileClickInfo) { |
| 22 | + const owner = this._owner.get(); |
| 23 | + if (owner && owner.onRasterTileClicked) { |
| 24 | + let position = info.getClickPos(); |
| 25 | + if (this.projection) { |
| 26 | + const layerProj = this._layer.get().getNative().getDataSource().getProjection(); |
| 27 | + const nProj = this.projection.getNative(); |
| 28 | + position = nProj.fromWgs84(layerProj.toWgs84(position)); |
| 29 | + } |
| 30 | + return ( |
| 31 | + owner.onRasterTileClicked({ |
| 32 | + clickType: info.getClickType() as any, |
| 33 | + layer: this._layer.get() as any, |
| 34 | + nearestColor: new Color(info.getNearestColor().getARGB()), |
| 35 | + interpolatedColor: new Color(info.getInterpolatedColor().getARGB()), |
| 36 | + position: fromNativeMapPos(position), |
| 37 | + }) || false |
| 38 | + ); |
| 39 | + } |
| 40 | + return false; |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +export abstract class RasterTileLayerCommon<NativeClass extends NTRasterTileLayer, U extends RasterTileLayerOptions> extends RasterTileLayerBase<NativeClass, U> { |
| 45 | + setRasterTileEventListener(listener: IRasterTileEventListener, projection?: Projection) { |
| 46 | + if (listener) { |
| 47 | + this.getNative().setRasterTileEventListener(NTRasterTileEventListenerImpl.initWithOwner(new WeakRef(listener), new WeakRef(this), projection)); |
| 48 | + } else { |
| 49 | + this.getNative().setRasterTileEventListener(null); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +export class RasterTileLayer extends RasterTileLayerCommon<NTRasterTileLayer, RasterTileLayerOptions> { |
6 | 55 | createNative(options: RasterTileLayerOptions) { |
7 | 56 | return NTRasterTileLayer.alloc().initWithDataSource(options.dataSource.getNative()); |
8 | 57 | } |
| 58 | + setRasterTileEventListener(listener: IRasterTileEventListener, projection?: Projection) { |
| 59 | + if (listener) { |
| 60 | + this.getNative().setRasterTileEventListener(NTRasterTileEventListenerImpl.initWithOwner(new WeakRef(listener), new WeakRef(this), projection)); |
| 61 | + } else { |
| 62 | + this.getNative().setRasterTileEventListener(null); |
| 63 | + } |
| 64 | + } |
9 | 65 | } |
10 | 66 |
|
11 | 67 | export class CartoOnlineRasterTileLayer extends RasterTileLayerBase<NTCartoOnlineRasterTileLayer, CartoOnlineRasterTileLayerOptions> { |
|
0 commit comments