Skip to content

Commit ddb7c43

Browse files
authored
Merge pull request #69 from benedictstrube/feat-project-back
feat(`projectBack`): added `projectBack` method as inverse method to project
2 parents 20fee40 + 99d0642 commit ddb7c43

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

src/ui-mapbox/common.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,8 @@ export interface MapboxApi {
705705

706706
removeImage(imageId: string, nativeMap?: any): Promise<void>;
707707
project(data: LatLng): { x: number; y: number };
708+
709+
projectBack(point: { x: number, y: number }): LatLng;
708710
}
709711

710712
// ------------------------------------------------------------
@@ -874,6 +876,13 @@ export interface MapboxViewApi {
874876
onLowMemory(): Promise<any>;
875877

876878
onDestroy(): Promise<any>;
879+
880+
project(data: LatLng): {
881+
x: number;
882+
y: number;
883+
};
884+
885+
projectBack(screenCoordinate: { x: number, y: number }): LatLng;
877886
}
878887

879888
// ----------------------------------------------------------------------------------------
@@ -1065,6 +1074,9 @@ export abstract class MapboxViewCommonBase extends ContentView implements Mapbox
10651074
project(data: LatLng) {
10661075
return this.mapbox && this.mapbox.project(data);
10671076
}
1077+
projectBack(screenCoordinate: { x: number, y: number }): LatLng {
1078+
return this.mapbox && this.mapbox.projectBack(screenCoordinate);
1079+
}
10681080
}
10691081

10701082
// -----------------------------------------------------------------

src/ui-mapbox/index.android.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3396,4 +3396,12 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
33963396
const screenLocation = this._mapboxMapInstance.getProjection().toScreenLocation(mapboxPoint);
33973397
return { x: Utils.layout.toDeviceIndependentPixels(screenLocation.x), y: Utils.layout.toDeviceIndependentPixels(screenLocation.y) };
33983398
}
3399+
projectBack(screenCoordinate: { x: number, y: number }): LatLng {
3400+
const pointf = new android.graphics.PointF(screenCoordinate.x, screenCoordinate.y);
3401+
const coordinate = this._mapboxMapInstance.getProjection().fromScreenLocation(pointf);
3402+
return {
3403+
lat: coordinate.getLatitude(),
3404+
lng: coordinate.getLongitude()
3405+
}
3406+
}
33993407
}

src/ui-mapbox/index.d.ts

Lines changed: 2 additions & 1 deletion
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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3161,6 +3161,19 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
31613161
const { x, y } = theMap.convertCoordinateToPointToView({ latitude: data.lat, longitude: data.lng }, theMap);
31623162
return { x, y };
31633163
}
3164+
3165+
projectBack(screenCoordinate: { x: number, y: number }): LatLng {
3166+
const theMap: MGLMapView = this._mapboxViewInstance;
3167+
const cgPoint = {
3168+
x: screenCoordinate.x,
3169+
y: screenCoordinate.y
3170+
}
3171+
const coordinate = theMap.convertPointToCoordinateFromView(cgPoint, theMap);
3172+
return {
3173+
lat: coordinate.latitude,
3174+
lng: coordinate.longitude
3175+
}
3176+
}
31643177
}
31653178

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

0 commit comments

Comments
 (0)