diff --git a/src/ui-mapbox/common.ts b/src/ui-mapbox/common.ts index e64fba1..b64260a 100755 --- a/src/ui-mapbox/common.ts +++ b/src/ui-mapbox/common.ts @@ -703,6 +703,8 @@ export interface MapboxApi { removeImage(imageId: string, nativeMap?: any): Promise; project(data: LatLng): { x: number; y: number }; + + projectBack(point: { x: number, y: number }): LatLng; } // ------------------------------------------------------------ @@ -870,6 +872,13 @@ export interface MapboxViewApi { onLowMemory(): Promise; onDestroy(): Promise; + + project(data: LatLng): { + x: number; + y: number; + }; + + projectBack(screenCoordinate: { x: number, y: number }): LatLng; } // ---------------------------------------------------------------------------------------- @@ -1061,6 +1070,9 @@ export abstract class MapboxViewCommonBase extends ContentView implements Mapbox project(data: LatLng) { return this.mapbox && this.mapbox.project(data); } + projectBack(screenCoordinate: { x: number, y: number }): LatLng { + return this.mapbox && this.mapbox.projectBack(screenCoordinate); + } } // ----------------------------------------------------------------- diff --git a/src/ui-mapbox/index.android.ts b/src/ui-mapbox/index.android.ts index 8e6d60e..406e902 100755 --- a/src/ui-mapbox/index.android.ts +++ b/src/ui-mapbox/index.android.ts @@ -3391,4 +3391,12 @@ export class Mapbox extends MapboxCommon implements MapboxApi { const screenLocation = this._mapboxMapInstance.getProjection().toScreenLocation(mapboxPoint); return { x: Utils.layout.toDeviceIndependentPixels(screenLocation.x), y: Utils.layout.toDeviceIndependentPixels(screenLocation.y) }; } + projectBack(screenCoordinate: { x: number, y: number }): LatLng { + const pointf = new android.graphics.PointF(screenCoordinate.x, screenCoordinate.y); + const coordinate = this._mapboxMapInstance.getProjection().fromScreenLocation(pointf); + return { + lat: coordinate.getLatitude(), + lng: coordinate.getLongitude() + } + } } diff --git a/src/ui-mapbox/index.d.ts b/src/ui-mapbox/index.d.ts index dce8922..ac35fca 100644 --- a/src/ui-mapbox/index.d.ts +++ b/src/ui-mapbox/index.d.ts @@ -97,4 +97,5 @@ export declare class Mapbox extends MapboxCommon implements MapboxApi { x: number; y: number; }; -} \ No newline at end of file + projectBack(screenCoordinate: { x: number, y: number }): LatLng; +} diff --git a/src/ui-mapbox/index.ios.ts b/src/ui-mapbox/index.ios.ts index e7769b4..de82922 100755 --- a/src/ui-mapbox/index.ios.ts +++ b/src/ui-mapbox/index.ios.ts @@ -3159,6 +3159,19 @@ export class Mapbox extends MapboxCommon implements MapboxApi { const { x, y } = theMap.convertCoordinateToPointToView({ latitude: data.lat, longitude: data.lng }, theMap); return { x, y }; } + + projectBack(screenCoordinate: { x: number, y: number }): LatLng { + const theMap: MGLMapView = this._mapboxViewInstance; + const cgPoint = { + x: screenCoordinate.x, + y: screenCoordinate.y + } + const coordinate = theMap.convertPointToCoordinateFromView(cgPoint, theMap); + return { + lat: coordinate.latitude, + lng: coordinate.longitude + } + } } const _addObserver = (eventName, callback) => NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(eventName, null, NSOperationQueue.mainQueue, callback);