Skip to content

Commit 7bbb6e0

Browse files
feat(projectBack): added projectBack method as inverse method to project
projectBack maps an on screen coordinate to a map coordinate. This is the inverse method to project which maps a map coordinate to an on screen coordinate.
1 parent e6c89b9 commit 7bbb6e0

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/ui-mapbox/common.ts

+5
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,8 @@ export interface MapboxApi {
703703

704704
removeImage(imageId: string, nativeMap?: any): Promise<void>;
705705
project(data: LatLng): { x: number; y: number };
706+
707+
projectBack(point: { x: number, y: number }): LatLng;
706708
}
707709

708710
// ------------------------------------------------------------
@@ -1061,6 +1063,9 @@ export abstract class MapboxViewCommonBase extends ContentView implements Mapbox
10611063
project(data: LatLng) {
10621064
return this.mapbox && this.mapbox.project(data);
10631065
}
1066+
projectBack(screenCoordinate: { x: number, y: number }): LatLng {
1067+
return this.mapbox && this.mapbox.projectBack(screenCoordinate);
1068+
}
10641069
}
10651070

10661071
// -----------------------------------------------------------------

src/ui-mapbox/index.android.ts

+8
Original file line numberDiff line numberDiff line change
@@ -3391,4 +3391,12 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
33913391
const screenLocation = this._mapboxMapInstance.getProjection().toScreenLocation(mapboxPoint);
33923392
return { x: Utils.layout.toDeviceIndependentPixels(screenLocation.x), y: Utils.layout.toDeviceIndependentPixels(screenLocation.y) };
33933393
}
3394+
projectBack(screenCoordinate: { x: number, y: number }): LatLng {
3395+
const pointf = new android.graphics.PointF(screenCoordinate.x, screenCoordinate.y);
3396+
const coordinate = this._mapboxMapInstance.getProjection().fromScreenLocation(pointf);
3397+
return {
3398+
lat: coordinate.getLatitude(),
3399+
lng: coordinate.getLongitude()
3400+
}
3401+
}
33943402
}

src/ui-mapbox/index.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,5 @@ export declare class Mapbox extends MapboxCommon implements MapboxApi {
9797
x: number;
9898
y: number;
9999
};
100-
}
100+
projectBack(screenCoordinate: { x: number, y: number }): LatLng;
101+
}

src/ui-mapbox/index.ios.ts

+13
Original file line numberDiff line numberDiff line change
@@ -3159,6 +3159,19 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
31593159
const { x, y } = theMap.convertCoordinateToPointToView({ latitude: data.lat, longitude: data.lng }, theMap);
31603160
return { x, y };
31613161
}
3162+
3163+
projectBack(screenCoordinate: { x: number, y: number }): LatLng {
3164+
const theMap: MGLMapView = this._mapboxViewInstance;
3165+
const cgPoint = {
3166+
x: screenCoordinate.x,
3167+
y: screenCoordinate.y
3168+
}
3169+
const coordinate = theMap.convertPointToCoordinateFromView(cgPoint, theMap);
3170+
return {
3171+
lat: coordinate.latitude,
3172+
lng: coordinate.longitude
3173+
}
3174+
}
31623175
}
31633176

31643177
const _addObserver = (eventName, callback) => NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(eventName, null, NSOperationQueue.mainQueue, callback);

0 commit comments

Comments
 (0)